static void deleteStudy(llist entries) { CONDITION cond; char dbKey[64]; char studyUID[65]; IDB_Query study; strcpy(dbKey, cgi_val(entries, "DBKey")); strcpy(studyUID, cgi_val(entries, "StudyUID")); TBL_SetOption("OPEN_SPEEDUP"); cond = deleteOneStudy(dbKey, studyUID); selectArchive(entries); #if 0 cond = searchOneStudy(dbKey, studyUID, &study); html_header(); html_begin_body_options("CTN Archive: Study Management", "bgcolor=#ffffff"); printf("<table>\n"); printf("<TR><TH>Name: <TH>%s</TR>\n", study.patient.PatNam); printf("<TR><TH>Date of Birth: <TH>%s</TR>\n", study.patient.PatBirDat); printf("<TR><TH>Accession Number: <TH>%s</TR>\n", study.study.AccNum); printf("</table>\n"); #endif }
static void fileSelect(llist entries) { LST_HEAD* l; char topDirectory[1024]; char currentDirectory[1024]; char key[1024]; FILE_ENTRY* f; struct stat buf; int i; int flag = 0; strcpy(currentDirectory, cgi_val(entries, "CurrentDirectory")); strcpy(key, cgi_val(entries, "Key")); strcat(currentDirectory, "/"); strcat(currentDirectory, key); memset(&buf, 0, sizeof(buf)); #ifdef WIN32 i = _stat(currentDirectory, &buf); if (i == 0) { flag = ((buf.st_mode & _S_IFDIR) != 0); } #else i = stat(currentDirectory, &buf); if (i == 0) { flag = (S_ISDIR(buf.st_mode)); } #endif if (flag == 0) fileToHTML(currentDirectory); else directoryToHTML(currentDirectory); }
static void moveSeries(llist entries) { CONDITION cond; char dbKey[64] = ""; char studyUID[65] = ""; char seriesUID[65] = ""; char destinationApplication[17] = ""; char password[64] = ""; int i; long successes = 0; long warnings = 0; long failures = 0; void *timeStamp = 0; double deltaTime = 0; DMAN_HANDLE *controlHandle; strcpy(dbKey, cgi_val(entries, "DBKey")); strcpy(studyUID, cgi_val(entries, "StudyUID")); strcpy(seriesUID, cgi_val(entries, "SeriesUID")); strcpy(password, cgi_val(entries, "password")); strcpy(destinationApplication, cgi_val(entries, "DestinationApplication")); TBL_SetOption("OPEN_SPEEDUP"); html_header(); html_begin_body_options("CTN Archive: Move Series", "bgcolor=#ffffff"); printf("<pre>\n"); printf("DB Key: %s<br>\n", dbKey); printf("Study UID: %s<br>\n", studyUID); printf("Series UID: %s<br>\n", seriesUID); /*printf("Password: %s<br>\n", password);*/ printf("Destination: %s<br>\n", destinationApplication); timeStamp = UTL_GetTimeStamp(); cond = moveSeriesRequest(dbKey, studyUID, seriesUID, destinationApplication, &successes, &warnings, &failures); deltaTime = UTL_DeltaTime(timeStamp); UTL_ReleaseTimeStamp(timeStamp); printf("Successes: %d<br>\n", successes); printf("Warnings: %d<br>\n", warnings); printf("Failures: %d<br>\n", failures); printf("Xmit time: %8.2f seconds <br>\n", deltaTime); printf("</pre>\n"); logMoveRequest(dbKey, studyUID, seriesUID, destinationApplication, successes, warnings, failures); html_end(); }
short is_field_exists(llist l, char *str) { if (cgi_val(l,str) == NULL) return 0; else return 1; }
/* is_field_empty returns true either if the field exists but is empty or if the field does not exist. */ short is_field_empty(llist l, char *str) { char *temp = cgi_val(l,str); if ( (temp == NULL) || (!strcmp(temp,"")) ) return 1; else return 0; }
static void retrieveStudies(llist entries) { html_header(); html_begin_body_options("DICOM Study Search", "bgcolor=#ffffff"); printf("%s<p>\n", cgi_val(entries, "patientID")); html_end(); }
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"); printf("<p>a: %s</p>", cgi_val(entries,"a")); printf("<p>b: %s</p>", cgi_val(entries,"b")); printf("<p>c: %s</p>", cgi_val(entries,"c")); html_end(); list_clear(&entries); return 0; }
char* TLib_Cgi_Cookie(char *key) { char* p; TLib_Cgi_Init(); p = cgi_val(stTLib_Cookie_Entries,key); if(p == NULL) return ""; else return p; }
char *TLib_Cgi_Value(char *sParam) { char *p; TLib_Cgi_Init(); p = cgi_val(stTLib_Cgi_Entries, sParam); if (p == NULL) return ""; else return p; }
MString MCGIParser::getValue(const MString& key) { if (ptrLlist == 0) return ""; llist* p = (llist*) ptrLlist; char* keyChar = key.strData(); char* c = cgi_val(*p, keyChar); if (c == 0) c = ""; delete []keyChar; return c; }
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; }
static void localPatientSelect(llist entries) { LST_HEAD *studyList; DCM_OBJECT *dirFile; DDR_STUDY *studyNode; CONDITION cond; cond = DCM_OpenFile("/tmp/dicomdir", DCM_ORDERLITTLEENDIAN | DCM_PART10FILE, &dirFile); studyList = LST_Create(); cond = DDR_GetStudyList(&dirFile, cgi_val(entries, "patientID"), &studyList); html_header(); html_begin_body_options("DICOM Study Search", "bgcolor=#ffffff"); studyNode = LST_Dequeue(&studyList); printf("<tt>\n"); while(studyNode != NULL) { printf("%s %s %s %s <br>\n", studyNode->StudyDate, studyNode->AccessionNumber, studyNode->StudyID, studyNode->StudyDescription); free(studyNode); studyNode = LST_Dequeue(&studyList); } printf("</tt>\n"); html_end(); DCM_CloseObject(&dirFile); }
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; }
static void selectSeries(llist entries) { CONDITION cond; char dbKey[64]; char studyUID[65]; char seriesUID[65]; IDB_Query series; QUERY_LIST_ITEM *item; IDB_InstanceListElement *instancePtr; unsigned long byteCount = 0; char password[64]; DMAN_HANDLE *controlHandle; LST_HEAD *destinationList; openCTN(&controlHandle); strcpy(dbKey, cgi_val(entries, "DBKey")); strcpy(studyUID, cgi_val(entries, "StudyUID")); strcpy(seriesUID, cgi_val(entries, "SeriesUID")); strcpy(password, cgi_val(entries, "password")); TBL_SetOption("OPEN_SPEEDUP"); cond = searchOneSeries(dbKey, studyUID, seriesUID, &series); html_header(); html_begin_body_options("CTN Archive: Series Management", "bgcolor=#ffffff"); printf("<table>\n"); printf("<TR><TH align=right>Name: <TH align=left>%s</TR>\n", series.patient.PatNam); printf("<TR><TH align=right>Date of Birth: <TH align=left>%s</TR>\n", series.patient.PatBirDat); printf("<TR><TH align=right>Series Number: <TH align=left>%s</TR>\n", series.series.SerNum); printf("<TR><TH align=right>Image Count: <TH align=left>%d</TR>\n", series.series.NumSerRelIma); printf("</table>\n"); printf("<form method=GET action=""archive_agent.cgi"">\n"); printf("<input type=hidden name=DBKey value=%s>\n", dbKey); printf("<input type=hidden name=StudyUID value=%s>\n", studyUID); printf("<input type=hidden name=SeriesUID value=%s>\n", seriesUID); printf("<input type=hidden name=password value=%s>\n", password); { DMAN_VIDEOIMAGEDEST *video; destinationList = LST_Create(); cond = listOfDestinations(&controlHandle, destinationList); printf("<select name=DestinationApplication size=10>\n"); video = LST_Dequeue(&destinationList); while (video != NULL) { /*char tmp[1024];*/ DMAN_APPLICATIONENTITY ae; memset(&ae, 0, sizeof(ae)); ae.Type = DMAN_K_APPLICATIONENTITY; DMAN_LookupApplication(&controlHandle, video->RespondingTitle, &ae); /*sprintf(tmp, "%17s %s", ae.Title, ae.Title, ae.Node, ae.Comment);*/ printf("<option value=""%s"">%16s %15s %d %s\n", /* ae.Title,*/ video->RespondingTitle, ae.Title, ae.Node, ae.Port, ae.Comment); free(video); video = LST_Dequeue(&destinationList); } printf("</select>\n"); } LST_Destroy(&destinationList); printf("<br>\n"); printf("<input type=submit value=""MoveSeries"" name=submitSearch>\n"); printf("</form>\n"); html_end(); }
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; }
static void selectStudy(llist entries) { CONDITION cond; char dbKey[64]; char studyUID[65]; IDB_Query study; LST_HEAD *imageList; LST_HEAD *seriesList; QUERY_LIST_ITEM *item; IDB_InstanceListElement *instancePtr; unsigned long byteCount = 0; char password[64]; strcpy(dbKey, cgi_val(entries, "DBKey")); strcpy(studyUID, cgi_val(entries, "StudyUID")); strcpy(password, cgi_val(entries, "password")); TBL_SetOption("OPEN_SPEEDUP"); cond = searchOneStudy(dbKey, studyUID, &study); imageList = LST_Create(); seriesList = LST_Create(); cond = searchImages(dbKey, studyUID, imageList); while ((item = LST_Dequeue(&imageList)) != NULL) { instancePtr = LST_Dequeue(&(item->query.image.InstanceList)); if (instancePtr != NULL) byteCount += instancePtr->Size; #if 0 while (instancePtr != NULL) { free(instancePtr); instancePtr = LST_Dequeue(&(item->query.image.InstanceList)); } free(item); #endif } html_header(); html_begin_body_options("CTN Archive: Study Management", "bgcolor=#ffffff"); printf("<table>\n"); printf("<TR><TH>Name: <TH>%s</TR>\n", study.patient.PatNam); printf("<TR><TH>Date of Birth: <TH>%s</TR>\n", study.patient.PatBirDat); printf("<TR><TH>Accession Number: <TH>%s</TR>\n", study.study.AccNum); printf("<TR><TH>Study Date: <TH>%s</TR>\n", study.study.StuDat); printf("<TR><TH>Study Description: <TH>%s</TR>\n", study.study.StuDes); printf("<TR><TH>Series: <TH>%d</TR>\n", study.study.NumStuRelSer); printf("<TR><TH>Images: <TH>%d</TR>\n", study.study.NumStuRelIma); printf("<TR><TH>Image Volume: <TH>%d bytes</TR>\n", byteCount); printf("</table>\n"); printf("<form method=GET action=""archive_agent.cgi"">\n"); printf("<input type=hidden name=DBKey value=%s>\n", dbKey); printf("<input type=hidden name=StudyUID value=%s>\n", studyUID); /*********/ printf("<pre>\n"); cond = searchSeries(dbKey, studyUID, seriesList); item = LST_Dequeue(&seriesList); printf("%-10s %6s %15s %15s %15s <br>", "Series #", "Images", "Proc Name", "Series Des", "Body Part"); while(item != NULL) { char tmp[1024]; sprintf(tmp, "%-10s %6d %15s %15s %15s", item->query.series.SerNum, item->query.series.NumSerRelIma, item->query.series.ProNam, item->query.series.SerDes, item->query.series.BodParExa); printf( "<a href=""/cgi-bin/archive_agent.cgi?submitSearch=%s&DBKey=%s&\ password=%s&StudyUID=%s&SeriesUID=%s"">%s</a>\n", "SeriesSelect", dbKey, password, studyUID, item->query.series.SerInsUID, tmp); free(item); item = LST_Dequeue(&seriesList); } printf("</pre>\n"); /**********/ if (strcmp(password, "READONLY") != 0) { printf("<input type=submit value=""Delete_Study"" name=submitSearch>\n"); } printf("</form>\n"); html_end(); }
static void selectArchive(llist entries) { CONDITION cond; LST_HEAD *studyList; char dbKey[64]; QUERY_LIST_ITEM *item; IDB_Limits limits; char password[64]; int flag = 0; studyList = LST_Create(); strcpy(dbKey, cgi_val(entries, "DBKey")); strcpy(password, cgi_val(entries, "password")); TBL_SetOption("OPEN_SPEEDUP"); cond = listOfStudies(dbKey, studyList); orderStudyListByName(studyList); flag = passwordCompare(dbKey, password); if (flag == 0) strcpy(password, "READONLY"); memset(&limits, 0, sizeof(limits)); cond = dbLimits(dbKey, &limits); html_header(); html_begin_body_options("CTN Archive: List of Studies", "bgcolor=#ffffff"); if (flag == 0) { printf("Read only access granted <br>\n"); } printf("CTN Archive: %s <br> \n", dbKey); { char *remoteUser; remoteUser = getenv("REMOTE_USER"); if (remoteUser == NULL) remoteUser = "******"; printf("Remote user: %s<br>\n", remoteUser); } printf("%d patients, %d studies, %d images <br>\n", limits.PatientCount, limits.StudyCount, limits.ImageCount); printf("DB Size/Limits (MB): %d/%d<br>\n", limits.DBSize/1000000, limits.DBLimit); #if 0 printf("%d studies <br><br>\n", LST_Count(&studyList)); #endif printf("<pre>\n"); item = LST_Dequeue(&studyList); while(item != NULL) { char tmp[1024]; sprintf(tmp, "%-30s %8s (%2d series) %-32s", item->query.patient.PatNam, item->query.study.StuDat, item->query.study.NumStuRelSer, item->query.study.StuDes); #if 0 printf("<a href=""/cgi-bin/archive_agent.cgi?submitSearch=%s&DBKey=%s&StudyUID=%s"">%s</a><br>\n", #endif printf( "<a href=""/cgi-bin/archive_agent.cgi?submitSearch=%s&DBKey=%s&\ password=%s&StudyUID=%s"">%s</a>\n", "StudySelect", dbKey, password, item->query.study.StuInsUID, tmp); free(item); item = LST_Dequeue(&studyList); } printf("</pre>\n"); LST_Destroy(&studyList); html_end(); }