<%@page import="java.net.InetAddress" %> <%@page import="java.net.UnknownHostException" %> <%@page import="java.io.PrintWriter" %> <% String ip = request.getRemoteAddr(); InetAddress localhost = null; InetAddress[] myIPs; boolean isValidIP = false; // Store my ips try { localhost= InetAddress.getLocalHost(); if (localhost != null) { if (ip.equals(localhost.getHostAddress())) isValidIP = true; } } catch (UnknownHostException e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Can't resolve server's localhost."); return; } try { myIPs = InetAddress.getAllByName("localhost"); for(int i = 0; i < myIPs.length; i++) { if (ip.equals(myIPs[i].getHostAddress())) { isValidIP = true; break; } } } catch (UnknownHostException e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Can't resolve server's address."); return; } if (! isValidIP) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The server can't be shutdown from a remote machine."); return; } %> OpenLaszlo Server: Stopped
<% String catalinaHome = System.getProperty("catalina.home"); String os = System.getProperty("os.name"); if (os.startsWith("Windows")) { String[] stop = { catalinaHome + "/bin/shutdown.bat" }; Runtime.getRuntime().exec(stop); } else { // assume Mac/Linux String[] stop = {"/bin/bash", "-c", catalinaHome + "/bin/shutdown.sh"}; Runtime.getRuntime().exec(stop); } %>