AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AutoHotkey as CGI handler for LightTPD web server on Windows

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> General Chat
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Wed Jan 16, 2008 4:28 pm    Post subject: AutoHotkey as CGI handler for LightTPD web server on Windows Reply with quote

If you ever need it, it's possible to have AutoHotkey work on your web server. This mini tut briefly explains the setup for LightTPD.

  1. Open conf/lighttpd-inc.conf
    1. Check that mod_cgi is enabled
    2. Add ".ahk" => "text/plain", to the top of the mimetype.assign list
    3. Add , ".ahks" to the static-file.exclude-extensions list
    4. Add , ".ahks" => "C:/Program Files/AutoHotkey/serv.bat" to the cgi.assign list

  2. Open Notepad or any editor, set the file contents to the following and save as C:\Program Files\AutoHotkey\serv.bat:

    Code:
    @echo off
    echo.
    for /F "tokens=*" %%t in ('""C:\Program Files\AutoHotkey\AutoHotkey.exe" "%1""') do echo %%t


  3. Restart the server. If running as a service you may need to grant super user rights for certain commands like RegRead and FileRead outside your wwwroot/htdocs directory

FastCGI will not work with AutoHotkey. Remember to change the path to AutoHotkey accordingly - it must be a full path, i.e. not /Program Files or %ProgramFiles%.

Just for fun of it here's a test script:

Code:
#NoTrayIcon

FileAppend, <html><head><title>Test from AutoHotkey</title></head><body>, *
FileAppend, <h2>Hello World from AutoHotkey!</h2><hr />, *

