?? servletadmin.java
字號:
/*This file is part of Socks via HTTP.This package is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.Socks via HTTP is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with Socks via HTTP; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/// Title : ServletAdmin.java// Version : 0.40// Copyright : Copyright (c) 2001// Author : Florent CUETO (fcueto@wanadoo.fr)// Description : Servlet of administrationpackage socks4;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;public class ServletAdmin extends HttpServlet{ private static final String PROPERTIES_FILE = "socks4.initsrv"; private java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); private java.text.NumberFormat nf = java.text.NumberFormat.getInstance(); private String accessPassword = null; private String servlet_url = null; // init method public void init(ServletConfig config) throws ServletException { super.init(config); nf.setMinimumFractionDigits(2); nf.setMaximumFractionDigits(2); // Get the connection password accessPassword = PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.admin.password"); // Get the url of the servlet servlet_url = PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.admin.servlet.url"); } // get method public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get the remote IP String ip = request.getRemoteAddr(); // Check the password String pass = request.getParameter("pass"); if ((pass == null) || (!pass.equals(accessPassword))) { // Access denied Log.printLog("Warning : Admin refused for IP " + ip + " (bad password)..."); // Set the headers response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); // Build the response response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<body>"); out.println("You need a password to access the administration console."); out.println("</body>"); out.println("</html>"); // Exit return; } // Do the job String sKey = request.getParameter("id_conn"); if (sKey != null) { // Kick the user ExtendedConnection extConn = ServletSocks.table.get(sKey); if (extConn != null) { Log.printLog("Connection " + sKey + " : kicked..."); extConn.conn.disconnect(); ServletSocks.table.remove(sKey); } } // Set the headers response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); // Build the response response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<body>"); out.println("<H1 align=CENTER>" + Const.APPLICATION_NAME + " v" + Const.APPLICATION_VERSION + " Administration</H1>"); out.println("<BR><BR>"); out.println("<FORM name=FormAdmin action=\"" + servlet_url + "\">"); out.println("<TABLE width=95% border=1 align=center>"); out.println("<TR>"); out.println("<TH> </TH>"); out.println("<TH>User</TH>"); out.println("<TH>IP</TH>"); out.println("<TH>Remote IP</TH>"); out.println("<TH>Remote Port</TH>"); out.println("<TH>Date of connection</TH>"); out.println("<TH>Last Access(ms)</TH>"); out.println("<TH>Bytes uploaded</TH>"); out.println("<TH>Bytes downloaded</TH>"); out.println("<TH>Upload speed (KB/s)</TH>"); out.println("<TH>Download speed (KB/s)</TH>"); out.println("</TR>"); if (ServletSocks.table != null) { for (Enumeration e = ServletSocks.table.keys(); e.hasMoreElements(); ) { String key = (String)e.nextElement(); ExtendedConnection extConn = ServletSocks.table.get(key); if (extConn != null) { out.println("<TR>"); out.println("<TD align=center><INPUT type=radio name=id_conn id=id_conn value=" + key + "></TD>"); out.println("<TD align=center>" + extConn.user.login + "</TD>"); out.println("<TD align=center>" + extConn.iprev + " (" + extConn.ip + ")</TD>"); out.println("<TD align=center>" + extConn.destIPrev + " (" + extConn.destIP + ")</TD>"); out.println("<TD align=center>" + extConn.destPort + "</TD>"); out.println("<TD align=center>" + sdf.format(new Date(extConn.creationDate)) + "</TD>"); out.println("<TD align=center>" + (new java.util.Date().getTime() - extConn.lastAccessDate) + "</TD>"); out.println("<TD align=center>" + extConn.uploadedBytes + "</TD>"); out.println("<TD align=center>" + extConn.downloadedBytes + "</TD>"); out.println("<TD align=center>" + nf.format(extConn.currentUploadSpeed) + "</TD>"); out.println("<TD align=center>" + nf.format(extConn.currentDownloadSpeed) + "</TD>"); out.println("</TR>"); } } } out.println("</TABLE>"); out.println("<BR><BR>"); out.println("<INPUT type=hidden name=pass value=\"" + accessPassword + "\">"); out.println("<INPUT type=submit value=\"Kick\">"); out.println("</FORM>"); out.println("</body>"); out.println("</html>"); } // destroy method public void destroy() { }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -