1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package goldengate.ftp.core.command.internal;
22
23 import goldengate.common.command.ReplyCode;
24 import goldengate.common.command.exception.Reply500Exception;
25 import goldengate.common.command.exception.Reply501Exception;
26 import goldengate.common.logging.GgInternalLogger;
27 import goldengate.common.logging.GgInternalLoggerFactory;
28 import goldengate.ftp.core.command.AbstractCommand;
29 import goldengate.ftp.core.config.FtpConfiguration;
30 import goldengate.ftp.core.utils.FtpChannelUtils;
31
32 import org.jboss.netty.channel.ChannelFuture;
33 import org.jboss.netty.channel.ChannelFutureListener;
34 import org.jboss.netty.channel.Channels;
35
36
37
38
39
40
41
42 public class INTERNALSHUTDOWN extends AbstractCommand {
43
44
45
46 private static final GgInternalLogger logger = GgInternalLoggerFactory
47 .getLogger(INTERNALSHUTDOWN.class);
48
49
50
51
52
53
54 private class ShutdownChannelFutureListener implements
55 ChannelFutureListener {
56
57 private final FtpConfiguration configuration;
58
59 protected ShutdownChannelFutureListener(FtpConfiguration configuration) {
60 this.configuration = configuration;
61 }
62
63
64
65
66
67
68
69
70 public void operationComplete(ChannelFuture arg0) throws Exception {
71 Channels.close(arg0.getChannel());
72 FtpChannelUtils.teminateServer(configuration);
73
74 }
75
76 }
77
78
79
80
81
82
83 public void exec() throws Reply501Exception, Reply500Exception {
84 if (!getSession().getAuth().isAdmin()) {
85
86 throw new Reply500Exception("Command Not Allowed");
87 }
88 if (!hasArg()) {
89 throw new Reply501Exception("Shutdown Need password");
90 }
91 String password = getArg();
92 if (!getConfiguration().checkPassword(password)) {
93 throw new Reply501Exception("Shutdown Need a correct password");
94 }
95 logger.warn("Shutdown...");
96 getSession().setReplyCode(
97 ReplyCode.REPLY_221_CLOSING_CONTROL_CONNECTION,
98 "System shutdown");
99 getSession().getNetworkHandler().writeIntermediateAnswer().addListener(
100 new ShutdownChannelFutureListener(getConfiguration()));
101 }
102
103 }