Random, r, 100, 10000
FileAppend, <p>Random number: %r%</p>`n, *

Loop, *.png, , 1
{
   img = %A_LoopFileFullPath%
   Break
}

StringReplace, img, img, \, /, All
FileAppend, <p>Last image in directory: %img%: <img src="%img%" /></p>, *

RegRead, val, HKCU, Software\MySQL AB\MySQL Administrator 1.2, Version
FileAppend, <p>ErrorLevel for reading a misc. registry key: <strong>%ErrorLevel%</strong> <em>(value: "%val%")</em></p>, *

f = Titan\zlib.txt
FileRead, txt, %f%
txt := coltxt(SubStr(txt, 54, 174), 0x80, -0x7ffff)
FileAppend, <p>Gradient coloured text from sample in file %f%:<br /><blockquote><pre>%txt%</pre></blockquote></p>, *

FileAppend, </body></html>, *


coltxt(str, a = 0x000000, i = -1) {
      f = %A_FormatInteger%
      SetFormat, Integer, Hex
      VarSetCapacity(bc, StrLen(str) * 24)
      If i = -1
         i := 0xff // StrLen(str)
      i &= k := 0xffffff
      Loop, Parse, str
      {
         c := SubStr(000000 . SubStr((a + i * (A_Index - 1)) & k, 3), -5)
         bc = %bc%<span style="color: #%c%">%A_LoopField%</span>
      }
      SetFormat, Integer, %f%
      Return, bc
}



_________________

Back to top
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3652
Location: Belgrade

PostPosted: Wed Jan 16, 2008 5:03 pm    Post subject: Reply with quote

ROFL.

Nice Smile
You never know when you need it Smile
Back to top
View user's profile Send private message MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Sat Jan 19, 2008 1:10 pm    Post subject: Reply with quote

By the way, the WLMP project hosts a compiled version of LightTPD.
FastCGI here would be pointless unless there are dramatic changes from the source.
_________________



Last edited by Titan on Sun Jan 27, 2008 5:04 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3652
Location: Belgrade

PostPosted: Sat Jan 19, 2008 1:38 pm    Post subject: Reply with quote

Quote:
FastCGI here would be pointless unless there are dramatic changes from the source.

AFAIK, only thing required for the client is to have sockets API, and there are probably some on the forum. This would let single ahk process stay and handle web events, much faster then executing it each time, especialy with Ajax.
Back to top
View user's profile Send private message MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Sat Jan 19, 2008 2:03 pm    Post subject: Reply with quote

What about multiple scripts, wouldn't you need a separate process for each one that way? Even then you can't cache opcodes since AutoHotkey was not designed this way.
_________________

Back to top
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3652
Location: Belgrade

PostPosted: Sat Jan 19, 2008 2:15 pm    Post subject: Reply with quote

Ah, I forgot, no theads in AHK....
Back to top
View user's profile Send private message MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Thu Jan 24, 2008 9:30 pm    Post subject: Reply with quote

I found that you can't output headers due to the echo. command in the batch file. Without it though the entire ouput is garbled - at least on Vista anyway.
_________________

Back to top
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3652
Location: Belgrade

PostPosted: Thu Jan 24, 2008 10:33 pm    Post subject: Reply with quote

Was that just experiment or you really want to use AHK for web apps ? IMO, using AHK for this is waste of time, but I can imagine some useful things in some special scenarios...
Back to top
View user's profile Send private message MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Thu Jan 24, 2008 10:46 pm    Post subject: Reply with quote

AutoHotkey is too inefficient to serve large web applications per se but it very well can be used for specialized purposes.
_________________

Back to top
View user's profile Send private message Visit poster's website
PAEz



Joined: 11 Feb 2008
Posts: 2
Location: South Australia

PostPosted: Mon Feb 11, 2008 6:22 am    Post subject: Reply with quote

Hi, Im trying to get it so that I can control my computer through a web page on my iTouch with safari and its just not working (on the PC aswell, not the iTouch).
Im mainly using Abyss Web server as it was very easy to get directory listing up and looking good (I use that to stream movies to my iTouch), but I am also trying the one your using and neither work.
If I try just dropping a script onto the serv.bat then I get any error message along the lines of....
The script file "H:\__iPod" doesnt exist create it now?
..and the directory the scripts in is... H:\__iPod Video__
when i remove the first echo in serv.bat it shows in the dos windows that the scripts location has two " around it so i tried removing the " around the %1 and then i can drop a script onto the bat and it works but still doesnt work with the server.
If i dont use the serv.bat and point directly at the autohotkey.exe then my monitor turns off (what im trying to achieve) but in my server logs i get broken pipe and obviously it doesnt return anything to the browser.
Any help on this would be GREATLY appreciated as this would be perfect for what i want (controling things on the pc with my ipod) if i could just get it working.
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Mon Feb 11, 2008 9:06 am    Post subject: Reply with quote

Are you sure you have all the paths right - is AutoHotkey installed under %ProgramFiles%\AutoHotkey and are you on a user account that's allowed to execute it?
_________________

Back to top
View user's profile Send private message Visit poster's website
PAEz



Joined: 11 Feb 2008
Posts: 2
Location: South Australia

PostPosted: Mon Feb 11, 2008 11:57 am    Post subject: Reply with quote

Im only using the server your using now as i seem to have got a touch further along....
I put this line at the top of your bat file...
"D:\Program Files\AutoHotkey\AutoHotkey.exe" "%1"
..and it ran the script, but still doesnt run the script in the for loop.
So Id guess that means that my paths and user rights are ok.....right?
If i drop a ahks script onto serv.bat it runs fine in windows (in the for loop), but still does nothing when i run it through the server?

Oh...and thanks for the reply, i really would like to get this working.

EDIT: Urgggghhh....
I reread what you wrote and noticed that some was for Vista (im on xp, dont like vista)...so I changed the bat again to this....
@echo off
echo.
"D:\Program Files\AutoHotkey\AutoHotkey.exe" "%1"
...and it nearly worked Wink
...except that I get an error message saying...
The script file "C:\LightTPD\HTDOCS\HTDOCS\his.ahks" does not exist. Create it now?
...so i had to create another htdocs dir in the htdocs dir, copy the script into that dir and it runs and your script returned the right stuff (still uses c:\lighttpd\htdocs as its working dir)....crap I know, but I dont care anymore, thats enough for me to have some fun till i find a better solution.
I cant find any other way to do what I want so this will do till I do, but I really like the idea of using AHK (Ive used it in the pass and I like it).
If anyone can think of any other way of doing what I want Id love to hear it, but until then....Thanks Titan

OH...and why is it that i need the serv.bat. Could the AHK source be modified so it returns stuff the way cgi would like so i wouldnt need the serv.bat and target the autohotkey.exe instead?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> General Chat All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group