?? quick.jsp
字號:
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.text.*"%>
<%@page import="java.util.*"%>
<%@page import="java.util.zip.*"%>
<%@page import="java.io.*"%>
<%@page import="upload.*"%>
<%@page import="com.paraster.servlet.CheckLogin" %>
<%
String _userARRAY[] = {"ken@paraster.com"};
String _userFOLDER[] = {""};
/**** check Logined ****/
String _userID = "";
String _linkCMD = CheckLogin.hasLogged(request);
if (_linkCMD != null)
response.sendRedirect(_linkCMD);
else
_userID = CheckLogin.getUserID(request);
//check Valid User ID
int _i = 0;
for (_i=0; _i<_userARRAY.length; _i++) {
if (_userID.compareTo(_userARRAY[_i]) == 0)
break;
}
if (_i == _userARRAY.length) {
out.println("access denied.");
return;
}
/**** check END ****/
String pathtxt = _userFOLDER[_i];
%>
<title>ADMIN ID <<< <%=_userID%> >>></title>
<%
ContentFactory cf_upload = null;
ZipOutputStream zipos= null;
/**** Try to get File Upload first ****/
try {
cf_upload = ContentFactory.getContentFactory(request,1024*1024*100);
}
catch (Exception e) {
out.println("Upload error: '" +e.getMessage() + "'");
return;
}
/**** File Processing ****/
try
{
String operation = cf_upload.getParameter("operation").trim();;
pathtxt += cf_upload.getParameter("pathtxt").trim();
/////////////////////////////////////////////////////////////////////////////////////////////////
//Upload File
/////////////////////////////////////////////////////////////////////////////////////////////////
if (operation.compareTo("1")==0) {
out.println("<h4>File Upload result:</h4>");
File tmpFile = new File(pathtxt);
if (!tmpFile.exists()) tmpFile.mkdir();
for (int i=1; i<6; i++) {
FileHolder uploadFile = cf_upload.getFileParameter("file"+i);
if (uploadFile != null) {
String _tmpStr = uploadFile.getFileName();
int _idx = _tmpStr.lastIndexOf("\\");
String filename = pathtxt + "/" + (_idx!=-1?_tmpStr.substring(_idx+1):_tmpStr);
uploadFile.saveTo(filename);
out.println("<small>\""+filename+"\" Saved.</small><br>");
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
//Download File
/////////////////////////////////////////////////////////////////////////////////////////////////
else
if (operation.compareTo("2")==0) {
out.println("<h4>Download result:</h4>");
int BLOCK = 1024*1024;
//Check File Exists
File tmpFile = new File(pathtxt);
if (!tmpFile.exists()) throw new Exception("File or Directory <font color=\"red\">\"" + pathtxt + "\"</font> not exists.");
//Check Directory Empty
if (tmpFile.isDirectory() && tmpFile.listFiles().length == 0) throw new Exception("Empty Directory <font color=\"red\">\"" + pathtxt + "\"</font>.");
//Prepared New Zip File
File zipFile=new File(getServletConfig().getServletContext().getRealPath("/") + "temporary.zip");
if(!zipFile.exists()) zipFile.createNewFile();
zipos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
zipos.setMethod(ZipOutputStream.DEFLATED);
//Write File
if (tmpFile.isFile()) {
BufferedInputStream fin = new BufferedInputStream(new FileInputStream(tmpFile));
zipos.putNextEntry(new ZipEntry( tmpFile.getName() ));
byte[] tmpByte = new byte[BLOCK];
int len = 0;
while ((len=fin.read(tmpByte)) != -1)
zipos.write(tmpByte,0,len);
fin.close();
zipos.closeEntry();
}
//Write Directory
else {
File file = tmpFile;
int path_Pos = tmpFile.getPath().lastIndexOf("/") + 1;
Stack dir1_stack = new Stack();
dir1_stack.push(file);
/**** Compress all File ****/
while (!dir1_stack.isEmpty()) {
File file_List[] = file.listFiles();
for (int i=0;i<file_List.length;i++) {
File tmp_file = file_List[i];
if (tmp_file.isDirectory()) {
dir1_stack.push(file_List[i]);
continue;
}
//Write File Bytes
String tmp_path = tmp_file.getPath().substring(path_Pos);
zipos.putNextEntry(new ZipEntry(tmp_path));
//Read File Bytes
BufferedInputStream fin = new BufferedInputStream(new FileInputStream(tmp_file));
byte[] tmpByte = new byte[BLOCK];
int len = 0;
while ((len=fin.read(tmpByte)) != -1)
zipos.write(tmpByte,0,len);
fin.close();
zipos.closeEntry();
}
file = (File)dir1_stack.pop();
}
zipos.finish();
}
response.sendRedirect("/pipe-eval/temporary.zip");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
//Browse File
/////////////////////////////////////////////////////////////////////////////////////////////////
else
if (operation.compareTo("3")==0) {
//Check Directory Exists
File tmpFile = new File(pathtxt);
if (!tmpFile.exists() || !tmpFile.isDirectory()) throw new IOException("Directory <font color=\"red\">\"" + pathtxt + "\"</font> not exists.");%>
<h4>Browse result: <%=tmpFile.getPath()%></h4>
<script>
function onclick_sub(s)
{
with (document.form1) {
operation.value = "3";
pathtxt.value = pathtext.value + "\\" + s;
window.opener.document.form1.pathtxt.value = pathtxt.value;
submit();
}
return false;
}
function onclick_download(s)
{
with (document.form1) {
operation.value = "2";
pathtxt.value = pathtext.value + "\\" + s;
submit();
}
return false;
}
function onclick_up()
{
with (document.form1) {
operation.value = "3";
var idx = pathtext.value.lastIndexOf("\\");
pathtxt.value = pathtext.value.substring(0,idx);
window.opener.document.form1.pathtxt.value = pathtxt.value;
submit();
}
return false;
}
function onclick_delete(s)
{
if (confirm("Delete \"" + s + "\"?")) {
with (document.form1) {
operation.value = "4";
pathtxt.value = pathtext.value + "\\" + s;
submit();
}
}
return false;
}
function onclick_rename(s)
{
with (document.form1) {
var str = prompt("Rename to:",pathtext.value + "\\" + s);
if (str) {
operation.value = "5";
pathtxt.value = pathtext.value;
orgname.value = s;
descname.value = str;
submit();
}
}
return false;
}
</script>
<form action="quick.jsp" name="form1" method="post" enctype="multipart/form-data">
<input type="hidden" name="operation" value="3">
<input type="hidden" name="pathtxt" value="">
<%
String _relPath = tmpFile.getPath();
if (_relPath.indexOf(_userFOLDER[_i]) != 0)
_relPath = "/";
else
_relPath = _relPath.substring(_userFOLDER[_i].length());
%>
<input type="hidden" name="pathtext" value="<%=_relPath%>">
<input type="hidden" name="orgname" value="">
<input type="hidden" name="descname" value="">
</form>
<table>
<%
//get File & Directory List
Map mapDir = new TreeMap();
Map mapFile = new TreeMap();
File file_List[] = tmpFile.listFiles();
for (int i=0; i<file_List.length; i++) {
if (file_List[i].isDirectory())
mapDir.put(file_List[i].getName(),file_List[i]);
else
mapFile.put(file_List[i].getName(),file_List[i]);
}%>
<b>Directory:</b> <%=mapDir.size()%> <b>File:</b> <%=mapFile.size()%>
<tr>
<td><%=tmpFile.getParent()!=null?"<a href=\"#\" onclick=\"javascript:return onclick_up()\"><font color=\"blue\"><small><b>..\\</a></b></small></font>":""%></td><td> </td><td> </td>
</tr>
<% Iterator itDir = mapDir.keySet().iterator();
Iterator itFile = mapFile.keySet().iterator();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm ");
//Print Directory
while (itDir.hasNext()) {
out.println("<tr>");
Object obj = itDir.next();
tmpFile = (File)mapDir.get(obj);
Date date = new Date(tmpFile.lastModified()); %>
<td nowrap>
<a href="#" onclick="javascript:return onclick_sub('<%=tmpFile.getName()%>')">
<font color="blue"><small><b><%=tmpFile.getName()%></b></small></font></a>
<a href="#" onclick="javascript:return onclick_download('<%=tmpFile.getName()%>')">
<font color="green"><small>DOWN</small></font></a>
<a href="#" onclick="javascript:return onclick_rename('<%=tmpFile.getName()%>')">
<font color="green"><small>REN</small></font></a>
<a href="#" onclick="javascript:return onclick_delete('<%=tmpFile.getName()%>')">
<font color="red"><small>DEL</small></font></a>
</td>
<td nowrap><small><%=formatter.format(date)%></small></td>
<td nowrap align="right"><small><%=tmpFile.length()%></small></td>
</tr>
<% }
//Print File
while (itFile.hasNext()) {
out.println("<tr>");
Object obj = itFile.next();
tmpFile = (File)mapFile.get(obj);
Date date = new Date(tmpFile.lastModified()); %>
<td nowrap>
<a href="#" onclick="javascript:return onclick_download('<%=tmpFile.getName()%>')">
<font color="red"><small><%=tmpFile.getName()%></small></font></a>
<a href="#" onclick="javascript:return onclick_rename('<%=tmpFile.getName()%>')">
<font color="green"><small>REN</small></font></a>
<a href="#" onclick="javascript:return onclick_delete('<%=tmpFile.getName()%>')">
<font color="red"><small>DEL</small></font></a>
</td>
<td nowrap><small><%=formatter.format(date)%></small></td>
<td nowrap align="right"><small><%=tmpFile.length()%></small></td></small>
</tr>
<% }
out.println("</table>");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
//Delete File
/////////////////////////////////////////////////////////////////////////////////////////////////
else
if (operation.compareTo("4")==0) {
//Check Directory Exists
File tmpFile = new File(pathtxt);
if (!tmpFile.exists()) throw new IOException("File or Directory <font color=\"red\">\"" + pathtxt + "\"</font> not exists.");%>
<h4>Delete result:</h4>
<% //Delete File
if (tmpFile.isFile()) { %>
<small>"<%=pathtxt%>" Deleted<%=(tmpFile.delete()?"":" <font color=\"red\">Failed</font>")%>.</small><br>
<% }
//Delete Directory
else {
File file = tmpFile;
Stack dir1_stack = new Stack();
Stack dir2_stack = new Stack();
dir1_stack.push(file);
dir2_stack.push(file);
/**** Delete all File ****/
while (!dir1_stack.isEmpty()) {
File file_List[] = file.listFiles();
for (int i=0;i<file_List.length;i++) {
File tmp_file = file_List[i];
if (tmp_file.isDirectory()) {
dir1_stack.push(file_List[i]);
dir2_stack.push(file_List[i]);
continue;
} %>
<small>"<%=tmp_file.getPath()%>" Deleted<%=(tmp_file.delete()?"":" <font color=\"red\">Failed</font>")%>.</small><br>
<% }
file = (File)dir1_stack.pop();
}
/**** Delete all Directory ****/
while (!dir2_stack.isEmpty()) {
File tmp_dir = (File)dir2_stack.pop(); %>
<small><b>"<%=tmp_dir.getPath()%>"</b> Deleted<%=(tmp_dir.delete()?"":" <font color=\"red\">Failed</font>")%>.</small><br>
<% }
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
//Rename File
/////////////////////////////////////////////////////////////////////////////////////////////////
else
if (operation.compareTo("5")==0) {
String orgname = cf_upload.getParameter("orgname").trim();;
String descname = cf_upload.getParameter("descname").trim();
//Check Directory Exists
File tmpFile = new File(pathtxt + "\\" + orgname);
if (!tmpFile.exists()) throw new IOException("File or Directory <font color=\"red\">\"" + pathtxt + "\"</font> not exists.");
File descFile = new File(descname); %>
<h4>Rename result:</h4>
<small>File "<%=tmpFile.getPath()%>" Renamed to "<%=descFile.getPath()%>" <%=(tmpFile.renameTo(descFile)?"OK":"<font color=\"red\">Failed</font>")%>.</small><br>
<%
}
/////////////////////////////////////////////////////////////////////////////////////////////////
//Execute File
/////////////////////////////////////////////////////////////////////////////////////////////////
else
if (operation.compareTo("6")==0) {
String commandtxt = cf_upload.getParameter("commandtxt").trim();
String commandpara = cf_upload.getParameter("commandpara").trim();
Runtime r = Runtime.getRuntime(); %>
<h4>Execute result:</h4>
Total Memory: <%=r.totalMemory()/(1024.0f*1024.0f)%> MKb<br>
Free Memory: <%=r.freeMemory()/(1024.0f*1024.0f)%> MKb
<% Process p = null;
StringTokenizer st = new StringTokenizer(commandpara,",");
int _paraCount = st.countTokens() + 1;
String cmd[] = new String[_paraCount];
cmd[0] = commandtxt;
if (_paraCount != 0) {
for (int i = 1; i < _paraCount; i++)
cmd[i] = st.nextToken();
}
File ff=new File ("c:\\");
p=r.exec(cmd,null,ff);
}
}
catch(Exception e) {
out.println("<br>"+e.toString());
return;
}
finally {
try {
if (zipos != null) zipos.close();
}
catch(Exception e){}
}
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -