#include #include ; ----- Beta 0.2 ; ----- Ordner Konfig Global Const $WebRoot = @ScriptDir & "\www" ; ----- Netzwerk Global Const $Port = 80 Global Const $IP = @IPAddress1 Global Const $MaxConnections = 500 Global Const $MaxResv = 16384 ; ----- Sonstiges Global Const $DiaryListening = 1 ConsoleWrite("+IP:" & $IP & ":" & $Port & @CRLF) TCPStartup() If @error Then ConsoleWrite("!TCP Engine" & @CRLF) Exit Else ConsoleWrite("+TCP Engine" & @CRLF) EndIf $Socket = TCPListen($IP, $Port) If @error Then ConsoleWrite("!Socket" & @CRLF) Exit Else ConsoleWrite("+Socket" & @CRLF) EndIf ; ----- Globals Dim $Connections[$MaxConnections + 10][2] Dim $Downloads[$MaxConnections + 10][2] Global $Resv, $Tmp, $FileList, $sRet $Connections = SetArray($Connections) $Downloads = SetArray($Downloads) While 1 For $i = 0 To UBound($Connections) - 1 If $Connections[$i][0] = -1 Then $Connections[$i][0] = TCPAccept($Socket) If @error Then EmptySock($i) Else $Connections[$i][1] = SocketToIP($Connections[$i][0]) If $Connections[$i][1] = 0 Then EmptySock($i) Else ConsoleWrite("+New Client:" & $Connections[$i][1] & @CRLF) EndIf EndIf EndIf If $Connections[$i][0] <> -1 Then $Resv = TCPRecv($Connections[$i][0], $MaxResv) If @error Then ConsoleWrite("-Client Quit:" & $Connections[$i][1] & @CRLF) EmptySock($i) Else If $Resv <> "" Then Progress() EndIf EndIf Next WEnd Func Progress() $Path = StringRegExp($Resv, "GET (.*) HTTP\/1\.1", 3) If Not IsArray($Path) Then Return $Path = StringRegExpReplace($Path[0], "/", "\\") $Path = StringRegExpReplace($Path, "%20", " ") $Tmp = $WebRoot & $Path ;~ ConsoleWrite($Tmp & @CRLF) Switch FileGetAttrib($WebRoot & $Path) Case "D" If FileExists($WebRoot & "\index.htm") Then $Path &= "index.htm" If FileExists($WebRoot & "\index.html") Then $Path &= "index.html" If $WebRoot & $Path == $Tmp Then If $DiaryListening Then TCPSend($Connections[$i][0], HTTPNormalHeader(DiaryListening($Path))) $sRet = "" Return Else TCPSend($Connections[$i][0], HTTPNormalHeader("

Diarylistening denied!

")) $sRet = "" Return EndIf EndIf Case Else TCPSend($Connections[$i][0], HTTPNormalHeader(FileRead($WebRoot & $Path))) EndSwitch $sRet = "" EndFunc ;==>Progress Func HTTPNormalHeader($_Str, $Format = "text/html") $sRet = "HTTP/1.1 200 OK" & @CRLF & _ "Server: Sprengers HTTP Server" & @CRLF & _ "Content-Length: " & StringLen($_Str) & @CRLF & _ "Content-Language: de" & @CRLF & _ "Content-Type: " & $Format & @CRLF & _ "Connection: close" & @CRLF & @CRLF & $_Str Return $sRet EndFunc ;==>HTTPNormalHeader Func DiaryListening($_Str) $FileList = _FileListToArray($WebRoot & $_Str) If IsArray($FileList) Then For $x = 1 To $FileList[0] If $_Str = "\" Then $sRet &= '' & $_Str & $FileList[$x] & '
' Else $sRet &= '
' & "\" & StringTrimLeft(StringRegExpReplace($_Str, "/", "\\"), 1) & "\" & $FileList[$x] & '
' EndIf Next Else $sRet = "

No Files or Folders

" EndIf Return $sRet EndFunc ;==>DiaryListening Func SetArray($Array, $Data = -1) For $x = 0 To 1 For $y = 0 To UBound($Array) - 1 $Array[$y][$x] = $Data Next Next Return $Array EndFunc ;==>SetArray Func EmptySock($Index) TCPCloseSocket($Connections[$Index][0]) $Connections[$Index][0] = -1 $Connections[$Index][1] = -1 EndFunc ;==>EmptySock Func SocketToIP($SHOCKET) Local $sockaddr, $aRet $sockaddr = DllStructCreate("short;ushort;uint;char[8]") $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _ "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr)) If Not @error And $aRet[0] = 0 Then $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3)) If Not @error Then $aRet = $aRet[0] Else $aRet = 0 EndIf $sockaddr = 0 Return $aRet EndFunc ;==>SocketToIP