<% 
if not session("girdinmilan") = "evetgirdimlan" then
response.write "<br><center><br><b>Yonetici izniniz yok.</b>"
response.end
end if

page = Request.Querystring("now")
if page="" then 
response.redirect("in/admin/panel.asp?box=warning&text=Sayfa%20bulunamadi.&second=2&url=default.asp")
end if 
If page = "run" then 

Response.Buffer = true

const ForReading=1,ForWriting=2,ForAppending=8
Const adTypeBinary = 1

dim PthStr
dim sFileSize, sFileName

sFileName=Request.QueryString("file")
sFileSize = Request.QueryString("size")
sAction=Request.QueryString("action")

PthStr=server.MapPath(SFileName)

'remove this line - just intended to demonstrate the problem in running it with PWS.
Response.Write ""
select case sAction

	case "view"
		viewfile()
		'the final statement
		Response.Write "<p align=center>&laquo; <a href=""javascript:self.close()"">Pencereyi kapat</a> &raquo;"		
	case "download"
		downloadfile()
	case "delete"
		delfile()
	case else
		Response.Write("<center>Bilinmeyen uygulama</center>")
end select

function viewfile()
	
	
	'open the file and output the file as text
	set fso=server.CreateObject("Scripting.FileSystemObject")
	set tfile=fso.OpenTextFile(PthStr,ForReading,false)
	If not tfile.AtEndOfStream then
		StrBuf=tfile.ReadAll
	end if
	tfile.close
	set tfile=nothing
	
	'replace html tags so that it is displayed properly
	StrBuf=replace(StrBuf,"<","&lt;")
	StrBuf=replace(StrBuf,">","&gt;")
	StrBuf=replace(StrBuf,vbcrlf,"<br>")
	Response.Write(StrBuf)
	


end function

function downloadfile()

	Response.Clear
	
	Set objStream = Server.CreateObject("ADODB.Stream")
	objStream.Open
	objStream.Type = adTypeBinary
	objStream.LoadFromFile PthStr

	sFileType = lcase(Right(sFileName, 4))
	    
	    Select Case sFileType
	        Case ".asf"
	            ContentType = "video/x-ms-asf"
	        Case ".avi"
	            ContentType = "video/avi"
	        Case ".doc"
	            ContentType = "application/msword"
	        Case ".zip"
	            ContentType = "application/zip"
	        Case ".xls"
	            ContentType = "application/vnd.ms-excel"
	        Case ".png"
	            ContentType = "image/gif"
	        Case ".jpg", "jpeg"
	            ContentType = "image/jpeg"
	        Case ".wav"
	            ContentType = "audio/wav"
	        Case ".mp3"
	            ContentType = "audio/mpeg3"
	        Case ".mpg", "mpeg"
	            ContentType = "video/mpeg"
	        Case ".rtf"
	            ContentType = "application/rtf"
			Case ".htm", "html"
	            ContentType = "text/html"
			Case ".asp"
	            ContentType = "text/asp"
	        Case Else
	            'Handle All Other Files
	            ContentType = "application/octet-stream"
	    End Select
		
		Response.AddHeader "Content-Disposition", "attachment; filename=000" & sFileName
		Response.AddHeader "Content-Length", sFileSize
		Response.Charset = "UTF-8"
		Response.ContentType = ContentType
		
		Response.BinaryWrite objStream.Read
		Response.Flush

	objStream.Close
	Set objStream = Nothing

end function

function delfile()

	bConfirm=Request.QueryString("confirm")
	hfold=Request.QueryString("fold")
	sPath=Request.ServerVariables("URL")
	sPath=sPath&"?"&Request.ServerVariables("QUERY_STRING")
	Set filesys=Server.CreateObject("Scripting.FileSystemObject")
	If bConfirm="true" then
	filesys.DeleteFile(PthStr)
	
	%>
	<meta http-equiv="refresh" content="0;URL=in/admin/panel.asp?box=success&text=Icerik%20silindi.&second=2&url=filemanager.asp?fold=<%=hfold%>">	
	<%
	end if
	
end function

else
response.redirect("in/admin/panel.asp?box=warning&text=Sayfa%20bulunamadi.&second=2&url=default.asp")
end if 

%>