/* * tvheadend, AJAX / HTML user interface * Copyright (C) 2008 Andreas Öman * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #define _GNU_SOURCE #include #include #include #include #include #include #include "tvhead.h" #include "http.h" #include "ajaxui.h" #include "cwc.h" /** * CWC configuration */ int ajax_config_cwc_tab(http_connection_t *hc, http_reply_t *hr) { htsbuf_queue_t *q = &hr->hr_q; ajax_box_begin(q, AJAX_BOX_SIDEBOX, NULL, NULL, "Code-word Client"); htsbuf_qprintf(q, "
"); ajax_js(q, "new Ajax.Updater('cwclist', '/ajax/cwclist', " "{method: 'get', evalScripts: true});"); htsbuf_qprintf(q, "
"); htsbuf_qprintf(q, "
" "
Hostname:
" "
" "" "
"); htsbuf_qprintf(q, "
" "
Port:
" "
" "" "
"); htsbuf_qprintf(q, "
" "
Username:
" "
" "" "
"); htsbuf_qprintf(q, "
" "
Password:
" "
" "" "
"); htsbuf_qprintf(q, "
" "
DES-key:
" "
" "" "
"); htsbuf_qprintf(q, "
" ""); htsbuf_qprintf(q, "
\r\n"); ajax_box_end(q, AJAX_BOX_SIDEBOX); htsbuf_qprintf(q, ""); http_output_html(hc, hr); return 0; } /** * */ static int ajax_cwclist(http_connection_t *hc, http_reply_t *hr, const char *remain, void *opaque) { htsbuf_queue_t *q = &hr->hr_q; ajax_table_t ta; cwc_t *cwc; char id[20]; ajax_table_top(&ta, hc, q, (const char *[]){"Code-word Server", "Username", "Enabled", "Status", "", NULL}, (int[]){3, 2, 1, 12, 1}); TAILQ_FOREACH(cwc, &cwcs, cwc_link) { snprintf(id, sizeof(id), "cwc_%d", cwc->cwc_id); ajax_table_row_start(&ta, id); ajax_table_cell(&ta, NULL, "%s:%d", cwc->cwc_tcp_session.tcp_hostname, cwc->cwc_tcp_session.tcp_port); ajax_table_cell(&ta, NULL, "%s", cwc->cwc_username); ajax_table_cell(&ta, NULL, "", cwc->cwc_tcp_session.tcp_enabled ? "checked " : "", cwc->cwc_id); ajax_table_cell(&ta, "status", cwc_status_to_text(cwc)); ajax_table_cell(&ta, NULL, "" "Delete...", cwc->cwc_id, cwc->cwc_tcp_session.tcp_hostname); } ajax_table_bottom(&ta); http_output_html(hc, hr); return 0; } /** * */ static int ajax_cwcadd(http_connection_t *hc, http_reply_t *hr, const char *remain, void *opaque) { htsbuf_queue_t *q = &hr->hr_q; const char *errtxt; errtxt = cwc_add(http_arg_get(&hc->hc_req_args, "hostname"), http_arg_get(&hc->hc_req_args, "port"), http_arg_get(&hc->hc_req_args, "username"), http_arg_get(&hc->hc_req_args, "password"), http_arg_get(&hc->hc_req_args, "deskey"), "1", 1, 1); if(errtxt != NULL) { htsbuf_qprintf(q, "alert('%s');", errtxt); } else { htsbuf_qprintf(q, "$('hostname').clear();\r\n"); htsbuf_qprintf(q, "$('port').clear();\r\n"); htsbuf_qprintf(q, "$('username').clear();\r\n"); htsbuf_qprintf(q, "$('password').clear();\r\n"); htsbuf_qprintf(q, "$('deskey').clear();\r\n"); htsbuf_qprintf(q, "new Ajax.Updater('cwclist', '/ajax/cwclist', " "{method: 'get', evalScripts: true});"); } http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0); return 0; } /** * */ static int ajax_cwcdel(http_connection_t *hc, http_reply_t *hr, const char *remain, void *opaque) { htsbuf_queue_t *q = &hr->hr_q; const char *txt; cwc_t *cwc; if((txt = http_arg_get(&hc->hc_req_args, "id")) == NULL) return HTTP_STATUS_BAD_REQUEST; if((cwc = cwc_find(atoi(txt))) == NULL) return HTTP_STATUS_BAD_REQUEST; cwc_delete(cwc); htsbuf_qprintf(q, "new Ajax.Updater('cwclist', '/ajax/cwclist', " "{method: 'get', evalScripts: true});"); http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0); return 0; } /** * */ static int ajax_cwcchange(http_connection_t *hc, http_reply_t *hr, const char *remain, void *opaque) { // htsbuf_queue_t *q = &hr->hr_q; const char *txt; cwc_t *cwc; if((txt = http_arg_get(&hc->hc_req_args, "id")) == NULL) return HTTP_STATUS_BAD_REQUEST; if((cwc = cwc_find(atoi(txt))) == NULL) return HTTP_STATUS_BAD_REQUEST; if((txt = http_arg_get(&hc->hc_req_args, "checked")) == NULL) return HTTP_STATUS_BAD_REQUEST; cwc_set_enable(cwc, !strcmp(txt, "true")); http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0); return 0; } /** * */ void ajax_config_cwc_init(void) { http_path_add("/ajax/cwclist" , NULL, ajax_cwclist, AJAX_ACCESS_CONFIG); http_path_add("/ajax/cwcadd" , NULL, ajax_cwcadd, AJAX_ACCESS_CONFIG); http_path_add("/ajax/cwcdel" , NULL, ajax_cwcdel, AJAX_ACCESS_CONFIG); http_path_add("/ajax/cwcchange" , NULL, ajax_cwcchange, AJAX_ACCESS_CONFIG); }