📄 webhttpd.c
字号:
"<form action=get>\n" "<select name='query'>\n", thread, thread); send_template(client_socket, res); for (i=0; config_params[i].param_name != NULL; i++) { if ((thread != 0) && (config_params[i].main_thread)) continue; sprintf(res, "<option value='%s'>%s</option>\n", config_params[i].param_name, config_params[i].param_name); send_template(client_socket, res); } sprintf(res, "</select>\n" "<input type='submit' value='get'>\n" "</form>\n"); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "get needs param_name\n"); send_template_raw(client_socket, res); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_valid_syntax, NULL); else response_client(client_socket, not_valid_syntax_raw, NULL); } } else if (!strcmp(command,"write")) { pointer = pointer + 5; length_uri = length_uri - 5; if (length_uri == 0) { if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/config><– back</a><br><br>" "Are you sure? <a href=/%hu/config/writeyes>Yes</a>\n", thread, thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { conf_print(cnt); send_template_ini_client_raw(client_socket); sprintf(res, "Thread %hu write\nDone\n", thread); send_template_raw(client_socket, res); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else if (!strcmp(command, "writeyes")) { pointer = pointer + 8; length_uri = length_uri - 8; if (length_uri==0) { conf_print(cnt); if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/config><– back</a><br><br>\n<b>Thread %hu</b> write done !\n", thread, thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "Thread %hu write\nDone\n", thread); send_template_raw(client_socket, res); } } else { /*error*/ if (cnt[0]->conf.control_html_output) { response_client(client_socket, not_found_response_valid_command, NULL); } else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } return 1;}/* This function manages/parses the actions for motion ( makemovie , snapshot , restart , quit ). return 0 for restart & quit return 1 for makemovie & snaphost*/static unsigned short int action(char *pointer, char *res, unsigned short int length_uri, unsigned short int thread, int client_socket, void *userdata){ /* parse action commands */ char command[256] = {'\0'}; struct context **cnt = userdata; unsigned short int i = 0; warningkill = sscanf (pointer, "%255[a-z]" , command); if (!strcmp(command,"makemovie")) { pointer = pointer + 9; length_uri = length_uri - 9; if (length_uri == 0) { /*call makemovie*/ if (thread == 0) { while (cnt[++i]) cnt[i]->makemovie=1; } else { cnt[thread]->makemovie=1; } if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/action><– back</a><br><br>\n" "makemovie for thread %hu done<br>\n", thread, thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "makemovie for thread %hu\nDone\n", thread); send_template_raw(client_socket, res); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket,not_found_response_valid_command,NULL); else response_client(client_socket,not_found_response_valid_command_raw,NULL); } } else if (!strcmp(command,"snapshot")) { pointer = pointer + 8; length_uri = length_uri - 8; if (length_uri == 0) { /*call snapshot*/ if (thread == 0) { while (cnt[++i]) cnt[i]->snapshot=1; } else { cnt[thread]->snapshot=1; } cnt[thread]->snapshot = 1; if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/action><– back</a><br><br>\n" "snapshot for thread %hu done<br>\n", thread, thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "snapshot for thread %hu\nDone\n", thread); send_template_raw(client_socket, res); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else if (!strcmp(command, "restart")) { pointer = pointer + 7; length_uri = length_uri - 7; if (length_uri == 0) { /*call restart*/ if (thread == 0) { motion_log(LOG_DEBUG, 0, "httpd restart"); kill(getpid(),SIGHUP); if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "restart in progress ... bye<br>\n<a href='/'>Home</a>"); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "restart in progress ...\nDone\n"); send_template_raw(client_socket, res); } return 0; // to restart } else { motion_log(LOG_DEBUG, 0, "httpd restart thread %d", thread); if (cnt[thread]->running) { cnt[thread]->makemovie=1; cnt[thread]->finish=1; } cnt[thread]->restart=1; if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/action><– back</a><br><br>\n" "restart for thread %hu done<br>\n", thread, thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "restart for thread %hu\nDone\n", thread); send_template_raw(client_socket, res); } } } else { if (cnt[0]->conf.control_html_output) response_client(client_socket,not_found_response_valid_command,NULL); else response_client(client_socket,not_found_response_valid_command_raw,NULL); } } else if (!strcmp(command,"quit")) { pointer = pointer + 4; length_uri = length_uri - 4; if (length_uri == 0) { /*call quit*/ if (thread == 0) { motion_log(LOG_DEBUG, 0, "httpd quit"); kill(getpid(),SIGQUIT); if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "quit in progress ... bye"); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res,"quit in progress ... bye\nDone\n"); send_template_raw(client_socket, res); } return 0; // to quit } else { motion_log(LOG_DEBUG, 0, "httpd quit thread %d", thread); cnt[thread]->restart=0; cnt[thread]->makemovie=1; cnt[thread]->finish=1; cnt[thread]->watchdog=WATCHDOG_OFF; if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/action><– back</a><br><br>\n" "quit for thread %hu done<br>\n", thread, thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "quit for thread %hu\nDone\n", thread); send_template_raw(client_socket, res); } } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else { if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } return 1;}/* This function manages/parses the detection actions for motion ( status , start , pause ). return 1 to exit from function.*/static unsigned short int detection(char *pointer, char *res, unsigned short int length_uri, unsigned short int thread, int client_socket, void *userdata){ char command[256]={'\0'}; struct context **cnt=userdata; unsigned short int i = 0; warningkill = sscanf (pointer, "%255[a-z]" , command); if (!strcmp(command,"status")) { pointer = pointer + 6; length_uri = length_uri - 6; if (length_uri == 0) { /*call status*/ if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/detection><– back</a><br><br><b>Thread %hu</b>" " Detection status %s\n", thread, thread, (!cnt[thread]->running)? "NOT RUNNING": (cnt[thread]->pause)? "PAUSE":"ACTIVE"); send_template(client_socket, res); send_template_end_client(client_socket); } else { sprintf(res, "Thread %hu Detection status %s\n",thread, (!cnt[thread]->running)? "NOT RUNNING": (cnt[thread]->pause)? "PAUSE":"ACTIVE"); send_template_ini_client_raw(client_socket); send_template_raw(client_socket, res); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else if (!strcmp(command, "start")) { pointer = pointer + 5; length_uri = length_uri - 5; if (length_uri == 0) { /*call start*/ if (thread == 0) { do { cnt[i]->pause = 0; } while (cnt[++i]); } else { cnt[thread]->pause = 0; } if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket,ini_template); sprintf(res, "<a href=/%hu/detection><– back</a><br><br>\n<b>Thread %hu</b>" " Detection resumed\n", thread, thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "Thread %hu Detection resumed\nDone\n", thread); send_template_raw(client_socket, res); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else if (!strcmp(command,"pause")){ pointer = pointer + 5; length_uri = length_uri - 5; if (length_uri==0) { /*call pause*/ if (thread == 0) { do { cnt[i]->pause = 1; } while (cnt[++i]); } else { cnt[thread]->pause = 1; } if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/detection><– back</a><br><br>\n<b>Thread %hu</b>" " Detection paused\n", thread, thread); send_template(client_socket,res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "<b>Thread %hu</b> Detection paused\nDone\n", thread); send_template_raw(client_socket, res); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else if (!strcmp(command,"connection")){ pointer = pointer + 10; length_uri = length_uri - 10; if (length_uri==0) { /*call connection*/ if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/detection><– back</a><br><br>\n", thread); send_template(client_socket,res); if (thread == 0){ do{ sprintf(res, "<b>Thread %hu</b> %s<br>\n",i, (!cnt[i]->running)? "NOT RUNNING" : (cnt[i]->lost_connection)?CONNECTION_KO:CONNECTION_OK); send_template(client_socket,res); }while (cnt[++i]); }else{ sprintf(res, "<b>Thread %hu</b> %s\n", thread, (!cnt[thread]->running)? "NOT RUNNING" : (cnt[thread]->lost_connection)? CONNECTION_KO: CONNECTION_OK); send_template(client_socket,res);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -