01: /**
02: * Gives out different IP addresses for LOCAL nd REMOTE connections.
03: *
04: * For more information about LOCAL/REMOTE:
05: * @see com.coldcore.coloradoftp.plugin.intellipack.connection.IntelDataConnectionWrapper
06: */package com.coldcore.coloradoftp.plugin.intellipack.command;
07:
08: import com.coldcore.coloradoftp.command.Reply;
09: import com.coldcore.coloradoftp.command.impl.ftp.PasvCommand;
10: import com.coldcore.coloradoftp.plugin.intellipack.util.Util;
11: import org.apache.log4j.Logger;
12:
13: public class IntelPasvCommand extends PasvCommand {
14:
15: private static Logger log = Logger
16: .getLogger(IntelPasvCommand.class);
17: protected String localIpRegexp;
18: protected String localIp;
19: protected String remoteIp;
20:
21: public IntelPasvCommand() {
22: super ();
23: localIpRegexp = "192.168.*";
24: }
25:
26: /** Get regular expression of IP to determine connections from local hosts
27: * @return Regular expression
28: */
29: public String getLocalIpRegexp() {
30: return localIpRegexp;
31: }
32:
33: /** Set regular expression of IP to determine connections from local hosts
34: * @param localIpRegexp Regular expression
35: */
36: public void setLocalIpRegexp(String localIpRegexp) {
37: if (localIpRegexp == null)
38: throw new IllegalArgumentException("Invalid argument");
39: this .localIpRegexp = localIpRegexp;
40: }
41:
42: /** Get IP for LOCAL connections
43: * @return IP address
44: */
45: public String getLocalIp() {
46: return localIp;
47: }
48:
49: /** Set IP for LOCAL connections
50: * @param localIp IP address
51: */
52: public void setLocalIp(String localIp) {
53: this .localIp = localIp;
54: }
55:
56: /** Get IP for REMOTE connections
57: * @return IP address
58: */
59: public String getRemoteIp() {
60: return remoteIp;
61: }
62:
63: /** Set IP for REMOTE connections
64: * @param remoteIp IP address
65: */
66: public void setRemoteIp(String remoteIp) {
67: this .remoteIp = remoteIp;
68: }
69:
70: public Reply execute() {
71: String ip = controlConnection.getSocketChannel().socket()
72: .getInetAddress().getHostAddress();
73: boolean local = Util.checkRegExp(ip, localIpRegexp);
74: log.debug("Local IP? " + local);
75:
76: //Change IP
77: super .ip = local ? localIp : remoteIp;
78:
79: //Continue as normal
80: return super.execute();
81: }
82: }
|