Where is the configuration file (init.d) in g-wan. Also how do I get rid of the '?' In the url to run php or c script ( I think you need to change this in the configure)?
Where is the configuration file in g-wan?
625 views Asked by matt AtThere are 2 answers
As Ken explained, there's no configuration file - but G-WAN scripts (servlets
, handlers
), including the init.c
and main.c
G-WAN startup scripts, can modify G-WAN by-default settings... even dynamically, during the life of the server, and sometimes on a per-request basis.
Here are the options that can be changed before G-WAN starts listening (they are documented in the PDF manual and on the G-WAN Web site):
US_SERVER_DATA // global server pointer for user-defined data
SERVER_SOFTWARE // "Server: G-WAN" HTTP response header
SCRIPT_TMO // time-out in ms running a script
KALIVE_TMO // time-out in ms for HTTP keep-alives
REQUEST_TMO // time-out in ms waiting for request
MIN_SEND_SPEED // send rate in bytes/sec (if < close)
MIN_READ_SPEED // read rate in bytes/sec (if < close)
MAX_ENTITY_SIZE // maximum POST entity size
QUERY_CHAR // replace '?' by - _ . ! ~ * ' ( )
USE_WWW_CACHE // enable static cache (default: off)
USE_CSP_CACHE // enable servlet cache (default: off)
CACHE_ALL_WWW // load all /www in cache (default: off)
USE_MINIFYING // enable JS/CSS/HTML minifying (default: off)
And here is how to change the default query character '?':
u8 *query_char = (u8*)get_env(argv, QUERY_CHAR);
if(query_char)
{
u8 old = *query_char;
*query_char = '!'; // "/!hello.c" instead of "/?hello.c"
printf("> changed query_char from '%c' to '%c' (%p)\n",
old, *query_char, query_char);
}
To completely remove the '?' (rather than replacing it) you will have to use a G-WAN connection handler, see this example just doing what you want on tab #2 'connection handlers'.
In many cases, dynamic settings are preferable to fixed options, like for adaptive timeouts (fixed timeouts leave a server vulnerable to timing attacks, like Slowloris
).
There is no configuration "file" per se. For example, port and IP address are configured as folder names (e.g., 172.16.42.2:8080/...) under the root gwan folder.
Servlets, whether written in php or C or whatever you choose, are in the .../csp folder under the IP:port path under the gwan folder. With G-WAN, by default, the path to a servlet begins with '?' followed by the servlet name AND extension (e.g., '.php'), and the first parameter is preceded by '&' like the 2nd - nth parameter is with most web servers.
You can change virtually ANYTHING you want about the URL, path, special characters, etc. in a handler, which you can also write in C/C++, etc. Handlers are in the .../handler folder under the IP:port path under the gwan folder. What you are asking about specifically is a form of URL-rewriting, and can be done in a handler via a simple string-replacement function (see the examples that come with G-WAN).
There are MANY examples of servlets in the .../csp folder, and several examples of handlers in the .../handler folder. Most likely you can choose among those and modify them to meet your needs.
FYI, typical naming convention used with G-WAN to disable something at a folder level is to precede it with '_' (e.g., _0.0.0.0:8080/...), and for an individual file to be disabled it is postfixed with '_' (e.g., hello.c_).
The G-WAN developers page has a Connection Handler URL-rewrite example that (I think) does what you want. The specific code to rewrite an incoming request URL (containing no "?") with a URL that references a specific G-WAN servlet (and contains the "?") looks like this:
See http://gwan.com/developers#tab2 for the complete example. You will need to create a similar Connection Handler (or just copy the example code and change to meet you needs), and then place that Handler code in the .../handlers path under the IP:port path under the gwan root folder.
Sorry I can't be more specific with a PHP example; I've done all my G-WAN work in C/C++ so far.