VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



The most powerful ASP Web-based file manager

by Anonymous (267 Submissions)
Category: Internet/HTML
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 20th August 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

The most powerful ASP Web-based file manager

Rate The most powerful ASP Web-based file manager



<%
'=============================================================
' The most powerful ASP Web-based file manager
' Jan-Hein (c)2001 - [email protected] - http://www.redir.as
' For general settings: see global.asa
' DISCLAIMER: We can not be held responsible for any damage caused by use of this script.
'=============================================================
Server.ScriptTimeout=300
'Debugging=True '### If set to True: "On error resume next" will be inactive on the page, error msg. will be shown
MaxZipItems=500 '### Maximum number of files in a ZIP file (only when recursing through subfolders, to prevent possible server overload) ###
MaxEditSize=100*1024

Response.buffer=True

'========================
'Main
'========================
If Session("User")="" Then Response.redirect("login.asp")
If NOT Debugging Then On Error resume next
Response.Write "<title>ASP FileMan</title><font face=arial size=2 color=222222>"

Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set oFind = New RegExp
oFind.IgnoreCase = True
Set oForbiddenList = New RegExp
oForbiddenList.IgnoreCase = True

a=Request("a")
Session("LastAction")=Session("ThisAction")
Session("ThisAction")=a
f=BuildPath(Request("f"))
Target=BuildPath(Request("Target"))

If a="" OR a="list" Then '==================== Show dir list
Dir=Request("Dir")
If a="list" Then Dir=Request("History")
If Dir<>"" Then 
Dir=Replace(Dir,"/","\")
If Right(Dir,1)<>"\" Then Dir=Dir & "\"
Dir=StartCapital(BuildPath(Dir))
If Session("UseRecycler") AND Instr(1,dir,Session("RootFolder") & Application("FMRecyclerName"),1)=1 AND NOT Ucase(dir)=UCase(Session("FMRecyclerName")) Then ShowError("This folder does not exist, or access is denied: " & DisplayPath(Dir))
Dir=Replace(Dir,";",",")
If not fso.folderexists(dir) Then ShowError("This folder does not exist, or access is denied: " & DisplayPath(Dir))
Session("Dir")=Startcapital(Dir)
Session("DisplayDir")=DisplayPath(Dir)
AddToHistory Session("DisplayDir")
End If
ShowToolbar Session("Dir")
ListFiles Session("Dir"),""
CloseList
ElseIf a="download" Then
Download f
ElseIf a="showlog" Then
If Session("IsAdmin") Then ShowLog Request("Findstr") 'Else ShowError("Only admins are allowed to view the log file!")
ElseIf a="edit" Then
If NOT Session("IsEditDisabled") Then Edit f
ElseIf a="newfolder" Then
If Session("ManageFolders") Then NewFolder Target
ElseIf a="addcopy" Then
If NOT Session("QuotaExceeded") AND f<>"" Then
Session("Queue")="Copy: " & f
a=Split(f,", ")
Session("NumInQueue")=UBound(a)+1
End If
Response.redirect "fileman.asp"
ElseIf a="addmove" Then
If f<>"" Then
Session("Queue")="Move: " & f
a=Split(f,", ")
Session("NumInQueue")=UBound(a)+1
End If
Response.redirect "fileman.asp"
ElseIf a="paste" Then
f=Session("Queue")
If InStr(f,"Move: ")=1 Then
Session("NumInQueue")=0
MoveItems Mid(f,7), Session("Dir")
ElseIf InStr(f,"Copy: ")=1 Then
Session("NumInQueue")=0
CopyItems Mid(f,7), Session("Dir")
Else
Response.redirect "fileman.asp"
End If
ElseIf a="zip" Then
If NOT Session("QuotaExceeded") AND NOT Session("IsZipDisabled") Then Zip f,Target
ElseIf a="showzip" Then
If NOT Session("IsZipDisabled") Then ShowZip f
ElseIf a="unzip" Then
If NOT Session("QuotaExceeded") AND NOT Session("IsZipDisabled") Then Unzip f, Session("Dir")
ElseIf a="unzipitems" Then
If NOT Session("QuotaExceeded") AND NOT Session("IsZipDisabled") Then UnzipItems Buildpath(Request("zipfile")), Request("fUnzip"), Session("Dir")
ElseIf a="info" Then
ShowInfo
ElseIf a="save" Then
Save Target
ElseIf a="del" Then
If NOT Session("IsDeleteDisabled") Then 
If Session("UseRecycler")=False OR Instr(1,f,Session("FMRecyclerName"),1)>0 Then
Del f
Else
If NOT fso.folderexists(Session("FMRecyclerName")) Then fso.createfolder Session("FMRecyclerName")
MoveItems f, Session("FMRecyclerName")
End If
End If
ElseIf a="rename" Then
Rename f,Request("NewName")
ElseIf a="upload" Then
If NOT Session("QuotaExceeded") AND NOT Session("IsUploadDisabled") Then Upload
ElseIf a="attribs" Then
SetAttribs f, Request("attr")
ElseIf a="find" Then
FindStr=Request("Findstr")
ShowToolbar Session("Dir")
ListFiles Session("Dir"),FindStr
CloseList
Else
Response.Write "Invalid action: " & a
End If
set fso=nothing
Set oFind = Nothing
Set oForbiddenList = Nothing

'========================
SUB ShowLog (findstr)
'========================
If NOT Debugging Then On Error resume next
f=Application("LogFile")
If request("clear")="" Then
 If fso.fileexists(f) Then 
Set tf=fso.getfile(f)
If findstr="" Then Response.Write "<b>FileMan Log</b>" Else Response.Write "<b>Searching for '" & findstr & "' in FileMan log</b>"
Response.Write " - <a href=fileman.asp?a=showlog&clear=true>Clear now (" & SizeString(tf.size) & ")</a>"
Response.Write "<pre><font face=arial size=2>"
Set fr=fso.OpenTextFile(f,1,false)
hits=0
numlines=0
Do While NOT fr.AtEndOfStream
s=fr.readline
If Instr(1,s,findstr,1)>0 Then
Response.write s & vbCrLf
hits=hits+1
End If
numlines=numlines+1
Loop
Response.Write "</pre>"
If findstr="" Then Response.write "<b>"& numlines & " lines</b>" Else Response.write "<b>Found in " & hits & " of " & numlines & " lines</b>"
 Else
Response.Write "<b>Logfile does not exist!</b>"
 End If
Else
Del(f)
End If
End SUB

'========================
SUB ShowZip(f)
'========================
If NOT Debugging Then On Error resume next
Set oZIP = Server.Createobject("aspZip.EasyZIP")
oZip.ZipFileName =Replace(f,";",",")
Cnt=oZip.GetZipItemsCount
Response.clear
%>
<SCRIPT>
function CheckAll(){
for (var i=0;i<document.unzip.elements.length;i++) {
var e=document.unzip.elements[i];
if (e.name !='allbox'){
e.checked=document.unzip.allbox.checked;
}
}
}

function unzipitems(){
if(confirm("Unzip selected items to current folder?")){
document.unzip.action="fileman.asp?a=unzipitems";
document.unzip.submit();
}
}

</SCRIPT>
<%
Response.Write "<FORM Name=unzip Method=post>"
Response.Write "<table cellspacing=2 cellpadding=2>"
Response.Write "<tr><td colspan=3><img src=img/t_zip.gif border=0> <font face=arial size=2 color=000080><b>Contents of " & DisplayPath(f) & "</b></font></td></tr><tr></tr>"
Response.Write "<td align=center bgcolor="& Application("BgColorHeader") & "><font face=arial size=2 color=ffffff><b>Name</b></font></td>"
Response.Write "<td align=center bgcolor="& Application("BgColorHeader") & "><font face=arial size=2 color=ffffff>&nbsp;<b>Date</b></font></td>"
  Response.Write "<td align=center bgcolor="& Application("BgColorHeader") & "><font face=arial size=2 color=ffffff>&nbsp;<b>Size</b></font></td>"
  Response.Write "<td align=center bgcolor="& Application("BgColorHeader") & "><font face=arial size=2 color=ffffff>&nbsp;<b>Compr.</b></font></td>"
For Item = 0 to Cnt-1
Name=oZip.GetZipItem_FileName(item)
us=oZip.GetZipItem_UNCompressedSize(item)
cs=oZip.GetZipItem_CompressedSize(item)
UnzippedSize=UnzippedSize + us
ZippedSize=ZippedSize + cs
Response.Write "<tr>"
Ext=fso.GetExtensionName(Name)
If Ext <>"" AND InStr(1,Application("TypeIcons"),VbTab & Ext & VbTab,1)>0 Then Icon="img/t_" & Ext & ".gif" Else Icon="img/t_unk.gif"
  Response.Write "<td bgcolor="& Application("BgColorFiles") & "><font face=arial size=2><input name=fUnzip type=checkbox color: #FFFFFF value=""" & Replace(Name,",",";") & """><img src=" & Icon & " border=0 Alt='Size: " & us & " bytes'> " & StartCapital(Name) & "&nbsp;</font></td>"
  Response.Write "<td bgcolor="& Application("BgColorFiles") & "><font face=arial size=2>&nbsp;" & oZip.GetZipItem_CDateTime(item) & "&nbsp;</font></td>"
  Response.Write "<td bgcolor="& Application("BgColorFiles") & "><font face=arial size=2>&nbsp;" & SizeString(us) & "&nbsp;</font></td>"
If cs=0 OR us=0 Then t="0" Else t=Round((1-cs/us)*100)
Response.Write "<td bgcolor="& Application("BgColorFiles") & "><font face=arial size=2>&nbsp;" & t & "%&nbsp;</font></td>"
  Response.Write "</tr>" &VbCrLf
Next
If ZippedSize=0 OR UnzippedSize=0 Then t="0" Else t=Round((1-ZippedSize/UnzippedSize)*100) 
Response.write "<tr><td colspan=4 bgcolor="& Application("BgColorHeader") & "><input name=allbox type=checkbox value='Check All' onclick=CheckAll();> <font face=arial size=2 color=ffffff><b>" & Cnt & " files ("& SizeString(UnzippedSize) & "), Compression: " & t & "%</b></font></td></tr><tr></tr>"
Response.Write "</table><br>"
Response.Write "<input type=hidden name=zipfile value='" & displayPath(f) & "'> "
Response.Write "<input type=button value= 'Back' onclick='history.go(-1)';> "
If NOT Session("QuotaExceeded") Then Response.Write "<input type=button value='Unzip' onclick=unzipitems();>"
Response.Write "</form>"
If Application("LogLevel")>1 Then WriteLogLine("View zip " & f & oZip.Error)
Set oZIP = Nothing
End SUB

'========================
SUB GetZipList (Dir,ZipList)
'========================
If NOT Debugging Then On Error resume next
Set ofolder=fso.getfolder(dir)
Set oFolders=oFolder.SubFolders
For each f in oFolders
GetZipList f, ZipList
Next
Set oFiles=oFolder.files
For each f in oFiles
If Session("ZipItems")>MaxZipItems Then Exit Sub
ZipList=ZipList & Replace(f.Path ,",",";") & ", "
Session("ZipItems")=Session("ZipItems")+1
Next
Set oFiles=Nothing
Set ofolder=Nothing
Set oFolders=Nothing
End SUB

'========================
SUB Zip(f,Target)
'========================
If NOT Debugging Then On Error resume next
If UCase(fso.GetExtensionName(Target))<> "ZIP" Then Target=Target & ".zip"
ZipList=""
Session("ZipItems")=0
tArr=Split(f,", ")
For i=0 to Ubound(tArr)
tArr(i)=Replace(tArr(i),";",",")
If Right(tArr(i),1)="\" Then
GetZipList tArr(i), ZipList
Else
ZipList=ZipList & Replace(tArr(i),",",";") & ", "
End If
Next
Set oZIP = Server.Createobject("aspZip.EasyZIP")
oZip.temp=fso.GetSpecialFolder(2)
oZip.ZipFileName = Target
oZip.RootDir=Session("Dir")
oZip.AddOptions = 1 + 8
tArr=Split(ZipList,", ")
For i=0 to Ubound(tArr)
tArr(i)=Replace(tArr(i),";",",")
If NOT IsForbidden(tArr(i)) AND tArr(i)<>"" Then oZip.ArgsAdd(Mid(tArr(i),Len(Session("Dir"))+1))
Next
oZip.Zip
Set oZIP = Nothing
CheckDiskSpace
If err<>0 Then Call ShowError("Zip " & DisplayPath(f) & " to" & DisplayPath(Target)) Else Response.redirect "fileman.asp"
If Application("LogLevel")>1 Then WriteLogLine("Zip " & f & VbTab & Target)
End SUB

'========================
SUB UnZip(f, Target)
'========================
If NOT Debugging Then On Error resume next
Set oZIP = Server.Createobject("aspZip.EasyZIP")
oZip.temp=fso.GetSpecialFolder(2)
If Session("ManageFolders") Then ZipOpt=1+2 Else ZipOpt=2
oZip.ExtrOptions = ZipOpt
oZip.ExtrBaseDir=Target
tArr=Split(f,", ")
For i=0 to Ubound(tArr)
If UCase(fso.GetExtensionName(tArr(i)))="ZIP" Then 
oZip.ZipFileName =Replace(tArr(i),";",",")
Cnt=oZip.GetZipItemsCount
For Item = 0 to Cnt-1
If NOT IsForbidden(Target & oZip.GetZipItem_FileName(item)) Then
n=n+1
oZip.ArgsAdd(oZip.GetZipItem_FileName(item))
End If
Next
If n>0 Then oZip.UnZip ' If no args were added, the whole archive would be unpacked!
If Application("LogLevel")>1 Then WriteLogLine("Unzip " & tArr(i) & VbTab & Target)
End If
Next
Set oZIP = Nothing
CheckDiskSpace
If err<>0 Then Call ShowError("Unzip " & DisplayPath(f) & " to" & DisplayPath(Target)) Else Response.redirect "fileman.asp"
End SUB


'========================
SUB UnZipItems(zipfile, f, Target)
'========================
If NOT Debugging Then On Error resume next
Set oZIP = Server.Createobject("aspZip.EasyZIP")
oZip.temp=fso.GetSpecialFolder(2)
If Session("ManageFolders") Then ZipOpt=1+2 Else ZipOpt=2
oZip.ExtrOptions = ZipOpt
oZip.ExtrBaseDir=Target
oZip.ZipFileName = zipfile
tArr=Split(f,", ")
n=0
For i=0 to Ubound(tArr)
tArr(i)=Replace(tArr(i),";",",")
If NOT IsForbidden(Target & tArr(i)) Then
n=n+1
oZip.ArgsAdd(tArr(i))
End If
Next
If n>0 Then oZip.UnZip ' If no args were added, the whole archive would be unpacked!
Set oZIP = Nothing
CheckDiskSpace
If Application("LogLevel")>1 Then WriteLogLine("Unzip items: " & f & VbTab & zipfile & VbTab & Target)
If err<>0 Then Call ShowError("Unzip from zip " & DisplayPath(zipfile) & " to " & DisplayPath(Target)) Else Response.redirect "fileman.asp"
End SUB


'========================
SUB ShowInfo
'========================
Response.Write "<dir><pre><font face=arial size=2>"
Response.Write "<b>FileMan information</b>" & VbCrLf
Response.Write GetInfo
Response.Write "</pre>"
Response.Write "<form><input type='button' value= 'Back' onclick='history.go(-1)';></form>"
End Sub

'========================
Function GetInfo
'========================
If NOT Debugging Then On Error resume next
If Session("IsAdmin") Then
Set objNet=server.CreateObject("WScript.Network")
If objNet.UserDomain<>"" Then s=s & "NT Domain: " & objNet.UserDomain & VbCrLf
Set objNet=Nothing
s=s & "Host name: " & StartCapital(Request.ServerVariables("SERVER_NAME")) & VbCrLf
s=s & "Server IP: " & Request.ServerVariables("LOCAL_ADDR") & VbCrLf
s=s & "Webserver: " & Request.ServerVariables("SERVER_SOFTWARE") & VbCrLf
s=s & "Script path: " & StartCapital(server.mappath(Request.ServerVariables("PATH_INFO"))) & VbCrLf
s=s & "FileMan version: " & Application("FMVersion") & VbCrLf
s=s & "Active users: " & Application("NumConn") & VbCrLf
s=s & "Accounts in database: " & Application("NumAccounts") & VbCrLf
If Application("MaxAccounts")<>"" Then s=s & "Maximum accounts: " & Application("MaxAccounts") & VbCrLf Else s=s & "Maximum accounts: Unlimited" & VbCrLf 
s=s & VbCrLf
End If
usr=Session("NTUser")
If usr="" Then usr="Anonymous" else usr=usr & " (Authentication: " & Request.ServerVariables("AUTH_TYPE") & ")"
s=s & "NT user: " & usr & VbCrLf
s= s & "FileMan user: " & StartCapital(Session("user")) & VbCrLf
s=s & "Client IP: " & Session("IP") & VbCrLf
s= s & "Login count: " & Session("NumLogins") & VbCrLf
s=s & "Browser: " & Request.ServerVariables("HTTP_USER_AGENT") & VbCrLf
If Session("NumInQueue")>0 Then s=s & "Clipboard: " & Session("NumInQueue") & " items" & VbCrLf
If Session("RootFolder")<>"" Then
If Session("MaxRootFolderSize")>0 Then
Free=Round(100*(1-Session("RootFolderSize")/Session("MaxRootFolderSize")))
s= s & VbCrLf & "Folder size: " & SizeString(Session("RootFolderSize")) & "."
If Free<0 Then
s=s & " Quota of " & SizeString(Session("MaxRootFolderSize")) & " exceeded!" & VbCrLf 
s=s & "Some functionality will remain disabled until you clean up excess files."
s=s & "<table border=0 cellpadding=0 cellspacing=0><tr>"
s=s & "<td width=400 bgcolor=#FF0000>&nbsp;</td>"
s=s & "</tr></table>"
Else
s=s & " (" & Free & "% free, " & SizeString(Session("MaxRootFolderSize")) & " max)"
s=s & "<table border=0 cellpadding=0 cellspacing=0><tr>"
s=s & "<td width=" & 4*(100-Free) & " bgcolor=#FF0000>&nbsp;</td>"
s=s & "<td width=" & 4*Free & " bgcolor=#00DD00>&nbsp;</td>"
s=s & "</tr></table>"
End If
End If
End If
GetInfo=s
End Function

'========================
SUB ShowToolbar(Dir)
'========================
If NOT Debugging Then On Error resume next
%>
 <SCRIPT>
 if (document.layers){
 document.captureEvents(Event.KEYPRESS);
 document.onkeypress=function (evt) {
 var key=document.all ? event.keyCode : evt.which ? evt.which : evt.keyCode;
 if (key==13)
 document.listform.submit();
}
}

function newfolder(){
var folder=prompt("Create new folder in: <%=Replace(Session("DisplayDir"),"\","\\")%>","");
if ((folder!="") && (folder!=null))
{
document.listform.action="fileman.asp?a=newfolder&target="+escape(folder);
document.listform.submit();
}
}

function findit(){
var findstr=prompt("Find files and folders using * and ? wildcards. \nAdd \"/ns\" to skip subfolder search.","");
if ((findstr!="") && (findstr!=null))
{
document.listform.action="fileman.asp?a=find&findstr="+escape(findstr);
document.listform.submit();
}
}

function showlog(){
var findstr=prompt("Find in log (empty=show everything):","");
if (findstr!=null)
{
document.listform.action="fileman.asp?a=showlog&findstr="+escape(findstr);
document.listform.submit();
}
}
function attribs(){
for (var f, msg, n=0, DL=document.listform, i=0; i<DL.elements.length; i++) {if ((DL.elements[i].name.indexOf('f') > -1)) {if (DL.elements[i].checked){n=n+1; }}}
if (n>0) {
var attr=prompt("Change attributes: +/- A(rchive) R(ead only) H(idden) S(ystem)\nExample: -H-S+A","");
if ((attr!="") && (attr!=null))
{
document.listform.action="fileman.asp?a=attribs&attr="+escape(attr);
document.listform.submit();
}}}

function GetFromHistory(){
document.listform.action="fileman.asp?a=list";
document.listform.submit();
}

function zip(){
for (var f, msg, n=0, DL=document.listform, i=0; i<DL.elements.length; i++) {if ((DL.elements[i].name.indexOf('f') > -1)) {if (DL.elements[i].checked){n=n+1; }}}
if (n>0) {
var target=prompt("Enter zip file name:","");
if ((target!="") && (target!=null)) {
document.listform.action="fileman.asp?a=zip&target="+escape(target);
document.listform.submit();
}}}

function unzip(){
for (var f, msg, n=0, DL=document.listform, i=0; i<DL.elements.length; i++) {if ((DL.elements[i].name.indexOf('f') > -1)) {if (DL.elements[i].checked){n=n+1; }}}
if (n>0) {
if(confirm("Unzip selected ZIP files to current folder?")){
document.listform.action="fileman.asp?a=unzip";
document.listform.submit();
}}}

function submitform(action){
for (var f, msg, n=0, DL=document.listform, i=0; i<DL.elements.length; i++) {if ((DL.elements[i].name.indexOf('f') > -1)) {if (DL.elements[i].checked){n=n+1; }}}
if (n>0 || action == "paste") {
document.listform.action="fileman.asp?a="+action;
document.listform.submit();
}}

<% If Session("UseRecycler") AND NOT UCase(Session("Dir"))=UCase(Session("FMRecyclerName")) Then DelMsg="Move selected items to the Recycle bin" Else delMsg="Permanently delete selected items" %>
function del(){
for (var f, msg, n=0, DL=document.listform, i=0; i<DL.elements.length; i++) {if ((DL.elements[i].name.indexOf('f') > -1)) {if (DL.elements[i].checked){n=n+1; }}}
if (n>0) {
if(confirm("<%=DelMsg%>?\nCAUTION: folders will be deleted including all subfolders!")){
document.listform.action="fileman.asp?a=del";
document.listform.submit();
}}}

function rename(){
for (var f, msg, n=0, DL=document.listform, i=0; i<DL.elements.length; i++) {if ((DL.elements[i].name.indexOf('f') > -1)) {if (DL.elements[i].checked){f=DL.elements[i].value.toLowerCase();n=n+1; }}}
if (n>0) {
if (n==1) {
if(f.indexOf("\\")!=-1){ var L=(f.length-1),S;
 while(f.charAt(L)=="\\"){f=f.substring(0,L);L--;}
S=f.split("\\"); f=S[(S.length-1)]; }
msg="Rename item to:";}
else {
f="<%=Session("RenameTemplate")%>";
msg="Rename pattern: FileName=*.*, AutoNum=%n(StartAt), Date=%d, Time=%t\nReplace in name: /r:(Find this,Replace with)";
}
var newname=prompt(msg,f);
if ((newname!="") && (newname!=null)){
document.listform.action="fileman.asp?a=rename&newname="+escape(newname);
document.listform.submit();
}
}
}

function CheckAll(){
for (var i=0;i<document.listform.elements.length;i++) {
var e=document.listform.elements[i];
if (e.name !='allbox'){
e.checked=document.listform.allbox.checked;
}
}
}
</SCRIPT>

<style type="text/css">
a:link {color: #000080 }
a:active {color: #0000FF }
a:visited {color: #000080 }
a:hover { color: #BB0000 }
</style>
<%
Response.Write "<FORM Name=listform Method=post action=fileman.asp>"
Response.Write "<table cellpadding=1 bgcolor=888888><tr bgcolor=EEEEEE>"
Response.Write "<td colspan=3><font face=arial size=2 color=333333>"
If Session("RootFolder")<>"" AND Session("DisplayDir")<>"\" Then Response.Write "<a href='fileman.asp?dir=\'><img src=img/home.gif border=0 Alt='Go to root folder'></a>"
If Session("ShowInputBox") Then Response.Write "<input name=Dir style='font-family: arial; font-size: 11' value='" & Session("DisplayDir") & "' size=25> "
If Session("ShowHistory") AND Session("History")<>"" Then Response.Write "<Select name=history style='font-family: arial; font-size: 11' onChange='GetFromHistory()'>" & Session("History") & "</Select>"
Response.Write "&nbsp;</td>"
Response.Write "<td>"
Response.Write "<a href='javascript:findit()'><img src=img/find.gif border=0 Alt='Find files and folders'></a>"
If Session("ManageFolders") Then Response.Write "<a href='javascript:newfolder()'><img src=img/newfolder.gif border=0 Alt='Create new folder'></a>"
If NOT Session("QuotaExceeded") Then
Response.Write "<a href=fileman.asp?a=edit><img src=img/newfile.gif border=0 Alt='Create new text file'></a>"
If NOT Session("IsUploadDisabled") Then Response.Write "<a href=fileman.asp?a=upload><img src=img/upload.gif border=0 Alt='Upload files'></a>"
End If
Response.Write "</font></td>"
%>

<td>
<% If NOT Session("QuotaExceeded") Then Response.Write "<a href='javascript:submitform(""addcopy"");'><img src=img/copy.gif border=0 Alt='Copy selected items to FM clipboard'></a>" %>
<a href='javascript:submitform("addmove");'><img src=img/move.gif border=0 Alt='Move selected items to FM clipboard'></a>
<% If Session("NumInQueue")>0 Then Response.Write "<a href='javascript:submitform(""paste"");'><img src=img/paste.gif border=0 Alt='Paste " & Session("NumInQueue") & " items from queue'></a>"%>
<a href='javascript:rename();'><img src=img/ren.gif border=0 Alt='Rename selected item(s)'></a>
<%If NOT Session("IsDeleteDisabled") Then Response.Write "<a href='javascript:del();'><img src=img/del.gif border=0 Alt='" & DelMsg & "'></a>"%>
<a href='javascript:attribs();'><img src=img/attribs.gif border=0 Alt='Change attributes of selected items'></a>
<%
If NOT Session("IsZipDisabled") AND NOT Session("QuotaExceeded") Then 
Response.Write "<a href='javascript:zip();'><img src=img/addzip.gif border=0 Alt='Zip selected files'></a>"
Response.Write "<a href='javascript:unzip();'><img src=img/unzip.gif border=0 Alt='Unzip selected zip files to current folder'></a>"
End If
%>

</font></td>
<%
If Session("RootFolder")="" AND Application("ShowDrives") Then
Response.Write "<td><font face=arial size=2>"
Set dc=fso.Drives
For Each d in dc
If d.Isready Then
If d.DriveType=1 Then img="drive_flop.gif"
If d.DriveType=2 Then img="drive_hd.gif"
If d.DriveType=3 Then img="drive_net.gif"
If d.DriveType=4 Then img="drive_cd.gif"
free=Round((d.availablespace/d.TotalSize)*100)
fs=d.FileSystem
vn=d.volumename
If vn="" Then vn="<No name>"
If err=0 Then dInfo=vn & " [" & fs & "]" & vbCrLf & SizeString(d.TotalSize) & " [" & free & "% Free]" else dInfo="Drive inaccessible!"
Response.Write "&nbsp;<a href=fileman.asp?dir=" & d.DriveLetter & ":\><img src=img/" & img & " ALT='" & dInfo & "' border=0> " & d.DriveLetter & ":</a>"
Err.clear
End If
Next
Response.Write "</td>"
End If
Response.Write "<td>"
If Session("UseRecycler") AND NOT Session("IsDeleteDisabled") Then Response.Write "<a href=fileman.asp?dir=" & server.urlencode(DisplayPath(Session("FMRecyclerName"))) & "><img src=img/recycler.gif alt='View Recycle bin' border=0></a>"
Response.Write "<a href=config.asp><img src=img/config.gif alt='Configuration options' border=0></a>"
If Session("IsAdmin") Then
Response.Write "<a href=admin.asp><img src=img/usrmgr.gif alt='Manage FileMan accounts' border=0></a>"
If Application("LogFile")<>"" Then Response.Write "<a href='javascript:showlog()'><img src=img/log.gif alt='View, search or clear FileMan log' border=0></a>"
End If
Response.Write "<a href=fileman.asp?a=info><img src=img/computer.gif border=0 Alt='FileMan user information'></a>"
Response.Write "<a href=http://redir.as/fileman><img src=img/help.gif alt='FileMan homepage' border=0></a>"
Response.Write "</font></td>"

If Application("CustomButtons")<>"" Then
Response.Write "<td><font face=arial size=2>"
Response.Write Application("CustomButtons")
Response.Write "</font></td>"
End If
Response.Write "</tr></table><img src=img/spacer.gif>"
End SUB

'========================
SUB ListFiles(Dir,FindString)
'========================
If NOT Debugging Then On Error resume next
Response.Write "<table cellspacing=2>"
NumCols=UBound(Split(Session("ShowItems")))+2
Response.Write "<tr bgcolor=" & Application("BgColorHeader") & "><td colspan=" & NumCols & ">"
If Instr(1,FindString," /ns",1)>0 Then
Recursive=False
FindString=Replace(FindString," /ns","",1,-1,1)
Else
Recursive=True
End If
If FindString<>"" Then
If Application("LogLevel") >1 Then WriteLogLine "Find " & FindString & " in " & Dir
If Len(FindString)<2 then showError("Please enter a search string with at least 2 characters.")
Response.Write "&nbsp;<a href=fileman.asp><img src=img/prev.gif border=0 Alt='Back'></a> <font face=arial size=2 color=FFFFFF>&nbsp;<b>Found '" & FindString & "' in " & Session("DisplayDir") & "</b></font>"
'*** Build regEx pattern
FindString=Replace(FindString,".","\.")
FindString=Replace(FindString,"^","\^")
FindString=Replace(FindString,"$","\$")
FindString=Replace(FindString,"+","\+")
If InStr(FindString,"*")=0 Then FindString="*" & FindString & "*" 
FindString=Replace(FindString,"*",".*")
FindString=Replace(FindString,"?",".?")
FindString="^" & FindString & "$"
Else
Response.Write "<font face=arial size=2 color=FFFFFF>&nbsp;<b>Index of " & Session("DisplayDir") & "</b></font>"
End If
Response.Write "<font size=4>&nbsp;</font></td></tr>"

If Session("ShowPropertyNames") Then
Response.Write "<tr bgcolor=" & Application("BgColorHeader") & "><td></td>"
If InStr(1,Session("ShowItems"),"fname",1)>0 Then Response.Write "<td align=center><font face=arial size=2 color=FFFFFF><b>Name</b></font></td>"
If InStr(1,Session("ShowItems"),"type",1)>0 Then Response.Write "<td align=center><font face=arial size=2 color=FFFFFF><b>Type</b></font></td>"
If InStr(1,Session("ShowItems"),"size",1)>0 Then Response.Write "<td align=center><font face=arial size=2 color=FFFFFF><b>Size</b></font></td>"
If InStr(1,Session("ShowItems"),"credate",1)>0 Then Response.Write "<td align=center><font face=arial size=2 color=FFFFFF><b>Created</b></font></td>"
If InStr(1,Session("ShowItems"),"moddate",1)>0 Then Response.Write "<td align=center><font face=arial size=2 color=FFFFFF><b>Modified</b></font></td>"
If InStr(1,Session("ShowItems"),"accdate",1)>0 Then Response.Write "<td align=center><font face=arial size=2 color=FFFFFF><b>Accessed</b></font></td>"
If InStr(1,Session("ShowItems"),"shortname",1)>0 Then Response.Write "<td align=center><font face=arial size=2 color=FFFFFF><b>Short name</b></font></td>"
If InStr(1,Session("ShowItems"),"attribs",1)>0 Then Response.Write "<td align=center><font face=arial size=2 color=FFFFFF><b>Attributes</b></font></td>"
Response.Write "</tr>"
End If

If FindString="" AND Len(dir)>3 AND (Len(Dir))>Len(Session("RootFolder")) Then
t=DisplayPath(fso.GetparentFoldername(Dir) & "\")
t=server.urlencode(Replace(t, ":\\",":\"))
Response.Write "<tr bgcolor=" & Application("BgColorFolders") & "><td>"
Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=fileman.asp?dir=" & t & "><img src=img/back.gif border=0 Alt='Parent folder' onMouseOut=""window.status='';return true"" onMouseOver=""window.status='Go to parent folder';return true""></a></td>"
Response.Write "<td>&nbsp;<a href=fileman.asp?dir=" & t & ">.. </a></td>"
For i= 3 to NumCols
Response.Write "<td>&nbsp;</td>"
Next
Response.Write "</tr>"
End If
Page=CInt(Request("page"))
If FindString="" Then
If page=0 OR NOT Session("ListingIsComplete") Then BuildRS Dir,"", False
Else
If Page=0 OR NOT Session("ListingIsComplete") Then BuildRS Dir,FindString, Recursive
End If
Set RS=Session("RS")
RS.Sort="IsFolder desc, " & Session("SortBy") & ", name"
RS.PageSize=Session("ItemsPerPage")
TotalPages=RS.PageCount
TotalItems=RS.recordcount
If Page>TotalPages OR Page<1 Then Page=1
If (Page-1)*Session("ItemsPerPage")<TotalItems Then RS.Move (Page-1)*Session("ItemsPerPage")
While NumItems<Session("ItemsPerPage") AND NOT RS.EOF
NumItems=NumItems+1
Info="Size: " & FormatNumber(RS("Size"),0,0,0,-1) & " Bytes" & VbCrLf & "Short name: " & RS("ShortName") & VbCrLf & "Attribs: " & GetAttr(RS("Attribs")) & VbCrLf & "Created: "& RS("CreDate") & VbCrLf & "Modified: " & RS("ModDate") & VbCrLf & "Accessed: " & RS("AccDate")
encPath=Replace(DisplayPath(RS("Path")),",",";")
encPath=server.urlencode(encPath)
DisplayName=DisplayPath(RS("Path"))

If RS("IsFolder") Then
Response.Write "<tr bgcolor=" & Application("BgColorFolders") & ">"
Response.Write "<td><input name=f type=checkbox color: #FFFFFF value=""" & Replace(DisplayName,",",";") & "\""><a href=fileman.asp?dir=" & encPath & "><img src=img/folder.gif border=0 Alt='" & Info & "'></a></td>"
If InStr(1,Session("ShowItems"),"fname",1)>0 Then
If FindString<>"" Then showname=DisplayName Else showname=StartCapital(RS("Name"))
Response.Write "<td><font face=arial size=2>&nbsp;<a href=fileman.asp?dir=" & encPath & ">" & showname & "</a>&nbsp;</font></td>"
End If
Else
If RS("Type")<>"" AND InStr(1,Application("TypeIcons"),VbTab & RS("Type") & VbTab,1)>0 Then Icon="img/t_" & RS("Type") & ".gif" Else Icon="img/t_unk.gif"
Response.Write "<tr bgcolor=" & Application("BgColorFiles") & ">"
Response.Write "<td><input name=f type=checkbox color: #FFFFFF value=""" & Replace(DisplayName,",",";") & """>"
If RS("Type")="ZIP" AND NOT Session("IsZipDisabled") Then 
Response.Write "<a href=fileman.asp?a=showzip&f=" & encPath & "><img src=" & Icon & " border=0 Alt='" & Info & "'></a></td>"
ElseIf IsEditable(RS("Name")) AND NOT Session("IsEditDisabled") AND RS("Size")<MaxEditSize Then
Response.Write "<a href=fileman.asp?a=edit&f=" & encPath & "><img src=" & Icon & " border=0 Alt='" & Info & "'></a></td>"
Else
Response.Write "<img src=" & Icon & " border=0 Alt='" & Info & "'></td>"
End If
If InStr(1,Session("ShowItems"),"fname",1)>0 Then
If FindString<>"" Then showname=DisplayName Else showname=StartCapital(RS("Name"))
If Application("DownloadInNewWindow") Then t="Target=New" Else t=""
Response.Write "<td><font face=arial size=2>&nbsp;<a " & t & " href=fileman.asp?a=download&f=" & encPath &">" & showname & "</a>&nbsp;</font></td>"
End If
End If
If InStr(1,Session("ShowItems"),"type",1)>0 Then Response.Write "<td><font face=arial size=2>&nbsp;" & RS("Type") & "</font>&nbsp;</td>"
If InStr(1,Session("ShowItems"),"size",1)>0 Then Response.Write "<td><font face=arial size=2>&nbsp;" & SizeString(RS("Size")) & "</font>&nbsp;</td>"
If InStr(1,Session("ShowItems"),"credate",1)>0 Then Response.Write "<td><font face=arial size=2>&nbsp;" & Displaydate(RS("CreDate")) & "&nbsp;</font></td>"
If InStr(1,Session("ShowItems"),"moddate",1)>0 Then Response.Write "<td><font face=arial size=2>&nbsp;" & Displaydate(RS("ModDate")) & "&nbsp;</font></td>"
If InStr(1,Session("ShowItems"),"accdate",1)>0 Then Response.Write "<td><font face=arial size=2>&nbsp;" & Displaydate(RS("accDate")) & "&nbsp;</font></td>"
If InStr(1,Session("ShowItems"),"shortname",1)>0 Then Response.Write "<td><font face=arial size=2>&nbsp;" & StartCapital(RS("ShortName")) & "</font>&nbsp;</td>"
If InStr(1,Session("ShowItems"),"Attribs",1)>0 Then Response.Write "<td><font face=arial size=2>&nbsp;" & GetAttr(RS("Attribs")) & "</font>&nbsp;</td>"
Response.Write "</tr>" & VbCrLf
RS.moveNext
Wend
Response.Write "<tr bgcolor=" & Application("BgColorHeader") & "><td><input name=allbox type=checkbox value='Check All' onclick=CheckAll();></td>"
If Session("GetFolderSize") then t=" (" & SizeString(Session("TotalFolderSize")) & ")" Else t=""
Response.Write "<td colspan=" & NumCols-1 & "><table width='100%'><tr><td><font face=arial size=2 color=FFFFFF>&nbsp;<b>"
Response.Write Session("fCnt") & " Files (" & SizeString(Session("TotalFileSize")) & "), "& Session("dCnt") & " Folders" & t
Response.Write "</b></font></td><td align=right width=130><font face=arial size=2 color=FFFFFF><b>"
If TotalItems>Session("ItemsPerPage") Then
If FindString="" then t="" Else t="&a=find&find=" & server.urlencode(FindString) & "&dir=" & Server.URLEncode(DisplayPath(Session("Dir")))
If page>2 Then Response.Write "<a href=fileman.asp?page=1" & t & "&dir=" & Server.URLEncode(DisplayPath(Session("Dir"))) & "><img src=img/first.gif border=0 Alt='First page'></a> "
If page>1 Then Response.Write "<a href=fileman.asp?page=" & page-1 & t & "&dir=" & Server.URLEncode(DisplayPath(Session("Dir"))) & "><img src=img/prev.gif border=0 Alt='Previous page'></a>"
Response.Write " " & page & "/" &TotalPages & "</b> "
If ((page)*Session("ItemsPerPage"))<TotalItems Then Response.Write "<a href=fileman.asp?page=" & page+1 & t & "&dir=" & Server.URLEncode(DisplayPath(Session("Dir"))) & "><img src=img/Next.gif border=0 Alt='Next page'></a>"
If ((page+1)*Session("ItemsPerPage"))<TotalItems Then Response.Write " <a href=fileman.asp?page=" & TotalPages & t & "&dir=" & Server.URLEncode(DisplayPath(Session("Dir"))) & "><img src=img/last.gif border=0 Alt='Last page'></a>"
End If
Response.Write "</b></font></td></tr></table></td></tr></table>"
End SUB


'========================
SUB Edit(f)
'========================
If NOT Debugging Then On Error resume next
tArr=Split(f,", ")
If Ubound(tArr)>=0 Then f=Replace(tArr(0),";",",") Else f=Replace(f,";",",")
If fso.fileexists(f) Then
Set tf=fso.getfile(f)
  If tf.size>0 Then 
  Set fr=fso.OpenTextFile(f,1,false)
  body=fr.readall
  fr.close
body=Server.HTMLEncode(body)
End If
Set tf=Nothing
End If
Backup=Request.cookies("wfm")("backup")
%>
<form name=editform method=post action=fileman.asp?a=save>
<font color=000080><b>Edit text file</b></font><br>
<font size=1>Note: use upload and download functions for files larger than <%=SizeString(MaxEditSize)%>!</font><br>
<textarea name=body COLS=130 ROWS=28 style='font-family: arial; font-size: 12'><%Response.flush%><%=body%></textarea><br>
<font color=000080><b>Save as</b></font> <input type=text name=target size=40 style='font-family: arial; font-size: 12' value='<%=fso.getFilename(f)%>'>
<input type='button' value='Cancel' onclick='history.go(-1)';> <input type=submit name=a value=' Save '><br>
<input type=checkbox name=backup " & <%=backup%> & "><font size=1 face=arial>Make backup copy</font><br>
</form>
<%
If Application("LogLevel")>0 Then WriteLogLine("Edit file " & f)
If err<>0 Then Call ShowError("Edit file " & DisplayPath(f))
End SUB

'========================
SUB Save(f)
'========================
If NOT Debugging Then On Error resume next
If Request("backup")="on" AND fso.fileexists(f) Then
Response.cookies("wfm")("backup")="checked"
dn=fso.getparentfoldername(f) & "\"
fn=fso.getbasename(f)
en=fso.GetExtensionName(f)
If Instr(fn,"(1)")=Len(fn)-2 then fn=Left(fn,len(fn)-3)
NewName=fn & "(1)." & en
While fso.fileexists(dn & NewName) and n<99
n=n+1
NewName=fn & "(" & n & ")." & en
Wend
fso.copyfile f,dn & NewName,Session("Overwrite")
fso.deletefile f, Session("Overwrite")
Else
Response.cookies("wfm")("backup")=""
End If
If err=0 AND NOT IsForbidden(f) Then
Set fw=fso.OpenTextFile(f,2,True)
fw.writeline Request("body")
fw.close
If Application("LogLevel")>0 Then WriteLogLine("Save file " & f )
Response.redirect "fileman.asp"
Else
If Application("LogLevel")>0 Then WriteLogLine("Error saving file " & f )
ShowError("Error while saving file " & DisplayPath(f))
End If
End SUB

'========================
SUB SetAttribs(f,SetAttr)
'========================
If NOT Debugging Then On Error resume next
SetAttr=Replace(UCase(SetAttr)," ","+")
tArr=Split(f,", ")
For i=0 to Ubound(tArr)
tArr(i)=Replace(tArr(i),";",",")
If Right(tArr(i),1)="\" Then
Set t=fso.getfolder(tArr(i))
  Else
Set t=fso.getfile(tArr(i))
End If
Attr=t.attributes
If Instr(SetAttr,"-A")>0 AND (Attr AND 32) Then Attr=Attr-32
If Instr(SetAttr,"+A")>0 AND NOT (Attr AND 32) Then Attr=Attr+32
If Instr(SetAttr,"-S")>0 AND (Attr AND 4) Then Attr=Attr-4
If Instr(SetAttr,"+S")>0 AND NOT (Attr AND 4) Then Attr=Attr+4
If Instr(SetAttr,"-H")>0 AND (Attr AND 2) Then Attr=Attr-2
If Instr(SetAttr,"+H")>0 AND NOT (Attr AND 2) Then Attr=Attr+2
If Instr(SetAttr,"-R")>0 AND (Attr AND 1) Then Attr=Attr-1
If Instr(SetAttr,"+R")>0 AND NOT (Attr AND 1) Then Attr=Attr+1
t.attributes=Attr
If Application("LogLevel")>0 Then WriteLogLine("Set attributes " & SetAttr & " on " & tArr(i))
Next
If err<>0 Then Call ShowError("Set attributes " & attr & " on " & DisplayPath(f)) Else Response.redirect "fileman.asp"
End SUB

'========================
SUB Download(f)
'========================
If NOT Debugging Then On Error resume next
f=Replace(f,";",",")
If NOT Debugging Then On Error resume next
Set ObjStream=Server.CreateObject("Adodb.stream")
ObjStream.Open
ObjStream.Type=1
ObjStream.LoadFromFile(f)
Response.Clear
Response.ContentType="application/octet-stream"
If Application("AlwaysDownload") Then Response.AddHeader "Content-disposition","attachment;filename=" & fso.getfilename(f) Else Response.AddHeader "Content-disposition","inline;filename=" & fso.getfilename(f)
  If ObjStream.Size>0 Then Response.BinaryWrite ObjStream.read
If Application("LogLevel")>0 Then WriteLogLine("Download " & f & " (" & SizeString(ObjStream.Size) & ")")
ObjStream.Close
Set ObjStream=Nothing
If err<>0 Then Call ShowError("Download " & DisplayPath(f))
End SUB


'========================
SUB Del(f)
'========================
If NOT Debugging Then On Error resume next
tArr=Split(f,", ")
For i=0 to Ubound(tArr)
tArr(i)=Replace(tArr(i),";",",")
If Application("LogLevel")>0 Then WriteLogLine("Delete file " & tArr(i))
If Right(tArr(i),1)="\" Then ' Dir
If Session("ManageFolders") Then
tArr(i)=Left(tArr(i),Len(tArr(i))-1) ' Remove trailing "\"
fso.deleteFolder tArr(i), Session("Overwrite")

Download this snippet    Add to My Saved Code

The most powerful ASP Web-based file manager Comments

No comments have been posted about The most powerful ASP Web-based file manager. Why not be the first to post a comment about The most powerful ASP Web-based file manager.

Post your comment

Subject:
Message:
0/1000 characters