01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * DrFTPD is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with DrFTPD; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package org.drftpd.usermanager;
19:
20: import org.apache.log4j.BasicConfigurator;
21:
22: import org.drftpd.master.ConnectionManager;
23: import org.drftpd.slave.Slave;
24:
25: import org.drftpd.tests.DummyGlobalContext;
26:
27: import java.io.FileInputStream;
28:
29: import java.lang.reflect.Field;
30: import java.lang.reflect.Method;
31:
32: import java.util.Date;
33: import java.util.Iterator;
34: import java.util.Properties;
35:
36: /**
37: * @author mog
38: * @version $Id: ResetMonthlyStats.java 806 2004-11-17 22:29:13Z mog $
39: */
40: public class ResetMonthlyStats {
41: public ResetMonthlyStats() {
42: super ();
43: }
44:
45: public static void main(String[] args) throws Exception {
46: System.out.println(Slave.VERSION + " resetmonth starting.");
47: System.out.println("All your sites are belong to mog ^^");
48: System.out.println("http://drftpd.org/");
49: BasicConfigurator.configure();
50:
51: String cfgFileName;
52:
53: if (args.length >= 1) {
54: cfgFileName = args[0];
55: } else {
56: cfgFileName = "drftpd.conf";
57: }
58:
59: /** load master config **/
60: Properties cfg = new Properties();
61: cfg.load(new FileInputStream(cfgFileName));
62:
63: CM cm = new CM(cfg, cfgFileName);
64: cm.getGlobalContext().getUserManager().getAllUsers();
65:
66: Method m = AbstractUser.class.getDeclaredMethod("resetMonth",
67: new Class[] { ConnectionManager.class, Date.class });
68: m.setAccessible(true);
69:
70: Field f = AbstractUser.class.getDeclaredField("lastReset");
71: f.setAccessible(true);
72:
73: for (Iterator iter = cm.getGlobalContext().getUserManager()
74: .getAllUsers().iterator(); iter.hasNext();) {
75: AbstractUser user = (AbstractUser) iter.next();
76: f.setLong(user, System.currentTimeMillis());
77:
78: //user.resetMonth(cm, new Date())
79: m.invoke(user, new Object[] { cm, new Date() });
80: user.commit();
81: }
82:
83: f.setAccessible(false);
84: m.setAccessible(false);
85: }
86:
87: public static class CM extends ConnectionManager {
88: private DummyGlobalContext _gctx;
89:
90: public CM(Properties cfg, String cfgFileName) {
91: _gctx = new DummyGlobalContext();
92: super._gctx = _gctx;
93: _gctx.loadUserManager(cfg, cfgFileName);
94: _gctx.loadPlugins(cfg);
95: }
96: }
97: }
|