void TLib_Cgi_Init(void) { if (iTLib_Cgi_Initialized != 0) { return; } list_create(&stTLib_Cgi_Entries); list_create(&stTLib_Cookie_Entries); iTLib_Cgi_Initialized = 1; read_cgi_input(&stTLib_Cgi_Entries); parse_cookies(&stTLib_Cookie_Entries); }
int main() { llist entries; int status; html_header(); html_begin("Query Results"); status = read_cgi_input(&entries); printf("<h1>Status = %d</h1>\n",status); h1("Query results"); print_entries(entries); html_end(); list_clear(&entries); return 0; }
int main() { llist entries; int status; html_header(); html_begin("Test CGI"); h1("CGI Test Program"); printf("<hr>\n"); h2("CGI Environment Variables"); print_cgi_env(); status = read_cgi_input(&entries); printf("<h2>Status = %d</h2>\n",status); h2("CGI Entries"); print_entries(entries); html_end(); list_clear(&entries); return 0; }
int main() { llist entries; int status; char *form; status = read_cgi_input(&entries); form = cgi_val(entries, "submitSearch"); if (strcmp(form, "View") == 0) view(entries); else if (strcmp(form, "FileSelect") == 0) fileSelect(entries); else { html_header(); html_begin_body_options("Query Results", "bgcolor=#ffffff"); printf("<h1>Status = %d</h1>\n",status); h1("Query results"); print_entries(entries); html_end(); } list_clear(&entries); return 0; }
/** Needs nargs to be at least 2 for GC roots. * * JS method returns true if values were read. */ static JSBool query_readQuery(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { extern cfgHnd cfg; query_private_t *hnd = JS_GetPrivate(cx, obj); node *n; JSString *str; int retval; jsrefcount depth; jsval val; if (hnd->query) return gpsee_throw(cx, OBJECT_ID ".readQuery.alreadyRead"); else hnd->query = JS_malloc(cx, sizeof(*hnd->query)); if (argc > 0) { str = JS_ValueToString(cx, argv[0]); hnd->uploadDir = JS_strdup(cx, JS_GetStringBytes(str)); } else hnd->uploadDir = cfg_value(cfg, OBJECT_ID ".default_upload_dir"); /* fix this later by making upload files == /dev/null in libcgihtml.so when upload dir is null */ if (!hnd->uploadDir) gpsee_log(cx, GLOG_NOTICE, "Unspecified upload dir is a security problem! Specify rc." OBJECT_ID ".default_upload_dir!"); depth = JS_SuspendRequest(cx); retval = read_cgi_input(cx, hnd->query, hnd->uploadDir); JS_ResumeRequest(cx, depth); *rval = retval ? JSVAL_TRUE : JSVAL_FALSE; for (n = hnd->query->head; n; n = n->next) { /* temporary fix? we don't want to overwrite our module readQuery() member */ if (!n->entry.name || !strcmp(n->entry.name,"readQuery")) continue; if (n->entry.value == NULL) n->entry.value = strdup(""); /* Match eekim's horrible semantics */ /* later optimization note: almost all of the cases where we'd need to * create arrays instead of strings are also cases where the CGI * variables of the same name are adjacent in the query */ if ((JS_GetProperty(cx, obj, n->entry.name, &val) == JS_TRUE) && (!JSVAL_IS_VOID(val))) { /* Already seen a CGI variable with this name */ if (JSVAL_IS_STRING(val)) /* Only seen one, create a new array */ { argv[0] = val; argv[1] = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, n->entry.value)); argv[0] = OBJECT_TO_JSVAL(JS_NewArrayObject(cx, 2, argv)); if (JS_SetProperty(cx, obj, n->entry.name, argv + 0) == JS_FALSE) return gpsee_throw(cx, OBJECT_ID ".readQuery.property.recreate.%s", n->entry.name); } else { jsuint length; /* seen many: append to the array */ if (JS_IsArrayObject(cx, JSVAL_TO_OBJECT(val)) != JS_TRUE) return gpsee_throw(cx, OBJECT_ID ".readQuery.property.type.%s", n->entry.name); if (JS_GetArrayLength(cx, JSVAL_TO_OBJECT(val), &length) != JS_TRUE) return gpsee_throw(cx, OBJECT_ID ".readQuery.property.%s.length.get", n->entry.name); if (JS_DefineElement(cx, JSVAL_TO_OBJECT(val), length, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, n->entry.value)), JS_PropertyStub, JS_PropertyStub, JSPROP_ENUMERATE) != JS_TRUE) return gpsee_throw(cx, OBJECT_ID ".readQuery.property.%s.element.%u", n->entry.name, length); if (JS_SetArrayLength(cx, JSVAL_TO_OBJECT(val), length + 1) != JS_TRUE) return gpsee_throw(cx, OBJECT_ID ".readQuery.property.%s.length.set", n->entry.name); } } else { /* First time for this property, insert it as a string */ argv[0] = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, n->entry.value)); if (JS_SetProperty(cx, obj, n->entry.name, argv + 0) == JS_FALSE) return gpsee_throw(cx, OBJECT_ID ".readQuery.property.create.%s", n->entry.name); } } return JS_TRUE; }
int main() { LIST_STRU entries; LIST_STRU configs; char *configname = "simple-webmail.conf"; FILE *mail; char *dest,*name,*from,*subject,*content; char command[256]; html_header(); read_cgi_input(&entries); read_configs(&configs,configname); if( (is_field_empty(entries,"name")) && (is_field_empty(entries,"from")) && (is_field_empty(entries,"subject")) && (is_field_empty(entries,"content")) ) { printf("重新输入!"); } else { if (is_field_empty(entries,"to")) dest = strdup(TO); else dest = strdup(cgi_val(entries,"to")); if (!xstrcmp("*@*.*",dest)) { printf("收件人 %s 不是标准的邮件格式 *@*.*\n",dest); exit(-1); } name = strdup(cgi_val(entries,"name")); from = strdup(cgi_val(entries,"from")); subject = strdup(cgi_val(entries,"subject")); if (dest[0] == '\0') strcpy(dest,WEBADMIN); sprintf(command,"%s %s",SENDMAIL,dest); mail = popen(command,"w"); if (mail == NULL) { html_begin("系统出错!"); printf("系统出错!"); printf("请发信给 %s 。 \r\n",WEBADMIN); printf("<hr>\r\n简单WEB邮件发送程序 v 0.1 . 作者: "); printf("<i>%s</i>.\r\n",WEBADMIN); exit(-1); html_end(); } else { content = strdup(cgi_val(entries,"content")); fprintf(mail,"From: %s (%s)\n",from,name); fprintf(mail,"Subject: %s\n",subject); fprintf(mail,"To: %s\n",dest); fprintf(mail,"X-Sender: %s\n\n",WEBADMIN); if (REMOTE_ADDR != NULL) fprintf(mail,"发送者 IP 地址 %s\n",REMOTE_ADDR); // 增加 http 代理 相关环境变量,可判断是否有代理服务器,可显示出非匿名代理的源地址 2003.08.17 if (HTTP_X_FORWARDED_FOR != NULL) fprintf(mail,"经过代理前IP地址 %s\n",HTTP_X_FORWARDED_FOR); if (HTTP_CLIENT_IP != NULL) fprintf(mail,"代理服务器地址 %s\n",HTTP_CLIENT_IP); fprintf(mail,"%s\n\n",content); pclose(mail); html_begin("邮件发送成功"); printf("邮件发送成功"); printf("你发送了以下的信息:\r\n<pre>\r\n"); printf("收信人: %s \r\n",dest); printf("发信人: %s (%s)\r\n",from,name); printf("标 题: %s\r\n\r\n",subject); printf("%s\r\n</pre>\r\n",content); if (REMOTE_ADDR != NULL) printf("发送者 IP 地址 %s<br>\n",REMOTE_ADDR); // 增加 http 代理 相关环境变量,可判断是否有代理服务器,可显示出非匿名代理的源地址 2003.08.17 if (HTTP_X_FORWARDED_FOR != NULL) printf("经过代理前IP地址 %s<br>\n",HTTP_X_FORWARDED_FOR); if (HTTP_CLIENT_IP != NULL) printf("代理服务器地址 %s<br>\n",HTTP_CLIENT_IP); printf("谢谢使用!<p>\r\n"); printf("<hr>\r\n简单WEB邮件发送程序 v 0.1 . 作者: "); printf("<i>%s</i>.\r\n",WEBADMIN); html_end(); } } list_clear(&entries); list_clear(&configs); return 0; }
int main() { llist entries; int status; char error[128]; mime_header("application/json"); fflush(stdout); obj = json_object_new_object(); status = read_cgi_input(&entries); char *act = cgi_val(entries, "act"); if (!act) { sprintf(error, "%s", "act required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } if (STRCMP(act, "apply_ping")) apply_ping(); char *dev = cgi_val(entries, "dev"); if (!dev) { sprintf(error, "%s", "dev required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int dev_num = atoi(dev); if (dev_num < 0 || dev_num >= MAX_DEV_NUM) { sprintf(error, "dev_num(%d) out of reange!", dev_num); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } if (STRCMP(act, "apply_on")) apply_on(dev_num); if (STRCMP(act, "apply_off")) apply_off(dev_num); if (STRCMP(act, "apply_query")) apply_query(dev_num); if (STRCMP(act, "apply_delay")) { char *delay = cgi_val(entries, "delay"); if (!delay) { sprintf(error, "%s", "delay required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } apply_delay(dev_num, atoi(delay)); } if (STRCMP(act, "apply_time")) { char *year = cgi_val(entries, "year"); if (!year) { sprintf(error, "%s", "year required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _year = atoi(year); char *month = cgi_val(entries, "month"); if (!month) { sprintf(error, "%s", "month required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _month = atoi(month); char *day = cgi_val(entries, "day"); if (!day) { sprintf(error, "%s", "day required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _day = atoi(day); char *hour = cgi_val(entries, "hour"); if (!hour) { sprintf(error, "%s", "hour required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _hour = atoi(hour); char *minute = cgi_val(entries, "minute"); if (!minute) { sprintf(error, "%s", "minute required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _minute = atoi(minute); char *second = cgi_val(entries, "second"); if (!second) { sprintf(error, "%s", "second required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _second = atoi(second); apply_time(dev_num, _year, _month, _day, _hour, _minute, _second); } if (STRCMP(act, "apply_schedule")) { char *index = cgi_val(entries, "index"); if (!index) { sprintf(error, "%s", "index required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _index = atoi(index); char *hour_start = cgi_val(entries, "hour_start"); if (!hour_start) { sprintf(error, "%s", "hour_start required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _hour_start = atoi(hour_start); char *minute_start = cgi_val(entries, "minute_start"); if (!minute_start) { sprintf(error, "%s", "minute_start required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _minute_start = atoi(minute_start); char *hour_end = cgi_val(entries, "hour_end"); if (!hour_end) { sprintf(error, "%s", "hour_end required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _hour_end = atoi(hour_end); char *minute_end = cgi_val(entries, "minute_end"); if (!minute_end) { sprintf(error, "%s", "minute_end required!"); json_object_object_add(obj, "error", json_object_new_string(error)); goto end; } int _minute_end = atoi(minute_end); apply_schedule(dev_num, _index, _hour_start, _minute_start, _hour_end, _minute_end); } if (STRCMP(act, "get_status")) get_status(dev_num); sprintf(error, "act(%s) not support!", act); json_object_object_add(obj, "error", json_object_new_string(error)); end: printf("%s", json_object_to_json_string(obj)); json_object_put(obj); return 0; }
int main() { llist entries; FILE *mail; char command[256] = "/usr/lib/sendmail "; char *dest,*name,*email,*subject,*content; html_header(); read_cgi_input(&entries); if ( !strcmp("",cgi_val(entries,"name")) && !strcmp("",cgi_val(entries,"email")) && !strcmp("",cgi_val(entries,"subject")) && !strcmp("",cgi_val(entries,"content")) ) NullForm(); else { if (is_field_empty(entries,"to")) dest = newstr(WEBADMIN); else dest = newstr(cgi_val(entries,"to")); name = newstr(cgi_val(entries,"name")); email = newstr(cgi_val(entries,"email")); subject = newstr(cgi_val(entries,"subject")); if (dest[0]=='\0') strcpy(dest,WEBADMIN); else authenticate(dest); /* no need to escape_input() on dest, since we assume there aren't insecure entries in the authentication file. */ strcat(command,dest); mail = popen(command,"w"); if (mail == NULL) { html_begin("System Error!"); h1("System Error!"); printf("Please mail %s and inform\r\n",WEBADMIN); printf("the web maintainers that the comments script is improperly\r\n"); printf("configured. We apologize for the inconvenience<p>\r\n"); printf("<hr>\r\nWeb page created on the fly by "); printf("<i>%s</i>.\r\n",WEBADMIN); html_end(); } else { content = newstr(cgi_val(entries,"content")); fprintf(mail,"From: %s (%s)\n",email,name); fprintf(mail,"Subject: %s\n",subject); fprintf(mail,"To: %s\n",dest); fprintf(mail,"X-Sender: %s\n\n",WEBADMIN); fprintf(mail,"%s\n\n",content); pclose(mail); html_begin("Comment Submitted"); h1("Comment Submitted"); printf("You submitted the following comment:\r\n<pre>\r\n"); printf("From: %s (%s)\r\n",email,name); printf("Subject: %s\r\n\r\n",subject); printf("%s\r\n</pre>\r\n",content); printf("Thanks again for your comments.<p>\r\n"); printf("<hr>\r\nWeb page created on the fly by "); printf("<i>%s</i>.\r\n",WEBADMIN); html_end(); } } list_clear(&entries); return 0; }