I have a compiled c binary (setch) which takes the parameters HIGH/LOW/OFF
so I am trying to execute the command eg setch OFF
from javascript/jquery thus:
$.get("cgi-bin/setch.cgi","OFF"); -or
$.get("cgi-bin/setch OFF");
As it's a get then the space is encoded into %20, of course. However the server then tries to execute the command setch%20OFF
and returns:
404 Not Found
Without the parameter the program executes and returns my message:
no parameters
ie all paths, permissions etc are OK
Am I trying to do the impossible here? Or am I missing something in the server (lighttpd) config? Thanks
You want to pass a parameter to a CGI. The way to do that is not to separate them with a space, instead you want to put the parameter behind a "?" character. The HTTP server will then store everything that follows behind the question mark in the QUERY_STRING environment variable that your CGI can then read.
I.e.
$.get("cgi-bin/setch?OFF");
In your C program use getenv("QUERY_STRING")
to access the passed parameter.
Check https://en.wikipedia.org/wiki/Common_Gateway_Interface for a list of all environment variables that the HTTP server set for CGI programs. Be sure to treat the values as untrusted data.