Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

xanburzum

[Resolvido] gerenciador de arquivos

Recommended Posts

gerenciador de arquivos, com funções de transferência, criação, remoção, renomeação de arquivos e pastas, visualização de arquivos e das propriedades dos mesmo.

São 3 arquivos:

 

1- default.asp

<%@ Language=VBScript %>
<%Option Explicit%>
<%

	Const appName = "Gerenciador de Arquivos"
	Const appVersion = "2.0"
	
	%><!-- #include file="config.asp" --><%

	Dim FSO, re
	Dim scriptName, wexId
	Dim wexMessage, wexRootPath, targetPath
	Dim encoding, codepage, charset

	InitApp()

	' Actions in the popup windows
	Select Case Request.Form("command")
		Case "Edit"
			Editor()
		Case "View"
			Viewer()
		Case "FileDetails", "FolderDetails"
			Details()
		Case "Upload"
			Upload(false)
	End Select
	

	Select Case Request.Form("command")
		Case "NewFile", "NewFolder"
			CreateItem()
		Case "DeleteFile", "DeleteFolder"
			DeleteItem()
		Case "RenameFile", "RenameFolder"
			RenameItem()
		Case "OpenFolder"
			targetPath = WexMapPath(Request.Form("folder") & Request.Form("parameter"))
		Case "LevelUp"
			targetPath = WexMapPath(FSO.GetParentFolderName(Request.Form("folder")))
		Case "Logout"
			Logout()
	End Select

	List()

	DestroyApp()

' ------------------------------------------------------------

'  Functions -------------------------------


	Sub InitApp()
		scriptName = Request.ServerVariables("SCRIPT_NAME")
		wexId = appName & appVersion & "-"

		Response.Buffer = true
		
		If not Secure() Then 
			If Request.Form("popup")="true" or Request.QueryString("popup")="true" Then PopupRelogin() Else Login()
		End If
		
		Set FSO = server.CreateObject ("Scripting.FileSystemObject")
		Set re = new regexp

		wexRootPath = RealizePath(wexRoot)

		encoding = -2 


		Select Case Request.QueryString("precommand")
			Case "ProcessUpload"
				Upload(true)
			Case "Download"
				Download()
			Case "Encoding"
				If Request.QueryString("value")<>"" Then encoding = Int(Request.QueryString("value"))
				If encoding=-1 Then 'Unicode encoding
					codepage = Session.CodePage
					Session.CodePage = 65001
					Response.CharSet = "UTF-8"
				End If
		End Select
		
		targetPath = WexMapPath(Request.Form("folder"))
	End Sub
	

	Sub DestroyApp()
		If encoding=-1 Then Session.CodePage = codepage
		Set FSO = Nothing
		Set re = Nothing
		Response.End
	End Sub
	

	Sub HtmlHeader(title)
%>
<!--
	<%=appName%> v<%=appVersion%>
	
-->

<html>
<head>
<title><%=title%></title>
<%HtmlStyle%>
<%HtmlJavaScript%>
</head>
<body>
<%	
	End Sub
	

	Sub HtmlFooter()
%>	
</body>
</html>
<%
	End Sub


	Sub HtmlCopyright()
	%>
		<table cellspacing=0 cellpadding=0 border=0 align=center><tr><td>
			<a href="mailto:contact@wexfms.com?subject=WebExplorer Free - Contact" title="Email me for errors, comments or suggestions">Copyright © 2000-2003 by Cem Alacayir</a> - <a target="_blank" href="http://www.wexfms.com" title="Visit the web page for updates and support">Web page</a>
		</td></tr></table>
	<%
	End Sub
	

	Sub HtmlStyle()
%>
<style>
BODY
{
	BACKGROUND-COLOR: #FFFFFF
}
TD
{
	FONT-WEIGHT: normal;
	FONT-SIZE: 10pt;
	COLOR: white;
	FONT-FAMILY: Verdana,Tahoma,Arial,Helvetica
}
.formClass
{
	BACKGROUND-COLOR: #000000;
	FONT-WEIGHT: normal;
	FONT-SIZE: 10pt;
	COLOR: black;
	FONT-FAMILY: Verdana,Tahoma,Arial,Helvetica
}
.lightRow {
	BACKGROUND-COLOR: #FFFFCC
}
.darkRow {
	BACKGROUND-COLOR: #FFFFFF
}
.titleRow {
	BACKGROUND-COLOR: black
}
.loginRow {
	border: black solid 1px;
	BACKGROUND-COLOR: DodgerBlue
}
.boldText
{
	FONT-WEIGHT: bold
}
A
{
	FONT-WEIGHT: normal;
	COLOR: #330000;
	TEXT-DECORATION: none
}
A:hover
{
	COLOR: #CC0000;
	TEXT-DECORATION: none
}
A:visited
{
	TEXT-DECORATION: none
}
A:active
{
	COLOR: #330000;
	TEXT-DECORATION: none
}
</style>
<%
	End Sub
	

	Sub HtmlJavaScript()
%>
<script language=javascript>
	function Command(cmd, param) {
		var str;
		var someWin;
		switch (cmd) {
			case "NewFile":
				str = prompt("Please enter a name for the new file", "New File");
				if(!str) return;
				else if (!CheckName(str)) {alert("File name can not contain any of the\nfollowing characters: \\ / : * ? \" < > |"); return;}
				document.forms.formBuffer.parameter.value = str;
				break;
			case "NewFolder":
				str = prompt("Please enter a name for the new folder", "New Folder");
				if(!str) return;
				else if (!CheckName(str)) {alert("Folder name can not contain any of the\nfollowing characters: \\ / : * ? \" < > |"); return;}
				document.forms.formBuffer.parameter.value = str;
				break;
			case "Edit":
				str = document.forms.formBuffer.folder.value + param;
				someWin = openWin(cmd + str, "", 600, 440, false, false);
				someWin.focus();
				createPage(someWin,cmd,param);
				someWin = null;
				return;
				break;
			case "View":
				str = document.forms.formBuffer.folder.value + param;
				someWin = openWin(cmd + str, "", 600, 440, false, true);
				someWin.focus();
				createPage(someWin,cmd,param);
				someWin = null;
				return;
				break;
			case "FileDetails":
			case "FolderDetails":
				str = document.forms.formBuffer.folder.value + param;
				someWin = openWin(cmd + str, "", 350, 220, false, false);
				someWin.focus();
				createPage(someWin,cmd,param);
				someWin = null;
				return;
				break;
			case "Upload":
				someWin = openWin(cmd, "", 400, 150, true, false);
				someWin.focus(); 
				createPage(someWin,cmd,param);
				someWin = null;
				return;
				break;
			case "DeleteFolder":
				if (!confirm('Are you sure to delete the folder "' + param + '" and all its contents ?')) return;
				document.forms.formBuffer.parameter.value = param;
				break;
			case "DeleteFile":
				if (!confirm('Are you sure to delete "' + param + '" ?')) return;
				document.forms.formBuffer.parameter.value = param;				
				break;
			case "RenameFile":
				str = prompt("Please enter the new name for the file", param);
				if(!str) return;
				else if (!CheckName(str)) {alert("File name can not contain any of the\nfollowing characters: \\ / : * ? \" < > |"); return;}
				document.forms.formBuffer.parameter.value = param + "|" + str;
				break;
			case "RenameFolder":
				str = prompt("Please enter the new name for the folder", param);
				if(!str) return;
				else if (!CheckName(str)) {alert("Folder name can not contain any of the\nfollowing characters: \\ / : * ? \" < > |"); return;}
				document.forms.formBuffer.parameter.value = param + "|" + str;
				break;
			case "NoWebAccess":
				alert("You don't have web access for this folder so\nweb browsing of files/folders will not be available!");
				return;
				break;
			default:
				document.forms.formBuffer.parameter.value = param;
		}
		document.forms.formBuffer.target = "";
		document.forms.formBuffer.command.value = cmd
		document.forms.formBuffer.submit();	
	}
	
	function Check() {
		if (document.forms.formBuffer.pwd.value == "") {
			alert("You haven't entered the password!"); 
			return false;
		} else return true;
	}

	function openWin(winName, urlLoc, w, h, showStatus, isViewer) {
		l = (screen.availWidth - w)/2;
		t = (screen.availHeight - h)/2;
		features  = "toolbar=no";	  // yes|no 
		features += ",location=no";	// yes|no 
		features += ",directories=no"; // yes|no 
		features += ",status=" + (showStatus?"yes":"no");  // yes|no 
		features += ",menubar=no";	 // yes|no 
		features += ",scrollbars=" + (isViewer?"yes":"no");   // auto|yes|no 
		features += ",resizable=" + (isViewer?"yes":"no");   // yes|no 
		features += ",dependent";	  // close the parent, close the popup, omit if you want otherwise 
		features += ",height=" + h;
		features += ",width=" + w;
		features += ",left=" + l;
		features += ",top=" + t;
		winName = winName.replace(/[^a-z]/gi,"_");
		return window.open(urlLoc,winName,features);
	} 
	
	function createPage (theWin, cmd, param){
		document.forms.formBuffer.target = theWin.name;
		document.forms.formBuffer.command.value = cmd;
		document.forms.formBuffer.parameter.value = param;
		document.forms.formBuffer.popup.value = "true";
		document.forms.formBuffer.submit();
		document.forms.formBuffer.popup.value = "false";
	}

	function EditorCommand (cmd) {
		switch (cmd) {
			case "Info":
				alert(document.forms.formBuffer.info.value.replace(/\|/gi,"\n"));
				break;
			case "Reload":
				document.forms.formBuffer.reset();
				break;
			case "Save":
				document.forms.formBuffer.action += "?precommand=Encoding&value=";
				document.forms.formBuffer.action += document.forms.formBuffer.encoding.options[document.forms.formBuffer.encoding.selectedIndex].value;
				document.forms.formBuffer.subcommand.value = "Save";
				document.forms.formBuffer.submit();
				break;
			case "SaveAs":
				var str, oldname;
				oldname = document.forms.formBuffer.parameter.value;
				str = prompt("Save the file as :", oldname);
				if (!str || str==oldname) return;
				document.forms.formBuffer.action += "?precommand=Encoding&value=";
				document.forms.formBuffer.action += document.forms.formBuffer.encoding.options[document.forms.formBuffer.encoding.selectedIndex].value;
				document.forms.formBuffer.parameter.value = str;
				document.forms.formBuffer.subcommand.value = "SaveAs";
				document.forms.formBuffer.submit();
				break;
			case "Encoding":
				document.forms.formBuffer.action += "?precommand=Encoding&value=";
				document.forms.formBuffer.action += document.forms.formBuffer.encoding.options[document.forms.formBuffer.encoding.selectedIndex].value;
				document.forms.formBuffer.subcommand.value = cmd;
				document.forms.formBuffer.submit();
				break;
		}
	}

	function ViewerCommand (cmd) {
		switch (cmd) {
			case "Info":
				alert(document.forms.formBuffer.info.value.replace(/\|/gi,"\n"));
				break;
			case "Reload":
				document.forms.formBuffer.submit();
				break;
		}
	}

	function Upload() {
		document.forms.formBuffer.submit();
	}
	
	function PopupRelogin() {	
		opener.Command('Refresh');
		window.close();
	}
	
	function CheckName(str) {
		var re;
		re = /[\\/:*?"<>|]/gi;
		if (re.test(str)) return false;	
		else return true;
	}	
</script>
<%
	End Sub

	' Writes file listing of the given folder
	Sub List()
		Dim objFolder, virtual, folder
		Dim item, arr
		Dim rowType
		Dim listed

		HtmlHeader appName
		
		on error resume next
		Set objFolder = FSO.GetFolder(targetPath)
		If err.Number<>0 Then wexMessage = "Error opening folder !"
		
		virtual = VirtualPath(targetPath)
		folder = right(targetPath, len(targetPath)-len(wexRootPath))
		
%>
<form name=formGlobal action="noaction" onSubmit="return(false);">
<table cellspacing=0 cellpadding=0 border=0 width=100%>
	<tr class=titleRow>
		<td align=left> <span class=boldText><%=appName%></span> - <a href="http://<%=Request.ServerVariables("SERVER_NAME")%>" target="_blank" title="Browse the web root"><%=Request.ServerVariables("SERVER_NAME")%></a></td>
		<td align=right><span class=boldText>v<%=appVersion%></span> - <%=Date()%> </td>
	</tr>
</table>
<table cellspacing=0 cellpadding=2 border=0 width=100%>
	<tr class=lightRow height=60>
		<td>
			<div style="font-size:12pt;"> <img align=absmiddle border=0 width=32 height=27 src="./images/folder_open_big.png"> <span class=boldText><%=objFolder.Name%></span></div>
			<%If displayPath Then%>
			<div style="font-size:8pt;">  <%=objFolder.path%></div>
			<%End If%>
			<%If virtual<>"" Then%>
				<div style="font-size:8pt;">  (<a href="<%=virtual%>" target="_blank" title="Browse the virtual folder"><%=virtual%></a>)</div>
			<%Else%>
				<div style="font-size:8pt;">  (<a href="java script:Command('NoWebAccess');">no web access</a>)</div>
			<%End If%>
		</td>
		<td nowrap>
			<span class=boldText><%=objFolder.subfolders.count%></span> Pasta(s)<br>
			<span class=boldText><%=objFolder.files.count%></span> Arquivo(s)
		</td>
		<td nowrap>
			Total: <span class=boldText><%If err.Number<>0 or (not calculateTotalSize) Then Response.Write "N/A" Else Response.Write FormatSize(objFolder.size)%></span>
		</td>
		<td colspan=2 align=center>
			<a href="java script:Command('Refresh');"><img align=absmiddle border=0 width=21 height=20 src="./images/refresh.png" alt="Refresh file listing"></a> 
			<a href="java script:Command('NewFile');"><img align=absmiddle border=0 width=21 height=20 src="./images/create_file.png" alt="Create new file"></a> 
			<a href="java script:Command('NewFolder');"><img align=absmiddle border=0 width=21 height=20 src="./images/create_folder.png" alt="Create new folder"></a> 
			<a href="java script:Command('Upload');"><img align=absmiddle border=0 width=21 height=20 src="./images/upload.png" alt="Upload to this folder"></a> 
<%If wexPassword <> "" Then%>
			<a href="java script:Command('Logout');"><img align=absmiddle border=0 width=21 height=20 src="./images/logout.png" alt="Log out from WebExplorer Free"></a>
<%End If%>
			<br><input name=wexMessage type=text class=formClass size=20 value="<%=server.HTMLEncode(wexMessage)%>" readonly>
		</td>
	</tr>
	<tr class=titleRow>
		<td> <span class=boldText>Name</span></td>
		<td> <span class=boldText>Size</span></td>
		<td> <span class=boldText>Type</span></td>
		<td> <span class=boldText>Modified</span></td>
		<td> </td>
	</tr>
<%
	rowType = "darkRow"

	If len(targetPath) > len(wexRootPath) Then
%>
	<tr class=<%=rowType%>><td> <a href="java script:Command('LevelUp');" title="Up One level"><img align=absmiddle border=0 width=15 height=13 src="./images/folder_up.png"></a> <a href="java script:Command('LevelUp');" title="Up One level">..</a></td><td> </td><td> </td><td> </td><td> </td></tr>
<%
		rowType = "lightRow"
	End If
	
	listed = 0
	If (objFolder.subfolders.Count + objFolder.files.Count) = 0 Then

	Else
		For each item in objFolder.subfolders
			If showHiddenItems or not item.Attributes and 2 Then
				listed = listed + 1
%>
	<tr class=<%=rowType%>>
		<td> <%=GetIcon(item.Name, true)%> <a href="java script:Command('OpenFolder',"<%=item.Name%>");" title="Open Folder"><%=item.Name%></a></td>
		<td> <%If calculateFolderSize Then Response.write FormatSize(item.Size)%></td><td> <%=item.Type%></td>
		<td nowrap> <%=item.DateLastModified%></td>
		<td nowrap>
			<%If virtual<>"" Then%>
			<a href="<%=virtual & item.Name%>" target="_blank"><img align=absmiddle border=0 width=11 height=14 src="./images/browse.png" alt="Browse Folder"></a>
			<%End If%>
			<a href="java script:Command('RenameFolder', "<%=item.Name%>");"><img align=absmiddle border=0 width=11 height=14 src="./images/rename.png" alt="Rename Folder"></a>
			<a href="java script:Command('DeleteFolder', "<%=item.Name%>");"><img align=absmiddle border=0 width=14 height=14 src="./images/delete.png" alt="Delete Folder"></a>
		</td>
	</tr>
<%
				If rowType = "darkRow" Then rowType = "lightRow" Else rowType = "darkRow"
			End If
		Next

		For each item in objFolder.files
			If showHiddenItems or not item.Attributes and 2 Then
				listed = listed + 1
%>
	<tr class=<%=rowType%>>
		<td> <%=GetIcon(item.Name, false)%> <a href="<%=scriptName & "?precommand=Download&folder=" & Server.URLEncode(folder) & "&file=" & Server.URLEncode(item.Name)%>" title="Download File"><%=item.Name%></a></td>
		<td> <%=FormatSize(item.Size)%></td><td> <%=item.Type%></td>
		<td nowrap> <%=item.DateLastModified%></td>
		<td nowrap>
			<%If virtual<>"" Then%>
			<a href="<%=virtual & item.Name%>" target="_blank"><img align=absmiddle border=0 width=11 height=14 src="./images/browse.png" alt="Browse File"></a>
			<%End If%>
			<a href="java script:Command('RenameFile', "<%=item.Name%>");"><img align=absmiddle border=0 width=11 height=14 src="./images/rename.png" alt="Rename File"></a>
			<a href="java script:Command('DeleteFile', "<%=item.Name%>");"><img align=absmiddle border=0 width=14 height=14 src="./images/delete.png" alt="Delete File"></a>
		</td>
	</tr>
<%
				If rowType = "darkRow" Then rowType = "lightRow" Else rowType = "darkRow"
			End If	
		Next
	End If
%>
	<tr></tr>
</table>
<table cellspacing=0 cellpadding=0 border=0 width=100%>
	<tr class=titleRow>
		<td> </td>
	</tr>
</table>
</form>
<form method=post action="<%=scriptName%>" name=formBuffer>
	<input type="hidden" name=command value="">
	<input type="hidden" name=parameter value="">
	<input type="hidden" name=virtual value="<%=virtual%>">
	<input type="hidden" name=folder value="<%=folder%>">
	<input type="hidden" name=popup value="false">
</form>
<%
		If wexMessage="" Then 
			If (objFolder.subfolders.Count + objFolder.files.Count) <> listed Then
				wexMessage = "Listed " & listed & " of " & (objFolder.subfolders.Count + objFolder.files.Count) & " item(s) , " & (objFolder.subfolders.Count + objFolder.files.Count - listed) & " item(s) are hidden..."
			Else
				wexMessage = "Listed " & (objFolder.subfolders.Count + objFolder.files.Count) & " item(s)..."
			End If
			Response.Write "<script language=""javascript"">document.forms.formGlobal.wexMessage.value='" & wexMessage & "'</script>"
		End If
		
		Set objFolder = Nothing
		
		HtmlCopyright
		HtmlFooter
	End Sub


	Sub Error(title, message, popup)
		HtmlHeader appName
%>
<table cellpadding=0 cellspacing=0 border=0 align=center width=300>
	<tr class=titleRow>
		<td> <b>An error occured</b></td>
	</tr>
	<tr class=lightRow>
		<td>
			<table cellpadding=0 cellspacing=5 border=0>
				<tr>
					<td valign=top><img width=32 height=32 border=0 align=absmiddle src="./images/error.png"></td>
					<td><b><%=title%>:</b><br><%=message%></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr class=titleRow align=center>
		<td>
			<%If popup Then%>
			<a href="java script:this.close();">Close</a>
			<%Else%>
			<a href="java script:history.back();">Back</a>
			<%End If%>
		</td>
	</tr>
</table>
<%
		HtmlFooter
		DestroyApp()
	End Sub
	

	Sub	Login()
		If Request.Form("command") = "Login" Then
			If Request.Form("pwd") = wexPassword Then
				Session(wexId & "Login") = true
				Exit Sub
			Else
				wexMessage = "Senha errada!"
			End If
		End If
		
		HtmlHeader appName
		If(wexMessage<>"") Then Response.Write "<script language=""javascript"">alert('" & wexMessage & "');</script>"
%>
<form name=formBuffer method=post action="<%=scriptName%>" onSubmit="java script:return(Check());">
<table border=0 cellspacing=0 cellpadding=0 width=400 align=center>
	<tr><td><br><br><br></td></tr>
	<tr><td>
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr class=titleRow>
				<td align=left>
					 <span class=boldText>Login</span>
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr align=center class=lightRow>
				<td>
					<br>
					<span class=boldText>Welcome to <%=appName%> v<%=appVersion%></span>
					<br><br>
					<table cellspacing=0 cellpadding=5 border=0 class=loginRow>
						<tr>
							<td align=left> <span class=boldText>Password</span></td>
						</tr>
						<tr>
							<td align=center><input type="password" class=formClass name=pwd value="" size=21></td>
						</tr>
						<tr>
							<td align=right><input type=submit name=submitter value="Login" class=formClass></td>
						</tr>
					</table>
					<br><br><br>
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr class=titleRow>
				<td align=center> </td>
			</tr>
		</table>
	</td></tr>
</table>
<input type="hidden" name=command value="Login">
</form>
<script language="javascript">document.forms.formBuffer.pwd.focus();</script>
<%	
		HtmlFooter
		DestroyApp() 
	End Sub
	

	Sub PopupRelogin()
		HtmlHeader appName
%>
		<div style="COLOR: white; FONT-FAMILY: Verdana,Tahoma,Arial,Helvetica; FONT-SIZE: 10pt; FONT-WEIGHT: bold;">
		<%=appName%> sessão é destruída, por favor <a href="java script:PopupRelogin();">relogin</a>.
		</div>
<%
		HtmlFooter
		DestroyApp() 
	End Sub


	Function Secure()
		If wexPassword = "" Then
			Secure = true
		Else
			If Session(wexId & "Login") Then Secure = true Else Secure = false
		End If
	End Function
		

	Sub Logout()
		Session.Abandon()
		Login
	End Sub
		

	Function GetIcon(fileName, isFolder)
		Dim ext

		If isFolder Then
			GetIcon = "<a href=""java script:Command('FolderDetails', "" & fileName & "");""><img align=absmiddle border=0 width=15 height=13 src=""./images/folder.png"" alt=""Folder - Clique para saber mais  detalhes""></a>"
		Else
			ext = FSO.GetExtensionName(fileName)
			
			re.IgnoreCase = true
			re.Pattern = "^" & ext & ",|," & ext & ",|," & ext & "$"

			If re.test(editableExtensions) Then
				GetIcon = "<a href=""java script:Command('Edit', "" & fileName & "");""><img align=absmiddle border=0 width=11 height=14 src=""./images/file_editable.png"" alt=""Text file - Clique para editar e  detalhes""></a>"
			ElseIf re.test(viewableExtensions) Then
				GetIcon = "<a href=""java script:Command('View', "" & fileName & "");""><img align=absmiddle border=0 width=11 height=14 src=""./images/file_viewable.png"" alt=""Picture file - Cclique para ver detalhes""></a>"
			Else
				GetIcon = "<a href=""java script:Command('FileDetails', "" & fileName & "");""><img align=absmiddle border=0 width=11 height=14 src=""./images/file.png"" alt=""File - Clique para saber mais detalhes""></a>"
			End If
		End If
	End Function
	
	' Formats given size in bytes,KB,MB and GB
	Function FormatSize(givenSize)
		If (givenSize < 1024) Then
			FormatSize = givenSize & " B"
		ElseIf (givenSize < 1024*1024) Then
			FormatSize = FormatNumber(givenSize/1024,2) & " KB"
		ElseIf (givenSize < 1024*1024*1024) Then
			FormatSize = FormatNumber(givenSize/(1024*1024),2) & " MB"
		Else
			FormatSize = FormatNumber(givenSize/(1024*1024*1024),2) & " GB"
		End If
	End Function


	Function FixPath(path, slash)
		If Right(path, 1) <> slash Then
			FixPath = path & slash
		Else
			FixPath = path
		End If
	End Function


	Function RealizePath(path)
		Dim fpath
		fpath = replace(path,"/","\")
		If left(fpath,1) = "\" Then 'Virtual path
			on error resume next
			RealizePath = server.MapPath(fpath)
			If err.Number<>0 Then RealizePath = fpath '
		Else 'Physical Path
			RealizePath = fpath
		End If
		RealizePath = FixPath(RealizePath, "\")
	End Function	


	Function VirtualPath(path)
		Dim webRoot, fpath
		webRoot = FixPath(server.MapPath("/"),"\")
		fpath = FixPath(path,"\")
		VirtualPath = ""
		If left(wexRoot,1) = "/" Then
			VirtualPath = FixPath(wexRoot, "/")
			VirtualPath = VirtualPath & right(fpath, len(fpath) - len(wexRootPath))
			VirtualPath = replace(VirtualPath, "\", "/")
			VirtualPath = FixPath(VirtualPath,"/")
		ElseIf left(lcase(fpath), len(webRoot)) = lcase(webRoot) Then
			VirtualPath = "/" & right(fpath, len(fpath) - len(webRoot))
			VirtualPath = replace(VirtualPath, "\", "/")
			VirtualPath = FixPath(VirtualPath,"/")
		End If
	End Function


	Function WexMapPath(path)
		If SecurePath(path) Then WexMapPath = FixPath(wexRootPath & path, "\") Else Error "Security Error", "Caminho relativo sintaxe é proibido por razões de segurança.", false
	End Function
		

	Function SecurePath(path)
		Dim fpath
		fpath = replace(path,"/","\")
		
		If fpath="." Then fpath=".\"

		re.IgnoreCase = false
		re.Pattern = "^\.\.$|^\.\.\\|\\\.\.\\|\\\.\.$"
		re.Pattern = re.Pattern & "|^\.\\|\\\.\\|\\\.$"
		
		If re.Test(fpath) Then SecurePath=false Else SecurePath=true
	End Function
	

	Function SecureFileName(name)
		SecureFileName = replace(name,"/","?")
		SecureFileName = replace(SecureFileName,"\","?")
	End Function


	Function CreateItem()
		Dim itemType, itemName, itemPath
		itemType = Request.Form("command")
		itemName = SecureFileName(Request.Form("parameter"))
		itemPath = targetPath & itemName

		on error resume next
		
		Select Case itemType
			Case "NewFolder"
				If FSO.FolderExists(itemPath) = false and FSO.FileExists(itemPath) = false Then 
					FSO.CreateFolder(itemPath)
					If err.Number <> 0 Then 
						wexMessage = "Não foi possível criar a pasta""" & itemName & """, um erro ocorreu..." 
					Else
						wexMessage = "Criada a pasta """ & itemName & """..."
					End If
				Else
					wexMessage = "Não foi possível criar a pasta """ & itemName & """, existe um arquivo ou uma pasta com o mesmo nome..."
				End If
			Case "NewFile"
				If FSO.FolderExists(itemPath) = false and FSO.FileExists(itemPath) = false Then 
					FSO.CreateTextFile(itemPath)
					If err.Number <> 0 Then 
						wexMessage = "Não foi possível criar o arquivo """ & itemName & """, um erro ocorreu..."
					Else
						wexMessage = "Criada o arquivo """ & itemName & """..."
					End If
				Else 
					wexMessage = "Não foi possível criar o arquivo """ & itemName & """, existe um arquivo ou uma pasta com o mesmo nome..."
				End IF
		End Select
	End Function
	

	Function DeleteItem()
		Dim itemType, itemName, itemPath
		itemType = Request.Form("command")
		itemName = SecureFileName(Request.Form("parameter"))
		itemPath = targetPath & itemName

		on error resume next
		
		Select Case itemType
			Case "DeleteFolder"
				FSO.DeleteFolder itemPath, true
				If err.Number <> 0 Then 
					wexMessage = "Não foi possível excluir a pasta """ & itemName & """, um erro ocorreu..." 
				Else
					wexMessage = "Eliminado da pasta """ & itemName & """..."
				End If
			Case "DeleteFile"
				FSO.DeleteFile itemPath, true
				If err.Number <> 0 Then 
					wexMessage = "Não foi possível excluir o arquivo """ & itemName & """, um erro ocorreu..." 
				Else
					wexMessage = "Eliminado o arquivo """ & itemName & """..."
				End If
		End Select
	End Function


	Function RenameItem()
		Dim item, itemType, itemName, itemPath
		Dim param, newName
		itemType = Request.Form("command")
		param = split(Request.Form("parameter"), "|")
		itemName = SecureFileName(param(0))
		newName = SecureFileName(param(1))
		itemPath = targetPath & newName

		on error resume next
		
		Select Case itemType
			Case "RenameFolder"
				If FSO.FolderExists(itemPath) = false and FSO.FileExists(itemPath) = false Then 
					itemPath = targetPath & itemName
					Set item = FSO.GetFolder(itemPath)
					item.Name = newName
					If err.Number <> 0 Then 
						wexMessage = "Não é possível mudar o nome da pasta """ & itemName & """, um erro ocorreu..." 
					Else
						wexMessage = "Renomeada a pasta""" & itemName & """ para """ & newName & """..."
					End If
				Else
					wexMessage = "Não é possível mudar o nome da pasta """ & itemName & """, existe um arquivo ou uma pasta com o nome novo""" & newName & """..."
				End If
			Case "RenameFile"
				If FSO.FolderExists(itemPath) = false and FSO.FileExists(itemPath) = false Then 
					itemPath = targetPath & itemName
					Set item = FSO.GetFile(itemPath)
					item.Name = newName
					If err.Number <> 0 Then 
						wexMessage = "Não foi possível renomear o arquivo """ & itemName & """, um erro ocorreu..." 
					Else
						wexMessage = "Renomeado o arquivo """ & itemName & """ para """ & newName & """..."
					End If
				Else
					wexMessage = "Não é possível mudar o nome do arquivo """ & itemName & """, xiste um arquivo ou uma pasta com o nome novo""" & newName & """..."
				End If
		End Select
		
		Set item = Nothing
	End Function
		

	Sub Editor()
		Dim fileName, filePath, file
		
		on error resume next

		Select Case Request.Form("subcommand")
			Case "Save", "SaveAs"
				fileName = SecureFileName(Request.Form("parameter"))
				filePath = targetPath & fileName
				Set file = FSO.OpenTextFile (filePath, 2, true, encoding)
				If (err.Number<>0) Then 
					wexMessage = "Não é possível gravar no arquivo """ & fileName & """, permissão negada!"
					err.Clear
				Else
					file.write Request.Form("content")
				End If
				Set file = Nothing
				Set file = FSO.OpenTextFile (filePath, 1, false, encoding)
			Case Else
				fileName = SecureFileName(Request.Form("parameter"))
				filePath = targetPath & fileName
				
				If not FSO.FileExists(filePath) Then
					wexMessage = "The file """ & fileName & """ não existe"
					Set file = FSO.CreateTextFile (filePath, false)
					If err.Number<>0 Then 
						wexMessage = wexMessage & ", igualmente incapaz de criar novos arquivos."
						err.Clear 
					Else
						wexMessage = wexMessage & ", Criar novo arquivo."
					End If
				Else
					Set file = FSO.OpenTextFile (filePath, 1, false, encoding)
					If err.Number<>0 Then 
						wexMessage = "Não é possível ler a partir do arquivo """ & fileName & """, permissão negada!"
						err.Clear 
					End If
				End If
		End Select

		HtmlHeader appName
		If(wexMessage<>"") Then Response.Write "<script language=""javascript"">alert('" & wexMessage & "');</script>"
%>
<form name=formBuffer method=post action="<%=scriptName%>">
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr class=titleRow>
				<td align=left>
					 <span class=boldText>Editing</span> - <%=fileName%>
				</td>
				<td align=right>
					<b>Encoding:</b>
					<select name=encoding class=formClass onChange="EditorCommand('Encoding')">
						<option value="-2"<%If encoding=-2 Then Response.Write " selected"%>>Default</option>
						<option value="-1"<%If encoding=-1 Then Response.Write " selected"%>>Unicode</option>
					</select>
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=100% height=90%>
			<tr align=center class=lightRow>
				<td valign=middle>
<textarea name=content class=formClass rows=22 cols=46 style="width:580; height:370;" wrap="off">
<%=Server.HTMLEncode(file.ReadAll)%></textarea>
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr class=titleRow>
				<td align=center>					
					<a href="java script:EditorCommand('Save');">Save</a> | <a href="java script:EditorCommand('SaveAs');">Save As</a> | <a href="java script:EditorCommand('Reload');">Reload</a> | <a href="java script:EditorCommand('Info');">Info</a> | <a href="java script:this.close();">Close</a>
				</td>
			</tr>
		</table>
<%
		Set file = Nothing
		Set file = FSO.GetFile (filePath)
%>
<input type="hidden" name=command value="Edit">
<input type="hidden" name=subcommand value="">
<input type="hidden" name=parameter value="<%=fileName%>">
<input type="hidden" name=folder value="<%=Request.Form("folder")%>">
<input type="hidden" name=info value="Size: <%=FormatSize(file.Size)%>|Type: <%=file.Type%>|Created: <%=file.DateCreated%>|Last Accessed: <%=file.DateLastAccessed%>|Last Modified: <%=file.DateLastModified%>">
<input type="hidden" name=popup value="true">
</form>
<%
		Set file = Nothing

		HtmlFooter
		DestroyApp() 
	End Sub


	Sub Viewer()
		Dim filePath, file

		filePath = targetPath & Request.Form("parameter")
		If not FSO.FileExists(filePath) Then Error "Erro Viewer", "Arquivo não encontrado. Atualize a lista para ver se o arquivo realmente existe.", true
		
		on error resume next
		Set file = FSO.GetFile(filePath)

		HtmlHeader appName
%>
<form name=formBuffer method=post action="<%=scriptName%>">
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr class=titleRow>
				<td align=left>
					 <span class=boldText>Viewing</span> - <%=file.Name%>
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=100% height=90%>
			<tr align=center class=lightRow>
				<td valign=middle>
					<img src="<%=scriptName & "?precommand=Download&folder=" & Server.URLEncode(Request.Form("folder")) & "&file=" & Server.URLEncode(file.Name)%>">
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr class=titleRow>
				<td align=center>					
					<a href="java script:ViewerCommand('Reload');">Reload</a> | <a href="java script:ViewerCommand('Info');">Info</a> | <a href="java script:this.close();">Close</a>
				</td>
			</tr>
		</table>
<input type="hidden" name=command value="View">
<input type="hidden" name=subcommand value="Refresh">
<input type="hidden" name=parameter value="<%=file.Name%>">
<input type="hidden" name=folder value="<%=Request.Form("folder")%>">
<input type="hidden" name=info value="Size: <%=FormatSize(file.Size)%>|Type: <%=file.Type%>|Created: <%=file.DateCreated%>|Last Accessed: <%=file.DateLastAccessed%>|Last Modified: <%=file.DateLastModified%>">
<input type="hidden" name=popup value="true">
</form>
<%
		Set file = Nothing
		HtmlFooter
		DestroyApp() 
	End Sub

	' File/Folder Details
	Sub Details()
		Dim fileName, filePath, file
		
		on error resume next
		fileName = Request.Form("parameter")
		filePath = targetPath & fileName

		HtmlHeader appName
%>
<form name=formBuffer method=post action="<%=scriptName%>">
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr class=titleRow>
				<td align=left>
					 <span class=boldText>Details</span> - <%=fileName%>
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=100% height=80%>
			<tr align=center class=lightRow>
				<td valign=middle>
<%
		If Request.Form("command") = "FileDetails" Then
				Set file = FSO.GetFile (filePath)
		Else
				Set file = FSO.GetFolder (filePath)
		End If
%>
				<table border=0 cellspacing=5 cellpadding=0>
					<tr><td><span class=boldText>Size:</span></td><td><%=FormatSize(file.Size)%></td></tr>
					<tr><td><span class=boldText>Type:</span></td><td><%=file.Type%></td></tr>
					<tr><td><span class=boldText>Created:</span></td><td><%=file.DateCreated%></td></tr>
					<tr><td><span class=boldText>Last Accessed:</span></td><td><%=file.DateLastAccessed%></td></tr>
					<tr><td><span class=boldText>Last Modified:</span></td><td><%=file.DateLastModified%></td></tr>
				</table>
<%
		Set file = Nothing
%>
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr class=titleRow>
				<td align=center>					
					<a href="java script:this.close();">Close</a>
				</td>
			</tr>
		</table>
<input type="hidden" name=command value="<%=Request.Form("command")%>">
<input type="hidden" name=parameter value="<%=fileName%>">
<input type="hidden" name=folder value="<%=Request.Form("folder")%>">
<input type="hidden" name=popup value="true">
</form>
<%
		HtmlFooter
		DestroyApp() 
	End Sub
	
	' Uploads  file
	Sub Upload(process)
		Dim fileTransfer, result

		on error resume next
		Set fileTransfer = New pluginFileTransfer
		If err.number<>0 Then Error "File Transfer Plugin Erro", "Plugin não pode ser inicializado. Por favor, certifique-se que os elementos exigidos pelo plugin é instalado no server.", true

		If process Then targetPath = WexMapPath(Request.QueryString("folder"))
		
		HtmlHeader appName
%>
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr class=titleRow>
				<td align=left>
					 <span class=boldText>Upload</span> - <%=FSO.GetBaseName(targetPath)%>
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=100% height=80%>
			<tr align=center class=lightRow>
				<td valign=middle>
					<span class=boldText>
<%
		' Actual upload process
		If process Then
			fileTransfer.path = targetPath
			
			result = fileTransfer.Upload()
			
			Select Case result
				Case 0
					Response.Write fileTransfer.uploadedFileName & " é carregado<br>"
					Response.Write FormatSize(fileTransfer.uploadedFileSize) & " (" & fileTransfer.uploadedFileSize & " bytes) written<br>"
					Response.Write "Tipo de conteúdo: " & fileTransfer.contentType
					Response.Write "<script language=""javascript"">opener.Command('Refresh');</script>"
				Case 1
					Response.Write "Nenhum arquivo foi enviado"
				Case 2
					Response.Write "Caminho não encontrado"
				Case 3
					Response.Write fileTransfer.uploadedFileName & " não pode ser escrito"
			End Select
%>
					</span>
					<form name=formBuffer method=post action="<%=scriptName%>">
						<input type=hidden name=command value="Upload">
						<input type=hidden name=folder value="<%=Request.QueryString("folder")%>">
					</form>
<%	
		Else
%>
					<form enctype="multipart/form-data" name=formBuffer method=post action="<%=scriptName%>?precommand=ProcessUpload&folder=<%=server.URLEncode(Request.Form("folder"))%>&popup=true">
						<input type=file name=file class=formClass>
					</form>
<%
		End If
%>					
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=100%>
			<tr class=titleRow>
				<td align=center>					
					<a href="java script:Upload();">Upload</a> | <a href="java script:this.close();">Fechar</a>
				</td>
			</tr>
		</table>
<%
		Set fileTransfer = Nothing

		HtmlFooter
		DestroyApp() 
	End Sub
	
	' Downloads a file
	Sub Download()
		Dim fileTransfer, result
		
		on error resume next
		Set fileTransfer = New pluginFileTransfer
		If err.number<>0 Then Error "File Transfer Plugin Erro", "Plugin não pode ser inicializado. Por favor, certifique-se que os elementos exigidos pelo plugin é instalado no server.", false
		
		fileTransfer.path = WexMapPath(Request.QueryString("folder"))
		
		result = fileTransfer.Download(Request.QueryString("file"))
		
		Select Case result
			Case 0
				'Success
			Case 1
				Error "Erro de download", "Arquivo não encontrado. Atualize a lista para ver se o arquivo realmente existe.", false
			Case 2
				Error "Erro de download", "Arquivo não pode ser lido. Por favor, certifique-se de que você tem permissão de ler o arquivo.", false
		End Select
		
		Set fileTransfer = Nothing

		DestroyApp() 
	End Sub
%>

2- config.asp

<%

' - Constants ------------------------------------------------
	
	Const wexPassword = "admin"

	Const wexRoot = "/"

	Const showHiddenItems = true
	
	Const calculateTotalSize = true

	Const calculateFolderSize = true
	
	Const editableExtensions = "htm,html,asp,asa,txt,inc,css,aspx,js,vbs,shtm,shtml,xml,xsl,log"
	
	Const viewableExtensions = "gif,jpg,jpeg,png,bmp,jpe"

	Const displayPath = true

	Response.CharSet = "ISO-8859-1"
	
	Session.CodePage = 1252
	
	Session.LCID = 1046


' - Plugins --------------------------------------------------
	%><!-- #include file="./plugins/file transfer/WexGeneric.asp" --><%
' ------------------------------------------------------------

%>

3- Plugin WexGeneric.asp

<%

	Class pluginFileTransfer
		Public path
		Public uploadedFileName, uploadedFileSize
		Public contentType
		

		Private Sub Class_Initialize()

			Set stream = Server.CreateObject("ADODB.Stream")
		End Sub
		

		Private Sub Class_Terminate()

			Set stream = Nothing
		End Sub
	
		
		Public Function Upload()
			Dim file

			stream.Type = 1
			stream.Open
			
			ParsePost()
			
			If uploadedFileSize<=0 Then
				Upload = 1
			ElseIf not FSO.FolderExists(path) Then 
				Upload = 2
			Else
				on error resume next

				stream.SaveToFile FSO.BuildPath(path, uploadedFileName), 2
				
				If err.Number<>0 Then
					Upload = 3
				Else
					Upload = 0
				End If
			End If
			
			stream.Close
		End Function
		

		Public Function Download(fileName)
			Dim filePath
			filePath = FSO.BuildPath(path, fileName)
		
			If not FSO.FileExists(filePath) Then 
				Download = 1
			Else
				stream.Type = 1
				stream.Open 

				on error resume next					
				stream.LoadFromFile(filePath)
				
				If err.Number<>0 Then
					Download = 2
				Else
					Response.AddHeader "Content-Disposition","attachment;filename="  & fileName
					Response.AddHeader "Content-Length", stream.Size
					Response.CharSet = "UTF-8" 
					Response.ContentType = "application/octet-stream"
					Response.BinaryWrite stream.Read
					Download = 0
				End If
				
				stream.Close 
			End If
		End Function

		
		Private stream


		Private Sub ParsePost()
			Dim biData, sInputName
			Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
			Dim nPosFile, nPosBound
			
			Dim tmpStream
	
			biData = Request.BinaryRead(Request.TotalBytes)

			nPosBegin = 1
			nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
			
			If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
			 
			vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
			nDataBoundPos = InstrB(1, biData, vDataBounds)
			
			nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
			nPos = InstrB(nPos, biData, CByteString("name="))
			nPosBegin = nPos + 6
			nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
			sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
			nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
			nPosBound = InstrB(nPosEnd, biData, vDataBounds)
			
			If nPosFile <> 0 And nPosFile < nPosBound Then
				nPosBegin = nPosFile + 10
				nPosEnd =  InstrB(nPosBegin, biData, CByteString(Chr(34)))
				uploadedFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
				uploadedFileName = Right(uploadedFileName, Len(uploadedFileName)-InStrRev(uploadedFileName, "\"))
	
				nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
				nPosBegin = nPos + 14
				nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
					
				contentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
				
				nPosBegin = nPosEnd+4
				nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
		
				Set tmpStream = Server.CreateObject("ADODB.Stream")
				tmpStream.Type = 1
				tmpStream.Open
				tmpStream.Write biData
				tmpStream.Position = nPosBegin-1
				tmpStream.CopyTo stream, nPosEnd-nPosBegin
				Set tmpStream = Nothing
				
				uploadedFileSize = stream.Size
			End If
		End Sub


		Private Function CByteString(sString)
			Dim nIndex
			For nIndex = 1 to Len(sString)
				CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
			Next
		End Function
	

		Private Function CWideString(bsString)
			Dim nIndex
			CWideString =""
			For nIndex = 1 to LenB(bsString)
				CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1))) 
			Next	
		End Function
	End Class
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.