6f3056fb1c519aeb262d6c1cc9f352652e3086ae max Mon May 27 07:49:54 2024 -0700 not setting pix if run from command line, email from Lou that qa scripts are not running anymore diff --git src/lib/cheapcgi.c src/lib/cheapcgi.c index bcbfa18..f8f27aa 100644 --- src/lib/cheapcgi.c +++ src/lib/cheapcgi.c @@ -245,35 +245,38 @@ void dumpCookieList() /* Print out the cookie list. */ { struct cgiVar *v; for (v=cookieList; v != NULL; v = v->next) printf("%s=%s (%d)\n", v->name, v->val, v->saved); } void useTempFile() /* tell cheapcgi to use temp files */ { doUseTempFile = TRUE; } boolean cgiIsOnWeb() -/* Return TRUE if looks like we're being run as a CGI. */ +/* Return TRUE if looks like we're being run as a CGI. + * You cannot use this in your own CGIs to determine if you're run from the command line, + * as cgiFromCommandLine() will set this parameter.*/ { return getenv("REQUEST_METHOD") != NULL; } + char *cgiRequestMethod() /* Return CGI REQUEST_METHOD (such as 'GET/POST/PUT/DELETE/HEAD') */ { return getenv("REQUEST_METHOD"); } char *cgiRequestUri() /* Return CGI REQUEST_URI */ { return getenv("REQUEST_URI"); } char *cgiRequestContentLength() /* Return HTTP REQUEST CONTENT_LENGTH if available*/ { @@ -2508,59 +2511,64 @@ dyStringAppend(dy, var); dyStringAppendC(dy, '='); char *s = cgiEncode(val); dyStringAppend(dy, s); freez(&s); } void cgiContinueAllVars() /* Write back all CGI vars as hidden input for next time around. */ { struct cgiVar *cv; for (cv = inputList; cv != NULL; cv = cv->next) cgiMakeHiddenVar(cv->name, cv->val); } +// flag to keep track if the current process was run from the command line (true) or not (false) +static boolean wasSpoofed = FALSE; boolean cgiFromCommandLine(int *pArgc, char *argv[], boolean preferWeb) /* Use the command line to set up things as if we were a CGI program. * User types in command line (assuming your program called cgiScript) * like: * cgiScript nonCgiArg1 var1=value1 var2=value2 var3=value3 nonCgiArg2 * or like * cgiScript nonCgiArg1 var1=value1&var2=value2&var3=value3 nonCgiArg2 * or even like * cgiScript nonCgiArg1 -x -y=bogus z=really * (The non-cgi arguments can occur anywhere. The cgi arguments (all containing * the character '=' or starting with '-') are erased from argc/argv. Normally * you call this cgiSpoof(&argc, argv); */ { int argc = *pArgc; int i; int argcLeft = argc; char *name; static char queryString[65536]; char *q = queryString; boolean needAnd = TRUE; boolean gotAny = FALSE; boolean startDash; boolean gotEq; static char hostLine[512]; if (preferWeb && cgiIsOnWeb()) return TRUE; /* No spoofing required! */ + +wasSpoofed = TRUE; + q += safef(q, queryString + sizeof(queryString) - q, "%s", "QUERY_STRING=cgiSpoof=on"); for (i=0; i= maxArgc) { ExpandArray(argv, maxArgc, 2*maxArgc); maxArgc *= 2; } /* Fill in another argument to our psuedo arguments. */ argv[argc++] = cloneString(line); } spoof = cgiSpoof(&argc, argv); /* Cleanup. */ lineFileClose(&lf); for(i=0; i