|
@@ -896,9 +896,6 @@ static void ui_handle_paddle_input(struct mg_connection *nc, struct http_message
|
|
|
ret = mg_get_http_var(&(hm->body), "paddle", s_paddle, _SLEN);
|
|
ret = mg_get_http_var(&(hm->body), "paddle", s_paddle, _SLEN);
|
|
|
if (ret<=0) { mg_http_send_error(nc, 404, NULL); return; }
|
|
if (ret<=0) { mg_http_send_error(nc, 404, NULL); return; }
|
|
|
|
|
|
|
|
- //DEBUG
|
|
|
|
|
- printf("#got paddle %s\n", s_paddle);
|
|
|
|
|
-
|
|
|
|
|
ipaddle = atoi(s_paddle);
|
|
ipaddle = atoi(s_paddle);
|
|
|
make_paddle_request(ipaddle);
|
|
make_paddle_request(ipaddle);
|
|
|
|
|
|
|
@@ -986,6 +983,66 @@ static void ui_handle_volume(struct mg_connection *nc, struct http_message *hm)
|
|
|
(unsigned long)strlen(msg_success), msg_success);
|
|
(unsigned long)strlen(msg_success), msg_success);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// custom script
|
|
|
|
|
+//
|
|
|
|
|
+static void ui_handle_custom(struct mg_connection *nc, struct http_message *hm) {
|
|
|
|
|
+ int i, j, ret;
|
|
|
|
|
+ char s_func[128], s_func_clean[128];
|
|
|
|
|
+ char s_param[128], s_param_clean[128];
|
|
|
|
|
+ char _cmd[128*3];
|
|
|
|
|
+
|
|
|
|
|
+ char msg_fail[] = "fail custom";
|
|
|
|
|
+ char msg_success[] = "ok custom";
|
|
|
|
|
+
|
|
|
|
|
+ memset(s_func, 0, sizeof(char)*128);
|
|
|
|
|
+ memset(s_param, 0, sizeof(char)*128);
|
|
|
|
|
+
|
|
|
|
|
+ ret = mg_get_http_var(&(hm->body), "function", s_func, 127);
|
|
|
|
|
+ if (ret<=0) { mg_http_send_error(nc, 404, NULL); return; }
|
|
|
|
|
+
|
|
|
|
|
+ ret = mg_get_http_var(&(hm->body), "parameter", s_param, 127);
|
|
|
|
|
+
|
|
|
|
|
+ memset(_cmd, 0, sizeof(char)*3*128);
|
|
|
|
|
+
|
|
|
|
|
+ // restrict to only alphnum and ',' '.'
|
|
|
|
|
+ //
|
|
|
|
|
+ memset(s_func_clean, 0, sizeof(char)*128);
|
|
|
|
|
+ for (i=0, j=0; (s_func[i]) && (i<(128-1)); i++) {
|
|
|
|
|
+ if ( ((s_func[i] >= 'a') && (s_func[i] <= 'z')) ||
|
|
|
|
|
+ ((s_func[i] >= 'A') && (s_func[i] <= 'Z')) ||
|
|
|
|
|
+ ((s_func[i] >= '0') && (s_func[i] <= '9')) ||
|
|
|
|
|
+ (s_func[i] == ',') || (s_func[i] == '.') ) {
|
|
|
|
|
+ s_func_clean[j] = s_func[i];
|
|
|
|
|
+ j++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ memset(s_param_clean, 0, sizeof(char)*128);
|
|
|
|
|
+ for (i=0, j=0; (s_param[i]) && (i<(128-1)); i++) {
|
|
|
|
|
+ if ( ((s_param[i] >= 'a') && (s_param[i] <= 'z')) ||
|
|
|
|
|
+ ((s_param[i] >= 'A') && (s_param[i] <= 'Z')) ||
|
|
|
|
|
+ ((s_param[i] >= '0') && (s_param[i] <= '9')) ||
|
|
|
|
|
+ (s_param[i] == ' ') || (s_param[i] == ',') || (s_param[i] == '.') ) {
|
|
|
|
|
+ s_param_clean[j] = s_param[i];
|
|
|
|
|
+ j++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // assuming we're running as root for now
|
|
|
|
|
+ //
|
|
|
|
|
+ snprintf(_cmd, (3*128)-1, "/home/bus/bin/custom '%s' '%s' &", s_func_clean, s_param_clean);
|
|
|
|
|
+ ret = system(_cmd);
|
|
|
|
|
+
|
|
|
|
|
+ if (ret!=0) {
|
|
|
|
|
+ mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
|
|
|
|
|
+ (unsigned long)strlen(msg_fail), msg_fail);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
|
|
|
|
|
+ (unsigned long)strlen(msg_success), msg_success);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// bring network interface up/down
|
|
// bring network interface up/down
|
|
|
//
|
|
//
|
|
|
static void ui_handle_interfaceupdown(struct mg_connection *nc, struct http_message *hm) {
|
|
static void ui_handle_interfaceupdown(struct mg_connection *nc, struct http_message *hm) {
|
|
@@ -1249,6 +1306,10 @@ static void api_handle_req(struct mg_connection *nc, struct http_message *hm) {
|
|
|
ui_handle_switchserver(nc, hm);
|
|
ui_handle_switchserver(nc, hm);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ else if (strncmp(s_action, "custom", strlen("custom")+1)==0) {
|
|
|
|
|
+ ui_handle_custom(nc, hm);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
else {
|
|
else {
|
|
|
mg_http_send_error(nc, 404, NULL);
|
|
mg_http_send_error(nc, 404, NULL);
|
|
|
}
|
|
}
|