daslick Posted March 29, 2008 Posted March 29, 2008 (edited) expandcollapse popup#include <String.au3> HotKeySet("{ESC}", "end") TCPStartup() ClipPut(@IPAddress1) $htmlstart = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Directory Listing</title><style type="text/css"><!--body{font-family: "Times New Roman";font-size: 12pt;background-color: #ffffff;color: #000000;text-align: left;}td{ font-family: "Times New Roman";font-size: 12pt;color: #000000;text-align: left;}a, a:visited {color: #000000;}a:hover { color: #ffffff; background: #000000;}table {border: none; width:100%; padding:3px;}.header {text-align:center;background-color: #ccccff; font-weight:bold;border: outset 1px;}.odd {background-color: #ffffff;}.even {background-color: #e3e3e3;}.rite {text-align:right;}--></style></head><body><table style="table-layout:fixed; width:100%;"><tr><td class="header" style="width:36%">Name</td><td class="header" style="width:15%">Size</td><td class="header" style="width:25%">Type</td><td class="header" style="width:24%">Modified Date</td></tr>' $html = '' $htmlend = '</table><!-- /////// SUMMARY //////////////// --><br /><table><tr><td>Total folders: 0</td></tr><tr><td>Total files: 5</td></tr><tr><td>Total size of all files: 3,173,959</td></tr><tr><td>Date generated: 2/9/2006 11:41 PM</td></tr></table><!-- /////// END OF SUMMARY //////////////// --></body></html>' $listen = TCPListen(@IPAddress1, 80, 100) While 1 $sock = TCPAccept($listen) Switch $sock Case -1 Case Else $rawdata = TCPRecv($sock, 12800) $request = StringTrimLeft(StringLeft($rawdata,StringInStr($rawdata, "HTTP/1.1")-2),StringInStr($rawdata, "GET /")+4) checkstring($request) Select Case StringInStr(FileGetAttrib(StringReplace($request,'/','\')),"D") = 1 $search = FileFindFirstFile($request & '\*.*') if $search <> -1 then;if not @error then $count = 1 $file = '' While 1 $file = FileFindNextFile($search) If @error Then ExitLoop;exit loop before messing up $html If Mod($count,2) = 0 Then $html = $html & htmleven($file) If Mod($count,2) = 1 Then $html = $html & htmlodd($file) $count+=1 WEnd EndIf $html = $htmlstart & htmlodd('..\', 1) & $html & $htmlend Case StringInStr(FileGetAttrib($request),"N") = 1 $html = FileRead($request) Case Else MsgBox(0,'','error') EndSelect TCPSend($sock, $html) $html = '' EndSwitch TCPCloseSocket($sock) WEnd Func checkstring(ByRef $input) $input = StringReplace(StringReplace(StringReplace(StringReplace($input,'%5C','/'),'%20',' '),'\','/'),'//','/') if StringRight($input, 1) = '/' then $input = StringTrimRight($input, 1) EndFunc Func htmleven($file, $directory = 0) $filepath = $request & '/' & $file checkstring($filepath) Switch $directory Case 0 Return '<tr class="even"><td><img src="../images/audio.gif" width="24" height="24" alt="icon"/><a href="/' & $filepath & '">' & $file & '</a></td><td class="rite">' & FileGetSize($file) & ' </td><td></td><td class="rite">' & FileGetTime($file,0,1) & '</td></tr>' Case 1 Return '<tr class="even"><td><img src="../images/audio.gif" width="24" height="24" alt="icon"/><a href="/' & StringLeft($filepath,StringInStr($filepath,'/')) & '">' & $file & '</a></td><td class="rite">' & FileGetSize($file) & ' </td><td></td><td class="rite">' & FileGetTime($file,0,1) & '</td></tr>' EndSwitch EndFunc Func htmlodd($file, $directory = 0) $filepath = $request & '/' & $file checkstring($filepath) Switch $directory Case 0 Return '<tr class="odd"><td><img src="../images/audio.gif" width="24" height="24" alt="icon"/><a href="/' & $filepath & '">' & $file & '</a></td><td class="rite">' & FileGetSize($file) & ' </td><td></td><td class="rite">' & FileGetTime($file,0,1) & '</td></tr>' Case 1 Return '<tr class="odd"><td><img src="../images/audio.gif" width="24" height="24" alt="icon"/><a href="/' & StringLeft($filepath,StringInStr($filepath,'/')) & '">' & $file & '</a></td><td class="rite">' & FileGetSize($file) & ' </td><td></td><td class="rite">' & FileGetTime($file,0,1) & '</td></tr>' EndSwitch EndFunc Func end() Exit EndFunc Having some problems with this code... if anyone is interested in the project then I'd appreciate the help. Edited April 1, 2008 by daslick
martin Posted March 29, 2008 Posted March 29, 2008 (edited) #include <String.au3> TCPStartup() $listen = TCPListen(@IPAddress1, 80, 100) While 1 $sock = TCPAccept($listen) Switch $sock Case -1 Case Else $rawdata = TCPRecv($sock, 12800) $request = StringTrimLeft(StringLeft($rawdata,StringInStr($rawdata, "HTTP/1.1")-2),StringInStr($rawdata, "GET /")+4) $request = StringReplace($request,'/','\') MsgBox(0,'',$request) Switch $request Case '' Case FileExists($request) $html = FileRead($request) Case StringInStr(FileGetAttrib($request),"D") = 1 dim $file $search = FileFindFirstFile("C:\Drivers\*.*") $next = '' While 1 $next = FileFindNextFile($search) $next = $next = $next & '<a href="' & @IPAddress1 & '\' & $next & '">' & $next & '</a></br>' If @error Then ExitLoop WEnd Case Else $html = $request EndSwitch TCPSend($sock, $html) EndSwitch TCPCloseSocket($sock) WEnd After the first request (tcp connection), the script runs through and exits, rather than looping. Why? There is something wrong with this section, although I don't think it's causing your problem Case StringInStr(FileGetAttrib($request),"D") = 1 dim $file $search = FileFindFirstFile("C:\Drivers\*.*") $next = '';why set this to '' because it's set again 2 lines later While 1 $next = FileFindNextFile($search) ;next line will always set $next to false $next = $next = $next & '<a href="' & @IPAddress1 & '\' & $next & '">' & $next & '</a></br>' If @error Then ExitLoop WEnd I assume that what you want is something like ;??dim $file $search = FileFindFirstFile("C:\Drivers\*.*") if $search <> -1 then;if not @error then $html = '' While 1 $next = FileFindNextFile($search) If @error Then ExitLoop;exit loop before messing up $html $html = $html & '<a href="' & @IPAddress1 & '\' & $next & '">' & $next & '</a></br>' WEnd EndIf Edited March 29, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
daslick Posted April 1, 2008 Author Posted April 1, 2008 I found the problem. $html was undeclared. Adding dim $html solved the problem.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now