Can't figure out how to receive http requests using lighttpd

1.1k views Asked by At

I have a simple lighttpd web server running off my router. In it's .conf file I know I need to set

$HTTP["querystring"] =~ "cams=on" { telnet to turn on cams via managed poe switch }

The issue I am having is trying to figure out how to actually get it to run a script that sends telnet commands to my poe switch. I've never done anything like this and I'm unable to find any help for anyone not angry familiar with web serving.

1

There are 1 answers

0
gstrauss On BEST ANSWER

There are multiple ways to do this with lighttpd. One of the simplest is by using CGI. https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModCGI

server.modules += ( mod_cgi )
$HTTP["query-string"] =~ "cams=on" {
  cgi.assign = ( "" => "/path/to/control-script" )
}

Your /path/to/control-script will be executed when lighttpd receives requests with that query string. (Search the web for tutorials on what to expect in the environment for your CGI script, like the environment variable QUERY_STRING="cams=on")

Please note that it is recommended that you restrict the script to certain paths, rather than intercepting that query string on any request to any other part of your server. You can omit the $HTTP["query-string"] condition if your script runs at a known path and can handle multiple different commands in the query string.

server.modules += ( mod_cgi )
$HTTP["url"] =~ "^/control/" {
  $HTTP["query-string"] =~ "cams=on" {
    cgi.assign = ( "" => "/path/to/control-script" )
  }
}

Lastly, you probably want to use lighttpd mod_auth to restrict who can access the control script. https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModAuth