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