1 7 package org.drftpd.usermanager; 8 9 import java.io.FileInputStream ; 10 import java.lang.reflect.Field ; 11 import java.lang.reflect.Method ; 12 import java.util.Date ; 13 import java.util.Iterator ; 14 import java.util.Properties ; 15 16 import net.sf.drftpd.master.ConnectionManager; 17 import net.sf.drftpd.master.usermanager.AbstractUser; 18 import net.sf.drftpd.slave.SlaveImpl; 19 20 import org.apache.log4j.BasicConfigurator; 21 22 26 public class ResetMonthlyStats { 27 28 public ResetMonthlyStats() { 29 super(); 30 } 31 32 public static void main(String [] args) throws Exception { 33 System.out.println(SlaveImpl.VERSION + " resetmonth starting."); 34 System.out.println("All your sites are belong to mog ^^"); 35 System.out.println("http://drftpd.org/"); 36 BasicConfigurator.configure(); 37 String cfgFileName; 38 if (args.length >= 1) { 39 cfgFileName = args[0]; 40 } else { 41 cfgFileName = "drftpd.conf"; 42 } 43 44 45 Properties cfg = new Properties (); 46 cfg.load(new FileInputStream (cfgFileName)); 47 48 CM cm = new CM(cfg, cfgFileName); 49 cm.getUserManager().getAllUsers(); 50 Method m = 51 AbstractUser.class.getDeclaredMethod( 52 "resetMonth", 53 new Class [] { ConnectionManager.class, Date .class }); 54 m.setAccessible(true); 55 56 Field f = AbstractUser.class.getDeclaredField("lastReset"); 57 f.setAccessible(true); 58 59 for (Iterator iter = cm.getUserManager().getAllUsers().iterator(); 60 iter.hasNext(); 61 ) { 62 AbstractUser user = (AbstractUser) iter.next(); 63 f.setLong(user, System.currentTimeMillis()); 64 m.invoke(user, new Object [] { cm, new Date ()}); 66 user.commit(); 67 } 68 f.setAccessible(false); 69 m.setAccessible(false); 70 } 71 72 public static class CM extends ConnectionManager { 73 public CM(Properties cfg, String cfgFileName) { 74 loadUserManager(cfg, cfgFileName); 75 loadPlugins(cfg); 76 } 77 } 78 } 79 | Popular Tags |