1 6 7 package com.quikj.server.web; 8 9 import java.net.*; 10 import com.quikj.server.framework.*; 11 15 public class AppServerShutdownCommandHandler implements 16 com.quikj.server.framework.AceCommandHandlerInterface 17 { 18 private byte[] selfAddress; 19 private byte[] localHostAddress; 20 21 22 public AppServerShutdownCommandHandler() throws UnknownHostException 23 { 24 selfAddress = InetAddress.getLocalHost().getAddress(); 25 localHostAddress = InetAddress.getByName("127.0.0.1").getAddress(); 26 } 27 28 public void actionPerformed(String command_line, AceCommandSession session) 29 { 30 byte[] from = session.getSocket().getInetAddress().getAddress(); 31 if (compareBytes(from, selfAddress) == false) 32 { 33 if (compareBytes (from, localHostAddress) == false) 34 { 35 session.sendMessage("You are not allowed to issue shutdown command from your terminal\n"); 36 return; 37 } 38 } 39 session.sendMessage("Shutdown Initiated. Your session will be closed, shortly.\n"); 40 41 ShutdownThread thread = new ShutdownThread(true); 42 thread.start(); 43 } 44 45 public String usage() 46 { 47 return "shutdown - command to shutdown the Ace Application Server"; 48 } 49 50 private boolean compareBytes (byte[] b1, byte[] b2) 51 { 52 for (int i = 0; i < b1.length; i++) 53 { 54 if (b1[i] != b2[i]) return false; 55 } 56 57 return true; 58 } 59 } 60 | Popular Tags |