- if (script != NULL)
- *script = '\0'; /* reduce /PATH_INFO */
- /* SCRIPT_FILENAME required by PHP in CGI mode */
- if (realpath(purl + 1, realpath_buff))
- addEnv("SCRIPT", "FILENAME", realpath_buff);
- else
- *realpath_buff = 0;
- /* set SCRIPT_NAME as full path: /cgi-bin/dirs/script.cgi */
- addEnv("SCRIPT_NAME", "", purl);
- addEnv("QUERY_STRING", "", config->query);
- addEnv("SERVER", "SOFTWARE", httpdVersion);
- addEnv("SERVER", "PROTOCOL", "HTTP/1.0");
- addEnv("GATEWAY_INTERFACE", "", "CGI/1.1");
- addEnv("REMOTE", "ADDR", config->rmt_ip_str);
+ *script = '/'; /* is directory, find next '/' */
+ }
+ setenv1("PATH_INFO", script); /* set /PATH_INFO or "" */
+ setenv1("REQUEST_METHOD", request);
+ if (g_query) {
+ char *uri = alloca(strlen(purl) + 2 + strlen(g_query));
+ if (uri)
+ sprintf(uri, "%s?%s", purl, g_query);
+ setenv1("REQUEST_URI", uri);
+ } else {
+ setenv1("REQUEST_URI", purl);
+ }
+ if (script != NULL)
+ *script = '\0'; /* cut off /PATH_INFO */
+
+ /* SCRIPT_FILENAME required by PHP in CGI mode */
+ fullpath = concat_path_file(home_httpd, purl);
+ setenv1("SCRIPT_FILENAME", fullpath);
+ /* set SCRIPT_NAME as full path: /cgi-bin/dirs/script.cgi */
+ setenv1("SCRIPT_NAME", purl);
+ /* http://hoohoo.ncsa.uiuc.edu/cgi/env.html:
+ * QUERY_STRING: The information which follows the ? in the URL
+ * which referenced this script. This is the query information.
+ * It should not be decoded in any fashion. This variable
+ * should always be set when there is query information,
+ * regardless of command line decoding. */
+ /* (Older versions of bbox seem to do some decoding) */
+ setenv1("QUERY_STRING", g_query);
+ putenv((char*)"SERVER_SOFTWARE=busybox httpd/"BB_VER);
+ putenv((char*)"SERVER_PROTOCOL=HTTP/1.0");
+ putenv((char*)"GATEWAY_INTERFACE=CGI/1.1");
+ /* Having _separate_ variables for IP and port defeats
+ * the purpose of having socket abstraction. Which "port"
+ * are you using on Unix domain socket?
+ * IOW - REMOTE_PEER="1.2.3.4:56" makes much more sense.
+ * Oh well... */
+ {
+ char *p = rmt_ip_str ? : (char*)"";
+ char *cp = strrchr(p, ':');
+ if (ENABLE_FEATURE_IPV6 && cp && strchr(cp, ']'))
+ cp = NULL;
+ if (cp) *cp = '\0'; /* delete :PORT */
+ setenv1("REMOTE_ADDR", p);
+ if (cp) *cp = ':';
+ }