|
楼主 |
发表于 2005 年 4 月 5 日 16:09:43
|
显示全部楼层
服务器文件管理程序
忙了几天,没做什么东西出来这!上次知道FSO的一些问题后,专门写了个程序,用来管理服务器上的所有文件,源文件如下,默认的用户名为:admin密码为admin2004,暂时没有提供修改用户名和密码的功能!将此文件上传到服务器后,就可以管理服务器上的所有文件和文件夹了!当然得看服务器给我们什么样的权限了!做了些测试,在万网上也很正常运行,不会出什么问题!在一些安全性不高的服务器上可以说是文件管理系统了!
这几天的工作,主要就是公司的一个小网站的后台程序了,写了几天,没日没夜的!目前也只是初步完成。有时间还是把ISAPI好好的看一下,觉得那太有用了!还有就是数据库,没有数据,程序简直没得任何用!
关于这个程序的使用密码,可以将(char_change(m_user)="bfpms" and char_change(m_pass)="bfpms878=") 删除,这样就不用密码了,管理完了就把文件自己给删除也行!
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>管理员专用文件,非管理员请勿用!否则后果自负......</title>
<style type="text/css">
<!--
body { font-size: 9pt; line-height: 14pt}
td {font-size:12px;line-height: 14pt}
p,li,input,select {font-size:12px;}
.box1 { border: 1px #CCCCCC solid; font-size: 9pt;}
.pc1 { font-size: 9pt; line-height: 13pt}
.p14 { font-size: 14.8px; line-height: 20px}
.box { border: 1px solid; font-size: 9pt; border-color: black #000000}
.unline { border: solid; font-size: 9pt ; border-color: #ffffff black #CCCCCC solid; border-width: 1px 0px 1px 0px}
.s02 {border-left:1 ridge #ffffff;border-top:1 ridge #ffffff;border-bottom:1;border-right:1;border-style:ridge;background-color:#cccccc;font-size:9pt; }
.p9 { font-size: 9pt}
.s9 { font-size: 9pt; line-height: 13pt}
a:visited { color: #0033CC; font-size: 9pt}
a:link { color: #0033CC; font-size: 9pt}
a:hover { font-size: 9pt; color: #FF0000}
-->
</style>
</head>
<body>
<form name="form1" method="post" action="">
<%
m_user=Request.Form("m_user")
m_pass=Request.Form("m_pass")
if not (char_change(m_user)="bfpms" and char_change(m_pass)="bfpms878=") then
%>
<table width="699" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#000099">
<tr align="center" bgcolor="#FFFFFF">
<td colspan="3"> <p><br>
服务器文件管理系统--[管理员登录]<br>
<font color="#FF0000">非管理员请勿登录使用,否则后果自负<br>
<br>
</font></p>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="63"> </td>
<td align="center"> 管理员名:
<input name="m_user" type="text" id="m_user"></td>
<td width="45"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td> </td>
<td align="center">管理密码:
<input name="m_pass" type="password" id="m_pass"></td>
<td> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td> </td>
<td align="center">
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重置"></td>
<td> </td>
</tr>
</table>
<%
else
base_path =Request.ServerVariables("APPL_PHYSICAL_PATH") '网站物理路径
base_file =Request.ServerVariables("ATH_TRANSLATED") '文件物理路径
current_path =Request.Form("m_current_path") '当前目录
m_type =Request.Form("m_type") '当前操作
if current_path="" or current_path=false then
current_path=base_path
end if
' response.Write(base_file)
if m_type="delete_folder" then
m_delete_folder =Request.Form("m_delete_obj")
Set fs = CreateObject("Scripting.FileSystemObject")
if fs.FolderExists(m_delete_folder) then
fs.DeleteFolder m_delete_folder,true
msg_box("文件夹已经删除!请返回后刷新!")
else
msg_box("目标文件夹不存在,无法删除!")
end if
set fs=nothing
end if
if m_type="delete_file" then
m_delete_file=Request.Form("m_delete_obj")
Set fs = CreateObject("Scripting.FileSystemObject")
if fs.FileExists(m_delete_file) then
fs.DeleteFile m_delete_file,true
msg_box("文件已经删除!请返回后刷新!")
else
msg_box("目标文件不存在,无法删除!")
end if
set fs=nothing
end if
if m_type="copy_folder" then
m_from_folder=Request.Form("m_from_obj")
m_to_obj =Request.Form("m_to_obj")
m_corver =Request.Form("m_cover")
if m_to_obj="" then
m_to_obj=base_path
end if
Set fs = CreateObject("Scripting.FileSystemObject")
if not (fs.FolderExists(m_from_folder) and fs.FolderExists(m_to_obj)) then
msg_box("源目录不存在或目录目录不存在,拷贝失败!")
else
if m_corver="yes" then
fs.CopyFolder m_from_folder,m_to_obj,true
msg_box("文件夹拷贝成功!")
else
file_name=right(m_from_folder,len(m_from_folder)-InStr(1,m_from_folder,"\",1))
'response.write(m_to_obj&file_name)
if fs.FolderExists(m_to_obj&file_name) then
msg_box("目标文件夹已经存在,文件夹拷贝失败!")
else
fs.CopyFolder m_from_folder,m_to_obj,true
msg_box("文件夹拷贝成功!")
end if
end if
end if
set fs=nothing
end if
if m_type="copy_file" then
m_from_file =Request.Form("m_from_obj")
m_to_obj =Request.Form("m_to_obj")
m_corver =Request.Form("m_cover")
if m_to_obj="" then
m_to_obj=base_path
end if
Set fs = CreateObject("Scripting.FileSystemObject")
if not (fs.FileExists(m_from_file) and fs.FolderExists(m_to_obj)) then
msg_box("源文件不存在或目录目录不存在,拷贝失败!")
else
if m_corver="yes" then
fs.CopyFile m_from_file,m_to_obj,true
msg_box("文件拷贝成功!")
else
file_name=right(m_from_file,len(m_from_file)-InStr(1,m_from_file,"\",1))
'response.write(m_to_obj&file_name)
if fs.FileExists(m_to_obj&file_name) then
msg_box("目标文件已经存在,文件拷贝失败!")
else
fs.CopyFile m_from_file,m_to_obj,true
msg_box("文件拷贝成功!")
end if
end if
end if
set fs=nothing
end if
if m_type="list_file" or m_type="" then
%>
<br>
<table width="700" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="#9BADDD">
<td colspan="4" align="center" class="p9">服务器文件管理系统
<input name="m_user" type="hidden" id="m_user" value="<%=Request.Form("m_user")%>">
<input name="m_pass" type="hidden" id="m_pass" value="<%=Request.Form("m_pass")%>">
<input name="m_type" type="hidden" id="m_type">
<input name="m_current_path" type="hidden" id="m_current_path">
<input name="m_delete_obj" type="hidden" id="m_delete_obj">
<br>
[非管理员请勿登录使用,否则后果自负]<br>
[<strong style="cursor:hand" onclick="history.go(-1)">-=后退=-</strong>] [<strong style="cursor:hand" onclick="history.go(0)">-=刷新=-</strong>] [<strong style="cursor:hand" onclick="history.go(1)">-=前进=-</strong>]
</td>
</tr>
<tr bgcolor="#f0f0f0">
<td width="78" nowrap class="p9">当前目录: </td>
<td width="346" nowrap class="p9"> <%=current_path%></td>
<td width="66" nowrap class="p9">网站目录: </td>
<td width="189" nowrap class="p9"><b style="cursor:hand" onclick="change_path('<%=replace(base_path,"\","\\")%>')"><%=base_path%></b></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>服务器磁盘:</td>
<td colspan="3" bgcolor="#FFFFFF"> <% call server_disk()%> </td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td colspan=4>
从
<input name="m_from_obj" type="text" size="30">
到
<input name="m_to_obj" type="text" size="30">
<input type="button" name="Submit3" value="Copy File" OnClick="copy_file()">
<input type="button" name="Submit4" value="Copy Folder" OnClick="copy_folder()">
<input name="m_cover" type="checkbox" id="m_cover" value="yes">
覆盖 </td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan=4><table width="680" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="#f0f0f0">
<td width="386" align="center">文件或文件夹</td>
<td width="110" align="center">文件大小</td>
<td width="122" align="center">最后修改日期</td>
<td width="41" align="center"> 删除</td>
</tr>
<%
Set fs = CreateObject("Scripting.FileSystemObject")
if not fs.FolderExists(current_path) then
msg_box("该目录不存在!")
else
set folder=fs.GetFolder(current_path)
set s_folder=folder.SubFolders
for each m_folder in s_folder
%>
<tr bgcolor="#E6F2FF">
<td nowrap><a href="#" onClick="change_path('<%=replace(m_folder.Path,"\","\\")%>')"><%=m_folder.path%></a></td>
<td align="center" nowrap bgcolor="#E6F2FF"> 未知[文件夹]</td>
<td align="center" nowrap bgcolor="#E6F2FF"> <%=m_folder.DateLastModified%></td>
<td align="center" nowrap bgcolor="#E6F2FF"><a href="#" onClick="delete_folder('<%=replace(m_folder.path,"\","\\")%>')">[X]</a></td>
</tr>
<%
next
set s_folder=nothing
set s_file=folder.Files
for each m_file in s_file
%>
<tr bgcolor="#FFFFFF">
<td nowrap><a><%=m_file.path%></a></td>
<td nowrap bgcolor="#FFFFFF"> 文件:<%=m_file.Size%> 字节</td>
<td align="center" nowrap bgcolor="#FFFFFF"> <%=m_file.DateLastModified%></td>
<td align="center" nowrap bgcolor="#FFFFFF"><a href="#" onClick="delete_file('<%=replace(m_file.path,"\","\\")%>')">[X]</a></td>
</tr>
<%
next
set s_file=nothing
end if
%>
</table></td>
</tr>
<tr bgcolor="#9BADDD">
<td height="5" colspan=4></td>
</tr>
</table>
<script language="javascript">
<!--
function delete_file(m_file){
if(confirm("删除文件"+m_file+"吗?")){
form1.m_type.value="delete_file";
form1.m_delete_obj.value=m_file;
form1.submit();
}
}
function delete_folder(m_folder){
if(confirm("删除文件"+m_folder+"吗?")){
form1.m_type.value="delete_folder";
form1.m_delete_obj.value=m_folder;
form1.submit();
}
}
function change_path(m_current_path){
//alert(m_current_path);
form1.m_current_path.value=m_current_path;
form1.m_type.value="list_file"
form1.submit();
}
function copy_file(){
//alert(m_current_path);
m_file=form1.m_from_obj.value;
if (m_file=="") return false;
m_cover=form1.m_cover.value;
if (form1.m_cover.checked){
msg="拷贝并覆盖文件:"+m_file+"吗?"
}else{
msg="拷贝文件:"+m_file+"吗?"
}
if (confirm(msg)){
form1.m_delete_obj.value=m_file;
form1.m_type.value="copy_file";
form1.submit();
}
}
function copy_folder(){
//alert(m_current_path);
m_folder=form1.m_from_obj.value;
if (m_folder=="") return false;
if (form1.m_cover.checked){
msg="拷贝并覆盖文件夹:"+m_folder+"吗?"
}else{
msg="拷贝文件夹:"+m_folder+"吗?"
}
if (confirm(msg)){
form1.m_delete_obj.value=m_folder;
form1.m_type.value="copy_folder";
form1.submit();
}
}
-->
</script>
<%
end if
end if
%>
</form>
</body>
</html>
<%
'一些常用函数
sub server_disk()
Set fs = CreateObject("Scripting.FileSystemObject")
set dc = fs.Drives
For Each d in dc
s = s &" [<b style='cursor:hand' onclick='change_path("&chr(34)&d.DriveLetter&":\\"&chr(34)&")'>"& d.DriveLetter & ":盘</b>] "
Next
response.write s
set dc=nothing
set fs=nothing
end sub 'server_disk()
sub msg_box(m_msg)
Response.Write("<script language='javascript'>"&chr(13))
Response.Write("<!--"&chr(13))
Response.Write("alert('"&m_msg&"');"&chr(13))
Response.Write("history.go(-1);"&chr(13))
Response.Write("-->"&chr(13))
Response.Write("</script>"&chr(13))
end sub 'msg_box(m_msg)
function char_change(m_str)
for i=1 to len(m_str)
s=s+chr(asc(mid(m_str,i,1))+i)
next
char_change=s
end function
%> |
|