01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify it under the
05: * terms of the GNU General Public License as published by the Free Software
06: * Foundation; either version 2 of the License, or (at your option) any later
07: * version.
08: *
09: * DrFTPD is distributed in the hope that it will be useful, but WITHOUT ANY
10: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11: * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12: *
13: * You should have received a copy of the GNU General Public License along with
14: * DrFTPD; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
15: * Suite 330, Boston, MA 02111-1307 USA
16: */
17: package org.drftpd.sitebot;
18:
19: import java.util.ArrayList;
20: import java.util.StringTokenizer;
21:
22: import org.apache.log4j.Level;
23: import org.apache.log4j.Logger;
24: import org.drftpd.GlobalContext;
25: import org.drftpd.commands.UserManagement;
26: import org.drftpd.plugins.SiteBot;
27: import org.drftpd.usermanager.NoSuchUserException;
28: import org.drftpd.usermanager.User;
29: import org.drftpd.usermanager.UserFileException;
30: import org.tanesha.replacer.ReplacerEnvironment;
31:
32: import f00f.net.irc.martyr.commands.MessageCommand;
33:
34: /**
35: * @author Teflon
36: */
37: public class Ident extends IRCCommand {
38: private static final Logger logger = Logger.getLogger(Ident.class);
39:
40: public Ident(GlobalContext gctx) {
41: super (gctx);
42: }
43:
44: public ArrayList<String> doIdent(String args, MessageCommand msgc) {
45: ArrayList<String> out = new ArrayList<String>();
46: out.add("");
47: ReplacerEnvironment env = new ReplacerEnvironment(
48: SiteBot.GLOBAL_ENV);
49:
50: StringTokenizer st = new StringTokenizer(args);
51: if (st.countTokens() < 2)
52: return out;
53:
54: String username = st.nextToken();
55: String password = st.nextToken();
56:
57: User user;
58: try {
59: user = getGlobalContext().getUserManager().getUserByName(
60: username);
61: } catch (NoSuchUserException e) {
62: logger.log(Level.WARN, username + " " + e.getMessage(), e);
63: return out;
64: } catch (UserFileException e) {
65: logger.log(Level.WARN, "", e);
66: return out;
67: }
68:
69: if (user.checkPassword(password)) {
70: String ident = msgc.getSource().getNick() + "!"
71: + msgc.getSource().getUser() + "@"
72: + msgc.getSource().getHost();
73: user.getKeyedMap()
74: .setObject(UserManagement.IRCIDENT, ident);
75: try {
76: user.commit();
77: logger.info("Set IRC ident to '" + ident + "' for "
78: + user.getName());
79: out.add("Set IRC ident to '" + ident + "' for "
80: + user.getName());
81: } catch (UserFileException e1) {
82: logger.warn("Error saving userfile for "
83: + user.getName(), e1);
84: out.add("Error saving userfile for " + user.getName());
85: }
86: }
87:
88: return out;
89: }
90:
91: }
|