int process_cgivars(void) { char **variables; int error = FALSE; int x; variables = getcgivars(); for (x = 0; variables[x] != NULL; x++) { /* do some basic length checking on the variable identifier to prevent buffer overflows */ if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) continue; /* we found the service severity divisor option */ if (!strcmp(variables[x], "service_divisor")) { x++; if (variables[x] == NULL) { error = TRUE; break; } service_severity_divisor = atoi(variables[x]); if (service_severity_divisor < 1) service_severity_divisor = 1; } /* we found the CSV output option */ else if (!strcmp(variables[x], "csvoutput")) { display_header = FALSE; content_type = CSV_CONTENT; } else if (!strcmp(variables[x], "jsonoutput")) { display_header = FALSE; content_type = JSON_CONTENT; } /* we found the embed option */ else if (!strcmp(variables[x], "embedded")) embedded = TRUE; /* we found the noheader option */ else if (!strcmp(variables[x], "noheader")) display_header = FALSE; /* we found the pause option */ else if (!strcmp(variables[x], "paused")) refresh = FALSE; /* we found the nodaemoncheck option */ else if (!strcmp(variables[x], "nodaemoncheck")) daemon_check = FALSE; } /* free memory allocated to the CGI variables */ free_cgivars(variables); return error; }
int process_cgivars(void) { char **variables; int error = FALSE; int x; variables = getcgivars(); for(x = 0; variables[x] != NULL; x++) { /* do some basic length checking on the variable identifier to prevent buffer overflows */ if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { continue; } /* we found the archive argument */ else if(!strcmp(variables[x], "archive")) { x++; if(variables[x] == NULL) { error = TRUE; break; } log_archive = atoi(variables[x]); if(log_archive < 0) log_archive = 0; } /* we found the order argument */ else if(!strcmp(variables[x], "oldestfirst")) { use_lifo = FALSE; } /* we found the embed option */ else if(!strcmp(variables[x], "embedded")) embedded = TRUE; /* we found the noheader option */ else if(!strcmp(variables[x], "noheader")) display_header = FALSE; /* we found the nofrills option */ else if(!strcmp(variables[x], "nofrills")) display_frills = FALSE; /* we found the notimebreaks option */ else if(!strcmp(variables[x], "notimebreaks")) display_timebreaks = FALSE; /* we received an invalid argument */ else error = TRUE; } /* free memory allocated to the CGI variables */ free_cgivars(variables); return error; }
int main() { char **cgivars; int i; char *action_event; int pid; char *action_name; char *process_filename; /** First, get the CGI variables into a list of strings **/ cgivars = getcgivars(); action_event = (char *) getvalue("action_event", cgivars); pid = atoi((char *) getvalue("pid", cgivars)); action_name = (char *) getvalue("act_name", cgivars); process_filename = get_process_filename(); peos_set_process_table_file(process_filename); peos_set_loginname(process_filename); if(strcmp(action_event, "Abort") == 0) { peos_notify(pid, action_name, PEOS_EVENT_ABORT); printf("Location: active_processes.cgi?action=continue\r\n\r\n"); } if(strcmp(action_event, "Suspend") == 0) { peos_notify(pid, action_name, PEOS_EVENT_SUSPEND); printf("Location: active_processes.cgi?action=continue\r\n\r\n"); } if(strcmp(action_event, "Run") == 0) { printf("Location: action_page.cgi?resource_type=requires&pid=%d&action_name=%s\r\n\r\n", pid, action_name); } if(strcmp(action_event, "Finish") == 0) { printf("Location: action_page.cgi?resource_type=provides&pid=%d&action_name=%s\r\n\r\n", pid, action_name); } /** Free anything that needs to be freed **/ for (i=0; cgivars[i]; i++) free(cgivars[i]) ; free(cgivars) ; exit(0) ; }
static int process_cgivars(void) { char **variables; int error = FALSE; int x; variables = getcgivars(); for(x = 0; variables[x] != NULL; x++) { /* do some basic length checking on the variable identifier to prevent buffer overflows */ if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { x++; continue; } } return error; }
int main (int argc, char **argv) { int i; char *dims; char isCGI=0; char **cgivars; if (argc > 1) { cgivars = getCLIvars(argc,argv); } else { cgivars = getcgivars(); if (cgivars) isCGI = 1; } if (!cgivars) { usage(argc,argv); exit (-1); } dims = get_param (cgivars,"Dims"); if (!dims) { fprintf (stderr,"Dims parameter not set.\n"); usage(argc,argv); exit (-1); } if (isCGI) fprintf (stdout,"Content-type: text/plain\n\n"); fprintf (stdout,"Wave\tTime\tMin\tMax\tMean\tGeoMean\tSigma\tCentroid_x\tCentroid_y\tCentroid_z\tGeoSigma\n"); /* This dumps stuff directly on stdout */ Get_Image_Stats (dims); for(i=0; cgivars[i]; i++) free (cgivars[i]); free (cgivars); return (0); }
void process_cgivars(void) { char *key = NULL; char *value = NULL; html_request *temp_request_item = NULL; html_request_list = getcgivars(); for (temp_request_item = html_request_list; temp_request_item != NULL; temp_request_item = temp_request_item->next) { key = temp_request_item->option; value = temp_request_item->value; /* we found the service severity divisor option */ if (!strcmp(key, "service_divisor") && value != NULL) { service_severity_divisor = atoi(value); if (service_severity_divisor < 1) service_severity_divisor = 1; temp_request_item->is_valid = TRUE; } /* we found the CSV output option */ else if (!strcmp(key, "csvoutput")) { display_header = FALSE; content_type = CSV_CONTENT; temp_request_item->is_valid = TRUE; my_free(temp_request_item->value); } else if (!strcmp(key, "jsonoutput")) { display_header = FALSE; content_type = JSON_CONTENT; temp_request_item->is_valid = TRUE; my_free(temp_request_item->value); } /* we found the embed option */ else if (!strcmp(key, "embedded")) { embedded = TRUE; temp_request_item->is_valid = TRUE; my_free(temp_request_item->value); } /* we found the noheader option */ else if (!strcmp(key, "noheader")) { display_header = FALSE; temp_request_item->is_valid = TRUE; my_free(temp_request_item->value); } /* we found the pause option */ else if (!strcmp(key, "paused")) { refresh = FALSE; temp_request_item->is_valid = TRUE; my_free(temp_request_item->value); } /* we found the nodaemoncheck option */ else if (!strcmp(key, "nodaemoncheck")) { daemon_check = FALSE; temp_request_item->is_valid = TRUE; my_free(temp_request_item->value); } } return; }
int process_cgivars(void) { char **variables; char *key = NULL; char *value = NULL; int error = FALSE; int x; variables = getcgivars(); for (x = 0; variables[x] != NULL; x+=2) { key = variables[x]; value = variables[x+1]; /* do some basic length checking on the variable identifier to prevent buffer overflows */ if (strlen(key) >= MAX_INPUT_BUFFER - 1) { error = TRUE; break; } /* likewise, check the value if it exists */ if (value != NULL) if (strlen(value) >= MAX_INPUT_BUFFER - 1) { error = TRUE; break; } /* we found the host argument */ if (!strcmp(key, "host")) { query_type = DISPLAY_HOSTS; if (value == NULL) { error = TRUE; break; } if ((query_host_name = strdup(value)) == NULL) query_host_name = ""; strip_html_brackets(query_host_name); if (!strcmp(query_host_name, "all")) find_all = TRUE; else find_all = FALSE; } /* we found the contact argument */ else if (!strcmp(key, "contact")) { query_type = DISPLAY_CONTACTS; if (value == NULL) { error = TRUE; break; } if ((query_contact_name = strdup(value)) == NULL) query_contact_name = ""; strip_html_brackets(query_contact_name); if (!strcmp(query_contact_name, "all")) find_all = TRUE; else find_all = FALSE; } /* we found the service argument */ else if (!strcmp(key, "service")) { query_type = DISPLAY_SERVICES; if (value == NULL) { error = TRUE; break; } if ((query_svc_description = strdup(value)) == NULL) query_svc_description = ""; strip_html_brackets(query_svc_description); } /* we found the hostgroup argument */ else if (!strcmp(key, "hostgroup")) { query_type = DISPLAY_HOSTGROUPS; if (value == NULL) { error = TRUE; break; } if ((query_hostgroup_name = strdup(value)) == NULL) query_hostgroup_name = ""; strip_html_brackets(query_hostgroup_name); } /* we found the servicegroup argument */ else if (!strcmp(key, "servicegroup")) { query_type = DISPLAY_SERVICEGROUPS; if (value == NULL) { error = TRUE; break; } if ((query_servicegroup_name = strdup(value)) == NULL) query_servicegroup_name = ""; strip_html_brackets(query_servicegroup_name); } /* we found the notification type argument */ else if (!strcmp(key, "type")) { if (value == NULL) { error = TRUE; break; } notification_options = atoi(value); } /* we found first time argument */ else if (!strcmp(key, "ts_start")) { if (value == NULL) { error = TRUE; break; } ts_start = (time_t)strtoul(value, NULL, 10); } /* we found last time argument */ else if (!strcmp(key, "ts_end")) { if (value == NULL) { error = TRUE; break; } ts_end = (time_t)strtoul(value, NULL, 10); } /* we found the start time */ else if (!strcmp(key, "start_time")) { if (value == NULL) { error = TRUE; break; } start_time_string = (char *)malloc(strlen(value) + 1); if (start_time_string == NULL) start_time_string = ""; else strcpy(start_time_string, value); } /* we found the end time */ else if (!strcmp(key, "end_time")) { if (value == NULL) { error = TRUE; break; } end_time_string = (char *)malloc(strlen(value) + 1); if (end_time_string == NULL) end_time_string = ""; else strcpy(end_time_string, value); } /* we found the standard timeperiod argument */ else if (!strcmp(key, "timeperiod")) { if (value == NULL) { error = TRUE; break; } if (!strcmp(value, "today")) timeperiod_type = TIMEPERIOD_TODAY; else if (!strcmp(value, "singelday")) timeperiod_type = TIMEPERIOD_SINGLE_DAY; else if (!strcmp(value, "last24hours")) timeperiod_type = TIMEPERIOD_LAST24HOURS; else if (!strcmp(value, "thisweek")) timeperiod_type = TIMEPERIOD_THISWEEK; else if (!strcmp(value, "lastweek")) timeperiod_type = TIMEPERIOD_LASTWEEK; else if (!strcmp(value, "thismonth")) timeperiod_type = TIMEPERIOD_THISMONTH; else if (!strcmp(value, "lastmonth")) timeperiod_type = TIMEPERIOD_LASTMONTH; else if (!strcmp(value, "thisyear")) timeperiod_type = TIMEPERIOD_THISYEAR; else if (!strcmp(value, "lastyear")) timeperiod_type = TIMEPERIOD_LASTYEAR; else if (!strcmp(value, "last7days")) timeperiod_type = TIMEPERIOD_LAST7DAYS; else if (!strcmp(value, "last31days")) timeperiod_type = TIMEPERIOD_LAST31DAYS; else if (!strcmp(value, "custom")) timeperiod_type = TIMEPERIOD_CUSTOM; else continue; convert_timeperiod_to_times(timeperiod_type, &ts_start, &ts_end); } /* we found the order argument */ else if (!strcmp(key, "order")) { if (value == NULL) { error = TRUE; break; } if (!strcmp(value, "new2old")) reverse = FALSE; else if (!strcmp(value, "old2new")) reverse = TRUE; } /* we found the CSV output option */ else if (!strcmp(key, "csvoutput")) { display_header = FALSE; content_type = CSV_CONTENT; } /* we found the JSON output option */ else if (!strcmp(key, "jsonoutput")) { display_header = FALSE; content_type = JSON_CONTENT; } /* we found the embed option */ else if (!strcmp(key, "embedded")) embedded = TRUE; /* we found the noheader option */ else if (!strcmp(key, "noheader")) display_header = FALSE; /* we found the nodaemoncheck option */ else if (!strcmp(key, "nodaemoncheck")) daemon_check = FALSE; /* start num results to skip on displaying statusdata */ else if (!strcmp(key, "start")) { if (value == NULL) { error = TRUE; break; } result_start = atoi(value); if (result_start < 1) result_start = 1; } /* amount of results to display */ else if (!strcmp(key, "limit")) { if (value == NULL) { error = TRUE; break; } get_result_limit = atoi(value); } } /* * Set some default values if not already set. * Done here as they won't be set if variable * not provided via cgi parameters * Only required for hosts & contacts, not services * as there is no service_name=all option */ if (query_type == DISPLAY_HOSTS && strlen(query_host_name) == 0) { query_host_name = "all"; find_all = TRUE; } if (query_type == DISPLAY_CONTACTS && strlen(query_contact_name) == 0) { query_contact_name = "all"; find_all = TRUE; } /* free memory allocated to the CGI variables */ free_cgivars(variables); return error; }
int process_cgivars(void) { char **variables; int error = FALSE; int x; variables = getcgivars(); for(x = 0; variables[x] != NULL; x++) { /* we found the hostgroup argument */ if(!strcmp(variables[x], "hostgroup")) { display_type = DISPLAY_HOSTGROUP; x++; if(variables[x] == NULL) { error = TRUE; break; } if((hostgroup_name = (char *)strdup(variables[x])) == NULL) hostgroup_name = ""; strip_html_brackets(hostgroup_name); if(!strcmp(hostgroup_name, "all")) show_all_hostgroups = TRUE; else show_all_hostgroups = FALSE; } /* we found the host argument */ else if(!strcmp(variables[x], "host")) { display_type = DISPLAY_HOST; x++; if(variables[x] == NULL) { error = TRUE; break; } if((host_name = (char *)strdup(variables[x])) == NULL) host_name = ""; strip_html_brackets(host_name); } /* we found the service argument */ else if(!strcmp(variables[x], "service")) { display_type = DISPLAY_SERVICE; x++; if(variables[x] == NULL) { error = TRUE; break; } if((service_desc = (char *)strdup(variables[x])) == NULL) service_desc = ""; strip_html_brackets(service_desc); } /* we found the hostgroup style argument */ else if(!strcmp(variables[x], "style")) { x++; if(variables[x] == NULL) { error = TRUE; break; } if(!strcmp(variables[x], "overview")) hostgroup_style = DISPLAY_HOSTGROUP_OVERVIEW; else if(!strcmp(variables[x], "summary")) hostgroup_style = DISPLAY_HOSTGROUP_SUMMARY; else if(!strcmp(variables[x], "servicedetail")) host_style = DISPLAY_HOST_SERVICES; else if(!strcmp(variables[x], "processinfo")) display_type = DISPLAY_PROCESS; else if(!strcmp(variables[x], "aprobs")) display_type = DISPLAY_ALL_PROBLEMS; else if(!strcmp(variables[x], "uprobs")) display_type = DISPLAY_UNHANDLED_PROBLEMS; else display_type = DISPLAY_QUICKSTATS; } /* we found the ping argument */ else if(!strcmp(variables[x], "ping")) { display_type = DISPLAY_PING; x++; if(variables[x] == NULL) { error = TRUE; break; } if((ping_address = (char *)strdup(variables[x])) == NULL) ping_address = ""; strip_html_brackets(ping_address); } /* we found the traceroute argument */ else if(!strcmp(variables[x], "traceroute")) { display_type = DISPLAY_TRACEROUTE; x++; if(variables[x] == NULL) { error = TRUE; break; } if((traceroute_address = (char *)strdup(variables[x])) == NULL) traceroute_address = ""; strip_html_brackets(traceroute_address); } } /* free memory allocated to the CGI variables */ free_cgivars(variables); return error; }
int main (int argc, char **argv) { int status; char *pid; char *action; char *patientId; char *symptoms; char *bloodtest; //char *login = "******"; /* default login name */ //char *request_method= getenv("REQUEST_METHOD") ; char **cgivars = getcgivars(); setenv("COMPILER_DIR", ".", 1); //if (strcmp(request_method, "POST") == 0) { //set_login_name(login); action = getvalue("action", cgivars); patientId = getvalue("patientid", cgivars); if (strcmp(action, "sbmt_symptoms") == 0) { symptoms = getvalue("symptoms", cgivars); if (add_symptoms(symptoms) != 1) { fprintf(stderr, "Could not add symptoms\n"); return -1; } } else if (strcmp(action, "req_bloodtest") == 0) { bloodtest = getvalue("bloodtest", cgivars); if (peos_delete_process_instance(atoi(pid)) < 0) { fprintf(stderr, "Could not delete process instance\n"); return -1; } } else if (strcmp(action, "start") == 0) { pid = getvalue("pid", cgivars); action = getvalue("action", cgivars); if ((status = peos_notify(atoi(pid), action, PEOS_EVENT_START)) == VM_ERROR || (status == VM_INTERNAL_ERROR)) { fprintf(stderr, "unable to start action '%s' in process instance '%d'\n", action, atoi(pid)); return -1; } } else if (strcmp(action, "finish") == 0) { pid = getvalue("pid", cgivars); action = getvalue("action", cgivars); if ((status = peos_notify(atoi(pid), action,PEOS_EVENT_FINISH)) == VM_ERROR || status == VM_INTERNAL_ERROR) { fprintf(stderr, "process executed an illegal instruction and has been terminated\n"); return -1; } } else if (strcmp(action, "abort") == 0) { pid = getvalue("pid", cgivars); action = getvalue("action", cgivars); if ((status = peos_notify(atoi(pid), action,PEOS_EVENT_ABORT)) == VM_ERROR || status == VM_INTERNAL_ERROR) { fprintf(stderr, "process encountered an illegal event and has been terminated\n"); return -1; } } else if (strcmp(action, "suspend") == 0) { pid = getvalue("pid", cgivars); action = getvalue("action", cgivars); if ((status = peos_notify(atoi(pid), action,PEOS_EVENT_SUSPEND)) == VM_ERROR || status == VM_INTERNAL_ERROR) { fprintf(stderr, "process encountered an illegal event and has been terminated\n"); return -1; } } //} return_patient_record(patientId); return (0); }
int process_cgivars(void) { char **variables; int error = FALSE; int x; variables = getcgivars(); for(x = 0; variables[x] != NULL; x++) { /* do some basic length checking on the variable identifier to prevent buffer overflows */ if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) continue; /* we found the host argument */ else if(!strcmp(variables[x], "host")) { x++; if(variables[x] == NULL) { error = TRUE; break; } if((host_name = (char *)strdup(variables[x])) == NULL) host_name = ""; strip_html_brackets(host_name); display_type = DISPLAY_HOSTS; if(!strcmp(host_name, "all")) show_all_hosts = TRUE; else show_all_hosts = FALSE; } /* we found the service argument */ else if(!strcmp(variables[x], "service")) { x++; if(variables[x] == NULL) { error = TRUE; break; } if((svc_description = (char *)strdup(variables[x])) == NULL) svc_description = ""; strip_html_brackets(svc_description); display_type = DISPLAY_SERVICES; } /* we found the history type argument */ else if(!strcmp(variables[x], "type")) { x++; if(variables[x] == NULL) { error = TRUE; break; } history_options = atoi(variables[x]); } /* we found the history state type argument */ else if(!strcmp(variables[x], "statetype")) { x++; if(variables[x] == NULL) { error = TRUE; break; } state_options = atoi(variables[x]); } /* we found the log archive argument */ else if(!strcmp(variables[x], "archive")) { x++; if(variables[x] == NULL) { error = TRUE; break; } log_archive = atoi(variables[x]); if(log_archive < 0) log_archive = 0; } /* we found the order argument */ else if(!strcmp(variables[x], "oldestfirst")) { use_lifo = FALSE; } /* we found the embed option */ else if(!strcmp(variables[x], "embedded")) embedded = TRUE; /* we found the noheader option */ else if(!strcmp(variables[x], "noheader")) display_header = FALSE; /* we found the nofrills option */ else if(!strcmp(variables[x], "nofrills")) display_frills = FALSE; /* we found the notimebreaks option */ else if(!strcmp(variables[x], "notimebreaks")) display_timebreaks = FALSE; /* we found the no system messages option */ else if(!strcmp(variables[x], "nosystem")) display_system_messages = FALSE; /* we found the no flapping alerts option */ else if(!strcmp(variables[x], "noflapping")) display_flapping_alerts = FALSE; /* we found the no downtime alerts option */ else if(!strcmp(variables[x], "nodowntime")) display_downtime_alerts = FALSE; } /* free memory allocated to the CGI variables */ free_cgivars(variables); return error; }
int process_cgivars(void) { char **variables; int error = FALSE; int x; variables = getcgivars(); for (x = 0; variables[x] != NULL; x++) { /* do some basic length checking on the variable identifier to prevent buffer overflows */ if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) continue; /* we found the host argument */ else if (!strcmp(variables[x], "host")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if ((host_name = (char *)strdup(variables[x])) == NULL) host_name = ""; strip_html_brackets(host_name); display_type = DISPLAY_HOSTS; if (!strcmp(host_name, "all")) show_all_hosts = TRUE; else show_all_hosts = FALSE; } /* we found the service argument */ else if (!strcmp(variables[x], "service")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if ((service_desc = (char *)strdup(variables[x])) == NULL) service_desc = ""; strip_html_brackets(service_desc); display_type = DISPLAY_SERVICES; } /* we found the hostgroup argument */ else if (!strcmp(variables[x], "hostgroup")) { display_type = DISPLAY_HOSTGROUPS; x++; if (variables[x] == NULL) { error = TRUE; break; } if ((hostgroup_name = strdup(variables[x])) == NULL) hostgroup_name = ""; strip_html_brackets(hostgroup_name); } /* we found the servicegroup argument */ else if (!strcmp(variables[x], "servicegroup")) { display_type = DISPLAY_SERVICEGROUPS; x++; if (variables[x] == NULL) { error = TRUE; break; } if ((servicegroup_name = strdup(variables[x])) == NULL) servicegroup_name = ""; strip_html_brackets(servicegroup_name); } /* we found the history type argument */ else if (!strcmp(variables[x], "type")) { x++; if (variables[x] == NULL) { error = TRUE; break; } history_options = atoi(variables[x]); } /* we found the history state type argument */ else if (!strcmp(variables[x], "statetype")) { x++; if (variables[x] == NULL) { error = TRUE; break; } state_options = atoi(variables[x]); } /* we found first time argument */ else if (!strcmp(variables[x], "ts_start")) { x++; if (variables[x] == NULL) { error = TRUE; break; } ts_start = (time_t)strtoul(variables[x], NULL, 10); } /* we found last time argument */ else if (!strcmp(variables[x], "ts_end")) { x++; if (variables[x] == NULL) { error = TRUE; break; } ts_end = (time_t)strtoul(variables[x], NULL, 10); } /* we found the order argument */ else if (!strcmp(variables[x], "order")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "new2old")) reverse = FALSE; else if (!strcmp(variables[x], "old2new")) reverse = TRUE; } /* we found the embed option */ else if (!strcmp(variables[x], "embedded")) embedded = TRUE; /* we found the noheader option */ else if (!strcmp(variables[x], "noheader")) display_header = FALSE; /* we found the nodaemoncheck option */ else if (!strcmp(variables[x], "nodaemoncheck")) daemon_check = FALSE; /* we found the nofrills option */ else if (!strcmp(variables[x], "nofrills")) display_frills = FALSE; /* we found the notimebreaks option */ else if (!strcmp(variables[x], "notimebreaks")) display_timebreaks = FALSE; /* we found the no system messages option */ else if (!strcmp(variables[x], "nosystem")) display_system_messages = FALSE; /* we found the no flapping alerts option */ else if (!strcmp(variables[x], "noflapping")) display_flapping_alerts = FALSE; /* we found the no downtime alerts option */ else if (!strcmp(variables[x], "nodowntime")) display_downtime_alerts = FALSE; /* start num results to skip on displaying statusdata */ else if (!strcmp(variables[x], "start")) { x++; if (variables[x] == NULL) { error = TRUE; break; } result_start = atoi(variables[x]); if (result_start < 1) result_start = 1; } /* amount of results to display */ else if (!strcmp(variables[x], "limit")) { x++; if (variables[x] == NULL) { error = TRUE; break; } get_result_limit = atoi(variables[x]); } } /* free memory allocated to the CGI variables */ free_cgivars(variables); return error; }
int main (int argc, char **argv) { int pid, i, c; int input_pipe[2], result_pipe[2]; FILE *input_stream, *result_stream; char *editedText; char *login = "******"; /* default login name */ char *request_method = getenv("REQUEST_METHOD") ; char **cgivars = getcgivars(); if (strcmp(request_method, "POST") == 0) { set_login_name(login); editedText = getvalue("editedText", cgivars); /* Create a pipe so parent can write the pml code to child process running pmlcheck. */ if (pipe(input_pipe) == -1) { perror("error creating read pipe"); exit(EXIT_FAILURE); } if (pipe(result_pipe) == -1) { perror("error creating write pipe"); exit(EXIT_FAILURE); } /* * Now, create a child process to run pmlcheck. In the Unix * world, to run a program one must first create a new * process, which is done by cloning an existing process. * This is done with the fork() system call, which simply * makes a copy of the running program, then returns a value * to both copies. The parent gets the process id of the * forked child copy as return value, while the child gets 0. */ if ((pid = fork()) < 0) { /* A negative return value indicates an error. */ perror("error forking child"); exit(EXIT_FAILURE); } else if (pid == 0) { /* * This is the child (clone) process. It will communicate * with the parent via its stdout; the parent will then * write the result to the server, which will send it it * the browser. */ /* * First, connect the stdin of this child process to read * end of the read pipe. The unfortunately named dup2() makes * its second argument be a copy of its first argument, * after first closing the second argument if it's open. * So, the following will make stdin a copy of the read * end of the pipe. This is important, because after * calling exec() the executed program will read from the * pipe rather than some other stream. */ close(input_pipe[1]); /* Close write end; child is reading. */ dup2(input_pipe[0], STDIN_FILENO); /* Bind read end to stdin. */ /* Do the inverse for stdout */ close(result_pipe[0]); /* Close read end; child is writing. */ dup2(result_pipe[1], STDOUT_FILENO); /* Bind write end to stdout. */ /* * At last, run pmlcheck. It will read from stdin, which * is bound to the read end of the pipe, and write to * stdout, which is bound to the write end. */ execl("pmlcheck", "pmlcheck", (char *)NULL); /* If execution reaches here, execl() failed. */ write(STDOUT_FILENO, "exec pmlcheck failed", strlen("exec pmlcheck failed")); exit(EXIT_FAILURE); } else { /* * This code executes in the parent, which should write * the pml code to the pipe, then read pmlcheck's output */ /* First, print the HTTP header, in this case just the all-important content type. */ printf("Content-type: text/plain; charset=UTF-8\r\n\r\n"); /* Make the pipe ends into stdio FILE pointers. */ close(input_pipe[0]); /* Close read end; parent is writing. */ input_stream = fdopen(input_pipe[1], "w"); close(result_pipe[1]); /* Close write end; parent is reading. */ result_stream = fdopen(result_pipe[0], "r"); /* Write the pml content and close the stream. */ i = 0; while(editedText[i]) { fputc(editedText[i++], input_stream); } fputc('\n', input_stream); fclose(input_stream); while((c = fgetc(result_stream)) != EOF) { putchar(c); } /* Done; exit. */ exit(EXIT_SUCCESS); } } return(EXIT_FAILURE); }
int process_cgivars(void) { char **variables; int error = FALSE; int x; variables = getcgivars(); for(x = 0; variables[x] != NULL; x++) { /* do some basic length checking on the variable identifier to prevent buffer overflows */ if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { x++; continue; } /* we found the host argument */ else if(!strcmp(variables[x], "host")) { x++; if(variables[x] == NULL) { error = TRUE; break; } if((host_name = (char *)strdup(variables[x])) == NULL) host_name = "all"; else strip_html_brackets(host_name); if(!strcmp(host_name, "all")) show_all_hosts = TRUE; else show_all_hosts = FALSE; } /* we found the no textures argument*/ else if(!strcmp(variables[x], "notextures")) use_textures = FALSE; /* we found the no text argument*/ else if(!strcmp(variables[x], "notext")) use_text = FALSE; /* we found the no links argument*/ else if(!strcmp(variables[x], "nolinks")) use_links = FALSE; /* we found the layout method option */ else if(!strcmp(variables[x], "layout")) { x++; if(variables[x] == NULL) { error = TRUE; break; } layout_method = atoi(variables[x]); } /* we found custom viewpoint coord */ else if(!strcmp(variables[x], "viewx")) { x++; if(variables[x] == NULL) { error = TRUE; break; } custom_viewpoint_x = strtod(variables[x], NULL); custom_viewpoint = TRUE; } else if(!strcmp(variables[x], "viewy")) { x++; if(variables[x] == NULL) { error = TRUE; break; } custom_viewpoint_y = strtod(variables[x], NULL); custom_viewpoint = TRUE; } else if(!strcmp(variables[x], "viewz")) { x++; if(variables[x] == NULL) { error = TRUE; break; } custom_viewpoint_z = strtod(variables[x], NULL); custom_viewpoint = TRUE; } } /* free memory allocated to the CGI variables */ free_cgivars(variables); return error; }
int process_cgivars(void) { char **variables; int error = FALSE; int x; variables = getcgivars(); for (x = 0; variables[x] != NULL; x++) { /* do some basic length checking on the variable identifier to prevent buffer overflows */ if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) continue; /* found query string */ else if (!strcmp(variables[x], "query_string")) { x++; if (variables[x] == NULL) { error = TRUE; break; } query_string = strdup(variables[x]); strip_html_brackets(query_string); if (strlen(query_string) == 0) my_free(query_string); } /* we found first time argument */ else if (!strcmp(variables[x], "ts_start")) { x++; if (variables[x] == NULL) { error = TRUE; break; } ts_start = (time_t)strtoul(variables[x], NULL, 10); } /* we found last time argument */ else if (!strcmp(variables[x], "ts_end")) { x++; if (variables[x] == NULL) { error = TRUE; break; } ts_end = (time_t)strtoul(variables[x], NULL, 10); } /* we found the start time */ else if (!strcmp(variables[x], "start_time")) { x++; if (variables[x] == NULL) { error = TRUE; break; } start_time_string = (char *)malloc(strlen(variables[x]) + 1); if (start_time_string == NULL) start_time_string = ""; else strcpy(start_time_string, variables[x]); } /* we found the end time */ else if (!strcmp(variables[x], "end_time")) { x++; if (variables[x] == NULL) { error = TRUE; break; } end_time_string = (char *)malloc(strlen(variables[x]) + 1); if (end_time_string == NULL) end_time_string = ""; else strcpy(end_time_string, variables[x]); } /* we found the standard timeperiod argument */ else if (!strcmp(variables[x], "timeperiod")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "today")) timeperiod_type = TIMEPERIOD_TODAY; else if (!strcmp(variables[x], "singelday")) timeperiod_type = TIMEPERIOD_SINGLE_DAY; else if (!strcmp(variables[x], "last24hours")) timeperiod_type = TIMEPERIOD_LAST24HOURS; else if (!strcmp(variables[x], "thisweek")) timeperiod_type = TIMEPERIOD_THISWEEK; else if (!strcmp(variables[x], "lastweek")) timeperiod_type = TIMEPERIOD_LASTWEEK; else if (!strcmp(variables[x], "thismonth")) timeperiod_type = TIMEPERIOD_THISMONTH; else if (!strcmp(variables[x], "lastmonth")) timeperiod_type = TIMEPERIOD_LASTMONTH; else if (!strcmp(variables[x], "thisyear")) timeperiod_type = TIMEPERIOD_THISYEAR; else if (!strcmp(variables[x], "lastyear")) timeperiod_type = TIMEPERIOD_LASTYEAR; else if (!strcmp(variables[x], "last7days")) timeperiod_type = TIMEPERIOD_LAST7DAYS; else if (!strcmp(variables[x], "last31days")) timeperiod_type = TIMEPERIOD_LAST31DAYS; else if (!strcmp(variables[x], "custom")) timeperiod_type = TIMEPERIOD_CUSTOM; else continue; convert_timeperiod_to_times(timeperiod_type, &ts_start, &ts_end); } /* we found the order argument */ else if (!strcmp(variables[x], "order")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "new2old")) reverse = FALSE; else if (!strcmp(variables[x], "old2new")) reverse = TRUE; } /* show filter */ else if (!strcmp(variables[x], "display_filter")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "true")) display_filter = TRUE; } /* notification filter */ else if (!strcmp(variables[x], "noti")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "off")) show_notifications = FALSE; } /* host status filter */ else if (!strcmp(variables[x], "hst")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "off")) show_host_status = FALSE; } /* service status filter */ else if (!strcmp(variables[x], "sst")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "off")) show_service_status = FALSE; } /* external commands filter */ else if (!strcmp(variables[x], "cmd")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "off")) show_external_commands = FALSE; } /* system messages filter */ else if (!strcmp(variables[x], "sms")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "off")) show_system_messages = FALSE; } /* event handler filter */ else if (!strcmp(variables[x], "evh")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "off")) show_event_handler = FALSE; } /* flapping filter */ else if (!strcmp(variables[x], "flp")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "off")) show_flapping = FALSE; } /* downtime filter */ else if (!strcmp(variables[x], "dwn")) { x++; if (variables[x] == NULL) { error = TRUE; break; } if (!strcmp(variables[x], "off")) show_downtime = FALSE; } /* we found the CSV output option */ else if (!strcmp(variables[x], "csvoutput")) { display_header = FALSE; content_type = CSV_CONTENT; } /* we found the CSV output option */ else if (!strcmp(variables[x], "jsonoutput")) { display_header = FALSE; content_type = JSON_CONTENT; } /* we found the embed option */ else if (!strcmp(variables[x], "embedded")) embedded = TRUE; /* we found the noheader option */ else if (!strcmp(variables[x], "noheader")) display_header = FALSE; /* we found the nofrills option */ else if (!strcmp(variables[x], "nofrills")) display_frills = FALSE; /* we found the notimebreaks option */ else if (!strcmp(variables[x], "notimebreaks")) display_timebreaks = FALSE; /* we found the nodaemoncheck option */ else if (!strcmp(variables[x], "nodaemoncheck")) daemon_check = FALSE; /* start num results to skip on displaying statusdata */ else if (!strcmp(variables[x], "start")) { x++; if (variables[x] == NULL) { error = TRUE; break; } result_start = atoi(variables[x]); if (result_start < 1) result_start = 1; } /* amount of results to display */ else if (!strcmp(variables[x], "limit")) { x++; if (variables[x] == NULL) { error = TRUE; break; } get_result_limit = atoi(variables[x]); } /* we received an invalid argument */ else error = TRUE; } /* free memory allocated to the CGI variables */ free_cgivars(variables); return error; }
int process_cgivars(void) { char **variables; int error=FALSE; int x; variables=getcgivars(); for(x=0; variables[x]!=NULL; x++) { /* do some basic length checking on the variable identifier to prevent buffer overflows */ if(strlen(variables[x])>=MAX_INPUT_BUFFER-1) { x++; continue; } /* we found the host argument */ else if(!strcmp(variables[x],"host")) { query_type=FIND_HOST; x++; if(variables[x]==NULL) { error=TRUE; break; } if((query_host_name=strdup(variables[x]))==NULL) query_host_name=""; strip_html_brackets(query_host_name); if(!strcmp(query_host_name,"all")) find_all=TRUE; else find_all=FALSE; } /* we found the contact argument */ else if(!strcmp(variables[x],"contact")) { query_type=FIND_CONTACT; x++; if(variables[x]==NULL) { error=TRUE; break; } if((query_contact_name=strdup(variables[x]))==NULL) query_contact_name=""; strip_html_brackets(query_contact_name); if(!strcmp(query_contact_name,"all")) find_all=TRUE; else find_all=FALSE; } /* we found the service argument */ else if(!strcmp(variables[x],"service")) { query_type=FIND_SERVICE; x++; if(variables[x]==NULL) { error=TRUE; break; } if((query_svc_description=strdup(variables[x]))==NULL) query_svc_description=""; strip_html_brackets(query_svc_description); } /* we found the notification type argument */ else if(!strcmp(variables[x],"type")) { x++; if(variables[x]==NULL) { error=TRUE; break; } notification_options=atoi(variables[x]); } /* we found the log archive argument */ else if(!strcmp(variables[x],"archive")) { x++; if(variables[x]==NULL) { error=TRUE; break; } log_archive=atoi(variables[x]); if(log_archive<0) log_archive=0; } /* we found the order argument */ else if(!strcmp(variables[x],"oldestfirst")) { use_lifo=FALSE; } /* we found the embed option */ else if(!strcmp(variables[x],"embedded")) embedded=TRUE; /* we found the noheader option */ else if(!strcmp(variables[x],"noheader")) display_header=FALSE; } /* free memory allocated to the CGI variables */ free_cgivars(variables); return error; }
int main(int argc, char *argv[]) { char **params = NULL; int op = OP_UNKNOWN; int i, j; int indx = 0; bool dispfp = false; bool skshash = false; bool exact = false; bool ishex = false; bool isfp = false; bool mrhkp = false; uint64_t keyid = 0; struct openpgp_fingerprint fingerprint; char *search = NULL; char *end = NULL; struct openpgp_publickey *publickey = NULL; struct openpgp_packet_list *packets = NULL; struct openpgp_packet_list *list_end = NULL; int result; struct skshash hash; struct onak_dbctx *dbctx; params = getcgivars(argc, argv); for (i = 0; params != NULL && params[i] != NULL; i += 2) { if (!strcmp(params[i], "op")) { if (!strcmp(params[i+1], "get")) { op = OP_GET; } else if (!strcmp(params[i+1], "hget")) { op = OP_HGET; } else if (!strcmp(params[i+1], "index")) { op = OP_INDEX; } else if (!strcmp(params[i+1], "vindex")) { op = OP_VINDEX; } else if (!strcmp(params[i+1], "photo")) { op = OP_PHOTO; } } else if (!strcmp(params[i], "search")) { search = params[i+1]; params[i+1] = NULL; if (search != NULL && strlen(search) == 42 && search[0] == '0' && search[1] == 'x') { /* v4 fingerprint */ fingerprint.length = 20; for (j = 0; j < 20; j++) { fingerprint.fp[j] = (hex2bin( search[2 + j * 2]) << 4) + hex2bin(search[3 + j * 2]); } isfp = true; } else if (search != NULL && strlen(search) == 66 && search[0] == '0' && search[1] == 'x') { /* v5 fingerprint */ fingerprint.length = 32; for (j = 0; j < 32; j++) { fingerprint.fp[j] = (hex2bin( search[2 + j * 2]) << 4) + hex2bin(search[3 + j * 2]); } isfp = true; } else if (search != NULL) { keyid = strtoull(search, &end, 16); if (*search != 0 && end != NULL && *end == 0) { ishex = true; } } } else if (!strcmp(params[i], "idx")) { indx = atoi(params[i+1]); } else if (!strcmp(params[i], "fingerprint")) { if (!strcmp(params[i+1], "on")) { dispfp = true; } } else if (!strcmp(params[i], "hash")) { if (!strcmp(params[i+1], "on")) { skshash = true; } } else if (!strcmp(params[i], "exact")) { if (!strcmp(params[i+1], "on")) { exact = true; } } else if (!strcmp(params[i], "options")) { /* * TODO: We should be smarter about this; options may * have several entries. For now mr is the only valid * one though. */ if (!strcmp(params[i+1], "mr")) { mrhkp = true; } } free(params[i]); params[i] = NULL; if (params[i+1] != NULL) { free(params[i+1]); params[i+1] = NULL; } } if (params != NULL) { free(params); params = NULL; } if (mrhkp) { puts("Content-Type: text/plain\n"); } else if (op == OP_PHOTO) { puts("Content-Type: image/jpeg\n"); } else { start_html("Lookup of key"); } if (op == OP_UNKNOWN) { puts("Error: No operation supplied."); } else if (search == NULL) { puts("Error: No key to search for supplied."); } else { readconfig(NULL); initlogthing("lookup", config.logfile); catchsignals(); dbctx = config.dbinit(config.backend, false); switch (op) { case OP_GET: case OP_HGET: if (op == OP_HGET) { parse_skshash(search, &hash); result = dbctx->fetch_key_skshash(dbctx, &hash, &publickey); } else if (ishex) { result = dbctx->fetch_key_id(dbctx, keyid, &publickey, false); } else if (isfp) { result = dbctx->fetch_key_fp(dbctx, &fingerprint, &publickey, false); } else { result = dbctx->fetch_key_text(dbctx, search, &publickey); } if (result) { logthing(LOGTHING_NOTICE, "Found %d key(s) for search %s", result, search); puts("<pre>"); cleankeys(&publickey, config.clean_policies); flatten_publickey(publickey, &packets, &list_end); armor_openpgp_stream(stdout_putchar, NULL, packets); puts("</pre>"); } else { logthing(LOGTHING_NOTICE, "Failed to find key for search %s", search); puts("Key not found"); } break; case OP_INDEX: find_keys(dbctx, search, keyid, &fingerprint, ishex, isfp, dispfp, skshash, exact, false, mrhkp); break; case OP_VINDEX: find_keys(dbctx, search, keyid, &fingerprint, ishex, isfp, dispfp, skshash, exact, true, mrhkp); break; case OP_PHOTO: if (isfp) { dbctx->fetch_key_fp(dbctx, &fingerprint, &publickey, false); } else { dbctx->fetch_key_id(dbctx, keyid, &publickey, false); } if (publickey != NULL) { unsigned char *photo = NULL; size_t length = 0; if (getphoto(publickey, indx, &photo, &length) == ONAK_E_OK) { fwrite(photo, 1, length, stdout); } free_publickey(publickey); publickey = NULL; } break; default: puts("Unknown operation!"); } dbctx->cleanupdb(dbctx); cleanuplogthing(); cleanupconfig(); } if (!mrhkp) { puts("<hr>"); puts("Produced by onak " ONAK_VERSION ); end_html(); } if (search != NULL) { free(search); search = NULL; } return (EXIT_SUCCESS); }