1 | //FIXME Not checked on threadsafety yet; after checking please remove this line
|
---|
2 | #include "globals.h"
|
---|
3 | #ifdef WEBIF
|
---|
4 | //
|
---|
5 | // OSCam HTTP server module
|
---|
6 | //
|
---|
7 |
|
---|
8 | #include <stdio.h>
|
---|
9 | #include <string.h>
|
---|
10 | #include <time.h>
|
---|
11 | #include <sys/stat.h>
|
---|
12 | #include <dirent.h>
|
---|
13 | #include <sys/socket.h>
|
---|
14 | #include "oscam-http-helpers.c"
|
---|
15 | #include "module-cccam.h"
|
---|
16 | #include "module-cccshare.h"
|
---|
17 | #include "module-stat.h"
|
---|
18 |
|
---|
19 | extern void restart_cardreader(struct s_reader *rdr, int32_t restart);
|
---|
20 |
|
---|
21 | static int32_t running = 1;
|
---|
22 |
|
---|
23 | #ifdef CS_ANTICASC
|
---|
24 | static void kill_ac_client(void)
|
---|
25 | {
|
---|
26 | struct s_client *cl;
|
---|
27 | for (cl=first_client->next; cl ; cl=cl->next)
|
---|
28 | if (cl->typ=='a') {
|
---|
29 | cs_accounts_chk();
|
---|
30 | break;
|
---|
31 | }
|
---|
32 | }
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | struct s_reader *get_reader_by_label(char *lbl){
|
---|
36 | struct s_reader *rdr;
|
---|
37 | LL_ITER *itr = ll_iter_create(configured_readers);
|
---|
38 | while((rdr = ll_iter_next(itr)))
|
---|
39 | if (strcmp(lbl, rdr->label) == 0) break;
|
---|
40 | ll_iter_release(itr);
|
---|
41 | return rdr;
|
---|
42 | }
|
---|
43 |
|
---|
44 | struct s_client *get_client_by_name(char *name) {
|
---|
45 | struct s_client *cl;
|
---|
46 | for (cl = first_client; cl ; cl = cl->next) {
|
---|
47 | if (strcmp(name, cl->account->usr) == 0)
|
---|
48 | return cl;
|
---|
49 | }
|
---|
50 | return NULL;
|
---|
51 | }
|
---|
52 |
|
---|
53 | struct s_auth *get_account_by_name(char *name) {
|
---|
54 | struct s_auth *account;
|
---|
55 | for (account=cfg.account; (account); account=account->next) {
|
---|
56 | if(strcmp(name, account->usr) == 0)
|
---|
57 | return account;
|
---|
58 | }
|
---|
59 | return NULL;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void refresh_oscam(enum refreshtypes refreshtype, struct in_addr in) {
|
---|
63 |
|
---|
64 | switch (refreshtype) {
|
---|
65 | case REFR_ACCOUNTS:
|
---|
66 | cs_log("Refresh Accounts requested by WebIF from %s", inet_ntoa(in));
|
---|
67 |
|
---|
68 | cs_accounts_chk();
|
---|
69 | break;
|
---|
70 |
|
---|
71 | case REFR_READERS:
|
---|
72 | cs_card_info();
|
---|
73 | cs_log("Refresh Reader/Tiers requested by WebIF from %s", inet_ntoa(in));
|
---|
74 | break;
|
---|
75 |
|
---|
76 | case REFR_SERVER:
|
---|
77 | cs_log("Refresh Server requested by WebIF from %s", inet_ntoa(in));
|
---|
78 | //kill(first_client->pid, SIGHUP);
|
---|
79 | //todo how I can refresh the server after global settings
|
---|
80 | break;
|
---|
81 |
|
---|
82 | case REFR_SERVICES:
|
---|
83 | cs_log("Refresh Services requested by WebIF from %s", inet_ntoa(in));
|
---|
84 | //init_sidtab();
|
---|
85 | cs_reinit_clients(cfg.account);
|
---|
86 | break;
|
---|
87 |
|
---|
88 | #ifdef CS_ANTICASC
|
---|
89 | case REFR_ANTICASC:
|
---|
90 | cs_log("Refresh Anticascading requested by WebIF from %s", inet_ntoa(in));
|
---|
91 | kill_ac_client();
|
---|
92 | #endif
|
---|
93 | default:
|
---|
94 | break;
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | char *send_oscam_config_global(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
99 | int32_t i;
|
---|
100 |
|
---|
101 | if (strcmp(getParam(params, "action"), "execute") == 0) {
|
---|
102 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
103 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
104 | //tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
105 | //we use the same function as used for parsing the config tokens
|
---|
106 |
|
---|
107 | chk_t_global((*params).params[i], (*params).values[i]);
|
---|
108 | }
|
---|
109 | }
|
---|
110 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Global done. You should restart Oscam now.</B><BR><BR>");
|
---|
111 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
112 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
113 | }
|
---|
114 | if (cfg.srvip != 0)
|
---|
115 | tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.srvip));
|
---|
116 | tpl_printf(vars, TPLADD, "NICE", "%d", cfg.nice);
|
---|
117 | tpl_printf(vars, TPLADD, "BINDWAIT", "%d", cfg.bindwait);
|
---|
118 | tpl_printf(vars, TPLADD, "NETPRIO", "%ld", cfg.netprio);
|
---|
119 |
|
---|
120 |
|
---|
121 | if (cfg.usrfile != NULL) tpl_addVar(vars, TPLADD, "USERFILE", cfg.usrfile);
|
---|
122 | if (cfg.disableuserfile == 1) tpl_addVar(vars, TPLADD, "DISABLEUSERFILECHECKED", "selected");
|
---|
123 | if(cfg.usrfileflag == 1) tpl_addVar(vars, TPLADD, "USERFILEFLAGCHECKED", "selected");
|
---|
124 |
|
---|
125 | char *value = mk_t_logfile();
|
---|
126 | tpl_addVar(vars, TPLADD, "LOGFILE", value);
|
---|
127 | free_mk_t(value);
|
---|
128 | if(cfg.disablelog == 1) tpl_addVar(vars, TPLADD, "DISABLELOGCHECKED", "selected");
|
---|
129 | tpl_printf(vars, TPLADD, "MAXLOGSIZE", "%d", cfg.max_log_size);
|
---|
130 |
|
---|
131 | if (cfg.cwlogdir != NULL) tpl_addVar(vars, TPLADD, "CWLOGDIR", cfg.cwlogdir);
|
---|
132 | if (cfg.saveinithistory == 1) tpl_addVar(vars, TPLADD, "SAVEINITHISTORYCHECKED", "selected");
|
---|
133 |
|
---|
134 | tpl_printf(vars, TPLADD, "CLIENTTIMEOUT", "%ld", cfg.ctimeout);
|
---|
135 | tpl_printf(vars, TPLADD, "FALLBACKTIMEOUT", "%ld", cfg.ftimeout);
|
---|
136 | tpl_printf(vars, TPLADD, "CLIENTMAXIDLE", "%d", cfg.cmaxidle);
|
---|
137 | tpl_printf(vars, TPLADD, "CACHEDELAY", "%ld", cfg.delay);
|
---|
138 |
|
---|
139 | tpl_printf(vars, TPLADD, "SLEEP", "%d", cfg.tosleep);
|
---|
140 | if (cfg.ulparent == 1) tpl_addVar(vars, TPLADD, "UNLOCKPARENTALCHECKED", "selected");
|
---|
141 |
|
---|
142 | tpl_printf(vars, TPLADD, "SERIALTIMEOUT", "%d", cfg.srtimeout);
|
---|
143 |
|
---|
144 |
|
---|
145 | if (cfg.waitforcards == 1) tpl_addVar(vars, TPLADD, "WAITFORCARDSCHECKED", "selected");
|
---|
146 | tpl_printf(vars, TPLADD, "EXTRADELAY", "%d", cfg.waitforcards_extra_delay);
|
---|
147 | if (cfg.preferlocalcards == 1) tpl_addVar(vars, TPLADD, "PREFERLOCALCARDSCHECKED", "selected");
|
---|
148 |
|
---|
149 | if (cfg.c35_suppresscmd08)
|
---|
150 | tpl_addVar(vars, TPLADD, "SUPPRESSCMD08", "checked");
|
---|
151 |
|
---|
152 | if (cfg.reader_restart_seconds)
|
---|
153 | tpl_printf(vars, TPLADD, "READERRESTARTSECONDS", "%d", cfg.reader_restart_seconds);
|
---|
154 |
|
---|
155 | if (cfg.dropdups)
|
---|
156 | tpl_addVar(vars, TPLADD, "DROPDUPSCHECKED", "selected");
|
---|
157 |
|
---|
158 | if (cfg.resolve_gethostbyname == 1)
|
---|
159 | tpl_addVar(vars, TPLADD, "RESOLVER1", "selected");
|
---|
160 | else
|
---|
161 | tpl_addVar(vars, TPLADD, "RESOLVER0", "selected");
|
---|
162 |
|
---|
163 | tpl_printf(vars, TPLADD, "FAILBANTIME", "%d", cfg.failbantime);
|
---|
164 | tpl_printf(vars, TPLADD, "FAILBANCOUNT", "%d", cfg.failbancount);
|
---|
165 |
|
---|
166 | #ifdef CS_WITH_DOUBLECHECK
|
---|
167 | if(cfg.double_check == 1)
|
---|
168 | tpl_addVar(vars, TPLADD, "DCHECKCSELECTED", "selected");
|
---|
169 | #endif
|
---|
170 |
|
---|
171 | return tpl_getTpl(vars, "CONFIGGLOBAL");
|
---|
172 | }
|
---|
173 |
|
---|
174 | char *send_oscam_config_loadbalancer(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
175 | int32_t i;
|
---|
176 |
|
---|
177 | if (strcmp(getParam(params, "button"), "Load Stats") == 0) {
|
---|
178 | clear_all_stat();
|
---|
179 | load_stat_from_file();
|
---|
180 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Stats loades from file</B><BR><BR>");
|
---|
181 | }
|
---|
182 |
|
---|
183 | if (strcmp(getParam(params, "button"), "Save Stats") == 0) {
|
---|
184 | save_stat_to_file(1);
|
---|
185 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Stats saved to file</B><BR><BR>");
|
---|
186 | }
|
---|
187 |
|
---|
188 | if (strcmp(getParam(params, "button"), "Clear Stats") == 0) {
|
---|
189 | clear_all_stat();
|
---|
190 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Stats cleared completly</B><BR><BR>");
|
---|
191 | }
|
---|
192 |
|
---|
193 | if (strcmp(getParam(params, "action"),"execute") == 0) {
|
---|
194 |
|
---|
195 | memset(cfg.ser_device, 0, sizeof(cfg.ser_device));
|
---|
196 | memset(&cfg.lb_retrylimittab, 0, sizeof(CAIDVALUETAB));
|
---|
197 | memset(&cfg.lb_nbest_readers_tab, 0, sizeof(CAIDVALUETAB));
|
---|
198 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
199 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
200 | //tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
201 | //we use the same function as used for parsing the config tokens
|
---|
202 | if((*params).values[i][0])
|
---|
203 | chk_t_global((*params).params[i], (*params).values[i]);
|
---|
204 | }
|
---|
205 | }
|
---|
206 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Loadbalancer done.</B><BR><BR>");
|
---|
207 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
208 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
209 | }
|
---|
210 |
|
---|
211 | tpl_printf(vars, TPLADD, "TMP", "LBMODE%d", cfg.lb_mode);
|
---|
212 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
213 |
|
---|
214 | tpl_printf(vars, TPLADD, "LBSAVE", "%d",cfg.lb_save);
|
---|
215 | tpl_printf(vars, TPLADD, "LBSAVEPATH", cfg.lb_savepath?cfg.lb_savepath:"");
|
---|
216 |
|
---|
217 | tpl_printf(vars, TPLADD, "LBNBESTREADERS", "%d",cfg.lb_nbest_readers);
|
---|
218 | char *value = mk_t_caidvaluetab(&cfg.lb_nbest_readers_tab);
|
---|
219 | tpl_printf(vars, TPLADD, "LBNBESTPERCAID", value);
|
---|
220 | free_mk_t(value);
|
---|
221 | tpl_printf(vars, TPLADD, "LBNFBREADERS", "%d",cfg.lb_nfb_readers);
|
---|
222 | tpl_printf(vars, TPLADD, "LBMINECMCOUNT", "%d",cfg.lb_min_ecmcount);
|
---|
223 | tpl_printf(vars, TPLADD, "LBMAXECEMCOUNT", "%d",cfg.lb_max_ecmcount);
|
---|
224 | tpl_printf(vars, TPLADD, "LBRETRYLIMIT", "%d",cfg.lb_retrylimit);
|
---|
225 |
|
---|
226 | value = mk_t_caidvaluetab(&cfg.lb_retrylimittab);
|
---|
227 | tpl_printf(vars, TPLADD, "LBRETRYLIMITS", value);
|
---|
228 | free_mk_t(value);
|
---|
229 |
|
---|
230 | tpl_printf(vars, TPLADD, "LBREOPENSECONDS", "%d",cfg.lb_reopen_seconds);
|
---|
231 | tpl_printf(vars, TPLADD, "LBCLEANUP", "%d",cfg.lb_stat_cleanup);
|
---|
232 | if (cfg.lb_use_locking) tpl_addVar(vars, TPLADD, "USELOCKINGCHECKED", "selected");
|
---|
233 | if (cfg.lb_reopen_mode) tpl_addVar(vars, TPLADD, "REOPENMODE", "selected");
|
---|
234 |
|
---|
235 | value = mk_t_caidtab(&cfg.lb_noproviderforcaid);
|
---|
236 | tpl_addVar(vars, TPLADD, "LBNOPROVIDERFORCAID", value);
|
---|
237 | free_mk_t(value);
|
---|
238 |
|
---|
239 | return tpl_getTpl(vars, "CONFIGLOADBALANCER");
|
---|
240 | }
|
---|
241 |
|
---|
242 | char *send_oscam_config_camd33(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
243 | int32_t i;
|
---|
244 |
|
---|
245 | if (strcmp(getParam(params, "action"), "execute") == 0) {
|
---|
246 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
247 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
248 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
249 | if (strcmp((*params).params[i], "nocrypt") == 0) {
|
---|
250 | clear_sip(&cfg.c33_plain);
|
---|
251 | }
|
---|
252 | //we use the same function as used for parsing the config tokens
|
---|
253 | chk_t_camd33((*params).params[i], (*params).values[i]);
|
---|
254 | }
|
---|
255 | }
|
---|
256 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration camd33 done. You should restart Oscam now.</B><BR><BR>");
|
---|
257 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
258 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
259 | }
|
---|
260 |
|
---|
261 | if (cfg.c33_port) {
|
---|
262 | tpl_printf(vars, TPLADD, "PORT", "%d", cfg.c33_port);
|
---|
263 | if (cfg.c33_srvip != 0) tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.c33_srvip));
|
---|
264 | if (cfg.c33_passive == 1) tpl_addVar(vars, TPLADD, "PASSIVECHECKED", "selected");
|
---|
265 |
|
---|
266 | for (i = 0; i < (int) sizeof(cfg.c33_key); ++i) tpl_printf(vars, TPLAPPEND, "KEY", "%02X",cfg.c33_key[i]);
|
---|
267 | char *value = mk_t_iprange(cfg.c33_plain);
|
---|
268 | tpl_addVar(vars, TPLADD, "NOCRYPT", value);
|
---|
269 | free_mk_t(value);
|
---|
270 | }
|
---|
271 |
|
---|
272 | return tpl_getTpl(vars, "CONFIGCAMD33");
|
---|
273 | }
|
---|
274 |
|
---|
275 | char *send_oscam_config_camd35(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
276 | int32_t i;
|
---|
277 | if ((strcmp(getParam(params, "action"),"execute") == 0) && (getParam(params, "port"))[0]) {
|
---|
278 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
279 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
280 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
281 | //we use the same function as used for parsing the config tokens
|
---|
282 | chk_t_camd35((*params).params[i], (*params).values[i]);
|
---|
283 | }
|
---|
284 | }
|
---|
285 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration camd35 done. You should restart Oscam now.</B><BR><BR>");
|
---|
286 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
287 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
288 | }
|
---|
289 |
|
---|
290 | if (cfg.c35_port) {
|
---|
291 | tpl_printf(vars, TPLADD, "PORT", "%d", cfg.c35_port);
|
---|
292 | if (cfg.c35_srvip != 0)
|
---|
293 | tpl_addVar(vars, TPLAPPEND, "SERVERIP", cs_inet_ntoa(cfg.c35_srvip));
|
---|
294 |
|
---|
295 | if (cfg.c35_udp_suppresscmd08)
|
---|
296 | tpl_addVar(vars, TPLADD, "SUPPRESSCMD08UDP", "checked");
|
---|
297 |
|
---|
298 | }
|
---|
299 | return tpl_getTpl(vars, "CONFIGCAMD35");
|
---|
300 | }
|
---|
301 |
|
---|
302 | char *send_oscam_config_camd35tcp(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
303 | int32_t i;
|
---|
304 | if ((strcmp(getParam(params, "action"),"execute") == 0) && (getParam(params, "port"))[0]) {
|
---|
305 | clear_ptab(&cfg.c35_tcp_ptab); /*clear Porttab*/
|
---|
306 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
307 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
308 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
309 | //we use the same function as used for parsing the config tokens
|
---|
310 | chk_t_camd35_tcp((*params).params[i], (*params).values[i]);
|
---|
311 | }
|
---|
312 | }
|
---|
313 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration camd35 TCP done. You should restart Oscam now.</B><BR><BR>");
|
---|
314 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
315 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
316 | }
|
---|
317 |
|
---|
318 | if ((cfg.c35_tcp_ptab.nports > 0) && (cfg.c35_tcp_ptab.ports[0].s_port > 0)) {
|
---|
319 |
|
---|
320 | char *value = mk_t_camd35tcp_port();
|
---|
321 | tpl_addVar(vars, TPLADD, "PORT", value);
|
---|
322 | free_mk_t(value);
|
---|
323 |
|
---|
324 | if (cfg.c35_tcp_srvip != 0)
|
---|
325 | tpl_addVar(vars, TPLAPPEND, "SERVERIP", cs_inet_ntoa(cfg.c35_tcp_srvip));
|
---|
326 |
|
---|
327 | if (cfg.c35_tcp_suppresscmd08)
|
---|
328 | tpl_addVar(vars, TPLADD, "SUPPRESSCMD08TCP", "checked");
|
---|
329 | }
|
---|
330 | return tpl_getTpl(vars, "CONFIGCAMD35TCP");
|
---|
331 | }
|
---|
332 |
|
---|
333 | char *send_oscam_config_newcamd(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
334 | int32_t i;
|
---|
335 | if (strcmp(getParam(params, "action"),"execute") == 0) {
|
---|
336 | clear_ptab(&cfg.ncd_ptab); /*clear Porttab*/
|
---|
337 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
338 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
339 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
340 | //we use the same function as used for parsing the config tokens
|
---|
341 | if (strcmp((*params).params[i], "allowed") == 0) {
|
---|
342 | clear_sip(&cfg.ncd_allowed);
|
---|
343 | }
|
---|
344 | chk_t_newcamd((*params).params[i], (*params).values[i]);
|
---|
345 | }
|
---|
346 | }
|
---|
347 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Newcamd done. You should restart Oscam now.</B><BR><BR>");
|
---|
348 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
349 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
350 | }
|
---|
351 |
|
---|
352 | if ((cfg.ncd_ptab.nports > 0) && (cfg.ncd_ptab.ports[0].s_port > 0)) {
|
---|
353 |
|
---|
354 | char *value = mk_t_newcamd_port();
|
---|
355 | tpl_addVar(vars, TPLADD, "PORT", value);
|
---|
356 | free_mk_t(value);
|
---|
357 |
|
---|
358 | if (cfg.ncd_srvip != 0)
|
---|
359 | tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.ncd_srvip));
|
---|
360 |
|
---|
361 | for (i = 0; i < 14; i++) tpl_printf(vars, TPLAPPEND, "KEY", "%02X", cfg.ncd_key[i]);
|
---|
362 |
|
---|
363 | value = mk_t_iprange(cfg.ncd_allowed);
|
---|
364 | tpl_addVar(vars, TPLADD, "ALLOWED", value);
|
---|
365 | free_mk_t(value);
|
---|
366 |
|
---|
367 | if (cfg.ncd_keepalive)
|
---|
368 | tpl_addVar(vars, TPLADD, "KEEPALIVE", "checked");
|
---|
369 | if (cfg.ncd_mgclient)
|
---|
370 | tpl_addVar(vars, TPLADD, "MGCLIENTCHK", "checked");
|
---|
371 | }
|
---|
372 | return tpl_getTpl(vars, "CONFIGNEWCAMD");
|
---|
373 | }
|
---|
374 |
|
---|
375 | char *send_oscam_config_radegast(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
376 | int32_t i;
|
---|
377 | if (strcmp(getParam(params, "action"),"execute") == 0) {
|
---|
378 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
379 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
380 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
381 | if (strcmp((*params).params[i], "allowed") == 0) {
|
---|
382 | clear_sip(&cfg.rad_allowed);
|
---|
383 | }
|
---|
384 | //we use the same function as used for parsing the config tokens
|
---|
385 | chk_t_radegast((*params).params[i], (*params).values[i]);
|
---|
386 | }
|
---|
387 | }
|
---|
388 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Radegast done. You should restart Oscam now.</B><BR><BR>");
|
---|
389 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
390 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
391 | }
|
---|
392 | tpl_printf(vars, TPLADD, "PORT", "%d", cfg.rad_port);
|
---|
393 | if (cfg.rad_srvip != 0)
|
---|
394 | tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.rad_srvip));
|
---|
395 | tpl_addVar(vars, TPLADD, "USER", cfg.rad_usr);
|
---|
396 |
|
---|
397 | char *value = mk_t_iprange(cfg.rad_allowed);
|
---|
398 | tpl_addVar(vars, TPLADD, "ALLOWED", value);
|
---|
399 | free_mk_t(value);
|
---|
400 |
|
---|
401 | return tpl_getTpl(vars, "CONFIGRADEGAST");
|
---|
402 | }
|
---|
403 |
|
---|
404 | char *send_oscam_config_cccam(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
405 |
|
---|
406 |
|
---|
407 | if (strcmp(getParam(params, "button"), "Refresh global list") == 0) {
|
---|
408 | cs_debug_mask(D_TRACE, "Entitlements: Refresh Shares start");
|
---|
409 | refresh_shares();
|
---|
410 | cs_debug_mask(D_TRACE, "Entitlements: Refresh Shares finished");
|
---|
411 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Refresh Shares started</B><BR><BR>");
|
---|
412 | }
|
---|
413 |
|
---|
414 | int32_t i;
|
---|
415 | if (strcmp(getParam(params, "action"),"execute") == 0) {
|
---|
416 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
417 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
418 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
419 | //we use the same function as used for parsing the config tokens
|
---|
420 | chk_t_cccam((*params).params[i], (*params).values[i]);
|
---|
421 | }
|
---|
422 | }
|
---|
423 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
424 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
425 | }
|
---|
426 |
|
---|
427 | tpl_printf(vars, TPLAPPEND, "PORT", "%d", cfg.cc_port);
|
---|
428 | tpl_printf(vars, TPLADD, "RESHARE", "%d", cfg.cc_reshare);
|
---|
429 |
|
---|
430 | if (!strcmp((char*)cfg.cc_version,"2.0.11")) {
|
---|
431 | tpl_addVar(vars, TPLADD, "VERSIONSELECTED0", "selected");
|
---|
432 | } else if (!strcmp((char*)cfg.cc_version,"2.1.1")) {
|
---|
433 | tpl_addVar(vars, TPLADD, "VERSIONSELECTED1", "selected");
|
---|
434 | } else if (!strcmp((char*)cfg.cc_version,"2.1.2")) {
|
---|
435 | tpl_addVar(vars, TPLADD, "VERSIONSELECTED2", "selected");
|
---|
436 | } else if (!strcmp((char*)cfg.cc_version,"2.1.3")) {
|
---|
437 | tpl_addVar(vars, TPLADD, "VERSIONSELECTED3", "selected");
|
---|
438 | } else if (!strcmp((char*)cfg.cc_version,"2.1.4")) {
|
---|
439 | tpl_addVar(vars, TPLADD, "VERSIONSELECTED4", "selected");
|
---|
440 | } else if (!strcmp((char*)cfg.cc_version,"2.2.0")) {
|
---|
441 | tpl_addVar(vars, TPLADD, "VERSIONSELECTED5", "selected");
|
---|
442 | } else if (!strcmp((char*)cfg.cc_version,"2.2.1")) {
|
---|
443 | tpl_addVar(vars, TPLADD, "VERSIONSELECTED6", "selected");
|
---|
444 | }
|
---|
445 |
|
---|
446 | tpl_printf(vars, TPLADD, "UPDATEINTERVAL", "%d", cfg.cc_update_interval);
|
---|
447 | if (cfg.cc_stealth)
|
---|
448 | tpl_printf(vars, TPLADD, "STEALTH", "selected");
|
---|
449 |
|
---|
450 | tpl_printf(vars, TPLADD, "TMP", "MINIMIZECARDSELECTED%d", cfg.cc_minimize_cards);
|
---|
451 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
452 |
|
---|
453 | tpl_printf(vars, TPLADD, "TMP", "RESHAREMODE%d", cfg.cc_reshare_services);
|
---|
454 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
455 |
|
---|
456 | if (cfg.cc_ignore_reshare)
|
---|
457 | tpl_printf(vars, TPLADD, "IGNORERESHARE", "selected");
|
---|
458 |
|
---|
459 | if (cfg.cc_forward_origin_card)
|
---|
460 | tpl_printf(vars, TPLADD, "FORWARDORIGINCARD", "selected");
|
---|
461 |
|
---|
462 | if (cfg.cc_keep_connected)
|
---|
463 | tpl_printf(vars, TPLADD, "KEEPCONNECTED", "selected");
|
---|
464 |
|
---|
465 |
|
---|
466 | return tpl_getTpl(vars, "CONFIGCCCAM");
|
---|
467 | }
|
---|
468 |
|
---|
469 | char *send_oscam_config_monitor(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
470 | int32_t i;
|
---|
471 | if (strcmp(getParam(params, "action"),"execute") == 0) {
|
---|
472 |
|
---|
473 | //cleanup
|
---|
474 | clear_sip(&cfg.mon_allowed);
|
---|
475 | clear_sip(&cfg.http_allowed);
|
---|
476 |
|
---|
477 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
478 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
479 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
480 |
|
---|
481 | //we use the same function as used for parsing the config tokens
|
---|
482 | if (strstr((*params).params[i], "http")) {
|
---|
483 | chk_t_webif((*params).params[i], (*params).values[i]);
|
---|
484 | } else {
|
---|
485 | chk_t_monitor((*params).params[i], (*params).values[i]);
|
---|
486 | }
|
---|
487 | }
|
---|
488 | }
|
---|
489 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Monitor done. You should restart Oscam now.</B><BR><BR>");
|
---|
490 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
491 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
492 | }
|
---|
493 | tpl_printf(vars, TPLADD, "MONPORT", "%d", cfg.mon_port);
|
---|
494 | if (cfg.mon_srvip != 0)
|
---|
495 | tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.mon_srvip));
|
---|
496 | tpl_printf(vars, TPLADD, "AULOW", "%d", cfg.mon_aulow);
|
---|
497 | tpl_printf(vars, TPLADD, "HIDECLIENTTO", "%d", cfg.mon_hideclient_to);
|
---|
498 | if(cfg.mon_appendchaninfo)
|
---|
499 | tpl_addVar(vars, TPLADD, "APPENDCHANINFO", "checked");
|
---|
500 |
|
---|
501 | #ifdef WITH_SSL
|
---|
502 | if(cfg.http_use_ssl)
|
---|
503 | tpl_printf(vars, TPLADD, "HTTPPORT", "+%d", cfg.http_port);
|
---|
504 | else
|
---|
505 | tpl_printf(vars, TPLADD, "HTTPPORT", "%d", cfg.http_port);
|
---|
506 | #else
|
---|
507 | tpl_printf(vars, TPLADD, "HTTPPORT", "%d", cfg.http_port);
|
---|
508 | #endif
|
---|
509 |
|
---|
510 | tpl_addVar(vars, TPLADD, "HTTPUSER", cfg.http_user);
|
---|
511 | tpl_addVar(vars, TPLADD, "HTTPPASSWORD", cfg.http_pwd);
|
---|
512 |
|
---|
513 | // css style selector
|
---|
514 | if(strlen(cfg.http_css) == 0) {
|
---|
515 | tpl_addVar(vars, TPLADD, "CSSOPTIONS", "\t\t\t\t\t\t<option value=\"\" selected>embedded</option>\n");
|
---|
516 | } else {
|
---|
517 | tpl_addVar(vars, TPLADD, "CSSOPTIONS", "\t\t\t\t\t\t<option value=\"\">embedded</option>\n");
|
---|
518 | }
|
---|
519 |
|
---|
520 | DIR *hdir;
|
---|
521 | struct dirent *entry;
|
---|
522 | hdir = opendir(cs_confdir);
|
---|
523 | do {
|
---|
524 | entry = readdir(hdir);
|
---|
525 | if ((entry) && (strstr(entry->d_name, ".css"))) {
|
---|
526 | if (strstr(cfg.http_css, entry->d_name)) {
|
---|
527 | tpl_printf(vars, TPLAPPEND, "CSSOPTIONS", "\t\t\t\t\t\t<option value=\"%s%s\" selected>%s%s</option>\n",cs_confdir,entry->d_name,cs_confdir,entry->d_name);
|
---|
528 | } else {
|
---|
529 | tpl_printf(vars, TPLAPPEND, "CSSOPTIONS", "\t\t\t\t\t\t<option value=\"%s%s\">%s%s</option>\n",cs_confdir,entry->d_name,cs_confdir,entry->d_name);
|
---|
530 | }
|
---|
531 | }
|
---|
532 | } while (entry);
|
---|
533 | closedir(hdir);
|
---|
534 |
|
---|
535 | if (cfg.http_help_lang[0])
|
---|
536 | tpl_addVar(vars, TPLADD, "HTTPHELPLANG", cfg.http_help_lang);
|
---|
537 | else
|
---|
538 | tpl_addVar(vars, TPLADD, "HTTPHELPLANG", "en");
|
---|
539 |
|
---|
540 | tpl_printf(vars, TPLADD, "HTTPREFRESH", "%d", cfg.http_refresh);
|
---|
541 | tpl_addVar(vars, TPLADD, "HTTPTPL", cfg.http_tpl);
|
---|
542 | tpl_addVar(vars, TPLADD, "HTTPSCRIPT", cfg.http_script);
|
---|
543 | tpl_addVar(vars, TPLADD, "HTTPJSCRIPT", cfg.http_jscript);
|
---|
544 |
|
---|
545 | if (cfg.http_hide_idle_clients > 0) tpl_addVar(vars, TPLADD, "CHECKED", "checked");
|
---|
546 |
|
---|
547 | char *value = mk_t_iprange(cfg.mon_allowed);
|
---|
548 | tpl_addVar(vars, TPLADD, "NOCRYPT", value);
|
---|
549 | free_mk_t(value);
|
---|
550 |
|
---|
551 | value = mk_t_iprange(cfg.http_allowed);
|
---|
552 | tpl_addVar(vars, TPLADD, "HTTPALLOW", value);
|
---|
553 | free_mk_t(value);
|
---|
554 |
|
---|
555 | tpl_printf(vars, TPLADD, "HTTPDYNDNS", "%s", cfg.http_dyndns);
|
---|
556 |
|
---|
557 | //Monlevel selector
|
---|
558 | tpl_printf(vars, TPLADD, "TMP", "MONSELECTED%d", cfg.mon_level);
|
---|
559 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
560 |
|
---|
561 | if (cfg.http_full_cfg)
|
---|
562 | tpl_addVar(vars, TPLADD, "HTTPSAVEFULLSELECT", "selected");
|
---|
563 |
|
---|
564 | return tpl_getTpl(vars, "CONFIGMONITOR");
|
---|
565 | }
|
---|
566 |
|
---|
567 | char *send_oscam_config_serial(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
568 | int32_t i;
|
---|
569 | if (strcmp(getParam(params, "action"),"execute") == 0) {
|
---|
570 | //cfg.ser_device[0]='\0';
|
---|
571 | memset(cfg.ser_device, 0, sizeof(cfg.ser_device));
|
---|
572 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
573 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
574 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
575 | //we use the same function as used for parsing the config tokens
|
---|
576 | if((*params).values[i][0])
|
---|
577 | chk_t_serial((*params).params[i], (*params).values[i]);
|
---|
578 | }
|
---|
579 | }
|
---|
580 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Serial done. You should restart Oscam now.</B><BR><BR>");
|
---|
581 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
582 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
583 | }
|
---|
584 |
|
---|
585 | if (cfg.ser_device[0]){
|
---|
586 | char sdevice[512];
|
---|
587 | cs_strncpy(sdevice, cfg.ser_device, sizeof(sdevice));
|
---|
588 | char *ptr;
|
---|
589 | char delimiter[2]; delimiter[0] = 1; delimiter[1] = '\0';
|
---|
590 | ptr = strtok(sdevice, delimiter);
|
---|
591 | while(ptr != NULL) {
|
---|
592 | tpl_printf(vars, TPLADD, "SERIALDEVICE", "%s", ptr);
|
---|
593 | tpl_addVar(vars, TPLAPPEND, "DEVICES", tpl_getTpl(vars, "CONFIGSERIALDEVICEBIT"));
|
---|
594 | ptr = strtok(NULL, delimiter);
|
---|
595 | }
|
---|
596 | }
|
---|
597 |
|
---|
598 | tpl_printf(vars, TPLADD, "SERIALDEVICE", "%s", "");
|
---|
599 | tpl_addVar(vars, TPLAPPEND, "DEVICES", tpl_getTpl(vars, "CONFIGSERIALDEVICEBIT"));
|
---|
600 |
|
---|
601 | return tpl_getTpl(vars, "CONFIGSERIAL");
|
---|
602 | }
|
---|
603 |
|
---|
604 | #ifdef HAVE_DVBAPI
|
---|
605 | char *send_oscam_config_dvbapi(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
606 | int32_t i;
|
---|
607 | if (strcmp(getParam(params, "action"),"execute") == 0) {
|
---|
608 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
609 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
610 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
611 | //we use the same function as used for parsing the config tokens
|
---|
612 | chk_t_dvbapi((*params).params[i], (*params).values[i]);
|
---|
613 | }
|
---|
614 | }
|
---|
615 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration DVB Api done. You should restart Oscam now.</B><BR><BR>");
|
---|
616 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
617 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
618 | }
|
---|
619 |
|
---|
620 | if (cfg.dvbapi_enabled > 0)
|
---|
621 | tpl_addVar(vars, TPLADD, "ENABLEDCHECKED", "checked");
|
---|
622 |
|
---|
623 | if (cfg.dvbapi_au > 0)
|
---|
624 | tpl_addVar(vars, TPLADD, "AUCHECKED", "checked");
|
---|
625 |
|
---|
626 | tpl_printf(vars, TPLADD, "BOXTYPE", "<option value=\"\"%s>None</option>\n", cfg.dvbapi_boxtype == 0 ? " selected" : "");
|
---|
627 | for (i=1; i<=BOXTYPES; i++) {
|
---|
628 | tpl_printf(vars, TPLAPPEND, "BOXTYPE", "<option%s>%s</option>\n", cfg.dvbapi_boxtype == i ? " selected" : "", boxdesc[i]);
|
---|
629 | }
|
---|
630 |
|
---|
631 | if(cfg.dvbapi_usr[0])
|
---|
632 | tpl_addVar(vars, TPLADD, "USER", cfg.dvbapi_usr);
|
---|
633 |
|
---|
634 | //PMT Mode
|
---|
635 | tpl_printf(vars, TPLADD, "TMP", "PMTMODESELECTED%d", cfg.dvbapi_pmtmode);
|
---|
636 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
637 |
|
---|
638 | //Request Mode
|
---|
639 | tpl_printf(vars, TPLADD, "TMP", "REQMODESELECTED%d", cfg.dvbapi_requestmode);
|
---|
640 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
641 |
|
---|
642 | return tpl_getTpl(vars, "CONFIGDVBAPI");
|
---|
643 | }
|
---|
644 | #endif
|
---|
645 |
|
---|
646 | #ifdef CS_ANTICASC
|
---|
647 | char *send_oscam_config_anticasc(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
648 | int32_t i;
|
---|
649 | if (strcmp(getParam(params, "action"),"execute") == 0) {
|
---|
650 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
651 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
|
---|
652 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
653 | //we use the same function as used for parsing the config tokens
|
---|
654 | chk_t_ac((*params).params[i], (*params).values[i]);
|
---|
655 | }
|
---|
656 | }
|
---|
657 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Anticascading done. You should restart Oscam now.</B><BR><BR>");
|
---|
658 | refresh_oscam(REFR_ANTICASC, in);
|
---|
659 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
660 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
661 | }
|
---|
662 | if (cfg.ac_enabled > 0) tpl_addVar(vars, TPLADD, "CHECKED", "checked");
|
---|
663 | tpl_printf(vars, TPLADD, "NUMUSERS", "%d", cfg.ac_users);
|
---|
664 | tpl_printf(vars, TPLADD, "SAMPLETIME", "%d", cfg.ac_stime);
|
---|
665 | tpl_printf(vars, TPLADD, "SAMPLES", "%d", cfg.ac_samples);
|
---|
666 |
|
---|
667 | tpl_printf(vars, TPLADD, "TMP", "PENALTY%d", cfg.ac_penalty);
|
---|
668 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
669 |
|
---|
670 | tpl_addVar(vars, TPLADD, "ACLOGFILE", cfg.ac_logfile);
|
---|
671 | tpl_printf(vars, TPLADD, "FAKEDELAY", "%d", cfg.ac_fakedelay);
|
---|
672 | tpl_printf(vars, TPLADD, "DENYSAMPLES", "%d", cfg.ac_denysamples);
|
---|
673 | return tpl_getTpl(vars, "CONFIGANTICASC");
|
---|
674 | }
|
---|
675 | #endif
|
---|
676 |
|
---|
677 | char *send_oscam_config(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
678 | char *part = getParam(params, "part");
|
---|
679 | if (!strcmp(part,"camd33")) return send_oscam_config_camd33(vars, params, in);
|
---|
680 | else if (!strcmp(part,"camd35")) return send_oscam_config_camd35(vars, params, in);
|
---|
681 | else if (!strcmp(part,"camd35tcp")) return send_oscam_config_camd35tcp(vars, params, in);
|
---|
682 | else if (!strcmp(part,"newcamd")) return send_oscam_config_newcamd(vars, params, in);
|
---|
683 | else if (!strcmp(part,"radegast")) return send_oscam_config_radegast(vars, params, in);
|
---|
684 | else if (!strcmp(part,"cccam")) return send_oscam_config_cccam(vars, params, in);
|
---|
685 | #ifdef HAVE_DVBAPI
|
---|
686 | else if (!strcmp(part,"dvbapi")) return send_oscam_config_dvbapi(vars, params, in);
|
---|
687 | #endif
|
---|
688 | #ifdef CS_ANTICASC
|
---|
689 | else if (!strcmp(part,"anticasc")) return send_oscam_config_anticasc(vars, params, in);
|
---|
690 | #endif
|
---|
691 | else if (!strcmp(part,"monitor")) return send_oscam_config_monitor(vars, params, in);
|
---|
692 | else if (!strcmp(part,"serial")) return send_oscam_config_serial(vars, params, in);
|
---|
693 | else if (!strcmp(part,"loadbalancer")) return send_oscam_config_loadbalancer(vars, params, in);
|
---|
694 | else return send_oscam_config_global(vars, params, in);
|
---|
695 | }
|
---|
696 |
|
---|
697 | void inactivate_reader(struct s_reader *rdr)
|
---|
698 | {
|
---|
699 | if (rdr == first_active_reader)
|
---|
700 | first_active_reader = first_active_reader->next;
|
---|
701 | else {
|
---|
702 | struct s_reader *rdr2, *prev;
|
---|
703 | for (prev=first_active_reader, rdr2=first_active_reader->next; prev->next && rdr != rdr2 ; prev=prev->next, rdr2=rdr2->next); //find reader in active reader list, will not be found if first in list
|
---|
704 | if (rdr2 == rdr) //found
|
---|
705 | prev->next = rdr2->next; //remove from active reader list
|
---|
706 | }
|
---|
707 | if (rdr->client)
|
---|
708 | kill_thread(rdr->client);
|
---|
709 | }
|
---|
710 |
|
---|
711 | char *send_oscam_reader(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
712 | struct s_reader *rdr;
|
---|
713 | int32_t i;
|
---|
714 |
|
---|
715 | if ((strcmp(getParam(params, "action"), "disable") == 0) || (strcmp(getParam(params, "action"), "enable") == 0)) {
|
---|
716 | if(cfg.http_readonly) {
|
---|
717 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Webif is in readonly mode. Enabling or disabling readers is not possible!</b><BR>");
|
---|
718 | } else {
|
---|
719 | rdr = get_reader_by_label(getParam(params, "label"));
|
---|
720 | if (rdr) {
|
---|
721 | struct s_reader *rdr2;
|
---|
722 | if (strcmp(getParam(params, "action"), "enable") == 0) {
|
---|
723 | if (!rdr->enable) {
|
---|
724 | rdr->next = NULL; //terminate active reader list
|
---|
725 | if (!first_active_reader) {
|
---|
726 | first_active_reader = rdr;
|
---|
727 | } else {
|
---|
728 | for (rdr2 = first_active_reader; rdr2->next ; rdr2 = rdr2->next); //find last reader in active reader list
|
---|
729 | rdr2->next = rdr; //add
|
---|
730 | }
|
---|
731 | rdr->enable = 1;
|
---|
732 | restart_cardreader(rdr, 1);
|
---|
733 | }
|
---|
734 | } else {
|
---|
735 | if (rdr->enable) {
|
---|
736 | rdr->enable = 0;
|
---|
737 | inactivate_reader(rdr);
|
---|
738 | }
|
---|
739 | }
|
---|
740 | if(write_server() != 0)
|
---|
741 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
742 | }
|
---|
743 | }
|
---|
744 | }
|
---|
745 |
|
---|
746 | if (strcmp(getParam(params, "action"), "delete") == 0) {
|
---|
747 | if(cfg.http_readonly) {
|
---|
748 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Webif is in readonly mode. No deletion will be made!</b><BR>");
|
---|
749 | } else {
|
---|
750 | rdr = get_reader_by_label(getParam(params, "label"));
|
---|
751 | if (rdr) {
|
---|
752 | inactivate_reader(rdr);
|
---|
753 | ll_remove(configured_readers, rdr);
|
---|
754 |
|
---|
755 | if(write_server()==0) refresh_oscam(REFR_READERS, in);
|
---|
756 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
757 | }
|
---|
758 | }
|
---|
759 | }
|
---|
760 |
|
---|
761 | if (strcmp(getParam(params, "action"), "reread") == 0) {
|
---|
762 | rdr = get_reader_by_label(getParam(params, "label"));
|
---|
763 | if (rdr) {
|
---|
764 | //reset the counters
|
---|
765 | for (i = 0; i < 4; i++) {
|
---|
766 | rdr->emmerror[i] = 0;
|
---|
767 | rdr->emmwritten[i] = 0;
|
---|
768 | rdr->emmskipped[i] = 0;
|
---|
769 | rdr->emmblocked[i] = 0;
|
---|
770 | }
|
---|
771 | /*
|
---|
772 | if( rdr->enable == 1 && rdr->client->typ == 'r' && rdr->client->fd_m2c ) {
|
---|
773 | uchar dummy[1]={0x00};
|
---|
774 | write_to_pipe(rdr->client->fd_m2c, PIP_ID_CIN, dummy, 1);
|
---|
775 | }*/
|
---|
776 |
|
---|
777 | refresh_oscam(REFR_READERS, in); // refresh all reader because write pipe seams not work from here
|
---|
778 | }
|
---|
779 | }
|
---|
780 |
|
---|
781 | LL_ITER *itr = ll_iter_create(configured_readers);
|
---|
782 | for (i = 0, rdr = ll_iter_next(itr); rdr && rdr->label[0]; rdr = ll_iter_next(itr), i++);
|
---|
783 | tpl_printf(vars, TPLADD, "NEXTREADER", "Reader-%d", i); //Next Readername
|
---|
784 |
|
---|
785 | ll_iter_reset(itr); //going to iterate all configured readers
|
---|
786 | while ((rdr = ll_iter_next(itr))) {
|
---|
787 |
|
---|
788 | if(rdr->label[0] && rdr->typ) {
|
---|
789 |
|
---|
790 | if (rdr->enable)
|
---|
791 | tpl_addVar(vars, TPLADD, "READERCLASS", "enabledreader");
|
---|
792 | else
|
---|
793 | tpl_addVar(vars, TPLADD, "READERCLASS", "disabledreader");
|
---|
794 |
|
---|
795 | tpl_addVar(vars, TPLADD, "READERNAME", xml_encode(vars, rdr->label));
|
---|
796 | tpl_addVar(vars, TPLADD, "READERNAMEENC", urlencode(vars, rdr->label));
|
---|
797 | tpl_printf(vars, TPLADD, "EMMERRORUK", "%d", rdr->emmerror[UNKNOWN]);
|
---|
798 | tpl_printf(vars, TPLADD, "EMMERRORG", "%d", rdr->emmerror[GLOBAL]);
|
---|
799 | tpl_printf(vars, TPLADD, "EMMERRORS", "%d", rdr->emmerror[SHARED]);
|
---|
800 | tpl_printf(vars, TPLADD, "EMMERRORUQ", "%d", rdr->emmerror[UNIQUE]);
|
---|
801 |
|
---|
802 | tpl_printf(vars, TPLADD, "EMMWRITTENUK", "%d", rdr->emmwritten[UNKNOWN]);
|
---|
803 | tpl_printf(vars, TPLADD, "EMMWRITTENG", "%d", rdr->emmwritten[GLOBAL]);
|
---|
804 | tpl_printf(vars, TPLADD, "EMMWRITTENS", "%d", rdr->emmwritten[SHARED]);
|
---|
805 | tpl_printf(vars, TPLADD, "EMMWRITTENUQ", "%d", rdr->emmwritten[UNIQUE]);
|
---|
806 |
|
---|
807 | tpl_printf(vars, TPLADD, "EMMSKIPPEDUK", "%d", rdr->emmskipped[UNKNOWN]);
|
---|
808 | tpl_printf(vars, TPLADD, "EMMSKIPPEDG", "%d", rdr->emmskipped[GLOBAL]);
|
---|
809 | tpl_printf(vars, TPLADD, "EMMSKIPPEDS", "%d", rdr->emmskipped[SHARED]);
|
---|
810 | tpl_printf(vars, TPLADD, "EMMSKIPPEDUQ", "%d", rdr->emmskipped[UNIQUE]);
|
---|
811 |
|
---|
812 | tpl_printf(vars, TPLADD, "EMMBLOCKEDUK", "%d", rdr->emmblocked[UNKNOWN]);
|
---|
813 | tpl_printf(vars, TPLADD, "EMMBLOCKEDG", "%d", rdr->emmblocked[GLOBAL]);
|
---|
814 | tpl_printf(vars, TPLADD, "EMMBLOCKEDS", "%d", rdr->emmblocked[SHARED]);
|
---|
815 | tpl_printf(vars, TPLADD, "EMMBLOCKEDUQ", "%d", rdr->emmblocked[UNIQUE]);
|
---|
816 |
|
---|
817 | if (!(rdr->typ & R_IS_NETWORK)) { //reader is physical
|
---|
818 | tpl_addVar(vars, TPLADD, "REFRICO", "image?i=ICREF");
|
---|
819 | tpl_addVar(vars, TPLADD, "READERREFRESH", tpl_getTpl(vars, "READERREFRESHBIT"));
|
---|
820 | tpl_addVar(vars, TPLADD, "ENTICO", "image?i=ICENT");
|
---|
821 | tpl_addVar(vars, TPLADD, "ENTITLEMENT", tpl_getTpl(vars, "READERENTITLEBIT"));
|
---|
822 | } else {
|
---|
823 | tpl_addVar(vars, TPLADD, "READERREFRESH","");
|
---|
824 | if (rdr->typ == R_CCCAM) {
|
---|
825 | tpl_addVar(vars, TPLADD, "ENTICO", "image?i=ICENT");
|
---|
826 | tpl_addVar(vars, TPLADD, "ENTITLEMENT", tpl_getTpl(vars, "READERENTITLEBIT"));
|
---|
827 | } else {
|
---|
828 | tpl_addVar(vars, TPLADD, "ENTITLEMENT","");
|
---|
829 | }
|
---|
830 | }
|
---|
831 |
|
---|
832 | if(rdr->enable == 0) {
|
---|
833 | tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICENA");
|
---|
834 | tpl_addVar(vars, TPLADD, "SWITCHTITLE", "enable this reader");
|
---|
835 | tpl_addVar(vars, TPLADD, "SWITCH", "enable");
|
---|
836 | } else {
|
---|
837 | tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICDIS");
|
---|
838 | tpl_addVar(vars, TPLADD, "SWITCHTITLE", "disable this reader");
|
---|
839 | tpl_addVar(vars, TPLADD, "SWITCH", "disable");
|
---|
840 | }
|
---|
841 |
|
---|
842 | tpl_addVar(vars, TPLADD, "CTYP", reader_get_type_desc(rdr, 0));
|
---|
843 |
|
---|
844 | tpl_addVar(vars, TPLAPPEND, "READERLIST", tpl_getTpl(vars, "READERSBIT"));
|
---|
845 | }
|
---|
846 | }
|
---|
847 | ll_iter_release(itr);
|
---|
848 |
|
---|
849 | #ifdef HAVE_PCSC
|
---|
850 | tpl_addVar(vars, TPLAPPEND, "ADDPROTOCOL", "<option>pcsc</option>\n");
|
---|
851 | #endif
|
---|
852 |
|
---|
853 | for (i=0; i<CS_MAX_MOD; i++) {
|
---|
854 | if (cardreader[i].desc[0]!=0)
|
---|
855 | tpl_printf(vars, TPLAPPEND, "ADDPROTOCOL", "<option>%s</option>\n", cardreader[i].desc);
|
---|
856 | }
|
---|
857 |
|
---|
858 | return tpl_getTpl(vars, "READERS");
|
---|
859 | }
|
---|
860 |
|
---|
861 | char *send_oscam_reader_config(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
862 | int32_t i;
|
---|
863 | char *reader_ = getParam(params, "label");
|
---|
864 | char *value;
|
---|
865 |
|
---|
866 | struct s_reader *rdr;
|
---|
867 |
|
---|
868 | if(strcmp(getParam(params, "action"), "Add") == 0) {
|
---|
869 | // Add new reader
|
---|
870 | struct s_reader *newrdr;
|
---|
871 | if(!cs_malloc(&newrdr,sizeof(struct s_reader), -1)) return "0";
|
---|
872 | memset(newrdr, 0, sizeof(struct s_reader));
|
---|
873 | ll_append(configured_readers, newrdr);
|
---|
874 | newrdr->next = NULL; // terminate list
|
---|
875 | newrdr->enable = 0; // do not start the reader because must configured before
|
---|
876 | cs_strncpy(newrdr->pincode, "none", sizeof(newrdr->pincode));
|
---|
877 | for (i = 1; i < CS_MAXCAIDTAB; newrdr->ctab.mask[i++] = 0xffff);
|
---|
878 | for (i = 0; i < (*params).paramcount; ++i) {
|
---|
879 | if (strcmp((*params).params[i], "action"))
|
---|
880 | chk_reader((*params).params[i], (*params).values[i], newrdr);
|
---|
881 | }
|
---|
882 | if (newrdr->typ & R_IS_CASCADING) {
|
---|
883 | for (i=0; i<CS_MAX_MOD; i++) {
|
---|
884 | if (ph[i].num && newrdr->typ==ph[i].num) {
|
---|
885 | newrdr->ph=ph[i];
|
---|
886 | newrdr->ph.active=1;
|
---|
887 | }
|
---|
888 | }
|
---|
889 | }
|
---|
890 | reader_ = newrdr->label;
|
---|
891 | } else if(strcmp(getParam(params, "action"), "Save") == 0) {
|
---|
892 |
|
---|
893 | rdr = get_reader_by_label(getParam(params, "label"));
|
---|
894 | char servicelabels[1024]="";
|
---|
895 |
|
---|
896 | clear_caidtab(&rdr->ctab);
|
---|
897 | clear_ftab(&rdr->ftab);
|
---|
898 | clear_ftab(&rdr->fchid);
|
---|
899 | if(rdr->aes_list) {
|
---|
900 | aes_clear_entries(rdr);
|
---|
901 | }
|
---|
902 |
|
---|
903 | rdr->grp = 0;
|
---|
904 | rdr->auprovid = 0;
|
---|
905 | for(i = 0; i < (*params).paramcount; ++i) {
|
---|
906 | if ((strcmp((*params).params[i], "reader")) && (strcmp((*params).params[i], "action"))) {
|
---|
907 | if (!strcmp((*params).params[i], "services"))
|
---|
908 | snprintf(servicelabels + strlen(servicelabels), sizeof(servicelabels) - strlen(servicelabels), "%s,", (*params).values[i]);
|
---|
909 | else
|
---|
910 | /*if(strlen((*params).values[i]) > 0)*/
|
---|
911 | chk_reader((*params).params[i], (*params).values[i], rdr);
|
---|
912 | }
|
---|
913 | //printf("param %s value %s\n",(*params).params[i], (*params).values[i]);
|
---|
914 | }
|
---|
915 | chk_reader("services", servicelabels, rdr);
|
---|
916 |
|
---|
917 | if(write_server()==0) {
|
---|
918 | refresh_oscam(REFR_READERS, in);
|
---|
919 | // fixme: restart_cardreader causes segfaults sometimes
|
---|
920 | if (rdr->typ & R_IS_NETWORK)
|
---|
921 | restart_cardreader(rdr, 1); //physical readers make trouble if re-started
|
---|
922 | }
|
---|
923 | else
|
---|
924 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
925 | }
|
---|
926 |
|
---|
927 | rdr = get_reader_by_label(reader_);
|
---|
928 |
|
---|
929 | tpl_addVar(vars, TPLADD, "READERNAME", rdr->label);
|
---|
930 |
|
---|
931 | if(rdr->enable)
|
---|
932 | tpl_addVar(vars, TPLADD, "ENABLED", "checked");
|
---|
933 |
|
---|
934 | tpl_printf(vars, TPLADD, "ACCOUNT", "%s", rdr->r_usr);
|
---|
935 | tpl_printf(vars, TPLADD, "PASSWORD", "%s", rdr->r_pwd);
|
---|
936 |
|
---|
937 | for (i=0; i<14; i++)
|
---|
938 | tpl_printf(vars, TPLAPPEND, "NCD_KEY", "%02X", rdr->ncd_key[i]);
|
---|
939 |
|
---|
940 | tpl_addVar(vars, TPLADD, "PINCODE", rdr->pincode);
|
---|
941 | if (rdr->emmfile) tpl_addVar(vars, TPLADD, "EMMFILE", (char *)rdr->emmfile);
|
---|
942 | tpl_printf(vars, TPLADD, "INACTIVITYTIMEOUT", "%d", rdr->tcp_ito);
|
---|
943 | tpl_printf(vars, TPLADD, "RECEIVETIMEOUT", "%d", rdr->tcp_rto);
|
---|
944 | if(rdr->ncd_disable_server_filt)
|
---|
945 | tpl_addVar(vars, TPLADD, "DISABLESERVERFILTERCHECKED", "checked");
|
---|
946 |
|
---|
947 | if(rdr->fallback)
|
---|
948 | tpl_addVar(vars, TPLADD, "FALLBACKCHECKED", "checked");
|
---|
949 |
|
---|
950 | tpl_printf(vars, TPLADD, "LOGPORT", "%d", rdr->log_port);
|
---|
951 |
|
---|
952 | if(rdr->boxid)
|
---|
953 | tpl_printf(vars, TPLADD, "BOXID", "%08X", rdr->boxid);
|
---|
954 |
|
---|
955 | if(rdr->fix_9993)
|
---|
956 | tpl_addVar(vars, TPLADD, "FIX9993CHECKED", "checked");
|
---|
957 |
|
---|
958 | tpl_addVar(vars, TPLADD, "USER", rdr->r_usr);
|
---|
959 | tpl_addVar(vars, TPLADD, "PASS", rdr->r_pwd);
|
---|
960 |
|
---|
961 | if(rdr->audisabled)
|
---|
962 | tpl_addVar(vars, TPLADD, "AUDISABLED", "checked");
|
---|
963 |
|
---|
964 | if(rdr->auprovid)
|
---|
965 | tpl_printf(vars, TPLADD, "AUPROVID", "%06lX", rdr->auprovid);
|
---|
966 |
|
---|
967 | if(rdr->force_irdeto)
|
---|
968 | tpl_addVar(vars, TPLADD, "FORCEIRDETOCHECKED", "checked");
|
---|
969 |
|
---|
970 | int32_t len = check_filled(rdr->rsa_mod, 120);
|
---|
971 | if(len > 0) {
|
---|
972 | if(len > 64) len = 120;
|
---|
973 | else len = 64;
|
---|
974 | for (i = 0; i < len; i++) tpl_printf(vars, TPLAPPEND, "RSAKEY", "%02X", rdr->rsa_mod[i]);
|
---|
975 | }
|
---|
976 |
|
---|
977 | len = check_filled(rdr->nagra_boxkey, 8);
|
---|
978 | if(len > 0) {
|
---|
979 | for (i = 0; i < 8 ; i++) tpl_printf(vars, TPLAPPEND, "BOXKEY", "%02X", rdr->nagra_boxkey[i]);
|
---|
980 | }
|
---|
981 |
|
---|
982 | if ( rdr->atr[0])
|
---|
983 | for (i = 0; i < rdr->atrlen/2; i++)
|
---|
984 | tpl_printf(vars, TPLAPPEND, "ATR", "%02X", rdr->atr[i]);
|
---|
985 |
|
---|
986 | if(rdr->smargopatch)
|
---|
987 | tpl_addVar(vars, TPLADD, "SMARGOPATCHCHECKED", "checked");
|
---|
988 |
|
---|
989 | if (rdr->detect&0x80)
|
---|
990 | tpl_printf(vars, TPLADD, "DETECT", "!%s", RDR_CD_TXT[rdr->detect&0x7f]);
|
---|
991 | else
|
---|
992 | tpl_printf(vars, TPLADD, "DETECT", "%s", RDR_CD_TXT[rdr->detect&0x7f]);
|
---|
993 |
|
---|
994 | tpl_printf(vars, TPLADD, "MHZ", "%d", rdr->mhz);
|
---|
995 | tpl_printf(vars, TPLADD, "CARDMHZ", "%d", rdr->cardmhz);
|
---|
996 |
|
---|
997 | tpl_printf(vars, TPLADD, "DEVICE", "%s", rdr->device);
|
---|
998 | if(rdr->r_port)
|
---|
999 | tpl_printf(vars, TPLAPPEND, "DEVICE", ",%d", rdr->r_port);
|
---|
1000 | if(rdr->l_port) {
|
---|
1001 | if(rdr->r_port)
|
---|
1002 | tpl_printf(vars, TPLAPPEND, "DEVICE", ",%d", rdr->l_port);
|
---|
1003 | else
|
---|
1004 | tpl_printf(vars, TPLAPPEND, "DEVICE", ",,%d", rdr->l_port);
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 | //group
|
---|
1008 | value = mk_t_group(rdr->grp);
|
---|
1009 | tpl_printf(vars, TPLADD, "GRP", "%s", value);
|
---|
1010 | free_mk_t(value);
|
---|
1011 |
|
---|
1012 | if(rdr->lb_weight)
|
---|
1013 | tpl_printf(vars, TPLADD, "LBWEIGHT", "%d", rdr->lb_weight);
|
---|
1014 |
|
---|
1015 | //services
|
---|
1016 | char sidok[MAX_SIDBITS+1];
|
---|
1017 | uint64ToBitchar((uint64_t)rdr->sidtabok, MAX_SIDBITS, sidok);
|
---|
1018 | char sidno[MAX_SIDBITS+1];
|
---|
1019 | uint64ToBitchar((uint64_t)rdr->sidtabno,MAX_SIDBITS, sidno);
|
---|
1020 | struct s_sidtab *sidtab = cfg.sidtab;
|
---|
1021 | //build matrix
|
---|
1022 | i = 0;
|
---|
1023 | while(sidtab != NULL) {
|
---|
1024 | tpl_addVar(vars, TPLADD, "SIDLABEL", sidtab->label);
|
---|
1025 | if(sidok[i]=='1') tpl_addVar(vars, TPLADD, "CHECKED", "checked");
|
---|
1026 | else tpl_addVar(vars, TPLADD, "CHECKED", "");
|
---|
1027 | tpl_addVar(vars, TPLAPPEND, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDOKBIT"));
|
---|
1028 | if(sidno[i]=='1') tpl_addVar(vars, TPLADD, "CHECKED", "checked");
|
---|
1029 | else tpl_addVar(vars, TPLADD, "CHECKED", "");
|
---|
1030 | tpl_addVar(vars, TPLAPPEND, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDNOBIT"));
|
---|
1031 | sidtab=sidtab->next;
|
---|
1032 | i++;
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | // CAID
|
---|
1036 | value = mk_t_caidtab(&rdr->ctab);
|
---|
1037 | tpl_addVar(vars, TPLADD, "CAIDS", value);
|
---|
1038 | free_mk_t(value);
|
---|
1039 |
|
---|
1040 | // AESkeys
|
---|
1041 | value = mk_t_aeskeys(rdr);
|
---|
1042 | tpl_addVar(vars, TPLADD, "AESKEYS", value);
|
---|
1043 | free_mk_t(value);
|
---|
1044 |
|
---|
1045 | //ident
|
---|
1046 | value = mk_t_ftab(&rdr->ftab);
|
---|
1047 | tpl_printf(vars, TPLADD, "IDENTS", "%s", value);
|
---|
1048 | free_mk_t(value);
|
---|
1049 |
|
---|
1050 | //CHID
|
---|
1051 | value = mk_t_ftab(&rdr->fchid);
|
---|
1052 | tpl_printf(vars, TPLADD, "CHIDS", "%s", value);
|
---|
1053 | free_mk_t(value);
|
---|
1054 |
|
---|
1055 | //class
|
---|
1056 | CLASSTAB *clstab = &rdr->cltab;
|
---|
1057 | char *dot="";
|
---|
1058 | for(i = 0; i < clstab->an; ++i) {
|
---|
1059 | tpl_printf(vars, TPLAPPEND, "CLASS", "%s%02x", dot, (int)clstab->aclass[i]);
|
---|
1060 | dot=",";
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | for(i = 0; i < clstab->bn; ++i) {
|
---|
1064 | tpl_printf(vars, TPLADD, "CLASS", "%s!%02x", dot, (int)clstab->bclass[i]);
|
---|
1065 | dot=",";
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | if (rdr->show_cls)
|
---|
1069 | tpl_printf(vars, TPLADD, "SHOWCLS", "%d", rdr->show_cls);
|
---|
1070 |
|
---|
1071 | if(rdr->cachemm)
|
---|
1072 | tpl_printf(vars, TPLADD, "EMMCACHE", "%d,%d,%d", rdr->cachemm, rdr->rewritemm, rdr->logemm);
|
---|
1073 |
|
---|
1074 | //savenano
|
---|
1075 | value = mk_t_nano(rdr, 0x02);
|
---|
1076 | tpl_addVar(vars, TPLADD, "SAVENANO", value);
|
---|
1077 | free_mk_t(value);
|
---|
1078 |
|
---|
1079 | //blocknano
|
---|
1080 | value = mk_t_nano(rdr, 0x01);
|
---|
1081 | tpl_addVar(vars, TPLADD, "BLOCKNANO", value);
|
---|
1082 | free_mk_t(value);
|
---|
1083 |
|
---|
1084 | if (rdr->blockemm & EMM_UNKNOWN)
|
---|
1085 | tpl_addVar(vars, TPLADD, "BLOCKEMMUNKNOWNCHK", "checked");
|
---|
1086 | if (rdr->blockemm & EMM_UNIQUE)
|
---|
1087 | tpl_addVar(vars, TPLADD, "BLOCKEMMUNIQCHK", "checked");
|
---|
1088 | if (rdr->blockemm & EMM_SHARED)
|
---|
1089 | tpl_addVar(vars, TPLADD, "BLOCKEMMSHAREDCHK", "checked");
|
---|
1090 | if (rdr->blockemm & EMM_GLOBAL)
|
---|
1091 | tpl_addVar(vars, TPLADD, "BLOCKEMMGLOBALCHK", "checked");
|
---|
1092 |
|
---|
1093 | if (rdr->deprecated)
|
---|
1094 | tpl_addVar(vars, TPLADD, "DEPRECATEDCHCHECKED", "checked");
|
---|
1095 |
|
---|
1096 | if (!strcmp(rdr->cc_version, "2.0.11")) {
|
---|
1097 | tpl_addVar(vars, TPLADD, "CCCVERSIONSELECTED0", "selected");
|
---|
1098 | } else if (!strcmp(rdr->cc_version, "2.1.1")) {
|
---|
1099 | tpl_addVar(vars, TPLADD, "CCCVERSIONSELECTED1", "selected");
|
---|
1100 | } else if (!strcmp(rdr->cc_version, "2.1.2")) {
|
---|
1101 | tpl_addVar(vars, TPLADD, "CCCVERSIONSELECTED2", "selected");
|
---|
1102 | } else if (!strcmp(rdr->cc_version, "2.1.3")) {
|
---|
1103 | tpl_addVar(vars, TPLADD, "CCCVERSIONSELECTED3", "selected");
|
---|
1104 | } else if (!strcmp(rdr->cc_version, "2.1.4")) {
|
---|
1105 | tpl_addVar(vars, TPLADD, "CCCVERSIONSELECTED4", "selected");
|
---|
1106 | } else if (!strcmp(rdr->cc_version, "2.2.0")) {
|
---|
1107 | tpl_addVar(vars, TPLADD, "CCCVERSIONSELECTED5", "selected");
|
---|
1108 | } else if (!strcmp(rdr->cc_version, "2.2.1")) {
|
---|
1109 | tpl_addVar(vars, TPLADD, "CCCVERSIONSELECTED6", "selected");
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | #ifdef LIBUSB
|
---|
1113 | tpl_addVar(vars, TPLADD, "DEVICEEP", tpl_getTpl(vars, "READERCONFIGDEVICEEPBIT"));
|
---|
1114 |
|
---|
1115 | if(!rdr->device_endpoint) {
|
---|
1116 | tpl_addVar(vars, TPLADD, "DEVICEOUTEP0", "selected");
|
---|
1117 | } else if (rdr->device_endpoint32_t == 0x82) {
|
---|
1118 | tpl_addVar(vars, TPLADD, "DEVICEOUTEP1", "selected");
|
---|
1119 | } else if (rdr->device_endpoint32_t == 0x81) {
|
---|
1120 | tpl_addVar(vars, TPLADD, "DEVICEOUTEP2", "selected");
|
---|
1121 | }
|
---|
1122 | #else
|
---|
1123 | tpl_addVar(vars, TPLADD, "DEVICEEP", "not avail LIBUSB");
|
---|
1124 | #endif
|
---|
1125 |
|
---|
1126 | tpl_printf(vars, TPLADD, "TMP", "NDSVERSION%d", rdr->ndsversion);
|
---|
1127 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
1128 |
|
---|
1129 | tpl_printf(vars, TPLADD, "TMP", "NAGRAREAD%d", rdr->nagra_read);
|
---|
1130 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
1131 |
|
---|
1132 | tpl_printf(vars, TPLADD, "CCCMAXHOP", "%d", rdr->cc_maxhop);
|
---|
1133 | tpl_printf(vars, TPLADD, "CCCMINDOWN", "%d", rdr->cc_mindown);
|
---|
1134 | tpl_printf(vars, TPLADD, "CCCRESHARE", "%d", (rdr->cc_reshare==-1)?cfg.cc_reshare:rdr->cc_reshare);
|
---|
1135 | if(rdr->cc_want_emu)
|
---|
1136 | tpl_addVar(vars, TPLADD, "CCCWANTEMUCHECKED", "checked");
|
---|
1137 |
|
---|
1138 | if(rdr->cc_keepalive)
|
---|
1139 | tpl_addVar(vars, TPLADD, "KEEPALIVECHECKED", "selected");
|
---|
1140 |
|
---|
1141 | // Show only parameters which needed for the reader
|
---|
1142 | switch (rdr->typ) {
|
---|
1143 | case R_CONSTCW:
|
---|
1144 | tpl_addVar(vars, TPLADD, "PROTOCOL", "constcw");
|
---|
1145 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
|
---|
1146 | break;
|
---|
1147 | case R_DB2COM1:
|
---|
1148 | case R_DB2COM2:
|
---|
1149 | case R_MOUSE :
|
---|
1150 | tpl_addVar(vars, TPLADD, "PROTOCOL", "mouse");
|
---|
1151 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
|
---|
1152 | break;
|
---|
1153 | case R_MP35:
|
---|
1154 | tpl_addVar(vars, TPLADD, "PROTOCOL", "mp35");
|
---|
1155 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
|
---|
1156 | break;
|
---|
1157 | case R_SC8in1 :
|
---|
1158 | tpl_addVar(vars, TPLADD, "PROTOCOL", "sc8in1");
|
---|
1159 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
|
---|
1160 | break;
|
---|
1161 | case R_SMART :
|
---|
1162 | tpl_addVar(vars, TPLADD, "PROTOCOL", "smartreader");
|
---|
1163 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
|
---|
1164 | break;
|
---|
1165 | case R_INTERNAL:
|
---|
1166 | tpl_addVar(vars, TPLADD, "PROTOCOL", "internal");
|
---|
1167 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
|
---|
1168 | break;
|
---|
1169 | case R_SERIAL :
|
---|
1170 | tpl_addVar(vars, TPLADD, "PROTOCOL", "serial");
|
---|
1171 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
|
---|
1172 | break;
|
---|
1173 | case R_CAMD35 :
|
---|
1174 | tpl_addVar(vars, TPLADD, "PROTOCOL", "camd35");
|
---|
1175 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGCAMD35BIT"));
|
---|
1176 | break;
|
---|
1177 | case R_CS378X :
|
---|
1178 | tpl_addVar(vars, TPLADD, "PROTOCOL", "cs378x");
|
---|
1179 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGCS378XBIT"));
|
---|
1180 | break;
|
---|
1181 | case R_RADEGAST:
|
---|
1182 | tpl_addVar(vars, TPLADD, "PROTOCOL", "radegast");
|
---|
1183 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGRADEGASTBIT"));
|
---|
1184 | break;
|
---|
1185 | case R_NEWCAMD :
|
---|
1186 | if ( rdr->ncd_proto == NCD_525 ){
|
---|
1187 | tpl_addVar(vars, TPLADD, "PROTOCOL", "newcamd525");
|
---|
1188 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGNCD525BIT"));
|
---|
1189 | } else if ( rdr->ncd_proto == NCD_524 ) {
|
---|
1190 | tpl_addVar(vars, TPLADD, "PROTOCOL", "newcamd524");
|
---|
1191 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGNCD524BIT"));
|
---|
1192 | }
|
---|
1193 | break;
|
---|
1194 | case R_CCCAM :
|
---|
1195 | tpl_addVar(vars, TPLADD, "PROTOCOL", "cccam");
|
---|
1196 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGCCCAMBIT"));
|
---|
1197 | break;
|
---|
1198 | #ifdef HAVE_PCSC
|
---|
1199 | case R_PCSC :
|
---|
1200 | tpl_addVar(vars, TPLADD, "PROTOCOL", "pcsc");
|
---|
1201 | tpl_addVar(vars, TPLAPPEND, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
|
---|
1202 | break;
|
---|
1203 | #endif
|
---|
1204 | default :
|
---|
1205 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Error: protocol not resolvable</b><BR>");
|
---|
1206 | tpl_printf(vars, TPLAPPEND, "MESSAGE", "<b>Error: protocol number: %d readername: %s</b><BR>", rdr->typ, rdr->label);
|
---|
1207 | break;
|
---|
1208 |
|
---|
1209 | }
|
---|
1210 | return tpl_getTpl(vars, "READERCONFIG");
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | char *send_oscam_reader_stats(struct templatevars *vars, struct uriparams *params, struct in_addr in, int32_t apicall) {
|
---|
1214 |
|
---|
1215 | tpl_printf(vars, TPLADD, "CALLINGIP", "%s", inet_ntoa(in));
|
---|
1216 |
|
---|
1217 | struct s_reader *rdr = get_reader_by_label(getParam(params, "label"));
|
---|
1218 | if(!rdr) return "0";
|
---|
1219 |
|
---|
1220 | if (strcmp(getParam(params, "action"), "resetstat") == 0) {
|
---|
1221 | if(rdr) {
|
---|
1222 | clear_reader_stat(rdr);
|
---|
1223 | cs_log("Reader %s stats resetted by WebIF from %s", rdr->label, inet_ntoa(in));
|
---|
1224 | }
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | if (!apicall){
|
---|
1228 | tpl_printf(vars, TPLADD, "LABEL", "%s", rdr->label);
|
---|
1229 | tpl_printf(vars, TPLADD, "ENCODEDLABEL", "%s", urlencode(vars, rdr->label));
|
---|
1230 | } else {
|
---|
1231 | tpl_printf(vars, TPLADD, "READERNAME", "%s", rdr->label);
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | char *stxt[]={"found", "cache1", "cache2", "emu",
|
---|
1235 | "not found", "timeout", "sleeping",
|
---|
1236 | "fake", "invalid", "corrupt", "no card", "expdate",
|
---|
1237 | "disabled", "stopped"};
|
---|
1238 |
|
---|
1239 | if (apicall) {
|
---|
1240 | int32_t i, emmcount = 0;
|
---|
1241 | char *ttxt[]={"unknown", "unique", "shared", "global"};
|
---|
1242 |
|
---|
1243 | for (i=0; i<4; i++) {
|
---|
1244 | tpl_addVar(vars, TPLADD, "EMMRESULT", "error");
|
---|
1245 | tpl_printf(vars, TPLADD, "EMMTYPE", "%s", ttxt[i]);
|
---|
1246 | tpl_printf(vars, TPLADD, "EMMCOUNT", "%d", rdr->emmerror[i]);
|
---|
1247 | tpl_addVar(vars, TPLAPPEND, "EMMSTATS", tpl_getTpl(vars, "APIREADERSTATSEMMBIT"));
|
---|
1248 | emmcount += rdr->emmerror[i];
|
---|
1249 | tpl_printf(vars, TPLADD, "TOTALERROR", "%d", emmcount);
|
---|
1250 | }
|
---|
1251 | emmcount = 0;
|
---|
1252 | for (i=0; i<4; i++) {
|
---|
1253 | tpl_addVar(vars, TPLADD, "EMMRESULT", "written");
|
---|
1254 | tpl_printf(vars, TPLADD, "EMMTYPE", "%s", ttxt[i]);
|
---|
1255 | tpl_printf(vars, TPLADD, "EMMCOUNT", "%d", rdr->emmwritten[i]);
|
---|
1256 | tpl_addVar(vars, TPLAPPEND, "EMMSTATS", tpl_getTpl(vars, "APIREADERSTATSEMMBIT"));
|
---|
1257 | emmcount += rdr->emmwritten[i];
|
---|
1258 | tpl_printf(vars, TPLADD, "TOTALWRITTEN", "%d", emmcount);
|
---|
1259 | }
|
---|
1260 | emmcount = 0;
|
---|
1261 | for (i=0; i<4; i++) {
|
---|
1262 | tpl_addVar(vars, TPLADD, "EMMRESULT", "skipped");
|
---|
1263 | tpl_printf(vars, TPLADD, "EMMTYPE", "%s", ttxt[i]);
|
---|
1264 | tpl_printf(vars, TPLADD, "EMMCOUNT", "%d", rdr->emmskipped[i]);
|
---|
1265 | tpl_addVar(vars, TPLAPPEND, "EMMSTATS", tpl_getTpl(vars, "APIREADERSTATSEMMBIT"));
|
---|
1266 | emmcount += rdr->emmskipped[i];
|
---|
1267 | tpl_printf(vars, TPLADD, "TOTALSKIPPED", "%d", emmcount);
|
---|
1268 | }
|
---|
1269 | emmcount = 0;
|
---|
1270 | for (i=0; i<4; i++) {
|
---|
1271 | tpl_addVar(vars, TPLADD, "EMMRESULT", "blocked");
|
---|
1272 | tpl_printf(vars, TPLADD, "EMMTYPE", "%s", ttxt[i]);
|
---|
1273 | tpl_printf(vars, TPLADD, "EMMCOUNT", "%d", rdr->emmblocked[i]);
|
---|
1274 | tpl_addVar(vars, TPLAPPEND, "EMMSTATS", tpl_getTpl(vars, "APIREADERSTATSEMMBIT"));
|
---|
1275 | emmcount += rdr->emmblocked[i];
|
---|
1276 | tpl_printf(vars, TPLADD, "TOTALBLOCKED", "%d", emmcount);
|
---|
1277 | }
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 | int32_t rc2hide = (-1);
|
---|
1281 | if (strlen(getParam(params, "hide")) > 0)
|
---|
1282 | rc2hide = atoi(getParam(params, "hide"));
|
---|
1283 |
|
---|
1284 | int32_t rowcount = 0;
|
---|
1285 | uint64_t ecmcount = 0;
|
---|
1286 | time_t lastaccess=0;
|
---|
1287 |
|
---|
1288 | if (rdr->lb_stat) {
|
---|
1289 |
|
---|
1290 | LL_ITER *it = ll_iter_create(rdr->lb_stat);
|
---|
1291 | READER_STAT *stat = ll_iter_next(it);
|
---|
1292 | while (stat) {
|
---|
1293 |
|
---|
1294 | if (!(stat->rc == rc2hide)) {
|
---|
1295 | struct tm lt;
|
---|
1296 | localtime_r(&stat->last_received, <);
|
---|
1297 | ecmcount += stat->ecm_count;
|
---|
1298 | if (!apicall) {
|
---|
1299 | tpl_printf(vars, TPLADD, "CHANNEL", "%04X:%06lX:%04X", stat->caid, stat->prid, stat->srvid);
|
---|
1300 | tpl_printf(vars, TPLADD, "CHANNELNAME","%s", xml_encode(vars, get_servicename(stat->srvid, stat->caid)));
|
---|
1301 | tpl_printf(vars, TPLADD, "ECMLEN","%04hX", stat->ecmlen);
|
---|
1302 | tpl_printf(vars, TPLADD, "RC", "%s", stxt[stat->rc]);
|
---|
1303 | tpl_printf(vars, TPLADD, "TIME", "%dms", stat->time_avg);
|
---|
1304 | if (stat->time_stat[stat->time_idx])
|
---|
1305 | tpl_printf(vars, TPLADD, "TIMELAST", "%dms", stat->time_stat[stat->time_idx]);
|
---|
1306 | else
|
---|
1307 | tpl_printf(vars, TPLADD, "TIMELAST", "");
|
---|
1308 | tpl_printf(vars, TPLADD, "COUNT", "%d", stat->ecm_count);
|
---|
1309 |
|
---|
1310 | if(stat->last_received) {
|
---|
1311 | tpl_printf(vars, TPLADD, "LAST", "%02d.%02d.%02d %02d:%02d:%02d", lt.tm_mday, lt.tm_mon+1, lt.tm_year%100, lt.tm_hour, lt.tm_min, lt.tm_sec);
|
---|
1312 |
|
---|
1313 | } else {
|
---|
1314 | tpl_addVar(vars, TPLADD, "LAST","never");
|
---|
1315 | }
|
---|
1316 | } else {
|
---|
1317 | tpl_printf(vars, TPLADD, "ECMCAID", "%04X", stat->caid);
|
---|
1318 | tpl_printf(vars, TPLADD, "ECMPROVID", "%06lX", stat->prid);
|
---|
1319 | tpl_printf(vars, TPLADD, "ECMSRVID", "%04X", stat->srvid);
|
---|
1320 | tpl_printf(vars, TPLADD, "ECMLEN", "%04hX", stat->ecmlen);
|
---|
1321 | tpl_addVar(vars, TPLADD, "ECMCHANNELNAME", xml_encode(vars, get_servicename(stat->srvid, stat->caid)));
|
---|
1322 | tpl_printf(vars, TPLADD, "ECMTIME", "%d", stat->time_avg);
|
---|
1323 | tpl_printf(vars, TPLADD, "ECMTIMELAST", "%d", stat->time_stat[stat->time_idx]);
|
---|
1324 | tpl_printf(vars, TPLADD, "ECMRC", "%d", stat->rc);
|
---|
1325 | tpl_printf(vars, TPLADD, "ECMRCS", "%s", stxt[stat->rc]);
|
---|
1326 | if(stat->last_received) {
|
---|
1327 | char tbuffer [30];
|
---|
1328 | strftime(tbuffer, 30, "%Y-%m-%dT%H:%M:%S%z", <);
|
---|
1329 | tpl_addVar(vars, TPLADD, "ECMLAST", tbuffer);
|
---|
1330 | } else {
|
---|
1331 | tpl_addVar(vars, TPLADD, "ECMLAST", "");
|
---|
1332 | }
|
---|
1333 | tpl_printf(vars, TPLADD, "ECMCOUNT", "%d", stat->ecm_count);
|
---|
1334 |
|
---|
1335 | if (stat->last_received > lastaccess)
|
---|
1336 | lastaccess = stat->last_received;
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | if (!apicall) {
|
---|
1340 | if (stat->rc == 4) {
|
---|
1341 | tpl_addVar(vars, TPLAPPEND, "READERSTATSROWNOTFOUND", tpl_getTpl(vars, "READERSTATSBIT"));
|
---|
1342 | tpl_addVar(vars, TPLADD, "READERSTATSNFHEADLINE", "\t\t<TR><TD CLASS=\"subheadline\" colspan=\"7\">Not found</TD></TR>\n");
|
---|
1343 | }
|
---|
1344 | else
|
---|
1345 | tpl_addVar(vars, TPLAPPEND, "READERSTATSROWFOUND", tpl_getTpl(vars, "READERSTATSBIT"));
|
---|
1346 | } else {
|
---|
1347 |
|
---|
1348 | tpl_addVar(vars, TPLAPPEND, "ECMSTATS", tpl_getTpl(vars, "APIREADERSTATSECMBIT"));
|
---|
1349 | }
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 | stat = ll_iter_next(it);
|
---|
1353 | rowcount++;
|
---|
1354 | }
|
---|
1355 |
|
---|
1356 | ll_iter_release(it);
|
---|
1357 |
|
---|
1358 | } else {
|
---|
1359 | tpl_addVar(vars, TPLAPPEND, "READERSTATSROW","<TR><TD colspan=\"6\"> No statistics found </TD></TR>");
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | tpl_printf(vars, TPLADD, "ROWCOUNT", "%d", rowcount);
|
---|
1363 |
|
---|
1364 | if (lastaccess > 0){
|
---|
1365 | char tbuffer [30];
|
---|
1366 | struct tm lt;
|
---|
1367 | localtime_r(&lastaccess, <);
|
---|
1368 | strftime(tbuffer, 30, "%Y-%m-%dT%H:%M:%S%z", <);
|
---|
1369 | tpl_addVar(vars, TPLADD, "LASTACCESS", tbuffer);
|
---|
1370 | } else {
|
---|
1371 | tpl_addVar(vars, TPLADD, "LASTACCESS", "");
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | tpl_printf(vars, TPLADD, "TOTALECM", "%llu", ecmcount);
|
---|
1375 |
|
---|
1376 | if(!apicall)
|
---|
1377 | return tpl_getTpl(vars, "READERSTATS");
|
---|
1378 | else
|
---|
1379 | return tpl_getTpl(vars, "APIREADERSTATS");
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 | char *send_oscam_user_config_edit(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
1383 | struct s_auth *account, *ptr;
|
---|
1384 | char user[sizeof(first_client->account->usr)];
|
---|
1385 |
|
---|
1386 | if (strcmp(getParam(params, "action"), "Save As") == 0) cs_strncpy(user, getParam(params, "newuser"), sizeof(user)/sizeof(char));
|
---|
1387 | else cs_strncpy(user, getParam(params, "user"), sizeof(user)/sizeof(char));
|
---|
1388 |
|
---|
1389 | int32_t i;
|
---|
1390 |
|
---|
1391 | for (account = cfg.account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
1392 |
|
---|
1393 | // Create a new user if it doesn't yet
|
---|
1394 | if (account == NULL) {
|
---|
1395 | i = 1;
|
---|
1396 | while(strlen(user) < 1) {
|
---|
1397 | snprintf(user, sizeof(user)/sizeof(char) - 1, "NEWUSER%d", i);
|
---|
1398 | for (account = cfg.account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
1399 | if(account != NULL) user[0] = '\0';
|
---|
1400 | ++i;
|
---|
1401 | }
|
---|
1402 | if (!cs_malloc(&account, sizeof(struct s_auth), -1)) return "0";
|
---|
1403 | if(cfg.account == NULL) cfg.account = account;
|
---|
1404 | else {
|
---|
1405 | for (ptr = cfg.account; ptr != NULL && ptr->next != NULL; ptr = ptr->next);
|
---|
1406 | ptr->next = account;
|
---|
1407 | }
|
---|
1408 | memset(account, 0, sizeof(struct s_auth));
|
---|
1409 | cs_strncpy((char *)account->usr, user, sizeof(account->usr));
|
---|
1410 | account->monlvl=cfg.mon_level;
|
---|
1411 | account->tosleep=cfg.tosleep;
|
---|
1412 | for (i=1; i<CS_MAXCAIDTAB; account->ctab.mask[i++]=0xffff);
|
---|
1413 | for (i=1; i<CS_MAXTUNTAB; account->ttab.bt_srvid[i++]=0x0000);
|
---|
1414 | account->expirationdate=(time_t)NULL;
|
---|
1415 | #ifdef CS_ANTICASC
|
---|
1416 | account->ac_users=cfg.ac_users;
|
---|
1417 | account->ac_penalty=cfg.ac_penalty;
|
---|
1418 | #endif
|
---|
1419 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>New user has been added with default settings</b><BR>");
|
---|
1420 |
|
---|
1421 | if (write_userdb(cfg.account)==0)
|
---|
1422 | refresh_oscam(REFR_ACCOUNTS, in);
|
---|
1423 | else
|
---|
1424 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
1425 | // need to reget account as writing to disk changes account!
|
---|
1426 | for (account = cfg.account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | if((strcmp(getParam(params, "action"), "Save") == 0) || (strcmp(getParam(params, "action"), "Save As") == 0)) {
|
---|
1430 | char servicelabels[1024]="";
|
---|
1431 | //clear group
|
---|
1432 | account->grp = 0;
|
---|
1433 | //clear caidtab before it re-readed by chk_t
|
---|
1434 | clear_caidtab(&account->ctab);
|
---|
1435 | //clear Betatunnel before it re-readed by chk_t
|
---|
1436 | clear_tuntab(&account->ttab);
|
---|
1437 | //clear ident before it re-readed by chk_t
|
---|
1438 | clear_ftab(&account->ftab);
|
---|
1439 | //clear CHID before it re-readed by chk_t
|
---|
1440 | clear_ftab(&account->fchid);
|
---|
1441 |
|
---|
1442 | for(i=0;i<(*params).paramcount;i++) {
|
---|
1443 | if ((strcmp((*params).params[i], "action")) && (strcmp((*params).params[i], "user")) && (strcmp((*params).params[i], "newuser"))) {
|
---|
1444 | if (!strcmp((*params).params[i], "expdate"))
|
---|
1445 | account->expirationdate=(time_t)NULL;
|
---|
1446 | if (!strcmp((*params).params[i], "services"))
|
---|
1447 | snprintf(servicelabels + strlen(servicelabels), sizeof(servicelabels) - strlen(servicelabels), "%s,", (*params).values[i]);
|
---|
1448 | else
|
---|
1449 | chk_account((*params).params[i], (*params).values[i], account);
|
---|
1450 | }
|
---|
1451 | }
|
---|
1452 | chk_account("services", servicelabels, account);
|
---|
1453 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Settings updated</B><BR><BR>");
|
---|
1454 |
|
---|
1455 | if (write_userdb(cfg.account)==0)
|
---|
1456 | refresh_oscam(REFR_ACCOUNTS, in);
|
---|
1457 | else
|
---|
1458 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
1459 |
|
---|
1460 | // need to reget account as writing to disk changes account!
|
---|
1461 | for (account = cfg.account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
1462 | }
|
---|
1463 |
|
---|
1464 | tpl_addVar(vars, TPLADD, "USERNAME", account->usr);
|
---|
1465 | tpl_addVar(vars, TPLADD, "PASSWORD", account->pwd);
|
---|
1466 | tpl_addVar(vars, TPLADD, "DESCRIPTION", account->description);
|
---|
1467 |
|
---|
1468 | //Disabled
|
---|
1469 | if(account->disabled)
|
---|
1470 | tpl_addVar(vars, TPLADD, "DISABLEDCHECKED", "selected");
|
---|
1471 |
|
---|
1472 | //Expirationdate
|
---|
1473 | struct tm timeinfo;
|
---|
1474 | localtime_r (&account->expirationdate, &timeinfo);
|
---|
1475 | char buf [80];
|
---|
1476 | strftime (buf,80,"%Y-%m-%d",&timeinfo);
|
---|
1477 | if(strcmp(buf,"1970-01-01")) tpl_addVar(vars, TPLADD, "EXPDATE", buf);
|
---|
1478 |
|
---|
1479 | if(account->allowedtimeframe[0] && account->allowedtimeframe[1]) {
|
---|
1480 | tpl_printf(vars, TPLADD, "ALLOWEDTIMEFRAME", "%02d:%02d-%02d:%02d",
|
---|
1481 | account->allowedtimeframe[0]/60,
|
---|
1482 | account->allowedtimeframe[0]%60,
|
---|
1483 | account->allowedtimeframe[1]/60,
|
---|
1484 | account->allowedtimeframe[1]%60 );
|
---|
1485 | }
|
---|
1486 |
|
---|
1487 | //Group
|
---|
1488 | char *value = mk_t_group(account->grp);
|
---|
1489 | tpl_addVar(vars, TPLADD, "GROUPS", value);
|
---|
1490 | free_mk_t(value);
|
---|
1491 |
|
---|
1492 | //Hostname
|
---|
1493 | tpl_addVar(vars, TPLADD, "DYNDNS", (char *)account->dyndns);
|
---|
1494 |
|
---|
1495 | //Uniq
|
---|
1496 | tpl_printf(vars, TPLADD, "TMP", "UNIQSELECTED%d", account->uniq);
|
---|
1497 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
1498 |
|
---|
1499 | //Sleep
|
---|
1500 | if(!account->tosleep) tpl_addVar(vars, TPLADD, "SLEEP", "0");
|
---|
1501 | else tpl_printf(vars, TPLADD, "SLEEP", "%d", account->tosleep);
|
---|
1502 | //Monlevel selector
|
---|
1503 | tpl_printf(vars, TPLADD, "TMP", "MONSELECTED%d", account->monlvl);
|
---|
1504 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
1505 |
|
---|
1506 | //Au
|
---|
1507 | if (account->autoau == 1)
|
---|
1508 | tpl_addVar(vars, TPLADD, "AUREADER", "1");
|
---|
1509 | else if (account->aureader_list) {
|
---|
1510 | value = mk_t_aureader(account);
|
---|
1511 | tpl_addVar(vars, TPLADD, "AUREADER", value);
|
---|
1512 | free_mk_t(value);
|
---|
1513 | }
|
---|
1514 |
|
---|
1515 | /* SERVICES */
|
---|
1516 | //services - first we have to move the long sidtabok/sidtabno to a binary array
|
---|
1517 | char sidok[MAX_SIDBITS+1];
|
---|
1518 | uint64ToBitchar((uint64_t)account->sidtabok, MAX_SIDBITS, sidok);
|
---|
1519 | char sidno[MAX_SIDBITS+1];
|
---|
1520 | uint64ToBitchar((uint64_t)account->sidtabno, MAX_SIDBITS, sidno);
|
---|
1521 | struct s_sidtab *sidtab = cfg.sidtab;
|
---|
1522 | //build matrix
|
---|
1523 | i=0;
|
---|
1524 | while(sidtab != NULL) {
|
---|
1525 | tpl_addVar(vars, TPLADD, "SIDLABEL", sidtab->label);
|
---|
1526 | if(sidok[i]=='1') tpl_addVar(vars, TPLADD, "CHECKED", "checked");
|
---|
1527 | else tpl_addVar(vars, TPLADD, "CHECKED", "");
|
---|
1528 | tpl_addVar(vars, TPLAPPEND, "SIDS", tpl_getTpl(vars, "USEREDITSIDOKBIT"));
|
---|
1529 | if(sidno[i]=='1') tpl_addVar(vars, TPLADD, "CHECKED", "checked");
|
---|
1530 | else tpl_addVar(vars, TPLADD, "CHECKED", "");
|
---|
1531 | tpl_addVar(vars, TPLAPPEND, "SIDS", tpl_getTpl(vars, "USEREDITSIDNOBIT"));
|
---|
1532 | sidtab=sidtab->next;
|
---|
1533 | i++;
|
---|
1534 | }
|
---|
1535 |
|
---|
1536 | // CAID
|
---|
1537 | value = mk_t_caidtab(&account->ctab);
|
---|
1538 | tpl_addVar(vars, TPLADD, "CAIDS", value);
|
---|
1539 | free_mk_t(value);
|
---|
1540 |
|
---|
1541 | //ident
|
---|
1542 | value = mk_t_ftab(&account->ftab);
|
---|
1543 | tpl_printf(vars, TPLADD, "IDENTS", "%s", value);
|
---|
1544 | free_mk_t(value);
|
---|
1545 |
|
---|
1546 | //CHID
|
---|
1547 | value = mk_t_ftab(&account->fchid);
|
---|
1548 | tpl_printf(vars, TPLADD, "CHIDS", "%s", value);
|
---|
1549 | free_mk_t(value);
|
---|
1550 |
|
---|
1551 | //Betatunnel
|
---|
1552 | value = mk_t_tuntab(&account->ttab);
|
---|
1553 | tpl_addVar(vars, TPLADD, "BETATUNNELS", value);
|
---|
1554 | free_mk_t(value);
|
---|
1555 |
|
---|
1556 | //SUPPRESSCMD08
|
---|
1557 | if (account->c35_suppresscmd08)
|
---|
1558 | tpl_addVar(vars, TPLADD, "SUPPRESSCMD08", "selected");
|
---|
1559 |
|
---|
1560 | //Sleepsend
|
---|
1561 | tpl_printf(vars, TPLADD, "SLEEPSEND", "%d", account->c35_sleepsend);
|
---|
1562 |
|
---|
1563 | //Keepalive
|
---|
1564 | if (account->ncd_keepalive)
|
---|
1565 | tpl_addVar(vars, TPLADD, "KEEPALIVE", "selected");
|
---|
1566 |
|
---|
1567 | #ifdef CS_ANTICASC
|
---|
1568 | tpl_printf(vars, TPLADD, "AC_USERS", "%d", account->ac_users);
|
---|
1569 | tpl_printf(vars, TPLADD, "TMP", "PENALTY%d", account->ac_penalty);
|
---|
1570 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
|
---|
1571 | #endif
|
---|
1572 |
|
---|
1573 | tpl_printf(vars, TPLADD, "CCCMAXHOPS", "%d", account->cccmaxhops);
|
---|
1574 | tpl_printf(vars, TPLADD, "CCCRESHARE", "%d", (account->cccreshare==-1)?cfg.cc_reshare:account->cccreshare);
|
---|
1575 | if ((account->cccignorereshare==-1)?cfg.cc_ignore_reshare:account->cccignorereshare)
|
---|
1576 | tpl_printf(vars, TPLADD, "CCCIGNORERESHARE", "selected");
|
---|
1577 | if ((account->cccstealth==-1)?cfg.cc_stealth:account->cccstealth)
|
---|
1578 | tpl_printf(vars, TPLADD, "CCCSTEALTH", "selected");
|
---|
1579 |
|
---|
1580 | //Failban
|
---|
1581 | tpl_printf(vars, TPLADD, "FAILBAN", "%d", account->failban);
|
---|
1582 |
|
---|
1583 | return tpl_getTpl(vars, "USEREDIT");
|
---|
1584 | }
|
---|
1585 |
|
---|
1586 | char *send_oscam_user_config(struct templatevars *vars, struct uriparams *params, struct in_addr in, int32_t apicall) {
|
---|
1587 | struct s_auth *account, *account2;
|
---|
1588 | char *user = getParam(params, "user");
|
---|
1589 | int32_t found = 0, hideclient = 10;
|
---|
1590 |
|
---|
1591 | if (cfg.mon_hideclient_to > 10)
|
---|
1592 | hideclient = cfg.mon_hideclient_to;
|
---|
1593 |
|
---|
1594 | if (!apicall) {
|
---|
1595 | if (strcmp(getParam(params, "action"), "reinit") == 0) {
|
---|
1596 | if(!cfg.http_readonly)
|
---|
1597 | refresh_oscam(REFR_ACCOUNTS, in);
|
---|
1598 | }
|
---|
1599 |
|
---|
1600 | if (strcmp(getParam(params, "action"), "delete") == 0) {
|
---|
1601 | if(cfg.http_readonly) {
|
---|
1602 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Webif is in readonly mode. No deletion will be made!</b><BR>");
|
---|
1603 | } else {
|
---|
1604 | account = cfg.account;
|
---|
1605 | if(strcmp(account->usr, user) == 0) {
|
---|
1606 | cfg.account = account->next;
|
---|
1607 | free(account);
|
---|
1608 | found = 1;
|
---|
1609 | } else if (account->next != NULL) {
|
---|
1610 | do {
|
---|
1611 | if(strcmp(account->next->usr, user) == 0) {
|
---|
1612 | account2 = account->next;
|
---|
1613 | account->next = account2->next;
|
---|
1614 | free(account2);
|
---|
1615 | found = 1;
|
---|
1616 | break;
|
---|
1617 | }
|
---|
1618 | } while ((account = account->next) && (account->next != NULL));
|
---|
1619 | }
|
---|
1620 |
|
---|
1621 | if (found > 0) {
|
---|
1622 | if (write_userdb(cfg.account)==0)
|
---|
1623 | refresh_oscam(REFR_ACCOUNTS, in);
|
---|
1624 | else
|
---|
1625 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
1626 |
|
---|
1627 | } else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
|
---|
1628 | }
|
---|
1629 | }
|
---|
1630 |
|
---|
1631 | if ((strcmp(getParam(params, "action"), "disable") == 0) || (strcmp(getParam(params, "action"), "enable") == 0)) {
|
---|
1632 | account = get_account_by_name(getParam(params, "user"));
|
---|
1633 | if (account) {
|
---|
1634 | if(strcmp(getParam(params, "action"), "disable") == 0)
|
---|
1635 | account->disabled = 1;
|
---|
1636 | else
|
---|
1637 | account->disabled = 0;
|
---|
1638 | if (write_userdb(cfg.account) == 0)
|
---|
1639 | refresh_oscam(REFR_ACCOUNTS, in);
|
---|
1640 | } else {
|
---|
1641 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
|
---|
1642 | }
|
---|
1643 | }
|
---|
1644 |
|
---|
1645 | if (strcmp(getParam(params, "action"), "resetstats") == 0) {
|
---|
1646 | account = get_account_by_name(getParam(params, "user"));
|
---|
1647 | if (account) clear_account_stats(account);
|
---|
1648 | }
|
---|
1649 |
|
---|
1650 | if (strcmp(getParam(params, "action"), "resetserverstats") == 0) {
|
---|
1651 | clear_system_stats();
|
---|
1652 | }
|
---|
1653 |
|
---|
1654 | if (strcmp(getParam(params, "action"), "resetalluserstats") == 0) {
|
---|
1655 | clear_all_account_stats();
|
---|
1656 | }
|
---|
1657 |
|
---|
1658 | if ((strcmp(getParam(params, "part"), "adduser") == 0) && (!cfg.http_readonly)) {
|
---|
1659 | tpl_addVar(vars, TPLAPPEND, "NEWUSERFORM", tpl_getTpl(vars, "ADDNEWUSER"));
|
---|
1660 | } else {
|
---|
1661 | if(cfg.http_refresh > 0) {
|
---|
1662 | tpl_printf(vars, TPLADD, "REFRESHTIME", "%d", cfg.http_refresh);
|
---|
1663 | tpl_addVar(vars, TPLADD, "REFRESHURL", "userconfig.html");
|
---|
1664 | tpl_addVar(vars, TPLADD, "REFRESH", tpl_getTpl(vars, "REFRESH"));
|
---|
1665 | }
|
---|
1666 | }
|
---|
1667 | }
|
---|
1668 |
|
---|
1669 | /* List accounts*/
|
---|
1670 | char *status, *expired, *classname, *lastchan;
|
---|
1671 | time_t now = time((time_t)0);
|
---|
1672 | int32_t isec = 0;
|
---|
1673 |
|
---|
1674 | char *filter = NULL;
|
---|
1675 | int32_t clientcount = 0;
|
---|
1676 | if (apicall) {
|
---|
1677 | filter = getParam(params, "label");
|
---|
1678 | }
|
---|
1679 |
|
---|
1680 | for (account=cfg.account; (account); account=account->next) {
|
---|
1681 | //clear for next client
|
---|
1682 | status = "offline"; lastchan = " ", expired = ""; classname = "offline";
|
---|
1683 | isec = 0;
|
---|
1684 |
|
---|
1685 | if(account->expirationdate && account->expirationdate < time(NULL)) {
|
---|
1686 | expired = " (expired)";
|
---|
1687 | classname = "expired";
|
---|
1688 | } else {
|
---|
1689 | expired = "";
|
---|
1690 | }
|
---|
1691 |
|
---|
1692 | if(account->disabled != 0) {
|
---|
1693 | expired = " (disabled)"; classname = "disabled";
|
---|
1694 | tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICENA");
|
---|
1695 | tpl_addVar(vars, TPLADD, "SWITCHTITLE", "enable this account");
|
---|
1696 | tpl_addVar(vars, TPLADD, "SWITCH", "enable");
|
---|
1697 | } else {
|
---|
1698 | tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICDIS");
|
---|
1699 | tpl_addVar(vars, TPLADD, "SWITCHTITLE", "disable this account");
|
---|
1700 | tpl_addVar(vars, TPLADD, "SWITCH", "disable");
|
---|
1701 | }
|
---|
1702 |
|
---|
1703 | int32_t lastresponsetm = 0, latestactivity=0;
|
---|
1704 | char *proto = "";
|
---|
1705 | double cwrate = 0.0, cwrate2 = 0.0;
|
---|
1706 |
|
---|
1707 | //search account in active clients
|
---|
1708 | int32_t isactive = 0;
|
---|
1709 | struct s_client *cl, *latestclient=NULL;
|
---|
1710 | for (cl=first_client; cl ; cl=cl->next) {
|
---|
1711 | if (cl->account && !strcmp(cl->account->usr, account->usr)) {
|
---|
1712 | if(cl->lastecm > latestactivity || cl->login > latestactivity){
|
---|
1713 | if(cl->lastecm > cl->login) latestactivity = cl->lastecm;
|
---|
1714 | else latestactivity = cl->login;
|
---|
1715 | latestclient = cl;
|
---|
1716 | }
|
---|
1717 | }
|
---|
1718 | }
|
---|
1719 | if (account->cwfound + account->cwnot + account->cwcache > 0) {
|
---|
1720 | cwrate = now - account->firstlogin;
|
---|
1721 | cwrate /= (account->cwfound + account->cwnot + account->cwcache);
|
---|
1722 | }
|
---|
1723 | if(latestclient != NULL) {
|
---|
1724 | status = "<b>connected</b>";
|
---|
1725 | classname = "connected";
|
---|
1726 | proto = monitor_get_proto(latestclient);
|
---|
1727 | lastchan = xml_encode(vars, get_servicename(latestclient->last_srvid, latestclient->last_caid));
|
---|
1728 | lastresponsetm = latestclient->cwlastresptime;
|
---|
1729 | }
|
---|
1730 | if(latestactivity > 0){
|
---|
1731 | isec = now - latestactivity;
|
---|
1732 | if(isec < cfg.mon_hideclient_to) {
|
---|
1733 | isactive = 1;
|
---|
1734 | status = "<b>online</b>";
|
---|
1735 | classname = "online";
|
---|
1736 | if (latestclient->cwfound + latestclient->cwnot + latestclient->cwcache > 0) {
|
---|
1737 | cwrate2 = now - latestclient->login;
|
---|
1738 | cwrate2 /= (latestclient->cwfound + latestclient->cwnot + latestclient->cwcache);
|
---|
1739 | tpl_printf(vars, TPLADDONCE, "CWRATE2", " (%.2f)", cwrate2);
|
---|
1740 | }
|
---|
1741 | }
|
---|
1742 | }
|
---|
1743 |
|
---|
1744 | tpl_printf(vars, TPLADD, "CWOK", "%d", account->cwfound);
|
---|
1745 | tpl_printf(vars, TPLADD, "CWNOK", "%d", account->cwnot);
|
---|
1746 | tpl_printf(vars, TPLADD, "CWIGN", "%d", account->cwignored);
|
---|
1747 | tpl_printf(vars, TPLADD, "CWTOUT", "%d", account->cwtout);
|
---|
1748 | tpl_printf(vars, TPLADD, "CWCACHE", "%d", account->cwcache);
|
---|
1749 | tpl_printf(vars, TPLADD, "CWTUN", "%d", account->cwtun);
|
---|
1750 | tpl_printf(vars, TPLADD, "EMMOK", "%d", account->emmok);
|
---|
1751 | tpl_printf(vars, TPLADD, "EMMNOK", "%d", account->emmnok);
|
---|
1752 | tpl_printf(vars, TPLADD, "CWRATE", "%.2f", cwrate);
|
---|
1753 |
|
---|
1754 | if ( isactive > 0 || !cfg.http_hide_idle_clients) {
|
---|
1755 | tpl_addVar(vars, TPLADDONCE, "LASTCHANNEL", lastchan);
|
---|
1756 | tpl_printf(vars, TPLADDONCE, "CWLASTRESPONSET", "%d", lastresponsetm);
|
---|
1757 | tpl_addVar(vars, TPLADDONCE, "IDLESECS", sec2timeformat(vars, isec));
|
---|
1758 |
|
---|
1759 | if ((strcmp(proto,"newcamd") == 0) && (latestclient->typ == 'c'))
|
---|
1760 | tpl_printf(vars, TPLADDONCE, "CLIENTPROTO","%s (%s)", proto, get_ncd_client_name(latestclient->ncd_client_id));
|
---|
1761 | else if ((strncmp(proto,"cccam", 5) == 0)) {
|
---|
1762 | struct cc_data *cc = latestclient->cc;
|
---|
1763 | if(cc && cc->remote_version && cc->remote_build) {
|
---|
1764 | tpl_printf(vars, TPLADDONCE, "CLIENTPROTO", "%s (%s-%s)", proto, cc->remote_version, cc->remote_build);
|
---|
1765 | if(cc->extended_mode)
|
---|
1766 | tpl_addVar(vars, TPLADDONCE, "CLIENTPROTOTITLE", cc->remote_oscam);
|
---|
1767 | else
|
---|
1768 | tpl_addVar(vars, TPLADDONCE, "CLIENTPROTOTITLE", ""); //unset tpl var
|
---|
1769 | }
|
---|
1770 | else
|
---|
1771 | {
|
---|
1772 | tpl_addVar(vars, TPLADDONCE, "CLIENTPROTO", proto);
|
---|
1773 | tpl_addVar(vars, TPLADDONCE, "CLIENTPROTOTITLE", "");
|
---|
1774 | }
|
---|
1775 | }
|
---|
1776 | else {
|
---|
1777 | tpl_addVar(vars, TPLADDONCE, "CLIENTPROTO", proto);
|
---|
1778 | tpl_addVar(vars, TPLADDONCE, "CLIENTPROTOTITLE", "");
|
---|
1779 | }
|
---|
1780 | }
|
---|
1781 |
|
---|
1782 | tpl_addVar(vars, TPLADD, "CLASSNAME", classname);
|
---|
1783 | tpl_addVar(vars, TPLADD, "USER", xml_encode(vars, account->usr));
|
---|
1784 | tpl_addVar(vars, TPLADD, "USERENC", urlencode(vars, account->usr));
|
---|
1785 | tpl_addVar(vars, TPLADD, "DESCRIPTION", xml_encode(vars, account->description));
|
---|
1786 | tpl_addVar(vars, TPLADD, "STATUS", status);
|
---|
1787 | tpl_addVar(vars, TPLAPPEND, "STATUS", expired);
|
---|
1788 | // append row to table template
|
---|
1789 | if (!apicall)
|
---|
1790 | tpl_addVar(vars, TPLAPPEND, "USERCONFIGS", tpl_getTpl(vars, "USERCONFIGLISTBIT"));
|
---|
1791 | else
|
---|
1792 | if (!filter || strcmp(filter, account->usr) == 0 || strcmp(filter, "all") == 0 || strlen(filter) == 0) {
|
---|
1793 | tpl_addVar(vars, TPLAPPEND, "APIUSERCONFIGS", tpl_getTpl(vars, "APIUSERCONFIGLISTBIT"));
|
---|
1794 | ++clientcount;
|
---|
1795 | }
|
---|
1796 | }
|
---|
1797 |
|
---|
1798 | tpl_printf(vars, TPLADD, "TOTAL_CWOK", "%ld", first_client->cwfound);
|
---|
1799 | tpl_printf(vars, TPLADD, "TOTAL_CWNOK", "%ld", first_client->cwnot);
|
---|
1800 | tpl_printf(vars, TPLADD, "TOTAL_CWIGN", "%ld", first_client->cwignored);
|
---|
1801 | tpl_printf(vars, TPLADD, "TOTAL_CWTOUT", "%ld", first_client->cwtout);
|
---|
1802 | tpl_printf(vars, TPLADD, "TOTAL_CWCACHE", "%ld", first_client->cwcache);
|
---|
1803 | tpl_printf(vars, TPLADD, "TOTAL_CWTUN", "%ld", first_client->cwtun);
|
---|
1804 |
|
---|
1805 | if (!apicall)
|
---|
1806 | return tpl_getTpl(vars, "USERCONFIGLIST");
|
---|
1807 | else {
|
---|
1808 | if (!filter || clientcount > 0) {
|
---|
1809 | return tpl_getTpl(vars, "APIUSERCONFIGLIST");
|
---|
1810 | } else {
|
---|
1811 | tpl_printf(vars, TPLADD, "APIERRORMESSAGE", "Invalid client %s", filter);
|
---|
1812 | return tpl_getTpl(vars, "APIERROR");
|
---|
1813 | }
|
---|
1814 | }
|
---|
1815 |
|
---|
1816 | }
|
---|
1817 |
|
---|
1818 | #define ENTITLEMENT_PAGE_SIZE 500
|
---|
1819 |
|
---|
1820 | char *send_oscam_entitlement(struct templatevars *vars, struct uriparams *params, struct in_addr in, int32_t apicall) {
|
---|
1821 |
|
---|
1822 | //just to stop the guys open tedious tickets for warnings related to unused variables xD
|
---|
1823 | tpl_printf(vars, TPLADD, "CALLINGIP", "%s", inet_ntoa(in));
|
---|
1824 | tpl_printf(vars, TPLADD, "ISAPICALL", "%d", apicall);
|
---|
1825 | //**************
|
---|
1826 |
|
---|
1827 | /* build entitlements from reader init history */
|
---|
1828 | char *reader_ = getParam(params, "label");
|
---|
1829 | char *sharelist_ = getParam(params, "globallist");
|
---|
1830 | int32_t show_global_list = sharelist_ && sharelist_[0]=='1';
|
---|
1831 |
|
---|
1832 | int offset = atoi(getParam(params, "offset")); //should be 0 if parameter is missed on very first call
|
---|
1833 |
|
---|
1834 | struct s_reader *rdr = get_reader_by_label(getParam(params, "label"));
|
---|
1835 | if (show_global_list || (cfg.saveinithistory && strlen(reader_) > 0) || rdr->typ == R_CCCAM) {
|
---|
1836 |
|
---|
1837 | if (show_global_list || (rdr->typ == R_CCCAM && rdr->enable == 1)) {
|
---|
1838 |
|
---|
1839 | if (show_global_list) {
|
---|
1840 | tpl_addVar(vars, TPLADD, "READERNAME", "GLOBAL");
|
---|
1841 | tpl_addVar(vars, TPLADD, "APIHOST", "GLOBAL");
|
---|
1842 | tpl_printf(vars, TPLADD, "APIHOSTPORT", "GLOBAL");
|
---|
1843 | } else {
|
---|
1844 | tpl_addVar(vars, TPLADD, "READERNAME", rdr->label);
|
---|
1845 | tpl_addVar(vars, TPLADD, "APIHOST", rdr->device);
|
---|
1846 | tpl_printf(vars, TPLADD, "APIHOSTPORT", "%d", rdr->r_port);
|
---|
1847 | }
|
---|
1848 |
|
---|
1849 | int32_t cardcount = 0;
|
---|
1850 | int32_t providercount = 0;
|
---|
1851 | int32_t nodecount = 0;
|
---|
1852 |
|
---|
1853 | char *provider = "";
|
---|
1854 |
|
---|
1855 | struct cc_card *card;
|
---|
1856 |
|
---|
1857 | LLIST *cards = NULL;
|
---|
1858 | pthread_mutex_t *lock = NULL;
|
---|
1859 |
|
---|
1860 | if (show_global_list) {
|
---|
1861 | cards = get_and_lock_sharelist();
|
---|
1862 | } else {
|
---|
1863 | struct s_client *rc = rdr->client;
|
---|
1864 | struct cc_data *rcc = (rc)?rc->cc:NULL;
|
---|
1865 |
|
---|
1866 | if (rcc && rcc->cards) {
|
---|
1867 | cards = rcc->cards;
|
---|
1868 | lock = &rcc->cards_busy;
|
---|
1869 | pthread_mutex_lock(lock);
|
---|
1870 | }
|
---|
1871 | }
|
---|
1872 |
|
---|
1873 | if (cards) {
|
---|
1874 |
|
---|
1875 | uint8_t serbuf[8];
|
---|
1876 |
|
---|
1877 | // sort cards by hop
|
---|
1878 | LL_ITER *it;
|
---|
1879 | int32_t i;
|
---|
1880 | for (i = 0; i < ll_count(cards); i++) {
|
---|
1881 | it = ll_iter_create(cards);
|
---|
1882 | while ((card = ll_iter_next(it))) {
|
---|
1883 | if (it->cur->nxt) {
|
---|
1884 | struct cc_card *card2 = ll_iter_peek(it, 1);
|
---|
1885 | if (card->caid > card2->caid ||
|
---|
1886 | (card->caid==card2->caid && card->hop > card2->hop)) {
|
---|
1887 | it->cur->obj = it->cur->nxt->obj;
|
---|
1888 | it->cur->nxt->obj = card;
|
---|
1889 | }
|
---|
1890 | }
|
---|
1891 | }
|
---|
1892 | ll_iter_release(it);
|
---|
1893 | }
|
---|
1894 |
|
---|
1895 | it = ll_iter_create(cards);
|
---|
1896 | int offset2 = offset;
|
---|
1897 | int count = 0;
|
---|
1898 | while ((card = ll_iter_move(it, offset2))) {
|
---|
1899 | offset2 = 1;
|
---|
1900 | if (count == ENTITLEMENT_PAGE_SIZE)
|
---|
1901 | break;
|
---|
1902 | count++;
|
---|
1903 |
|
---|
1904 | if (!apicall) {
|
---|
1905 | if (show_global_list)
|
---|
1906 | rdr = card->origin_reader;
|
---|
1907 | if (rdr)
|
---|
1908 | tpl_printf(vars, TPLADD, "HOST", "%s:%d", rdr->device, rdr->r_port);
|
---|
1909 | tpl_printf(vars, TPLADD, "CAID", "%04X", card->caid);
|
---|
1910 | } else {
|
---|
1911 | tpl_printf(vars, TPLADD, "APICARDNUMBER", "%d", cardcount);
|
---|
1912 | tpl_printf(vars, TPLADD, "APICAID", "%04X", card->caid);
|
---|
1913 | }
|
---|
1914 |
|
---|
1915 | if (cc_UA_valid(card->hexserial)) { //Add UA:
|
---|
1916 | cc_UA_cccam2oscam(card->hexserial, serbuf, card->caid);
|
---|
1917 | tpl_printf(vars, TPLAPPEND, "HOST", "<BR>\nUA_Oscam:%s", cs_hexdump(0, serbuf, 8));
|
---|
1918 | tpl_printf(vars, TPLAPPEND, "HOST", "<BR>\nUA_CCcam:%s", cs_hexdump(0, card->hexserial, 8));
|
---|
1919 | }
|
---|
1920 | if (!apicall) {
|
---|
1921 | int32_t n;
|
---|
1922 | LL_ITER *its = ll_iter_create(card->goodsids);
|
---|
1923 | struct cc_srvid *srv;
|
---|
1924 | n=0;
|
---|
1925 | tpl_printf(vars, TPLADD, "SERVICESGOOD", "");
|
---|
1926 | while ((srv=ll_iter_next(its))) {
|
---|
1927 | tpl_printf(vars, TPLAPPEND, "SERVICESGOOD", "%04X%s", srv->sid, ++n%10==0?"<BR>\n":" ");
|
---|
1928 | }
|
---|
1929 | ll_iter_release(its);
|
---|
1930 |
|
---|
1931 | its = ll_iter_create(card->badsids);
|
---|
1932 | n=0;
|
---|
1933 | tpl_printf(vars, TPLADD, "SERVICESBAD", "");
|
---|
1934 | while ((srv=ll_iter_next(its))) {
|
---|
1935 | tpl_printf(vars, TPLAPPEND, "SERVICESBAD", "%04X%s", srv->sid, ++n%10==0?"<BR>\n":" ");
|
---|
1936 | }
|
---|
1937 | ll_iter_release(its);
|
---|
1938 | }
|
---|
1939 |
|
---|
1940 | struct s_cardsystem *cs = get_cardsystem_by_caid(card->caid);
|
---|
1941 |
|
---|
1942 | if (cs)
|
---|
1943 | tpl_addVar(vars, TPLADD, "SYSTEM", cs->desc ? cs->desc : "");
|
---|
1944 | else
|
---|
1945 | tpl_addVar(vars, TPLADD, "SYSTEM", "???");
|
---|
1946 |
|
---|
1947 | tpl_printf(vars, TPLADD, "SHAREID", "%08X", card->id);
|
---|
1948 | tpl_printf(vars, TPLADD, "REMOTEID", "%08X", card->remote_id);
|
---|
1949 | tpl_printf(vars, TPLADD, "UPHOPS", "%d", card->hop);
|
---|
1950 | tpl_printf(vars, TPLADD, "MAXDOWN", "%d", card->reshare);
|
---|
1951 |
|
---|
1952 | LL_ITER *pit = ll_iter_create(card->providers);
|
---|
1953 | struct cc_provider *prov;
|
---|
1954 |
|
---|
1955 | providercount = 0;
|
---|
1956 |
|
---|
1957 | if (!apicall)
|
---|
1958 | tpl_addVar(vars, TPLADD, "PROVIDERS", "");
|
---|
1959 | else
|
---|
1960 | tpl_addVar(vars, TPLADD, "PROVIDERLIST", "");
|
---|
1961 |
|
---|
1962 | while ((prov = ll_iter_next(pit))) {
|
---|
1963 | provider = xml_encode(vars, get_provider(card->caid, prov->prov));
|
---|
1964 |
|
---|
1965 | if (!apicall) {
|
---|
1966 | if (prov->sa[0] || prov->sa[1] || prov->sa[2] || prov->sa[3]) {
|
---|
1967 | tpl_printf(vars, TPLAPPEND, "PROVIDERS", "%s SA:%02X%02X%02X%02X<BR>\n", provider, prov->sa[0], prov->sa[1], prov->sa[2], prov->sa[3]);
|
---|
1968 | } else {
|
---|
1969 | tpl_printf(vars, TPLAPPEND, "PROVIDERS", "%s<BR>\n", provider);
|
---|
1970 | }
|
---|
1971 | } else {
|
---|
1972 | if (prov->sa[0] || prov->sa[1] || prov->sa[2] || prov->sa[3])
|
---|
1973 | tpl_printf(vars, TPLADD, "APIPROVIDERSA", "%02X%02X%02X%02X", prov->sa[0], prov->sa[1], prov->sa[2], prov->sa[3]);
|
---|
1974 | else
|
---|
1975 | tpl_addVar(vars, TPLADD, "APIPROVIDERSA","");
|
---|
1976 | tpl_printf(vars, TPLADD, "APIPROVIDERCAID", "%04X", card->caid);
|
---|
1977 | tpl_printf(vars, TPLADD, "APIPROVIDERPROVID", "%06X", prov->prov);
|
---|
1978 | tpl_printf(vars, TPLADD, "APIPROVIDERNUMBER", "%d", providercount);
|
---|
1979 | tpl_addVar(vars, TPLADD, "APIPROVIDERNAME", xml_encode(vars, provider));
|
---|
1980 | tpl_addVar(vars, TPLAPPEND, "PROVIDERLIST", tpl_getTpl(vars, "APICCCAMCARDPROVIDERBIT"));
|
---|
1981 | }
|
---|
1982 | providercount++;
|
---|
1983 | tpl_printf(vars, TPLADD, "APITOTALPROVIDERS", "%d", providercount);
|
---|
1984 | }
|
---|
1985 |
|
---|
1986 | ll_iter_release(pit);
|
---|
1987 | LL_ITER *nit = ll_iter_create(card->remote_nodes);
|
---|
1988 | uint8_t *node;
|
---|
1989 |
|
---|
1990 | nodecount = 0;
|
---|
1991 | if (!apicall) tpl_addVar(vars, TPLADD, "NODES", "");
|
---|
1992 | else tpl_addVar(vars, TPLADD, "NODELIST", "");
|
---|
1993 |
|
---|
1994 | while ((node = ll_iter_next(nit))) {
|
---|
1995 |
|
---|
1996 | if (!apicall) {
|
---|
1997 | tpl_printf(vars, TPLAPPEND, "NODES", "%02X%02X%02X%02X%02X%02X%02X%02X<BR>\n",
|
---|
1998 | node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7]);
|
---|
1999 | } else {
|
---|
2000 | tpl_printf(vars, TPLADD, "APINODE", "%02X%02X%02X%02X%02X%02X%02X%02X", node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7]);
|
---|
2001 | tpl_printf(vars, TPLADD, "APINODENUMBER", "%d", nodecount);
|
---|
2002 | tpl_addVar(vars, TPLAPPEND, "NODELIST", tpl_getTpl(vars, "APICCCAMCARDNODEBIT"));
|
---|
2003 | }
|
---|
2004 | nodecount++;
|
---|
2005 | tpl_printf(vars, TPLADD, "APITOTALNODES", "%d", nodecount);
|
---|
2006 | }
|
---|
2007 |
|
---|
2008 | ll_iter_release(nit);
|
---|
2009 |
|
---|
2010 | if (!apicall)
|
---|
2011 | tpl_addVar(vars, TPLAPPEND, "CCCAMSTATSENTRY", tpl_getTpl(vars, "ENTITLEMENTCCCAMENTRYBIT"));
|
---|
2012 | else
|
---|
2013 | tpl_addVar(vars, TPLAPPEND, "CARDLIST", tpl_getTpl(vars, "APICCCAMCARDBIT"));
|
---|
2014 |
|
---|
2015 | cardcount++;
|
---|
2016 | }
|
---|
2017 |
|
---|
2018 | int has_more = (card != NULL); //next/prev page
|
---|
2019 |
|
---|
2020 | // set previous Link if needed
|
---|
2021 | if (offset > ENTITLEMENT_PAGE_SIZE) {
|
---|
2022 | tpl_printf(vars, TPLAPPEND, "CONTROLS", "<A HREF=\"entitlements.html?offset=%d&globallist=%s&label=%s\"> << PREVIOUS < </A>",
|
---|
2023 | offset - ENTITLEMENT_PAGE_SIZE,
|
---|
2024 | getParam(params, "globallist"),
|
---|
2025 | getParam(params, "label"));
|
---|
2026 | }
|
---|
2027 |
|
---|
2028 | // set next link if needed
|
---|
2029 | if (has_more) {
|
---|
2030 | tpl_printf(vars, TPLAPPEND, "CONTROLS", "<A HREF=\"entitlements.html?offset=%d&globallist=%s&label=%s\"> > NEXT >> </A>",
|
---|
2031 | offset + ENTITLEMENT_PAGE_SIZE,
|
---|
2032 | getParam(params, "globallist"),
|
---|
2033 | getParam(params, "label"));
|
---|
2034 | }
|
---|
2035 | //todo alno: offset=ENTITLEMENT_PAGE_SIZE on the first page, 2*ENTITLEMENT_PAGE_SIZE on the second and so on
|
---|
2036 | //todo alno: if has_mode: next_btn(offset+ENTITLEMENT_PAGE_SIZE);
|
---|
2037 | //todo alno: if offset > ENTITLEMENT_PAGE_SIZE: prev_btn(offset-ENTITLEMENT_PAGE_SIZE);
|
---|
2038 |
|
---|
2039 | ll_iter_release(it);
|
---|
2040 |
|
---|
2041 | if (!apicall) {
|
---|
2042 | tpl_printf(vars, TPLADD, "TOTALS", "card count=%d", cardcount);
|
---|
2043 | tpl_addVar(vars, TPLADD, "ENTITLEMENTCONTENT", tpl_getTpl(vars, "ENTITLEMENTCCCAMBIT"));
|
---|
2044 | } else {
|
---|
2045 | tpl_printf(vars, TPLADD, "APITOTALCARDS", "%d", cardcount);
|
---|
2046 | }
|
---|
2047 |
|
---|
2048 | } else {
|
---|
2049 | if (!apicall) {
|
---|
2050 | tpl_addVar(vars, TPLADD, "ENTITLEMENTCONTENT", tpl_getTpl(vars, "ENTITLEMENTGENERICBIT"));
|
---|
2051 | tpl_addVar(vars, TPLADD, "LOGHISTORY", "no cards found<BR>\n");
|
---|
2052 | } else {
|
---|
2053 | tpl_printf(vars, TPLADD, "APITOTALCARDS", "%d", cardcount);
|
---|
2054 | }
|
---|
2055 | }
|
---|
2056 |
|
---|
2057 | if (show_global_list)
|
---|
2058 | unlock_sharelist();
|
---|
2059 | else if (lock)
|
---|
2060 | pthread_mutex_unlock(lock);
|
---|
2061 |
|
---|
2062 | } else {
|
---|
2063 | tpl_addVar(vars, TPLADD, "LOGHISTORY", "->");
|
---|
2064 | // normal non-cccam reader
|
---|
2065 |
|
---|
2066 | rdr = get_reader_by_label(reader_);
|
---|
2067 |
|
---|
2068 | if (rdr->init_history) {
|
---|
2069 | char *ptr, *ptr1 = NULL;
|
---|
2070 | for (ptr=strtok_r(rdr->init_history, "\n", &ptr1); ptr; ptr=strtok_r(NULL, "\n", &ptr1)) {
|
---|
2071 | tpl_printf(vars, TPLAPPEND, "LOGHISTORY", "%s<BR />", ptr);
|
---|
2072 | ptr1[-1]='\n';
|
---|
2073 | }
|
---|
2074 | }
|
---|
2075 |
|
---|
2076 | tpl_addVar(vars, TPLADD, "READERNAME", rdr->label);
|
---|
2077 | tpl_addVar(vars, TPLADD, "ENTITLEMENTCONTENT", tpl_getTpl(vars, "ENTITLEMENTGENERICBIT"));
|
---|
2078 | }
|
---|
2079 |
|
---|
2080 | } else {
|
---|
2081 | tpl_addVar(vars, TPLADD, "LOGHISTORY",
|
---|
2082 | "You have to set saveinithistory=1 in your config to see Entitlements!<BR>\n");
|
---|
2083 | tpl_addVar(vars, TPLADD, "ENTITLEMENTCONTENT", tpl_getTpl(vars, "ENTITLEMENTGENERICBIT"));
|
---|
2084 | }
|
---|
2085 |
|
---|
2086 | if (!apicall)
|
---|
2087 | return tpl_getTpl(vars, "ENTITLEMENTS");
|
---|
2088 | else
|
---|
2089 | return tpl_getTpl(vars, "APICCCAMCARDLIST");
|
---|
2090 | }
|
---|
2091 |
|
---|
2092 | char *send_oscam_status(struct templatevars *vars, struct uriparams *params, struct in_addr in, int32_t apicall) {
|
---|
2093 | int32_t i;
|
---|
2094 | char *usr;
|
---|
2095 | int32_t lsec, isec, con, cau = 0;
|
---|
2096 | time_t now = time((time_t)0);
|
---|
2097 | struct tm lt;
|
---|
2098 |
|
---|
2099 | if (strcmp(getParam(params, "action"), "kill") == 0) {
|
---|
2100 | struct s_client *cl = get_client_by_tid(atol(getParam(params, "threadid")));
|
---|
2101 | if (cl) {
|
---|
2102 | kill_thread(cl);
|
---|
2103 | cs_log("Client %s killed by WebIF from %s", cl->account->usr, inet_ntoa(in));
|
---|
2104 | }
|
---|
2105 | }
|
---|
2106 |
|
---|
2107 | if (strcmp(getParam(params, "action"), "restart") == 0) {
|
---|
2108 | struct s_reader *rdr = get_reader_by_label(getParam(params, "label"));
|
---|
2109 | if(rdr) {
|
---|
2110 | restart_cardreader(rdr, 1);
|
---|
2111 | cs_log("Reader %s restarted by WebIF from %s", rdr->label, inet_ntoa(in));
|
---|
2112 | }
|
---|
2113 | }
|
---|
2114 |
|
---|
2115 | char *debuglvl = getParam(params, "debug");
|
---|
2116 | if(strlen(debuglvl) > 0) {
|
---|
2117 | #ifndef WITH_DEBUG
|
---|
2118 | cs_log("*** Warning: Debug Support not compiled in ***");
|
---|
2119 | #else
|
---|
2120 | int32_t dblvl = atoi(debuglvl);
|
---|
2121 | if(dblvl >= 0 && dblvl <= 255) cs_dblevel = dblvl;
|
---|
2122 | cs_log("%s debug_level=%d", "all", cs_dblevel);
|
---|
2123 | #endif
|
---|
2124 | }
|
---|
2125 |
|
---|
2126 | char *hide = getParam(params, "hide");
|
---|
2127 | if(strlen(hide) > 0) {
|
---|
2128 | uint32_t clidx;
|
---|
2129 | clidx = atol(hide);
|
---|
2130 | struct s_client *hideidx = get_client_by_tid(clidx);
|
---|
2131 | if(hideidx)
|
---|
2132 | hideidx->wihidden = 1;
|
---|
2133 | }
|
---|
2134 |
|
---|
2135 | char *hideidle = getParam(params, "hideidle");
|
---|
2136 | if(strlen(hideidle) > 0) {
|
---|
2137 | if (atoi(hideidle) == 2) {
|
---|
2138 | struct s_client *cl;
|
---|
2139 | for (cl=first_client; cl ; cl=cl->next)
|
---|
2140 | cl->wihidden = 0;
|
---|
2141 | }
|
---|
2142 | else {
|
---|
2143 | int32_t oldval = cfg.http_hide_idle_clients;
|
---|
2144 | chk_t_webif("httphideidleclients", hideidle);
|
---|
2145 | if(oldval != cfg.http_hide_idle_clients) {
|
---|
2146 | refresh_oscam(REFR_SERVER, in);
|
---|
2147 | }
|
---|
2148 | }
|
---|
2149 | }
|
---|
2150 |
|
---|
2151 | if(cfg.http_hide_idle_clients > 0) tpl_addVar(vars, TPLADD, "HIDEIDLECLIENTSSELECTED1", "selected");
|
---|
2152 | else tpl_addVar(vars, TPLADD, "HIDEIDLECLIENTSSELECTED0", "selected");
|
---|
2153 |
|
---|
2154 | int32_t user_count_all = 0, user_count_shown = 0, user_count_active = 0;
|
---|
2155 | int32_t reader_count_all = 0, reader_count_conn = 0;
|
---|
2156 | int32_t proxy_count_all = 0, proxy_count_conn = 0;
|
---|
2157 | int32_t shown;
|
---|
2158 |
|
---|
2159 | struct s_client *cl;
|
---|
2160 | for (i=0, cl=first_client; cl ; cl=cl->next, i++) {
|
---|
2161 |
|
---|
2162 | // Reset template variables
|
---|
2163 | tpl_addVar(vars, TPLADD, "CLIENTLBVALUE","");
|
---|
2164 | tpl_addVar(vars, TPLADD, "LASTREADER", "");
|
---|
2165 | tpl_addVar(vars, TPLADD, "CLIENTPROTO", "");
|
---|
2166 | tpl_addVar(vars, TPLADD, "CLIENTDESCRIPTION", "");
|
---|
2167 | tpl_addVar(vars, TPLADD, "CLIENTLASTRESPONSETIME", "");
|
---|
2168 | tpl_addVar(vars, TPLADD, "CLIENTLASTRESPONSETIMEHIST", "");
|
---|
2169 |
|
---|
2170 | if (cl->typ=='c')
|
---|
2171 | user_count_all++;
|
---|
2172 | else if (cl->typ=='p')
|
---|
2173 | proxy_count_all++;
|
---|
2174 | else if (cl->typ=='r')
|
---|
2175 | reader_count_all++;
|
---|
2176 |
|
---|
2177 | shown = 0;
|
---|
2178 | if (cl->wihidden != 1) {
|
---|
2179 |
|
---|
2180 | if((cfg.http_hide_idle_clients != 1) || (cl->typ != 'c') || ((now - cl->lastecm) <= cfg.mon_hideclient_to)) {
|
---|
2181 |
|
---|
2182 | if (cl->typ=='c'){
|
---|
2183 | user_count_shown++;
|
---|
2184 | if (cfg.http_hide_idle_clients != 1 && cfg.mon_hideclient_to > 0 && (now - cl->lastecm) <= cfg.mon_hideclient_to){
|
---|
2185 | user_count_active++;
|
---|
2186 | tpl_addVar(vars, TPLADD, "CLIENTTYPE", "a");
|
---|
2187 | } else tpl_addVar(vars, TPLADD, "CLIENTTYPE", "c");
|
---|
2188 | if(cl->lastecm > cl->login) isec = now - cl->lastecm;
|
---|
2189 | else isec = now - cl->login;
|
---|
2190 | } else {
|
---|
2191 | if (cl->typ=='r' && cl->reader->card_status==CARD_INSERTED)
|
---|
2192 | reader_count_conn++;
|
---|
2193 | else if (cl->typ=='p' && (cl->reader->card_status==CARD_INSERTED ||cl->reader->tcp_connected))
|
---|
2194 | proxy_count_conn++;
|
---|
2195 | tpl_printf(vars, TPLADD, "CLIENTTYPE", "%c", cl->typ);
|
---|
2196 | isec = now - cl->last;
|
---|
2197 | }
|
---|
2198 |
|
---|
2199 | shown = 1;
|
---|
2200 | lsec=now-cl->login;
|
---|
2201 | usr=username(cl);
|
---|
2202 |
|
---|
2203 | if ((cl->typ=='r') || (cl->typ=='p')) usr=cl->reader->label;
|
---|
2204 |
|
---|
2205 | if (cl->dup) con=2;
|
---|
2206 | else if ((cl->tosleep) && (now-cl->lastswitch>cl->tosleep)) con=1;
|
---|
2207 | else con=0;
|
---|
2208 |
|
---|
2209 | // no AU reader == 0 / AU ok == 1 / Last EMM > aulow == -1
|
---|
2210 | if(cl->typ == 'c' || cl->typ == 'p' || cl->typ == 'r'){
|
---|
2211 | if ((cl->typ == 'c' && !cl->aureader_list) || ((cl->typ == 'p' || cl->typ == 'r') && cl->reader->audisabled)) cau = 0;
|
---|
2212 | else if ((now-cl->lastemm)/60 > cfg.mon_aulow) cau = -1;
|
---|
2213 | else cau = 1;
|
---|
2214 |
|
---|
2215 | if (!apicall){
|
---|
2216 | if (cau == 0) {
|
---|
2217 | tpl_addVar(vars, TPLADD, "CLIENTCAUHTTP", "OFF");
|
---|
2218 | } else {
|
---|
2219 | if (cau == -1) tpl_addVar(vars, TPLADD, "CLIENTCAUHTTP", "<a href=\"#\" class=\"tooltip\">ON");
|
---|
2220 | else tpl_addVar(vars, TPLADD, "CLIENTCAUHTTP", "<a href=\"#\" class=\"tooltip\">ACTIVE");
|
---|
2221 | tpl_addVar(vars, TPLAPPEND, "CLIENTCAUHTTP", "<span>");
|
---|
2222 | if (cl->typ == 'c'){
|
---|
2223 | struct s_reader *rdr;
|
---|
2224 | LL_ITER *itr = ll_iter_create(cl->aureader_list);
|
---|
2225 | while ((rdr = ll_iter_next(itr))) {
|
---|
2226 | if(rdr->audisabled) tpl_printf(vars, TPLAPPEND, "CLIENTCAUHTTP", "(%s)<br>", rdr->label);
|
---|
2227 | else tpl_printf(vars, TPLAPPEND, "CLIENTCAUHTTP", "%s<br>", rdr->label);
|
---|
2228 | }
|
---|
2229 | ll_iter_release(itr);
|
---|
2230 | } else tpl_addVar(vars, TPLAPPEND, "CLIENTCAUHTTP", cl->reader->label);
|
---|
2231 | tpl_addVar(vars, TPLAPPEND, "CLIENTCAUHTTP", "</span></a>");
|
---|
2232 | }
|
---|
2233 | }
|
---|
2234 | } else {
|
---|
2235 | cau = 0;
|
---|
2236 | tpl_addVar(vars, TPLADD, "CLIENTCAUHTTP", "");
|
---|
2237 | }
|
---|
2238 |
|
---|
2239 | localtime_r(&cl->login, <);
|
---|
2240 |
|
---|
2241 | tpl_printf(vars, TPLADD, "HIDEIDX", "%ld", cl->thread);
|
---|
2242 |
|
---|
2243 | if(cl->typ == 'c' && !cfg.http_readonly) {
|
---|
2244 | tpl_printf(vars, TPLADD, "CSIDX", "<A HREF=\"status.html?action=kill&threadid=%ld\" TITLE=\"Kill this client\"><IMG HEIGHT=\"16\" WIDTH=\"16\" SRC=\"image?i=ICKIL\" ALT=\"Kill\"></A>", cl->thread);
|
---|
2245 | }
|
---|
2246 | else if((cl->typ == 'p') && !cfg.http_readonly) {
|
---|
2247 | tpl_printf(vars, TPLADD, "CSIDX", "<A HREF=\"status.html?action=restart&label=%s\" TITLE=\"Restart this reader/ proxy\"><IMG HEIGHT=\"16\" WIDTH=\"16\" SRC=\"image?i=ICKIL\" ALT=\"Restart\"></A>", urlencode(vars, cl->reader->label));
|
---|
2248 | }
|
---|
2249 | else {
|
---|
2250 | tpl_printf(vars, TPLADD, "CSIDX", "%8X ", cl->thread);
|
---|
2251 | }
|
---|
2252 |
|
---|
2253 | tpl_printf(vars, TPLADD, "CLIENTTYPE", "%c", cl->typ);
|
---|
2254 | tpl_printf(vars, TPLADD, "CLIENTCNR", "%d", get_threadnum(cl));
|
---|
2255 | tpl_addVar(vars, TPLADD, "CLIENTUSER", xml_encode(vars, usr));
|
---|
2256 | if (cl->typ == 'c')
|
---|
2257 | tpl_addVar(vars, TPLADD, "CLIENTDESCRIPTION", xml_encode(vars, cl->account?cl->account->description:""));
|
---|
2258 | tpl_printf(vars, TPLADD, "CLIENTCAU", "%d", cau);
|
---|
2259 | if(!apicall){
|
---|
2260 | if(cl->typ == 'c' || cl->typ == 'p' || cl->typ == 'r'){
|
---|
2261 | if(cl->crypted) tpl_addVar(vars, TPLADD, "CLIENTCRYPTED", "ON");
|
---|
2262 | else tpl_addVar(vars, TPLADD, "CLIENTCRYPTED", "OFF");
|
---|
2263 | } else tpl_addVar(vars, TPLADD, "CLIENTCRYPTED", "");
|
---|
2264 | } else tpl_printf(vars, TPLADD, "CLIENTCRYPTED", "%d", cl->crypted);
|
---|
2265 | tpl_addVar(vars, TPLADD, "CLIENTIP", cs_inet_ntoa(cl->ip));
|
---|
2266 | tpl_printf(vars, TPLADD, "CLIENTPORT", "%d", cl->port);
|
---|
2267 | char *proto = monitor_get_proto(cl);
|
---|
2268 |
|
---|
2269 | if ((strcmp(proto,"newcamd") == 0) && (cl->typ == 'c'))
|
---|
2270 | tpl_printf(vars, TPLADD, "CLIENTPROTO","%s (%s)", proto, get_ncd_client_name(cl->ncd_client_id));
|
---|
2271 | else if ((strncmp(proto,"cccam", 5) == 0)) {
|
---|
2272 | struct cc_data *cc = cl->cc;
|
---|
2273 | if(cc && cc->remote_version && cc->remote_build) {
|
---|
2274 | tpl_printf(vars, TPLADD, "CLIENTPROTO", "%s (%s-%s)", proto, cc->remote_version, cc->remote_build);
|
---|
2275 | if(cc->extended_mode)
|
---|
2276 | tpl_addVar(vars, TPLADD, "CLIENTPROTOTITLE", cc->remote_oscam);
|
---|
2277 | else
|
---|
2278 | tpl_addVar(vars, TPLADD, "CLIENTPROTOTITLE", ""); //unset tpl var
|
---|
2279 | }
|
---|
2280 | else
|
---|
2281 | {
|
---|
2282 | tpl_addVar(vars, TPLADD, "CLIENTPROTO", proto);
|
---|
2283 | tpl_addVar(vars, TPLADD, "CLIENTPROTOTITLE", "");
|
---|
2284 | }
|
---|
2285 | }
|
---|
2286 | else {
|
---|
2287 | tpl_addVar(vars, TPLADD, "CLIENTPROTO", proto);
|
---|
2288 | tpl_addVar(vars, TPLADD, "CLIENTPROTOTITLE", "");
|
---|
2289 | }
|
---|
2290 |
|
---|
2291 | if (!apicall) {
|
---|
2292 | tpl_printf(vars, TPLADD, "CLIENTLOGINDATE", "%02d.%02d.%02d", lt.tm_mday, lt.tm_mon+1, lt.tm_year%100);
|
---|
2293 | tpl_printf(vars, TPLAPPEND, "CLIENTLOGINDATE", " %02d:%02d:%02d", lt.tm_hour, lt.tm_min, lt.tm_sec);
|
---|
2294 | tpl_addVar(vars, TPLADD, "CLIENTLOGINSECS", sec2timeformat(vars, lsec));
|
---|
2295 | } else {
|
---|
2296 | char tbuffer [30];
|
---|
2297 | strftime(tbuffer, 30, "%Y-%m-%dT%H:%M:%S%z", <);
|
---|
2298 | tpl_printf(vars, TPLADD, "CLIENTLOGINDATE", "%s", tbuffer);
|
---|
2299 | tpl_printf(vars, TPLADD, "CLIENTLOGINSECS", "%d", lsec);
|
---|
2300 | }
|
---|
2301 |
|
---|
2302 | if (isec < cfg.mon_hideclient_to || cfg.mon_hideclient_to == 0) {
|
---|
2303 |
|
---|
2304 | if (((cl->typ!='r') || (cl->typ!='p')) && (cl->lastreader[0])) {
|
---|
2305 | tpl_printf(vars, TPLADD, "CLIENTLBVALUE", "by %s", cl->lastreader);
|
---|
2306 | tpl_printf(vars, TPLAPPEND, "CLIENTLBVALUE", " (%dms)", cl->cwlastresptime);
|
---|
2307 | if (apicall)
|
---|
2308 | tpl_addVar(vars, TPLADD, "LASTREADER", cl->lastreader);
|
---|
2309 | }
|
---|
2310 |
|
---|
2311 | tpl_printf(vars, TPLADD, "CLIENTCAID", "%04X", cl->last_caid);
|
---|
2312 | tpl_printf(vars, TPLADD, "CLIENTSRVID", "%04X", cl->last_srvid);
|
---|
2313 | tpl_printf(vars, TPLADD, "CLIENTLASTRESPONSETIME", "%d", cl->cwlastresptime?cl->cwlastresptime:1);
|
---|
2314 |
|
---|
2315 | int32_t k;
|
---|
2316 | char *dot = "";
|
---|
2317 |
|
---|
2318 | if(cl->cwlastresptimes_last == CS_ECM_RINGBUFFER_MAX - 1){
|
---|
2319 | for(k = 0; k < CS_ECM_RINGBUFFER_MAX ; k++){
|
---|
2320 | tpl_printf(vars, TPLAPPEND, "CLIENTLASTRESPONSETIMEHIST", "%s%d", dot, cl->cwlastresptimes[k]);
|
---|
2321 | dot=",";
|
---|
2322 | }
|
---|
2323 | } else {
|
---|
2324 | for(k = cl->cwlastresptimes_last + 1; k < CS_ECM_RINGBUFFER_MAX; k++){
|
---|
2325 | tpl_printf(vars, TPLAPPEND, "CLIENTLASTRESPONSETIMEHIST", "%s%d", dot, cl->cwlastresptimes[k]);
|
---|
2326 | dot=",";
|
---|
2327 | }
|
---|
2328 |
|
---|
2329 | for(k = 0; k < cl->cwlastresptimes_last + 1 ; k++){
|
---|
2330 | tpl_printf(vars, TPLAPPEND, "CLIENTLASTRESPONSETIMEHIST", "%s%d", dot, cl->cwlastresptimes[k]);
|
---|
2331 | dot=",";
|
---|
2332 | }
|
---|
2333 | }
|
---|
2334 |
|
---|
2335 | int32_t j, found = 0;
|
---|
2336 | struct s_srvid *srvid = cfg.srvid;
|
---|
2337 |
|
---|
2338 | while (srvid != NULL) {
|
---|
2339 | if (srvid->srvid == cl->last_srvid) {
|
---|
2340 | for (j=0; j < srvid->ncaid; j++) {
|
---|
2341 | if (srvid->caid[j] == cl->last_caid) {
|
---|
2342 | found = 1;
|
---|
2343 | break;
|
---|
2344 | }
|
---|
2345 | }
|
---|
2346 | }
|
---|
2347 | if (found == 1)
|
---|
2348 | break;
|
---|
2349 | else
|
---|
2350 | srvid = srvid->next;
|
---|
2351 | }
|
---|
2352 |
|
---|
2353 | if (found == 1) {
|
---|
2354 | tpl_printf(vars, TPLADD, "CLIENTSRVPROVIDER","%s: ", srvid->prov ? xml_encode(vars, srvid->prov) : "");
|
---|
2355 | tpl_addVar(vars, TPLADD, "CLIENTSRVNAME", srvid->name ? xml_encode(vars, srvid->name) : "");
|
---|
2356 | tpl_addVar(vars, TPLADD, "CLIENTSRVTYPE", srvid->type ? xml_encode(vars, srvid->type) : "");
|
---|
2357 | tpl_addVar(vars, TPLADD, "CLIENTSRVDESCRIPTION", srvid->desc ? xml_encode(vars, srvid->desc) : "");
|
---|
2358 | } else {
|
---|
2359 | tpl_addVar(vars, TPLADD, "CLIENTSRVPROVIDER","");
|
---|
2360 | tpl_addVar(vars, TPLADD, "CLIENTSRVNAME","");
|
---|
2361 | tpl_addVar(vars, TPLADD, "CLIENTSRVTYPE","");
|
---|
2362 | tpl_addVar(vars, TPLADD, "CLIENTSRVDESCRIPTION","");
|
---|
2363 | }
|
---|
2364 |
|
---|
2365 | } else {
|
---|
2366 | tpl_addVar(vars, TPLADD, "CLIENTCAID", "0000");
|
---|
2367 | tpl_addVar(vars, TPLADD, "CLIENTSRVID", "0000");
|
---|
2368 | tpl_addVar(vars, TPLADD, "CLIENTSRVPROVIDER","");
|
---|
2369 | tpl_addVar(vars, TPLADD, "CLIENTSRVNAME","");
|
---|
2370 | tpl_addVar(vars, TPLADD, "CLIENTSRVTYPE","");
|
---|
2371 | tpl_addVar(vars, TPLADD, "CLIENTSRVDESCRIPTION","");
|
---|
2372 | tpl_addVar(vars, TPLADD, "CLIENTLBVALUE","");
|
---|
2373 |
|
---|
2374 | }
|
---|
2375 |
|
---|
2376 | if (!apicall) {
|
---|
2377 | tpl_addVar(vars, TPLADD, "CLIENTIDLESECS", sec2timeformat(vars, isec));
|
---|
2378 | } else {
|
---|
2379 | tpl_printf(vars, TPLADD, "CLIENTIDLESECS", "%d", isec);
|
---|
2380 | }
|
---|
2381 |
|
---|
2382 |
|
---|
2383 | if(con == 2) tpl_addVar(vars, TPLADD, "CLIENTCON", "Duplicate");
|
---|
2384 | else if (con == 1) tpl_addVar(vars, TPLADD, "CLIENTCON", "Sleep");
|
---|
2385 | else
|
---|
2386 | {
|
---|
2387 | char *txt = "OK";
|
---|
2388 | if (cl->typ == 'r' || cl->typ == 'p') //reader or proxy
|
---|
2389 | {
|
---|
2390 | struct s_reader *rdr = cl->reader;
|
---|
2391 | if (rdr->lbvalue)
|
---|
2392 | tpl_printf(vars, TPLADD, "CLIENTLBVALUE", "<A HREF=\"readerstats.html?label=%s&hide=4\" TITLE=\"Show statistics for this reader/ proxy\">%d</A>", urlencode(vars, rdr->label), rdr->lbvalue);
|
---|
2393 | else
|
---|
2394 | tpl_printf(vars, TPLADD, "CLIENTLBVALUE", "<A HREF=\"readerstats.html?label=%s&hide=4\" TITLE=\"Show statistics for this reader/ proxy\">%s</A>", urlencode(vars, rdr->label), "no data");
|
---|
2395 |
|
---|
2396 | switch(rdr->card_status)
|
---|
2397 | {
|
---|
2398 | case NO_CARD: txt = "OFF"; break;
|
---|
2399 | case UNKNOWN: txt = "UNKNOWN"; break;
|
---|
2400 | case CARD_NEED_INIT: txt = "NEEDINIT"; break;
|
---|
2401 | case CARD_INSERTED:
|
---|
2402 | if (cl->typ=='p')
|
---|
2403 | txt = "CONNECTED";
|
---|
2404 | else
|
---|
2405 | txt = "CARDOK";
|
---|
2406 | break;
|
---|
2407 | case CARD_FAILURE: txt = "ERROR"; break;
|
---|
2408 | default: txt = "UNDEF";
|
---|
2409 | }
|
---|
2410 | }
|
---|
2411 | tpl_addVar(vars, TPLADD, "CLIENTCON", txt);
|
---|
2412 | if((cl->typ == 'r' || cl->typ == 'p') && strncmp(proto,"cccam", 5) == 0){
|
---|
2413 | struct cc_data *rcc = cl->cc;
|
---|
2414 | if(cl->cc){
|
---|
2415 | LLIST *cards = rcc->cards;
|
---|
2416 | if (cards) {
|
---|
2417 | int32_t cnt = ll_count(cards);
|
---|
2418 | if(cnt == 1) tpl_printf(vars, TPLAPPEND, "CLIENTCON", " <A HREF=\"entitlements.html?label=%s\" title=\"Show cards\">(1 card)</A>", urlencode(vars, cl->reader->label));
|
---|
2419 | else if(cnt > 1) tpl_printf(vars, TPLAPPEND, "CLIENTCON", " <A HREF=\"entitlements.html?label=%s\" title=\"Show cards\">(%d cards)</A>", urlencode(vars, cl->reader->label), cnt);
|
---|
2420 | }
|
---|
2421 | }
|
---|
2422 | }
|
---|
2423 | }
|
---|
2424 | }
|
---|
2425 | }
|
---|
2426 |
|
---|
2427 | if (!apicall) {
|
---|
2428 | // select right suborder
|
---|
2429 | if (cl->typ == 'c') {
|
---|
2430 | if (shown) tpl_addVar(vars, TPLAPPEND, "CLIENTSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
|
---|
2431 | if(cfg.http_hide_idle_clients == 1 || cfg.mon_hideclient_to < 1) tpl_printf(vars, TPLADD, "CLIENTHEADLINE", "\t\t<TR><TD CLASS=\"subheadline\" colspan=\"17\">Clients %d/%d</TD></TR>\n",
|
---|
2432 | user_count_shown, user_count_all);
|
---|
2433 | else tpl_printf(vars, TPLADD, "CLIENTHEADLINE", "\t\t<TR><TD CLASS=\"subheadline\" colspan=\"17\">Clients %d/%d (%d with ECM within last %d seconds)</TD></TR>\n",
|
---|
2434 | user_count_shown, user_count_all, user_count_active, cfg.mon_hideclient_to);
|
---|
2435 | }
|
---|
2436 | else if (cl->typ == 'r') {
|
---|
2437 | if (shown) tpl_addVar(vars, TPLAPPEND, "READERSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
|
---|
2438 | tpl_printf(vars, TPLADD, "READERHEADLINE", "\t\t<TR><TD CLASS=\"subheadline\" colspan=\"17\">Readers %d/%d</TD></TR>\n",
|
---|
2439 | reader_count_conn, reader_count_all);
|
---|
2440 | }
|
---|
2441 | else if (cl->typ == 'p') {
|
---|
2442 | if (shown) tpl_addVar(vars, TPLAPPEND, "PROXYSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
|
---|
2443 | tpl_printf(vars, TPLADD, "PROXYHEADLINE", "\t\t<TR><TD CLASS=\"subheadline\" colspan=\"17\">Proxies %d/%d</TD></TR>\n",
|
---|
2444 | proxy_count_conn, proxy_count_all);
|
---|
2445 | }
|
---|
2446 | else
|
---|
2447 | if (shown) tpl_addVar(vars, TPLAPPEND, "SERVERSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
|
---|
2448 |
|
---|
2449 | } else {
|
---|
2450 | if (shown) tpl_addVar(vars, TPLAPPEND, "APISTATUSBITS", tpl_getTpl(vars, "APISTATUSBIT"));
|
---|
2451 | }
|
---|
2452 | }
|
---|
2453 |
|
---|
2454 | #ifdef CS_LOGHISTORY
|
---|
2455 | for (i=(loghistidx+3) % CS_MAXLOGHIST; i!=loghistidx; i=(i+1) % CS_MAXLOGHIST) {
|
---|
2456 | char *p_usr, *p_txt;
|
---|
2457 | p_usr=(char *)(loghist+(i*CS_LOGHISTSIZE));
|
---|
2458 | p_txt=p_usr+32;
|
---|
2459 |
|
---|
2460 | if (!apicall) {
|
---|
2461 | if (p_txt[0]) tpl_printf(vars, TPLAPPEND, "LOGHISTORY", "\t\t<span class=\"%s\">%s\t\t</span><br>\n", p_usr, p_txt+8);
|
---|
2462 | } else {
|
---|
2463 | if (strcmp(getParam(params, "appendlog"), "1") == 0)
|
---|
2464 | tpl_printf(vars, TPLAPPEND, "LOGHISTORY", "%s", p_txt+8);
|
---|
2465 | }
|
---|
2466 | }
|
---|
2467 | #else
|
---|
2468 | tpl_addVar(vars, TPLADD, "LOGHISTORY", "the flag CS_LOGHISTORY is not set in your binary<BR>\n");
|
---|
2469 | #endif
|
---|
2470 |
|
---|
2471 | #ifdef WITH_DEBUG
|
---|
2472 | // Debuglevel Selector
|
---|
2473 | int32_t lvl;
|
---|
2474 | for (i = 0; i < 8; i++) {
|
---|
2475 | lvl = 1 << i;
|
---|
2476 | tpl_printf(vars, TPLADD, "TMPC", "DCLASS%d", lvl);
|
---|
2477 | tpl_printf(vars, TPLADD, "TMPV", "DEBUGVAL%d", lvl);
|
---|
2478 | if (cs_dblevel & lvl) {
|
---|
2479 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMPC"), "debugls");
|
---|
2480 | tpl_printf(vars, TPLADD, tpl_getVar(vars, "TMPV"), "%d", cs_dblevel - lvl);
|
---|
2481 | } else {
|
---|
2482 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMPC"), "debugl");
|
---|
2483 | tpl_printf(vars, TPLADD, tpl_getVar(vars, "TMPV"), "%d", cs_dblevel + lvl);
|
---|
2484 | }
|
---|
2485 | }
|
---|
2486 |
|
---|
2487 | if (cs_dblevel == 255)
|
---|
2488 | tpl_addVar(vars, TPLADD, "DCLASS255", "debugls");
|
---|
2489 | else
|
---|
2490 | tpl_addVar(vars, TPLADD, "DCLASS255", "debugl");
|
---|
2491 |
|
---|
2492 | tpl_addVar(vars, TPLADD, "NEXTPAGE", "status.html");
|
---|
2493 | tpl_addVar(vars, TPLADD, "DCLASS", "debugl"); //default
|
---|
2494 | tpl_printf(vars, TPLADD, "ACTDEBUG", "%d", cs_dblevel);
|
---|
2495 | tpl_addVar(vars, TPLADD, "SDEBUG", tpl_getTpl(vars, "DEBUGSELECT"));
|
---|
2496 | #endif
|
---|
2497 |
|
---|
2498 | if(!apicall)
|
---|
2499 | return tpl_getTpl(vars, "STATUS");
|
---|
2500 | else
|
---|
2501 | return tpl_getTpl(vars, "APISTATUS");
|
---|
2502 |
|
---|
2503 | }
|
---|
2504 |
|
---|
2505 | char *send_oscam_services_edit(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
2506 | struct s_sidtab *sidtab,*ptr;
|
---|
2507 | char label[sizeof(cfg.sidtab->label)];
|
---|
2508 | int32_t i;
|
---|
2509 |
|
---|
2510 | cs_strncpy(label, strtolower(getParam(params, "service")), sizeof(label));
|
---|
2511 |
|
---|
2512 | for (sidtab = cfg.sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
|
---|
2513 |
|
---|
2514 | if (sidtab == NULL) {
|
---|
2515 | i = 1;
|
---|
2516 | while(strlen(label) < 1) {
|
---|
2517 | snprintf(label, sizeof(label)/sizeof(char) - 1, "newservice%d", i);
|
---|
2518 | for (sidtab = cfg.sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab = sidtab->next);
|
---|
2519 | if(sidtab != NULL) label[0] = '\0';
|
---|
2520 | ++i;
|
---|
2521 | }
|
---|
2522 | if (!cs_malloc(&sidtab, sizeof(struct s_sidtab), -1)) return "0";
|
---|
2523 |
|
---|
2524 | if(cfg.sidtab == NULL) cfg.sidtab = sidtab;
|
---|
2525 | else {
|
---|
2526 | for (ptr = cfg.sidtab; ptr != NULL && ptr->next != NULL; ptr = ptr->next);
|
---|
2527 | ptr->next = sidtab;
|
---|
2528 | }
|
---|
2529 | memset(sidtab, 0, sizeof(struct s_sidtab));
|
---|
2530 | cs_strncpy((char *)sidtab->label, label, sizeof(sidtab->label));
|
---|
2531 |
|
---|
2532 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>New service has been added</b><BR>");
|
---|
2533 | if (write_services()==0) refresh_oscam(REFR_SERVICES, in);
|
---|
2534 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Writing services to disk failed!</b><BR>");
|
---|
2535 |
|
---|
2536 | for (sidtab = cfg.sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
|
---|
2537 | }
|
---|
2538 |
|
---|
2539 | if (strcmp(getParam(params, "action"), "Save") == 0) {
|
---|
2540 | for(i=0;i<(*params).paramcount;i++) {
|
---|
2541 | if ((strcmp((*params).params[i], "action")) && (strcmp((*params).params[i], "service"))) {
|
---|
2542 | chk_sidtab((*params).params[i], (*params).values[i], sidtab);
|
---|
2543 | }
|
---|
2544 | }
|
---|
2545 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Services updated</B><BR><BR>");
|
---|
2546 | if (write_services()==0) refresh_oscam(REFR_SERVICES, in);
|
---|
2547 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
2548 |
|
---|
2549 | for (sidtab = cfg.sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
|
---|
2550 | }
|
---|
2551 |
|
---|
2552 | tpl_addVar(vars, TPLADD, "LABEL", sidtab->label);
|
---|
2553 | tpl_addVar(vars, TPLADD, "LABELENC", urlencode(vars, sidtab->label));
|
---|
2554 |
|
---|
2555 |
|
---|
2556 | for (i=0; i<sidtab->num_caid; i++) {
|
---|
2557 | if (i==0) tpl_printf(vars, TPLADD, "CAIDS", "%04X", sidtab->caid[i]);
|
---|
2558 | else tpl_printf(vars, TPLAPPEND, "CAIDS", ",%04X", sidtab->caid[i]);
|
---|
2559 | }
|
---|
2560 | for (i=0; i<sidtab->num_provid; i++) {
|
---|
2561 | if (i==0) tpl_printf(vars, TPLADD, "PROVIDS", "%06lX", sidtab->provid[i]);
|
---|
2562 | else tpl_printf(vars, TPLAPPEND, "PROVIDS", ",%06lX", sidtab->provid[i]);
|
---|
2563 | }
|
---|
2564 | for (i=0; i<sidtab->num_srvid; i++) {
|
---|
2565 | if (i==0) tpl_printf(vars, TPLADD, "SRVIDS", "%04X", sidtab->srvid[i]);
|
---|
2566 | else tpl_printf(vars, TPLAPPEND, "SRVIDS", ",%04X", sidtab->srvid[i]);
|
---|
2567 | }
|
---|
2568 | return tpl_getTpl(vars, "SERVICEEDIT");
|
---|
2569 | }
|
---|
2570 |
|
---|
2571 | char *send_oscam_services(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
|
---|
2572 | struct s_sidtab *sidtab, *sidtab2;
|
---|
2573 | char *service = getParam(params, "service");
|
---|
2574 | int32_t i, found = 0;
|
---|
2575 |
|
---|
2576 | if (strcmp(getParam(params, "action"), "delete") == 0) {
|
---|
2577 | if(cfg.http_readonly) {
|
---|
2578 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry, Webif is in readonly mode. No deletion will be made!</b><BR>");
|
---|
2579 | } else {
|
---|
2580 | sidtab=cfg.sidtab;
|
---|
2581 | if(strcmp(sidtab->label, service) == 0) {
|
---|
2582 | cfg.sidtab = sidtab->next;
|
---|
2583 | free_sidtab(sidtab);
|
---|
2584 | found = 1;
|
---|
2585 | } else if (sidtab->next != NULL) {
|
---|
2586 | do {
|
---|
2587 | if(strcmp(sidtab->next->label, service) == 0) {
|
---|
2588 | sidtab2 = sidtab->next;
|
---|
2589 | sidtab->next = sidtab2->next;
|
---|
2590 | free_sidtab(sidtab2);
|
---|
2591 | found = 1;
|
---|
2592 | break;
|
---|
2593 | }
|
---|
2594 | } while ((sidtab = sidtab->next) && (sidtab->next != NULL));
|
---|
2595 | }
|
---|
2596 | if (found > 0) {
|
---|
2597 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Service has been deleted!</b><BR>");
|
---|
2598 | if (write_services() == 0) refresh_oscam(REFR_SERVICES, in);
|
---|
2599 | else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Writing services to disk failed!</b><BR>");
|
---|
2600 | } else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified service doesn't exist. No deletion will be made!</b><BR>");
|
---|
2601 | }
|
---|
2602 | }
|
---|
2603 |
|
---|
2604 | sidtab = cfg.sidtab;
|
---|
2605 | // Show List
|
---|
2606 | while(sidtab != NULL) {
|
---|
2607 | tpl_printf(vars, TPLADD, "SID","");
|
---|
2608 | if ((strcmp(getParam(params, "service"), sidtab->label) == 0) && (strcmp(getParam(params, "action"), "list") == 0) ) {
|
---|
2609 | tpl_printf(vars, TPLADD, "SIDCLASS","sidlist");
|
---|
2610 | tpl_printf(vars, TPLAPPEND, "SID", "<div style=\"float:right;background-color:red;color:white\"><A HREF=\"services.html\" style=\"color:white;text-decoration:none\">X</A></div>");
|
---|
2611 | for (i=0; i<sidtab->num_srvid; i++) {
|
---|
2612 | tpl_printf(vars, TPLAPPEND, "SID", "%04X : %s<BR>", sidtab->srvid[i], xml_encode(vars, get_servicename(sidtab->srvid[i], sidtab->caid[0])));
|
---|
2613 | }
|
---|
2614 | } else {
|
---|
2615 | tpl_printf(vars, TPLADD, "SIDCLASS","");
|
---|
2616 | tpl_printf(vars, TPLADD, "SID","<A HREF=\"services.html?service=%s&action=list\">Show Services</A>", urlencode(vars, sidtab->label));
|
---|
2617 | }
|
---|
2618 | tpl_addVar(vars, TPLADD, "LABELENC", urlencode(vars, sidtab->label));
|
---|
2619 | tpl_addVar(vars, TPLADD, "LABEL", xml_encode(vars, sidtab->label));
|
---|
2620 | tpl_addVar(vars, TPLADD, "SIDLIST", tpl_getTpl(vars, "SERVICECONFIGSIDBIT"));
|
---|
2621 |
|
---|
2622 | tpl_addVar(vars, TPLAPPEND, "SERVICETABS", tpl_getTpl(vars, "SERVICECONFIGLISTBIT"));
|
---|
2623 | sidtab=sidtab->next;
|
---|
2624 | }
|
---|
2625 | return tpl_getTpl(vars, "SERVICECONFIGLIST");
|
---|
2626 | }
|
---|
2627 |
|
---|
2628 | char *send_oscam_savetpls(struct templatevars *vars) {
|
---|
2629 | if(strlen(cfg.http_tpl) > 0) {
|
---|
2630 | tpl_printf(vars, TPLADD, "CNT", "%d", tpl_saveIncludedTpls(cfg.http_tpl));
|
---|
2631 | tpl_addVar(vars, TPLADD, "PATH", cfg.http_tpl);
|
---|
2632 | } else tpl_addVar(vars, TPLADD, "CNT", "0");
|
---|
2633 | return tpl_getTpl(vars, "SAVETEMPLATES");
|
---|
2634 | }
|
---|
2635 |
|
---|
2636 | char *send_oscam_shutdown(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in, int32_t apicall) {
|
---|
2637 | if (strcmp(strtolower(getParam(params, "action")), "shutdown") == 0) {
|
---|
2638 | if(!apicall){
|
---|
2639 | tpl_addVar(vars, TPLADD, "STYLESHEET", CSS);
|
---|
2640 | tpl_printf(vars, TPLADD, "REFRESHTIME", "%d", SHUTDOWNREFRESH);
|
---|
2641 | tpl_addVar(vars, TPLADD, "REFRESHURL", "status.html");
|
---|
2642 | tpl_addVar(vars, TPLADD, "REFRESH", tpl_getTpl(vars, "REFRESH"));
|
---|
2643 | tpl_printf(vars, TPLADD, "SECONDS", "%d", SHUTDOWNREFRESH);
|
---|
2644 | send_headers(f, 200, "OK", NULL, "text/html", 0);
|
---|
2645 | webif_write(tpl_getTpl(vars, "SHUTDOWN"), f);
|
---|
2646 | cs_log("Shutdown requested by WebIF from %s", inet_ntoa(in));
|
---|
2647 | } else {
|
---|
2648 | tpl_addVar(vars, TPLADD, "APICONFIRMMESSAGE", "shutdown");
|
---|
2649 | cs_log("Shutdown requested by XMLApi from %s", inet_ntoa(in));
|
---|
2650 | }
|
---|
2651 | running = 0;
|
---|
2652 | cs_exit_oscam();
|
---|
2653 |
|
---|
2654 | if(!apicall)
|
---|
2655 | return "1";
|
---|
2656 | else
|
---|
2657 | return tpl_getTpl(vars, "APICONFIRMATION");
|
---|
2658 |
|
---|
2659 | }
|
---|
2660 | else if (strcmp(strtolower(getParam(params, "action")), "restart") == 0) {
|
---|
2661 | if(!apicall){
|
---|
2662 | tpl_addVar(vars, TPLADD, "STYLESHEET", CSS);
|
---|
2663 | tpl_printf(vars, TPLADD, "REFRESHTIME", "%d", 2);
|
---|
2664 | tpl_addVar(vars, TPLADD, "REFRESHURL", "status.html");
|
---|
2665 | tpl_addVar(vars, TPLADD, "REFRESH", tpl_getTpl(vars, "REFRESH"));
|
---|
2666 | tpl_printf(vars, TPLADD, "SECONDS", "%d", 2);
|
---|
2667 | send_headers(f, 200, "OK", NULL, "text/html", 0);
|
---|
2668 | webif_write(tpl_getTpl(vars, "SHUTDOWN"), f);
|
---|
2669 | cs_log("Restart requested by WebIF from %s", inet_ntoa(in));
|
---|
2670 | } else {
|
---|
2671 | tpl_addVar(vars, TPLADD, "APICONFIRMMESSAGE", "restart");
|
---|
2672 | cs_log("Restart requested by XMLApi from %s", inet_ntoa(in));
|
---|
2673 | }
|
---|
2674 | running = 0;
|
---|
2675 | cs_restart_oscam();
|
---|
2676 |
|
---|
2677 | if(!apicall)
|
---|
2678 | return "1";
|
---|
2679 | else
|
---|
2680 | return tpl_getTpl(vars, "APICONFIRMATION");
|
---|
2681 |
|
---|
2682 | } else {
|
---|
2683 | return tpl_getTpl(vars, "PRESHUTDOWN");
|
---|
2684 | }
|
---|
2685 | }
|
---|
2686 |
|
---|
2687 | char *send_oscam_script(struct templatevars *vars) {
|
---|
2688 |
|
---|
2689 | char *result = "not found";
|
---|
2690 | int32_t rc = 0;
|
---|
2691 | if(!cfg.http_readonly) {
|
---|
2692 | if(cfg.http_script[0]) {
|
---|
2693 | tpl_addVar(vars, TPLADD, "SCRIPTNAME",cfg.http_script);
|
---|
2694 | rc = system(cfg.http_script);
|
---|
2695 | if(rc == -1) {
|
---|
2696 | result = "done";
|
---|
2697 | } else {
|
---|
2698 | result = "failed";
|
---|
2699 | }
|
---|
2700 | } else {
|
---|
2701 | tpl_addVar(vars, TPLADD, "SCRIPTNAME", "no script defined");
|
---|
2702 | }
|
---|
2703 | tpl_addVar(vars, TPLADD, "SCRIPTRESULT", result);
|
---|
2704 | tpl_printf(vars, TPLADD, "CODE", "%d", rc);
|
---|
2705 | } else {
|
---|
2706 | tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry, Webif is in readonly mode. No script execution possible!</b><BR>");
|
---|
2707 | }
|
---|
2708 | return tpl_getTpl(vars, "SCRIPT");
|
---|
2709 |
|
---|
2710 | }
|
---|
2711 |
|
---|
2712 | char *send_oscam_scanusb(struct templatevars *vars) {
|
---|
2713 |
|
---|
2714 | #ifndef OS_CYGWIN32
|
---|
2715 | FILE *fp;
|
---|
2716 | int32_t err=0;
|
---|
2717 | char path[1035];
|
---|
2718 |
|
---|
2719 | fp = popen("lsusb -v | egrep '^Bus|^ *iSerial|^ *iProduct'", "r");
|
---|
2720 | if (fp == NULL) {
|
---|
2721 | tpl_addVar(vars, TPLADD, "USBENTRY", "Failed to run lusb");
|
---|
2722 | tpl_printf(vars, TPLADD, "USBENTRY", "%s", path);
|
---|
2723 | tpl_addVar(vars, TPLAPPEND, "USBBIT", tpl_getTpl(vars, "SCANUSBBIT"));
|
---|
2724 | err = 1;
|
---|
2725 | }
|
---|
2726 |
|
---|
2727 | if(!err) {
|
---|
2728 | while (fgets(path, sizeof(path)-1, fp) != NULL) {
|
---|
2729 | tpl_addVar(vars, TPLADD, "USBENTRYCLASS", "");
|
---|
2730 | if (strstr(path,"Bus ")) {
|
---|
2731 | tpl_printf(vars, TPLADD, "USBENTRY", "%s", path);
|
---|
2732 | tpl_addVar(vars, TPLADD, "USBENTRYCLASS", "CLASS=\"scanusbsubhead\"");
|
---|
2733 | } else {
|
---|
2734 | tpl_printf(vars, TPLADD, "USBENTRY", " %s", path);
|
---|
2735 | }
|
---|
2736 | tpl_addVar(vars, TPLAPPEND, "USBBIT", tpl_getTpl(vars, "SCANUSBBIT"));
|
---|
2737 | }
|
---|
2738 | }
|
---|
2739 | pclose(fp);
|
---|
2740 | #else
|
---|
2741 | tpl_addVar(vars, TPLADD, "MESSAGE", "Function not supported in CYGWIN environment");
|
---|
2742 | #endif
|
---|
2743 | return tpl_getTpl(vars, "SCANUSB");
|
---|
2744 | }
|
---|
2745 |
|
---|
2746 | char *send_oscam_files(struct templatevars *vars, struct uriparams *params) {
|
---|
2747 |
|
---|
2748 | int32_t writable=0;
|
---|
2749 |
|
---|
2750 | char *stoplog = getParam(params, "stoplog");
|
---|
2751 | if(strlen(stoplog) > 0)
|
---|
2752 | cfg.disablelog = atoi(stoplog);
|
---|
2753 |
|
---|
2754 | char *stopusrlog = getParam(params, "stopusrlog");
|
---|
2755 | if(strlen(stopusrlog) > 0)
|
---|
2756 | cfg.disableuserfile = atoi(stopusrlog);
|
---|
2757 |
|
---|
2758 | char *debuglvl = getParam(params, "debug");
|
---|
2759 | if(strlen(debuglvl) > 0) {
|
---|
2760 | #ifndef WITH_DEBUG
|
---|
2761 | cs_log("*** Warning: Debug Support not compiled in ***");
|
---|
2762 | #else
|
---|
2763 | int32_t dblvl = atoi(debuglvl);
|
---|
2764 | if(dblvl >= 0 && dblvl <= 255) cs_dblevel = dblvl;
|
---|
2765 | cs_log("%s debug_level=%d", "all", cs_dblevel);
|
---|
2766 | #endif
|
---|
2767 | }
|
---|
2768 |
|
---|
2769 | char targetfile[256];
|
---|
2770 |
|
---|
2771 | if (strcmp(getParam(params, "part"), "conf") == 0) {
|
---|
2772 | snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.conf");
|
---|
2773 | writable = 1;
|
---|
2774 | }
|
---|
2775 | else if (strcmp(getParam(params, "part"), "version") == 0)
|
---|
2776 | snprintf(targetfile, 255,"%s%s", get_tmp_dir(), "/oscam.version");
|
---|
2777 | else if (strcmp(getParam(params, "part"), "user") == 0) {
|
---|
2778 | snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.user");
|
---|
2779 | writable = 1;
|
---|
2780 | }
|
---|
2781 | else if (strcmp(getParam(params, "part"), "server") == 0) {
|
---|
2782 | snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.server");
|
---|
2783 | writable = 1;
|
---|
2784 | }
|
---|
2785 | else if (strcmp(getParam(params, "part"), "services") == 0) {
|
---|
2786 | snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.services");
|
---|
2787 | writable = 1;
|
---|
2788 | }
|
---|
2789 | else if (strcmp(getParam(params, "part"), "srvid") == 0) {
|
---|
2790 | snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.srvid");
|
---|
2791 | writable = 1;
|
---|
2792 | }
|
---|
2793 | else if (strcmp(getParam(params, "part"), "provid") == 0) {
|
---|
2794 | snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.provid");
|
---|
2795 | writable = 1;
|
---|
2796 | }
|
---|
2797 | else if (strcmp(getParam(params, "part"), "tiers") == 0) {
|
---|
2798 | snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.tiers");
|
---|
2799 | writable = 1;
|
---|
2800 | }
|
---|
2801 | else if (strcmp(getParam(params, "part"), "logfile") == 0) {
|
---|
2802 | snprintf(targetfile, 255,"%s", cfg.logfile);
|
---|
2803 |
|
---|
2804 | if (strcmp(getParam(params, "clear"), "logfile") == 0) {
|
---|
2805 | if(strlen(targetfile) > 0) {
|
---|
2806 | FILE *file = fopen(targetfile,"w");
|
---|
2807 | fclose(file);
|
---|
2808 | }
|
---|
2809 | }
|
---|
2810 |
|
---|
2811 | #ifdef WITH_DEBUG
|
---|
2812 | // Debuglevel Selector
|
---|
2813 | int32_t i, lvl;
|
---|
2814 | for (i = 0; i < 8; i++) {
|
---|
2815 | lvl = 1 << i;
|
---|
2816 | tpl_printf(vars, TPLADD, "TMPC", "DCLASS%d", lvl);
|
---|
2817 | tpl_printf(vars, TPLADD, "TMPV", "DEBUGVAL%d", lvl);
|
---|
2818 | if (cs_dblevel & lvl) {
|
---|
2819 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMPC"), "debugls");
|
---|
2820 | tpl_printf(vars, TPLADD, tpl_getVar(vars, "TMPV"), "%d", cs_dblevel - lvl);
|
---|
2821 | } else {
|
---|
2822 | tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMPC"), "debugl");
|
---|
2823 | tpl_printf(vars, TPLADD, tpl_getVar(vars, "TMPV"), "%d", cs_dblevel + lvl);
|
---|
2824 | }
|
---|
2825 | }
|
---|
2826 |
|
---|
2827 | if (cs_dblevel == 255)
|
---|
2828 | tpl_addVar(vars, TPLADD, "DCLASS255", "debugls");
|
---|
2829 | else
|
---|
2830 | tpl_addVar(vars, TPLADD, "DCLASS255", "debugl");
|
---|
2831 |
|
---|
2832 | tpl_addVar(vars, TPLADD, "CUSTOMPARAM", "&part=logfile");
|
---|
2833 | tpl_printf(vars, TPLADD, "ACTDEBUG", "%d", cs_dblevel);
|
---|
2834 | tpl_addVar(vars, TPLADD, "SDEBUG", tpl_getTpl(vars, "DEBUGSELECT"));
|
---|
2835 | tpl_addVar(vars, TPLADD, "NEXTPAGE", "files.html");
|
---|
2836 | #endif
|
---|
2837 |
|
---|
2838 | if(!cfg.disablelog)
|
---|
2839 | tpl_printf(vars, TPLADD, "SLOG", "<BR><A CLASS=\"debugl\" HREF=\"files.html?part=logfile&stoplog=%d\">%s</A><SPAN CLASS=\"debugt\"> | </SPAN>\n", 1, "Stop Log");
|
---|
2840 | else
|
---|
2841 | tpl_printf(vars, TPLADD, "SLOG", "<BR><A CLASS=\"debugl\" HREF=\"files.html?part=logfile&stoplog=%d\">%s</A><SPAN CLASS=\"debugt\"> | </SPAN>\n", 0, "Start Log");
|
---|
2842 |
|
---|
2843 | tpl_printf(vars, TPLADD, "SCLEAR", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&clear=logfile\">%s</A><BR><BR>\n", "Clear Log");
|
---|
2844 | }
|
---|
2845 | else if (strcmp(getParam(params, "part"), "userfile") == 0) {
|
---|
2846 | snprintf(targetfile, 255,"%s", cfg.usrfile);
|
---|
2847 | if (strcmp(getParam(params, "clear"), "usrfile") == 0) {
|
---|
2848 | if(strlen(targetfile) > 0) {
|
---|
2849 | FILE *file = fopen(targetfile,"w");
|
---|
2850 | fclose(file);
|
---|
2851 | }
|
---|
2852 | }
|
---|
2853 |
|
---|
2854 | if(!cfg.disableuserfile)
|
---|
2855 | tpl_printf(vars, TPLADD, "SLOG", "<A HREF=\"files.html?part=userfile&stopusrlog=%d\">%s</A> | \n", 1, "Stop Log");
|
---|
2856 | else
|
---|
2857 | tpl_printf(vars, TPLADD, "SLOG", "<A HREF=\"files.html?part=userfile&stopusrlog=%d\">%s</A> | \n", 0, "Start Log");
|
---|
2858 |
|
---|
2859 | tpl_printf(vars, TPLADD, "SCLEAR", "<A HREF=\"files.html?part=userfile&clear=usrfile\">%s</A><BR><BR>\n", "Clear Log");
|
---|
2860 | tpl_addVar(vars, TPLADD, "FILTER", "<FORM ACTION=\"files.html\" method=\"get\">\n");
|
---|
2861 | tpl_addVar(vars, TPLAPPEND, "FILTER", "<INPUT name=\"part\" type=\"hidden\" value=\"userfile\">\n");
|
---|
2862 | tpl_addVar(vars, TPLAPPEND, "FILTER", "<SELECT name=\"filter\">\n");
|
---|
2863 | tpl_printf(vars, TPLAPPEND, "FILTER", "<OPTION value=\"%s\">%s</OPTION>\n", "all", "all");
|
---|
2864 |
|
---|
2865 | struct s_auth *account;
|
---|
2866 | for (account = cfg.account; (account); account = account->next) {
|
---|
2867 | tpl_printf(vars, TPLAPPEND, "FILTER", "<OPTION value=\"%s\" %s>%s</OPTION>\n", account->usr, strcmp(getParam(params, "filter"), account->usr) ? "":"selected", account->usr);
|
---|
2868 | }
|
---|
2869 | tpl_addVar(vars, TPLAPPEND, "FILTER", "</SELECT><input type=\"submit\" name=\"action\" value=\"Filter\" title=\"Filter for a specific user\"></FORM>\n");
|
---|
2870 |
|
---|
2871 | }
|
---|
2872 | #ifdef CS_ANTICASC
|
---|
2873 | else if (strcmp(getParam(params, "part"), "anticasc") == 0)
|
---|
2874 | snprintf(targetfile, 255,"%s", cfg.ac_logfile);
|
---|
2875 | #endif
|
---|
2876 |
|
---|
2877 | #ifdef HAVE_DVBAPI
|
---|
2878 | else if (strcmp(getParam(params, "part"), "dvbapi") == 0) {
|
---|
2879 | snprintf(targetfile, 255, "%s%s", cs_confdir, "oscam.dvbapi");
|
---|
2880 | writable = 1;
|
---|
2881 | }
|
---|
2882 | #endif
|
---|
2883 |
|
---|
2884 |
|
---|
2885 | if (!strstr(targetfile, "/dev/")) {
|
---|
2886 |
|
---|
2887 | if (strcmp(getParam(params, "action"), "Save") == 0) {
|
---|
2888 | if((strlen(targetfile) > 0) /*&& (file_exists(targetfile) == 1)*/) {
|
---|
2889 | FILE *fpsave;
|
---|
2890 | char *fcontent = getParam(params, "filecontent");
|
---|
2891 |
|
---|
2892 | if((fpsave = fopen(targetfile,"w"))){
|
---|
2893 | fprintf(fpsave,"%s",fcontent);
|
---|
2894 | fclose(fpsave);
|
---|
2895 |
|
---|
2896 | if (strcmp(getParam(params, "part"), "srvid") == 0)
|
---|
2897 | init_srvid();
|
---|
2898 |
|
---|
2899 | if (strcmp(getParam(params, "part"), "user") == 0)
|
---|
2900 | cs_accounts_chk();
|
---|
2901 |
|
---|
2902 | #ifdef HAVE_DVBAPI
|
---|
2903 | if (strcmp(getParam(params, "part"), "dvbapi") == 0)
|
---|
2904 | dvbapi_read_priority();
|
---|
2905 | #endif
|
---|
2906 | }
|
---|
2907 | }
|
---|
2908 | }
|
---|
2909 |
|
---|
2910 | if((strlen(targetfile) > 0) && (file_exists(targetfile) == 1)) {
|
---|
2911 | FILE *fp;
|
---|
2912 | char buffer[256];
|
---|
2913 |
|
---|
2914 | if((fp = fopen(targetfile,"r")) == NULL) return "0";
|
---|
2915 | while (fgets(buffer, sizeof(buffer), fp) != NULL)
|
---|
2916 | if (!strcmp(getParam(params, "filter"), "all"))
|
---|
2917 | tpl_printf(vars, TPLAPPEND, "FILECONTENT", "%s", buffer);
|
---|
2918 | else
|
---|
2919 | if(strstr(buffer,getParam(params, "filter")))
|
---|
2920 | tpl_printf(vars, TPLAPPEND, "FILECONTENT", "%s", buffer);
|
---|
2921 | fclose (fp);
|
---|
2922 | } else {
|
---|
2923 | tpl_addVar(vars, TPLAPPEND, "FILECONTENT", "File does not exist or no file selected!");
|
---|
2924 | }
|
---|
2925 | } else {
|
---|
2926 | tpl_addVar(vars, TPLAPPEND, "FILECONTENT", "File not valid!");
|
---|
2927 | }
|
---|
2928 |
|
---|
2929 | tpl_addVar(vars, TPLADD, "PART", getParam(params, "part"));
|
---|
2930 |
|
---|
2931 | if (!writable) {
|
---|
2932 | tpl_addVar(vars, TPLADD, "WRITEPROTECTION", "You cannot change the content of this file!");
|
---|
2933 | tpl_addVar(vars, TPLADD, "BTNDISABLED", "DISABLED");
|
---|
2934 | }
|
---|
2935 |
|
---|
2936 | return tpl_getTpl(vars, "FILE");
|
---|
2937 | }
|
---|
2938 |
|
---|
2939 | char *send_oscam_failban(struct templatevars *vars, struct uriparams *params) {
|
---|
2940 |
|
---|
2941 | uint32_t ip2delete = 0;
|
---|
2942 | LL_ITER *itr = ll_iter_create(cfg.v_list);
|
---|
2943 | V_BAN *v_ban_entry;
|
---|
2944 |
|
---|
2945 | if (strcmp(getParam(params, "action"), "delete") == 0) {
|
---|
2946 |
|
---|
2947 | if(strcmp(getParam(params, "intip"), "all") == 0){
|
---|
2948 | // clear whole list
|
---|
2949 | while ((v_ban_entry=ll_iter_next(itr))) {
|
---|
2950 | ll_iter_remove_data(itr);
|
---|
2951 | }
|
---|
2952 |
|
---|
2953 | } else {
|
---|
2954 | //we have a single IP
|
---|
2955 | sscanf(getParam(params, "intip"), "%u", &ip2delete);
|
---|
2956 | while ((v_ban_entry=ll_iter_next(itr))) {
|
---|
2957 | if (v_ban_entry->v_ip == ip2delete) {
|
---|
2958 | ll_iter_remove_data(itr);
|
---|
2959 | break;
|
---|
2960 | }
|
---|
2961 | }
|
---|
2962 | }
|
---|
2963 | }
|
---|
2964 | ll_iter_reset(itr);
|
---|
2965 |
|
---|
2966 | time_t now = time((time_t)0);
|
---|
2967 |
|
---|
2968 | while ((v_ban_entry=ll_iter_next(itr))) {
|
---|
2969 |
|
---|
2970 | tpl_printf(vars, TPLADD, "IPADDRESS", "%s", cs_inet_ntoa(v_ban_entry->v_ip));
|
---|
2971 |
|
---|
2972 | struct tm st ;
|
---|
2973 | localtime_r(&v_ban_entry->v_time, &st);
|
---|
2974 |
|
---|
2975 | tpl_printf(vars, TPLADD, "VIOLATIONDATE", "%02d.%02d.%02d %02d:%02d:%02d",
|
---|
2976 | st.tm_mday, st.tm_mon+1,
|
---|
2977 | st.tm_year%100, st.tm_hour,
|
---|
2978 | st.tm_min, st.tm_sec);
|
---|
2979 |
|
---|
2980 | tpl_printf(vars, TPLADD, "VIOLATIONCOUNT", "%d", v_ban_entry->v_count);
|
---|
2981 | tpl_addVar(vars, TPLADD, "LEFTTIME", sec2timeformat(vars, (cfg.failbantime * 60) - (now - v_ban_entry->v_time)));
|
---|
2982 | tpl_printf(vars, TPLADD, "INTIP", "%u", v_ban_entry->v_ip);
|
---|
2983 | tpl_addVar(vars, TPLAPPEND, "FAILBANROW", tpl_getTpl(vars, "FAILBANBIT"));
|
---|
2984 | }
|
---|
2985 | ll_iter_release(itr);
|
---|
2986 |
|
---|
2987 | return tpl_getTpl(vars, "FAILBAN");
|
---|
2988 | }
|
---|
2989 |
|
---|
2990 | char *send_oscam_api(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
2991 | if (strcmp(getParam(params, "part"), "status") == 0) {
|
---|
2992 | return send_oscam_status(vars, params, in, 1);
|
---|
2993 | }
|
---|
2994 | else if (strcmp(getParam(params, "part"), "userstats") == 0) {
|
---|
2995 | return send_oscam_user_config(vars, params, in, 1);
|
---|
2996 | }
|
---|
2997 | else if (strcmp(getParam(params, "part"), "entitlement") == 0) {
|
---|
2998 |
|
---|
2999 | if (strcmp(getParam(params, "label"),"")) {
|
---|
3000 | struct s_reader *rdr = get_reader_by_label(getParam(params, "label"));
|
---|
3001 | if (rdr) {
|
---|
3002 | if (rdr->typ == R_CCCAM && rdr->enable == 1) {
|
---|
3003 | return send_oscam_entitlement(vars, params, in, 1);
|
---|
3004 | } else {
|
---|
3005 | //Send Errormessage
|
---|
3006 | tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "no cccam reader or disabled");
|
---|
3007 | return tpl_getTpl(vars, "APIERROR");
|
---|
3008 | }
|
---|
3009 | } else {
|
---|
3010 | //Send Errormessage
|
---|
3011 | tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "reader not exist");
|
---|
3012 | return tpl_getTpl(vars, "APIERROR");
|
---|
3013 | }
|
---|
3014 | } else {
|
---|
3015 | //Send Errormessage
|
---|
3016 | tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "no reader selected");
|
---|
3017 | return tpl_getTpl(vars, "APIERROR");
|
---|
3018 | }
|
---|
3019 | }
|
---|
3020 | else if (strcmp(getParam(params, "part"), "readerstats") == 0) {
|
---|
3021 | if (strcmp(getParam(params, "label"),"")) {
|
---|
3022 | struct s_reader *rdr = get_reader_by_label(getParam(params, "label"));
|
---|
3023 | if (rdr) {
|
---|
3024 | return send_oscam_reader_stats(vars, params, in, 1);
|
---|
3025 | } else {
|
---|
3026 | //Send Errormessage
|
---|
3027 | tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "reader not exist");
|
---|
3028 | return tpl_getTpl(vars, "APIERROR");
|
---|
3029 | }
|
---|
3030 | } else {
|
---|
3031 | //Send Errormessage
|
---|
3032 | tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "no reader selected");
|
---|
3033 | return tpl_getTpl(vars, "APIERROR");
|
---|
3034 | }
|
---|
3035 | } else if (strcmp(getParam(params, "part"), "shutdown") == 0) {
|
---|
3036 | if ((strcmp(strtolower(getParam(params, "action")), "restart") == 0) ||
|
---|
3037 | (strcmp(strtolower(getParam(params, "action")), "shutdown") == 0)){
|
---|
3038 | if(!cfg.http_readonly) {
|
---|
3039 | return send_oscam_shutdown(vars, f, params, in, 1);
|
---|
3040 | } else {
|
---|
3041 | tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "webif readonly mode");
|
---|
3042 | return tpl_getTpl(vars, "APIERROR");
|
---|
3043 | }
|
---|
3044 | } else {
|
---|
3045 | tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "missing parameter action");
|
---|
3046 | return tpl_getTpl(vars, "APIERROR");
|
---|
3047 | }
|
---|
3048 |
|
---|
3049 | }
|
---|
3050 | else {
|
---|
3051 | tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "part not found");
|
---|
3052 | return tpl_getTpl(vars, "APIERROR");
|
---|
3053 | }
|
---|
3054 | }
|
---|
3055 |
|
---|
3056 | char *send_oscam_image(struct templatevars *vars, FILE *f, struct uriparams *params, char *image) {
|
---|
3057 | char *wanted;
|
---|
3058 | if(image == NULL) wanted = getParam(params, "i");
|
---|
3059 | else wanted = image;
|
---|
3060 | if(strlen(wanted) > 3 && wanted[0] == 'I' && wanted[1] == 'C'){
|
---|
3061 | char *header = strstr(tpl_getTpl(vars, wanted), "data:");
|
---|
3062 | if(header != NULL){
|
---|
3063 | char *ptr = header + 5;
|
---|
3064 | while (ptr[0] != ';' && ptr[0] != '\0') ++ptr;
|
---|
3065 | if(ptr[0] != '\0' && ptr[1] != '\0') ptr[0] = '\0';
|
---|
3066 | else return "0";
|
---|
3067 | ptr = strstr(ptr + 1, "base64,");
|
---|
3068 | if(ptr != NULL){
|
---|
3069 | int32_t len = b64decode((uchar *)ptr + 7);
|
---|
3070 | if(len > 0){
|
---|
3071 | send_headers(f, 200, "OK", NULL, header + 5, 1);
|
---|
3072 | webif_write_raw(ptr + 7, f, len);
|
---|
3073 | return "1";
|
---|
3074 | }
|
---|
3075 | }
|
---|
3076 | }
|
---|
3077 | }
|
---|
3078 | return "0";
|
---|
3079 | }
|
---|
3080 |
|
---|
3081 | void webif_parse_request(struct uriparams *params, char *pch) {
|
---|
3082 | /* Parse url parameters; parsemode = 1 means parsing next param, parsemode = -1 parsing next
|
---|
3083 | value; pch2 points to the beginning of the currently parsed string, pch is the current position */
|
---|
3084 |
|
---|
3085 | char *pch2;
|
---|
3086 | int32_t parsemode = 1;
|
---|
3087 |
|
---|
3088 | pch2=pch;
|
---|
3089 | while(pch[0] != '\0') {
|
---|
3090 | if((parsemode == 1 && pch[0] == '=') || (parsemode == -1 && pch[0] == '&')) {
|
---|
3091 | pch[0] = '\0';
|
---|
3092 | urldecode(pch2);
|
---|
3093 | if(parsemode == 1) {
|
---|
3094 | if(params->paramcount >= MAXGETPARAMS) break;
|
---|
3095 | ++params->paramcount;
|
---|
3096 | params->params[params->paramcount-1] = pch2;
|
---|
3097 | } else {
|
---|
3098 | params->values[params->paramcount-1] = pch2;
|
---|
3099 | }
|
---|
3100 | parsemode = -parsemode;
|
---|
3101 | pch2 = pch + 1;
|
---|
3102 | }
|
---|
3103 | ++pch;
|
---|
3104 | }
|
---|
3105 | /* last value wasn't processed in the loop yet... */
|
---|
3106 | if(parsemode == -1 && params->paramcount <= MAXGETPARAMS) {
|
---|
3107 | urldecode(pch2);
|
---|
3108 | params->values[params->paramcount-1] = pch2;
|
---|
3109 | }
|
---|
3110 | }
|
---|
3111 |
|
---|
3112 | int32_t process_request(FILE *f, struct in_addr in) {
|
---|
3113 |
|
---|
3114 | cur_client()->last = time((time_t)0); //reset last busy time
|
---|
3115 |
|
---|
3116 | int32_t ok=0,v=cv();
|
---|
3117 | in_addr_t addr = in.s_addr;
|
---|
3118 |
|
---|
3119 | ok = check_ip(cfg.http_allowed, in.s_addr) ? v : 0;
|
---|
3120 |
|
---|
3121 | if (!ok && cfg.http_dyndns[0]) {
|
---|
3122 | cs_debug_mask(D_TRACE, "WebIf: IP not found in allowed range - test dyndns");
|
---|
3123 |
|
---|
3124 | if(cfg.http_dynip && cfg.http_dynip == addr) {
|
---|
3125 | ok = v;
|
---|
3126 | cs_debug_mask(D_TRACE, "WebIf: dyndns address previously resolved and ok");
|
---|
3127 |
|
---|
3128 | } else {
|
---|
3129 |
|
---|
3130 | if (cfg.resolve_gethostbyname) {
|
---|
3131 | cs_debug_mask(D_TRACE, "WebIf: try resolving IP with 'gethostbyname'");
|
---|
3132 | pthread_mutex_lock(&gethostbyname_lock);
|
---|
3133 | struct hostent *rht;
|
---|
3134 | struct sockaddr_in udp_sa;
|
---|
3135 |
|
---|
3136 | rht = gethostbyname((const char *) cfg.http_dyndns);
|
---|
3137 | if (rht) {
|
---|
3138 | memcpy(&udp_sa.sin_addr, rht->h_addr, sizeof(udp_sa.sin_addr));
|
---|
3139 | cfg.http_dynip = udp_sa.sin_addr.s_addr;
|
---|
3140 | cs_debug_mask(D_TRACE, "WebIf: dynip resolved %s access from %s",
|
---|
3141 | cs_inet_ntoa(cfg.http_dynip),
|
---|
3142 | cs_inet_ntoa(addr));
|
---|
3143 | if (cfg.http_dynip == addr)
|
---|
3144 | ok = v;
|
---|
3145 | } else {
|
---|
3146 | cs_log("can't resolve %s", cfg.http_dyndns); }
|
---|
3147 | pthread_mutex_unlock(&gethostbyname_lock);
|
---|
3148 |
|
---|
3149 | } else {
|
---|
3150 | cs_debug_mask(D_TRACE, "WebIf: try resolving IP with 'getaddrinfo'");
|
---|
3151 | struct addrinfo hints, *res = NULL;
|
---|
3152 | memset(&hints, 0, sizeof(hints));
|
---|
3153 | hints.ai_socktype = SOCK_STREAM;
|
---|
3154 | hints.ai_family = AF_INET;
|
---|
3155 | hints.ai_protocol = IPPROTO_TCP;
|
---|
3156 |
|
---|
3157 | int32_t err = getaddrinfo((const char*)cfg.http_dyndns, NULL, &hints, &res);
|
---|
3158 | if (err != 0 || !res || !res->ai_addr) {
|
---|
3159 | cs_log("can't resolve %s, error: %s", cfg.http_dyndns, err ? gai_strerror(err) : "unknown");
|
---|
3160 | }
|
---|
3161 | else {
|
---|
3162 | cfg.http_dynip = ((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr;
|
---|
3163 | cs_debug_mask(D_TRACE, "WebIf: dynip resolved %s access from %s",
|
---|
3164 | cs_inet_ntoa(cfg.http_dynip),
|
---|
3165 | cs_inet_ntoa(addr));
|
---|
3166 | if (cfg.http_dynip == addr)
|
---|
3167 | ok = v;
|
---|
3168 | }
|
---|
3169 | if (res) freeaddrinfo(res);
|
---|
3170 |
|
---|
3171 | }
|
---|
3172 | }
|
---|
3173 | } else {
|
---|
3174 | if (cfg.http_dyndns[0])
|
---|
3175 | cs_debug_mask(D_TRACE, "WebIf: IP found in allowed range - bypass dyndns");
|
---|
3176 | }
|
---|
3177 |
|
---|
3178 | if (!ok) {
|
---|
3179 | send_error(f, 403, "Forbidden", NULL, "Access denied.");
|
---|
3180 | cs_log("unauthorized access from %s flag %d", inet_ntoa(in), v);
|
---|
3181 | return 0;
|
---|
3182 | }
|
---|
3183 |
|
---|
3184 | int32_t authok = 0;
|
---|
3185 | char expectednonce[(MD5_DIGEST_LENGTH * 2) + 1];
|
---|
3186 |
|
---|
3187 | char *method, *path, *protocol;
|
---|
3188 | char *pch, *tmp;
|
---|
3189 | /* List of possible pages */
|
---|
3190 | char *pages[]= {
|
---|
3191 | "/config.html",
|
---|
3192 | "/readers.html",
|
---|
3193 | "/entitlements.html",
|
---|
3194 | "/status.html",
|
---|
3195 | "/userconfig.html",
|
---|
3196 | "/readerconfig.html",
|
---|
3197 | "/services.html",
|
---|
3198 | "/user_edit.html",
|
---|
3199 | "/site.css",
|
---|
3200 | "/services_edit.html",
|
---|
3201 | "/savetemplates.html",
|
---|
3202 | "/shutdown.html",
|
---|
3203 | "/script.html",
|
---|
3204 | "/scanusb.html",
|
---|
3205 | "/files.html",
|
---|
3206 | "/readerstats.html",
|
---|
3207 | "/failban.html",
|
---|
3208 | "/oscam.js",
|
---|
3209 | "/oscamapi.html",
|
---|
3210 | "/image",
|
---|
3211 | "/favicon.ico"};
|
---|
3212 |
|
---|
3213 | int32_t pagescnt = sizeof(pages)/sizeof(char *); // Calculate the amount of items in array
|
---|
3214 |
|
---|
3215 | int32_t pgidx = -1;
|
---|
3216 | int32_t i;
|
---|
3217 | struct uriparams params;
|
---|
3218 | params.paramcount = 0;
|
---|
3219 |
|
---|
3220 | /* First line always includes the GET/POST request */
|
---|
3221 | char *saveptr1=NULL;
|
---|
3222 | int32_t n, bufsize=0;
|
---|
3223 | char *filebuf = NULL;
|
---|
3224 | char buf2[1024];
|
---|
3225 | struct pollfd pfd2[1];
|
---|
3226 |
|
---|
3227 | while (1) {
|
---|
3228 | if ((n=webif_read(buf2, sizeof(buf2), f)) <= 0) {
|
---|
3229 | cs_debug_mask(D_CLIENT, "webif read error %d", n);
|
---|
3230 | #ifdef WITH_SSL
|
---|
3231 | if (cfg.http_use_ssl)
|
---|
3232 | ERR_print_errors_fp(stderr);
|
---|
3233 | #endif
|
---|
3234 | return -1;
|
---|
3235 | }
|
---|
3236 | if(!cs_realloc(&filebuf, bufsize+n+1, -1)){
|
---|
3237 | send_error500(f);
|
---|
3238 | return -1;
|
---|
3239 | }
|
---|
3240 |
|
---|
3241 | memcpy(filebuf+bufsize, buf2, n);
|
---|
3242 | bufsize+=n;
|
---|
3243 |
|
---|
3244 | //max request size 100kb
|
---|
3245 | if (bufsize>102400) {
|
---|
3246 | cs_log("error: too much data received from %s", inet_ntoa(in));
|
---|
3247 | free(filebuf);
|
---|
3248 | return -1;
|
---|
3249 | }
|
---|
3250 |
|
---|
3251 | #ifdef WITH_SSL
|
---|
3252 | if (cfg.http_use_ssl) {
|
---|
3253 | int32_t len = 0;
|
---|
3254 | len = SSL_pending((SSL*)f);
|
---|
3255 |
|
---|
3256 | if (len>0)
|
---|
3257 | continue;
|
---|
3258 |
|
---|
3259 | pfd2[0].fd = SSL_get_fd((SSL*)f);
|
---|
3260 |
|
---|
3261 | } else
|
---|
3262 | #endif
|
---|
3263 | pfd2[0].fd = fileno(f);
|
---|
3264 |
|
---|
3265 | pfd2[0].events = (POLLIN | POLLPRI);
|
---|
3266 |
|
---|
3267 | int32_t rc = poll(pfd2, 1, 100);
|
---|
3268 | if (rc>0)
|
---|
3269 | continue;
|
---|
3270 |
|
---|
3271 | break;
|
---|
3272 | }
|
---|
3273 |
|
---|
3274 | if (!filebuf) {
|
---|
3275 | cs_log("error: no data received");
|
---|
3276 | return -1;
|
---|
3277 | }
|
---|
3278 |
|
---|
3279 | filebuf[bufsize]='\0';
|
---|
3280 | char *buf=filebuf;
|
---|
3281 |
|
---|
3282 | method = strtok_r(buf, " ", &saveptr1);
|
---|
3283 | path = strtok_r(NULL, " ", &saveptr1);
|
---|
3284 | protocol = strtok_r(NULL, "\r", &saveptr1);
|
---|
3285 | if(method == NULL || path == NULL || protocol == NULL) return -1;
|
---|
3286 | tmp=protocol+strlen(protocol)+2;
|
---|
3287 |
|
---|
3288 | pch=path;
|
---|
3289 | /* advance pointer to beginning of query string */
|
---|
3290 | while(pch[0] != '?' && pch[0] != '\0') ++pch;
|
---|
3291 | if(pch[0] == '?') {
|
---|
3292 | pch[0] = '\0';
|
---|
3293 | ++pch;
|
---|
3294 | }
|
---|
3295 |
|
---|
3296 | /* Map page to our static page definitions */
|
---|
3297 | for (i=0; i<pagescnt; i++) {
|
---|
3298 | if (!strcmp(path, pages[i])) pgidx = i;
|
---|
3299 | }
|
---|
3300 |
|
---|
3301 | webif_parse_request(¶ms, pch);
|
---|
3302 |
|
---|
3303 | if(strlen(cfg.http_user) == 0 || strlen(cfg.http_pwd) == 0) authok = 1;
|
---|
3304 | else calculate_nonce(expectednonce);
|
---|
3305 |
|
---|
3306 | char *str1, *saveptr=NULL;
|
---|
3307 |
|
---|
3308 | for (str1=strtok_r(tmp, "\n", &saveptr); str1; str1=strtok_r(NULL, "\n", &saveptr)) {
|
---|
3309 | if (strlen(str1)==1) {
|
---|
3310 | if (strcmp(method, "POST")==0) {
|
---|
3311 | webif_parse_request(¶ms, str1+2);
|
---|
3312 | }
|
---|
3313 | break;
|
---|
3314 | }
|
---|
3315 | if(authok == 0 && strlen(str1) > 50 && strncmp(str1, "Authorization:", 14) == 0 && strstr(str1, "Digest") != NULL) {
|
---|
3316 | authok = check_auth(str1, method, path, expectednonce);
|
---|
3317 | }
|
---|
3318 | }
|
---|
3319 |
|
---|
3320 | if(authok != 1) {
|
---|
3321 | char temp[sizeof(AUTHREALM) + sizeof(expectednonce) + 100];
|
---|
3322 | snprintf(temp, sizeof(temp), "WWW-Authenticate: Digest algorithm=\"MD5\", realm=\"%s\", qop=\"auth\", opaque=\"\", nonce=\"%s\"", AUTHREALM, expectednonce);
|
---|
3323 | if(authok == 2) strncat(temp, ", stale=true", sizeof(temp));
|
---|
3324 | send_headers(f, 401, "Unauthorized", temp, "text/html", 0);
|
---|
3325 | free(filebuf);
|
---|
3326 | return 0;
|
---|
3327 | }
|
---|
3328 |
|
---|
3329 | /*build page*/
|
---|
3330 | if(pgidx == 8) {
|
---|
3331 | send_headers(f, 200, "OK", NULL, "text/css", 1);
|
---|
3332 | send_file(f, "CSS");
|
---|
3333 | } else if (pgidx == 17) {
|
---|
3334 | send_headers(f, 200, "OK", NULL, "text/javascript", 1);
|
---|
3335 | send_file(f, "JS");
|
---|
3336 | } else {
|
---|
3337 | time_t t;
|
---|
3338 | struct templatevars *vars = tpl_create();
|
---|
3339 | if(vars == NULL){
|
---|
3340 | send_error500(f);
|
---|
3341 | free(filebuf);
|
---|
3342 | return 0;
|
---|
3343 | }
|
---|
3344 | struct tm lt, st;
|
---|
3345 | time(&t);
|
---|
3346 |
|
---|
3347 | localtime_r(&t, <);
|
---|
3348 |
|
---|
3349 | tpl_addVar(vars, TPLADD, "CS_VERSION", CS_VERSION);
|
---|
3350 | tpl_addVar(vars, TPLADD, "CS_SVN_VERSION", CS_SVN_VERSION);
|
---|
3351 | if(cfg.http_refresh > 0 && (pgidx == 3 || pgidx == -1)) {
|
---|
3352 | tpl_printf(vars, TPLADD, "REFRESHTIME", "%d", cfg.http_refresh);
|
---|
3353 | tpl_addVar(vars, TPLADD, "REFRESHURL", "status.html");
|
---|
3354 | tpl_addVar(vars, TPLADD, "REFRESH", tpl_getTpl(vars, "REFRESH"));
|
---|
3355 | }
|
---|
3356 |
|
---|
3357 | tpl_printf(vars, TPLADD, "CURDATE", "%02d.%02d.%02d", lt.tm_mday, lt.tm_mon+1, lt.tm_year%100);
|
---|
3358 | tpl_printf(vars, TPLADD, "CURTIME", "%02d:%02d:%02d", lt.tm_hour, lt.tm_min, lt.tm_sec);
|
---|
3359 | localtime_r(&first_client->login, &st);
|
---|
3360 | tpl_printf(vars, TPLADD, "STARTDATE", "%02d.%02d.%02d", st.tm_mday, st.tm_mon+1, st.tm_year%100);
|
---|
3361 | tpl_printf(vars, TPLADD, "STARTTIME", "%02d:%02d:%02d", st.tm_hour, st.tm_min, st.tm_sec);
|
---|
3362 | tpl_printf(vars, TPLADD, "PROCESSID", "%d", server_pid);
|
---|
3363 |
|
---|
3364 | time_t now = time((time_t)0);
|
---|
3365 | // XMLAPI
|
---|
3366 | if (pgidx == 18) {
|
---|
3367 | char tbuffer [30];
|
---|
3368 | strftime(tbuffer, 30, "%Y-%m-%dT%H:%M:%S%z", &st);
|
---|
3369 | tpl_printf(vars, TPLADD, "APISTARTTIME", "%s", tbuffer);
|
---|
3370 | tpl_printf(vars, TPLADD, "APIUPTIME", "%u", now - first_client->login);
|
---|
3371 | tpl_printf(vars, TPLADD, "APIREADONLY", "%d", cfg.http_readonly);
|
---|
3372 | }
|
---|
3373 |
|
---|
3374 | // language code in helplink
|
---|
3375 | if (cfg.http_help_lang[0])
|
---|
3376 | tpl_addVar(vars, TPLADD, "LANGUAGE", cfg.http_help_lang);
|
---|
3377 | else
|
---|
3378 | tpl_addVar(vars, TPLADD, "LANGUAGE", "en");
|
---|
3379 |
|
---|
3380 | tpl_addVar(vars, TPLADD, "UPTIME", sec2timeformat(vars, (now - first_client->login)));
|
---|
3381 | tpl_printf(vars, TPLADD, "CURIP", "%s", inet_ntoa(in));
|
---|
3382 | if(cfg.http_readonly)
|
---|
3383 | tpl_addVar(vars, TPLAPPEND, "BTNDISABLED", "DISABLED");
|
---|
3384 |
|
---|
3385 | char *result = NULL;
|
---|
3386 |
|
---|
3387 | switch(pgidx) {
|
---|
3388 | case 0: result = send_oscam_config(vars, ¶ms, in); break;
|
---|
3389 | case 1: result = send_oscam_reader(vars, ¶ms, in); break;
|
---|
3390 | case 2: result = send_oscam_entitlement(vars, ¶ms, in, 0); break;
|
---|
3391 | case 3: result = send_oscam_status(vars, ¶ms, in, 0); break;
|
---|
3392 | case 4: result = send_oscam_user_config(vars, ¶ms, in, 0); break;
|
---|
3393 | case 5: result = send_oscam_reader_config(vars, ¶ms, in); break;
|
---|
3394 | case 6: result = send_oscam_services(vars, ¶ms, in); break;
|
---|
3395 | case 7: result = send_oscam_user_config_edit(vars, ¶ms, in); break;
|
---|
3396 | //case 8: css file
|
---|
3397 | case 9: result = send_oscam_services_edit(vars, ¶ms, in); break;
|
---|
3398 | case 10: result = send_oscam_savetpls(vars); break;
|
---|
3399 | case 11: result = send_oscam_shutdown(vars, f, ¶ms, in, 0); break;
|
---|
3400 | case 12: result = send_oscam_script(vars); break;
|
---|
3401 | case 13: result = send_oscam_scanusb(vars); break;
|
---|
3402 | case 14: result = send_oscam_files(vars, ¶ms); break;
|
---|
3403 | case 15: result = send_oscam_reader_stats(vars, ¶ms, in, 0); break;
|
---|
3404 | case 16: result = send_oscam_failban(vars, ¶ms); break;
|
---|
3405 | //case 17: js file
|
---|
3406 | case 18: result = send_oscam_api(vars, f, ¶ms, in); break;
|
---|
3407 | case 19: result = send_oscam_image(vars, f, ¶ms, NULL); break;
|
---|
3408 | case 20: result = send_oscam_image(vars, f, ¶ms, "ICMAI"); break;
|
---|
3409 | default: result = send_oscam_status(vars, ¶ms, in, 0); break;
|
---|
3410 | }
|
---|
3411 | if(result == NULL || !strcmp(result, "0") || strlen(result) == 0) send_error500(f);
|
---|
3412 | else if (strcmp(result, "1")) {
|
---|
3413 | if (pgidx == 18)
|
---|
3414 | send_headers(f, 200, "OK", NULL, "text/xml", 0);
|
---|
3415 | else
|
---|
3416 | send_headers(f, 200, "OK", NULL, "text/html", 0);
|
---|
3417 | webif_write(result, f);
|
---|
3418 | }
|
---|
3419 | tpl_clear(vars);
|
---|
3420 | }
|
---|
3421 | free(filebuf);
|
---|
3422 | return 0;
|
---|
3423 | }
|
---|
3424 |
|
---|
3425 | #ifdef WITH_SSL
|
---|
3426 | SSL_CTX *webif_init_ssl() {
|
---|
3427 | SSL_library_init();
|
---|
3428 | SSL_load_error_strings();
|
---|
3429 |
|
---|
3430 | SSL_METHOD *meth;
|
---|
3431 | SSL_CTX *ctx;
|
---|
3432 |
|
---|
3433 | static const char *cs_cert="oscam.pem";
|
---|
3434 |
|
---|
3435 | meth = SSLv23_server_method();
|
---|
3436 |
|
---|
3437 | ctx = SSL_CTX_new(meth);
|
---|
3438 |
|
---|
3439 | char path[128];
|
---|
3440 |
|
---|
3441 | if (cfg.http_cert[0]==0)
|
---|
3442 | snprintf(path, sizeof(path), "%s%s", cs_confdir, cs_cert);
|
---|
3443 | else
|
---|
3444 | cs_strncpy(path, cfg.http_cert, sizeof(path));
|
---|
3445 |
|
---|
3446 | if (!ctx) {
|
---|
3447 | ERR_print_errors_fp(stderr);
|
---|
3448 | return NULL;
|
---|
3449 | }
|
---|
3450 |
|
---|
3451 | if (SSL_CTX_use_certificate_file(ctx, path, SSL_FILETYPE_PEM) <= 0) {
|
---|
3452 | ERR_print_errors_fp(stderr);
|
---|
3453 | return NULL;
|
---|
3454 | }
|
---|
3455 |
|
---|
3456 | if (SSL_CTX_use_PrivateKey_file(ctx, path, SSL_FILETYPE_PEM) <= 0) {
|
---|
3457 | ERR_print_errors_fp(stderr);
|
---|
3458 | return NULL;
|
---|
3459 | }
|
---|
3460 |
|
---|
3461 | if (!SSL_CTX_check_private_key(ctx)) {
|
---|
3462 | cs_log("SSL: Private key does not match the certificate public key");
|
---|
3463 | return NULL;
|
---|
3464 | }
|
---|
3465 | cs_log("load ssl certificate file %s", path);
|
---|
3466 | return ctx;
|
---|
3467 | }
|
---|
3468 | #endif
|
---|
3469 |
|
---|
3470 | void http_srv() {
|
---|
3471 | struct s_client * cl = create_client(first_client->ip);
|
---|
3472 | if (cl == NULL) return;
|
---|
3473 | cl->thread = pthread_self();
|
---|
3474 | pthread_setspecific(getclient, cl);
|
---|
3475 | cl->typ = 'h';
|
---|
3476 | int32_t sock, reuse = 1;
|
---|
3477 | struct sockaddr_in sin;
|
---|
3478 | struct sockaddr_in remote;
|
---|
3479 | struct timeval stimeout;
|
---|
3480 |
|
---|
3481 | socklen_t len = sizeof(remote);
|
---|
3482 | /* Create random string for nonce value generation */
|
---|
3483 | create_rand_str(noncekey,32);
|
---|
3484 |
|
---|
3485 | /* Startup server */
|
---|
3486 | if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
|
---|
3487 | cs_log("HTTP Server: Creating socket failed! (errno=%d %s)", errno, strerror(errno));
|
---|
3488 | return;
|
---|
3489 | }
|
---|
3490 | if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) {
|
---|
3491 | cs_log("HTTP Server: Setting SO_REUSEADDR via setsockopt failed! (errno=%d %s)", errno, strerror(errno));
|
---|
3492 | }
|
---|
3493 |
|
---|
3494 | stimeout.tv_sec = 30;
|
---|
3495 | stimeout.tv_usec = 0;
|
---|
3496 |
|
---|
3497 | if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &stimeout, sizeof(stimeout)) < 0) {
|
---|
3498 | cs_log("HTTP Server: Setting SO_RCVTIMEO via setsockopt failed! (errno=%d %s)", errno, strerror(errno));
|
---|
3499 | }
|
---|
3500 |
|
---|
3501 | if (setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &stimeout, sizeof(stimeout)) < 0) {
|
---|
3502 | cs_log("HTTP Server: Setting SO_SNDTIMEO via setsockopt failed! (errno=%d %s)", errno, strerror(errno));
|
---|
3503 | }
|
---|
3504 |
|
---|
3505 | memset(&sin, 0, sizeof sin);
|
---|
3506 | sin.sin_family = AF_INET;
|
---|
3507 | sin.sin_addr.s_addr = INADDR_ANY;
|
---|
3508 | sin.sin_port = htons(cfg.http_port);
|
---|
3509 | if((bind(sock, (struct sockaddr *) &sin, sizeof(sin))) < 0) {
|
---|
3510 | cs_log("HTTP Server couldn't bind on port %d (errno=%d %s). Not starting HTTP!", cfg.http_port, errno, strerror(errno));
|
---|
3511 | close(sock);
|
---|
3512 | return;
|
---|
3513 | }
|
---|
3514 | if (listen(sock, SOMAXCONN) < 0) {
|
---|
3515 | cs_log("HTTP Server: Call to listen() failed! (errno=%d %s)", errno, strerror(errno));
|
---|
3516 | close(sock);
|
---|
3517 | return;
|
---|
3518 | }
|
---|
3519 | cs_log("HTTP Server listening on port %d%s", cfg.http_port, cfg.http_use_ssl ? " (SSL)" : "");
|
---|
3520 | struct pollfd pfd2[1];
|
---|
3521 | int32_t rc;
|
---|
3522 | pfd2[0].fd = sock;
|
---|
3523 | pfd2[0].events = (POLLIN | POLLPRI);
|
---|
3524 |
|
---|
3525 | #ifdef WITH_SSL
|
---|
3526 | SSL_CTX *ctx = NULL;
|
---|
3527 | if (cfg.http_use_ssl)
|
---|
3528 | ctx = webif_init_ssl();
|
---|
3529 |
|
---|
3530 | if (ctx==NULL)
|
---|
3531 | cfg.http_use_ssl = 0;
|
---|
3532 | #endif
|
---|
3533 |
|
---|
3534 | while (running) {
|
---|
3535 | int32_t s;
|
---|
3536 |
|
---|
3537 | rc = poll(pfd2, 1, 1000);
|
---|
3538 |
|
---|
3539 | if (rc > 0) {
|
---|
3540 | if((s = accept(sock, (struct sockaddr *) &remote, &len)) < 0) {
|
---|
3541 | cs_log("HTTP Server: Error calling accept() (errno=%d %s)", errno, strerror(errno));
|
---|
3542 | break;
|
---|
3543 | }
|
---|
3544 | #ifdef WITH_SSL
|
---|
3545 | if (cfg.http_use_ssl) {
|
---|
3546 | SSL *ssl;
|
---|
3547 | ssl = SSL_new(ctx);
|
---|
3548 | if(ssl != NULL){
|
---|
3549 | if(SSL_set_fd(ssl, s)){
|
---|
3550 | if (SSL_accept(ssl) != -1)
|
---|
3551 | process_request((FILE *)ssl, remote.sin_addr);
|
---|
3552 | else {
|
---|
3553 | FILE *f;
|
---|
3554 | f = fdopen(s, "r+");
|
---|
3555 | if(f != NULL) {
|
---|
3556 | // Note: This is quite dirty and only works because webif is not multithreaded!
|
---|
3557 | cfg.http_use_ssl=0;
|
---|
3558 | send_error(f, 200, "Bad Request", NULL, "This web server is running in SSL mode.");
|
---|
3559 | cfg.http_use_ssl=1;
|
---|
3560 | fflush(f);
|
---|
3561 | fclose(f);
|
---|
3562 | } else cs_log("WebIf: Error opening file descriptor using fdopen() (errno=%d %s)", errno, strerror(errno));
|
---|
3563 | }
|
---|
3564 | } else cs_log("WebIf: Error calling SSL_set_fd().");
|
---|
3565 | SSL_shutdown(ssl);
|
---|
3566 | close(s);
|
---|
3567 | SSL_free(ssl);
|
---|
3568 | } else {
|
---|
3569 | close(s);
|
---|
3570 | cs_log("WebIf: Error calling SSL_new().");
|
---|
3571 | }
|
---|
3572 | } else
|
---|
3573 | #endif
|
---|
3574 | {
|
---|
3575 | FILE *f;
|
---|
3576 | f = fdopen(s, "r+");
|
---|
3577 | if(f != NULL) {
|
---|
3578 | process_request(f, remote.sin_addr);
|
---|
3579 | fflush(f);
|
---|
3580 | fclose(f);
|
---|
3581 | } else cs_log("WebIf: Error opening file descriptor using fdopen() (errno=%d %s)", errno, strerror(errno));
|
---|
3582 | shutdown(s, SHUT_WR);
|
---|
3583 | close(s);
|
---|
3584 | }
|
---|
3585 | }
|
---|
3586 | }
|
---|
3587 | #ifdef WITH_SSL
|
---|
3588 | if (cfg.http_use_ssl)
|
---|
3589 | SSL_CTX_free(ctx);
|
---|
3590 | #endif
|
---|
3591 | cs_log("HTTP Server: Shutdown requested from %s", inet_ntoa(remote.sin_addr));
|
---|
3592 | close(sock);
|
---|
3593 | //exit(SIGQUIT);
|
---|
3594 | }
|
---|
3595 | #endif
|
---|