#cs GET /i.html HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */* Accept-Language: en-us Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705; .NET CLR 2.0.50727) Host: 127.0.0.1 Connection: Keep-Alive #ce #cs From: http://www.autoitscript.com/forum/index.php?s=&showtopic=19696&view=findpost&p=136138 GET request format: http://?=&= #ce #include #include #include ;;#include "DSO.au3" #include "RSUDF.au3" Global $filetypes = _ArrayCreateVals("html","text/html","htm","text/html","gif", "image/gif", "bmp", "image/x-xbitmap", "jpg", "image/jpeg", "jpeg", "image/jpeg", "jpe", "image/jpeg", "ppt", "application/vnd.ms-powerpoint", "xls", "application/vnd.ms-excel", "doc", "application/msword", "swf", "application/x-shockwave-flash") Global $newsession = 1 Global $listen Global $sock Global $serverName[100] Global $serverPids[100] Global $serverSPtr = 0 Global $recv Global $DSO_FORCE_MIME = "" Global Const $IP = InputBox( "Wood's General Server", "Input IP address:", _GetIP() ) Global Const $PORT = 80 Global Const $E404 = '%IP%:%PORT% - Error 404 - File %REQUEST% not found.'& _ '

Wood'&"'"&'s Technologies General Purpose Server

Error 404: File %REQUEST% not found

'& _ '

The server which you are requesting the file"%REQUEST%" from cannot find the file.


Wood'& _ "'"&'s Technologies General Server (0.4), IP: %IP%, PORT:%PORT% (%_MDAY%/%_MON%/%_YEAR% %_HOUR%:%_MIN%:%_SEC%)
' TCPStartup() $listen = TCPListen($IP, $PORT, 100) If $listen = -1 Then $err = @error MsgBox(16, "Error", "Unable to connect." & @CRLF & @CRLF & "dec: " & $err & @CRLF & "hex: 0x" & Hex($err, 8)) EndIf While 1 $sock = TCPAccept($listen) ;;Poll the socket for commands If $sock >= 0 Then $recv = _SockRecv($sock) ;;Get Command from socket _DSO_Referer($recv) ;;Do some DSO related stuff $recv = StringSplit($recv, " ") ;;Split up the Command $recvRequest = StringSplit($recv[2], "?") ;;Split up the Request If StringInStr($recv[2], "woodserverexeoutput=") Then ;$html = _VarsInterpret(_Server_Execute($recvRequest[2])) ;;Server-Related Command (not yet implemented) $html = "Sorry, WSE not yet implemented. Please intergrate your application into the server. Refer to DSO.txt" ElseIf StringInStr($recv[2], "directserveroutput=") Then $html = _VarsInterpret(_DirectServerOutput($recvRequest[2], _URLDecode($recvRequest[1]))) ;;'DSO'-Related Command Else $html = _Get(_URLDecode($recvRequest[1])) ;;Normal file request EndIf $mime = _GetFileType(_URLDecode($recvRequest[1])) If $DSO_FORCE_MIME <> "" Then $mime = $DSO_FORCE_MIME $DSO_FORCE_MIME = "" EndIf $send = _SockSend($sock, _GetHeader($mime) & $html);;Send the data EndIf TCPCloseSocket($sock) Wend Exit ;;;;Functions ;;Get Functions ;Gets the document header FUNc _GetHeader($filetype="text/plain") Return 'HTTP/1.0 200 OK' & @CRLF & 'Content-Type: ' & $filetype & @CRLF & @CRLF EndFunc ;Gets the filetype for the header using the extention Func _GetFileType($ext) For $i = 0 to UBound($filetypes)-1 Step 2 If StringInStr($ext, $filetypes[$i]) Then Return $filetypes[$i+1] Next Return "text/plain" EndFunc ;Get a file normally Func _GET($filename) ;;Default to index.html If $filename = "/" or $filename = "\" or $filename = "" Then $filename = "\index.html" $file = @ScriptDir & "\" & $filename ;;If file does not exist, send an error 404 If Not FileExists($file) Then If FileExists("ERROR_404.html") Then Return _GET("/ERROR_404.html") Else Return _VarsInterpret($E404) EndIf EndIf ;;Check for Unauthorized access If StringInStr(FileGetAttrib($file), "D") And IniRead(@ScriptDir & "\variables.ini", "Permissions", "folders", 0) = 0 THen Return _GET("/ERROR_401.html") If StringInStr($file, "..") And IniRead(@ScriptDir & "\variables.ini", "Permissions", "prevdir", 0) = 0 THen Return _GET("/ERROR_401.html") ;;Read the data from the file $data = FileRead($file, FileGetSize($file)) ;;If html file, transalte %% macros if StringInStr(FileGetExt($file), "htm") Then $data = _VarsInterpret($data) Return $data EndFunc ;;Sock Functions ;Recieve Data on a socket Func _SockRecv( $iSocket, $iBytes = 2048 ) Local $sData = "" ;;Loop Until you recieve data on the socket While $sData = "" $sData = TCPRecv($iSocket, $iBytes) Wend ;;Flash a MsgBox MsgBox(0,"",$sData,1) ;;Log the Command _FileWriteLog( @ScriptDir&"\log.txt", $sData ) Return $sData EndFunc ;Send Data on a socket Func _SockSend( $iSocket, $sData ) Return TCPSend($iSocket, $sData) EndFunc ;;OnExit Function Func OnAutoItExit() TCPCloseSocket($sock) TCPCloseSocket($listen) TCPShutdown() Exit EndFunc #cs The old code dump: $send = _SockSend($sock, _GetHeader(_GetFileType(FileGetExt(_URLDecode($recv[2])))) & $html) #ce Global $DSO_REFERER = "" Global $DSO_REFERER_ALLOW = 0 Func _DirectServerOutput($input, $file) $str = StringTrimLeft($input, StringLen("directserveroutput=")) Switch $str Case 'of0' If StringInStr(FileGetAttrib(@ScriptDir&'/'&$file), "D") THen Return _DSO_Dir($file&'/') Return _Get($file) EndSwitch EndFunc Func _DSO_Dir($s_Path) ;$data = '' ;#CS $s_Mask = '*' Local $html = '' $html &= ''&''&'
Directory Listing of '&_URLEncode($s_Path)&'
NameExtAttribSizeCreated OnModified ONAccessed OnLink' $h_Search = FileFindFirstFile(@ScriptDir & $s_Path & $s_Mask) $s_FileName = FileFindNextFile($h_Search) If Not @error Then While Not @error $s_FullName = $s_Path & $s_FileName $i_ExtMarker = StringInStr($s_FileName,'.',0,-1) If $i_ExtMarker Then $html &= '
'&StringLeft($s_FileName, $i_ExtMarker - 1)&''&StringMid($s_FileName, $i_ExtMarker + 1) Else $html &= '
'&$s_FileName&''&'' EndIf $html &= ''&FileGetAttrib(@ScriptDir & $s_FullName)&''&FileGetSize(@ScriptDir & $s_FullName)&''& _ FileGetTime(@ScriptDir & $s_FullName,1,1)&''&FileGetTime(@ScriptDir & $s_FullName,0,1)&''& _ FileGetTime(@ScriptDir & $s_FullName,2,1)&''&''& _ 'Open' $s_FileName = FileFindNextFile($h_Search) WEnd EndIf $html &= '
' ;#CE ;$PID = Run(@ComSpec & ' /c DIR "'&@ScriptDir&'\'&$s_Path&'"', '', @SW_HIDE, 2) ;Do ; $data = $data & StdoutRead($PID) ;Until @error ;Return $data Return $html EndFunc Func _DSO_OpenFile($file) If Not FileExists($file) Then Return _GET("/ERROR_404.html") If StringInStr($file, "..") And IniRead(@ScriptDir & "\variables.ini", "Permissions", "prevdir", 0) = 0 THen Return _GET("/ERROR_401.html") If StringInStr(FileGetAttrib($file), "D") THen Return _DSO_Dir($file) $data = FileRead($file, FileGetSize($file)) if StringInStr(FileGetExt($file), "htm") Then $data = _VarsInterpret($data) EndIf Return $data EndFunc Func _DSO_Referer($recv) $recvparams = StringSplit($recv, @CRLF) $DSO_REFERER = '' For $i = 1 to $recvparams[0] If StringLeft($recvparams[$i], StringLen("Referer: ")) == "Referer: " Then $DSO_REFERER = StringTrimLeft($recvparams[$i], StringLen("Referer: ")) EndIf Next EndFunc Func _DSO_Login() EndFunc Func _DSO_ProcessString($proc) ;;Get Rid of Starting and Ending slashes $c = StringLeft($proc, 1) If $c = "\" or $c = "/" then $proc = StringTrimLeft($proc, 1) $c = StringRight($proc, 1) If $c = "\" or $c = "/" then $proc = StringTrimRight($proc, 1) ;;Get Rid of Double Slashes while StringInStr($proc, "//") StringReplace($proc, "//", "/") wend while StringInStr($proc, "\\") StringReplace($proc, "\\", "\") wend Return StringSplit($proc, "\/") EndFunc Func _DSO_SetMIMEType($mime) $DSO_FORCE_MIME = $mime EndFunc