source: trunk/oscam-http.c@ 3181

Last change on this file since 3181 was 3181, checked in by dingo35, 10 years ago

Adding threadsafety FIXMEs, feel free to join checking..

File size: 90.7 KB
Line 
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
17extern struct s_reader *reader;
18
19static int running = 1;
20
21void refresh_oscam(enum refreshtypes refreshtype, struct in_addr in) {
22 int i;
23 switch (refreshtype) {
24 case REFR_ACCOUNTS:
25 cs_log("Refresh Accounts requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
26 //kill(client[0].pid, SIGHUP);
27 init_userdb(&cfg->account);
28#ifdef CS_ANTICASC
29 for (i=0; i<CS_MAXPID; i++)
30 if (client[i].typ=='a') {
31 kill(client[i].pid, SIGHUP);
32 break;
33 }
34#endif
35 break;
36
37 case REFR_READERS:
38 kill(client[0].pid, SIGUSR2);
39 cs_log("Refresh Reader/Tiers requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
40 break;
41
42 case REFR_SERVER:
43 cs_log("Refresh Server requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
44 //kill(client[0].pid, SIGHUP);
45 //todo how I can refresh the server after global settings
46 break;
47
48 case REFR_SERVICES:
49 cs_log("Refresh Services requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
50 //init_sidtab();
51 kill(client[0].pid, SIGHUP);
52 break;
53
54#ifdef CS_ANTICASC
55 case REFR_ANTICASC:
56 cs_log("Refresh Anticascading requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
57 for (i=0; i<CS_MAXPID; i++)
58 if (client[i].typ=='a') {
59 kill(client[i].pid, SIGHUP);
60 break;
61 }
62 break;
63#endif
64 }
65}
66
67void send_oscam_config_global(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
68 int i;
69
70 if (strcmp(getParam(params, "action"), "execute") == 0) {
71 for(i = 0; i < (*params).paramcount; ++i) {
72 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
73 //tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
74 //we use the same function as used for parsing the config tokens
75
76 chk_t_global((*params).params[i], (*params).values[i]);
77 }
78 }
79 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Global done. You should restart Oscam now.</B><BR><BR>");
80 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
81 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
82 }
83 if (cfg->srvip != 0)
84 tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->srvip));
85 if (cfg->pidfile != NULL) tpl_addVar(vars, 0, "PIDFILE", cfg->pidfile);
86 if(cfg->disableuserfile == 1)
87 tpl_addVar(vars, 0, "CHKDISABLEUSERFILE", "checked");
88 if (cfg->usrfile != NULL) tpl_addVar(vars, 0, "USERFILE", cfg->usrfile);
89 if(cfg->disablelog == 1)
90 tpl_addVar(vars, 0, "CHKDISABLELOG", "checked");
91 if (cfg->logfile != NULL) tpl_addVar(vars, 0, "LOGFILE", cfg->logfile);
92 if (cfg->cwlogdir != NULL) tpl_addVar(vars, 0, "CWLOGDIR", cfg->cwlogdir);
93 tpl_printf(vars, 0, "USERFILEFLAG", "%d", cfg->usrfileflag);
94 tpl_printf(vars, 0, "CLIENTTIMEOUT", "%ld", cfg->ctimeout);
95 tpl_printf(vars, 0, "FALLBACKTIMEOUT", "%ld", cfg->ftimeout);
96 tpl_printf(vars, 0, "CLIENTMAXIDLE", "%d", cfg->cmaxidle);
97 tpl_printf(vars, 0, "CACHEDELAY", "%ld", cfg->delay);
98 tpl_printf(vars, 0, "BINDWAIT", "%d", cfg->bindwait);
99 tpl_printf(vars, 0, "NETPRIO", "%ld", cfg->netprio);
100 if (cfg->clientdyndns)
101 tpl_addVar(vars, 0, "CHKCLIENTDYNDNS", "checked");
102 tpl_printf(vars, 0, "RESOLVEDELAY", "%d", cfg->resolvedelay);
103 tpl_printf(vars, 0, "SLEEP", "%d", cfg->tosleep);
104 if (cfg->ulparent == 1)
105 tpl_addVar(vars, 0, "UNLOCKPARENTAL", "checked");
106 tpl_printf(vars, 0, "NICE", "%d", cfg->nice);
107 tpl_printf(vars, 0, "SERIALTIMEOUT", "%d", cfg->srtimeout);
108 tpl_printf(vars, 0, "MAXLOGSIZE", "%d", cfg->max_log_size);
109 if (cfg->waitforcards == 1)
110 tpl_addVar(vars, 0, "WAITFORCARDS", "checked");
111 if (cfg->preferlocalcards == 1)
112 tpl_addVar(vars, 0, "PREFERLOCALCARDS", "checked");
113 if (cfg->saveinithistory == 1)
114 tpl_addVar(vars, 0, "SAVEINITHISTORY", "checked");
115 if (cfg->reader_restart_seconds)
116 tpl_printf(vars, 0, "READERRESTARTSECONDS", "%d", cfg->reader_restart_seconds);
117
118 if (cfg->resolve_gethostbyname == 1)
119 tpl_addVar(vars, 0, "RESOLVER1", "selected");
120 else
121 tpl_addVar(vars, 0, "RESOLVER0", "selected");
122
123#ifdef CS_WITH_DOUBLECHECK
124 if(cfg->double_check == 1)
125 tpl_addVar(vars, 0, "DCHECKCSELECTED", "selected");
126#endif
127
128
129
130 fputs(tpl_getTpl(vars, "CONFIGGLOBAL"), f);
131}
132
133void send_oscam_config_loadbalancer(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
134 int i;
135 if (strcmp(getParam(params, "action"),"execute") == 0) {
136
137 memset(cfg->ser_device, 0, sizeof(cfg->ser_device));
138 for(i = 0; i < (*params).paramcount; ++i) {
139 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
140 //tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
141 //we use the same function as used for parsing the config tokens
142 if((*params).values[i][0])
143 chk_t_global((*params).params[i], (*params).values[i]);
144 }
145 }
146 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Loadbalancer done.</B><BR><BR>");
147 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
148 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
149 }
150
151 tpl_printf(vars, 0, "TMP", "LBMODE%d", cfg->lb_mode);
152 tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
153
154 tpl_printf(vars, 0, "LBSAVE", "%d",cfg->lb_save);
155
156 tpl_printf(vars, 0, "LBNBESTREADERS", "%d",cfg->lb_nbest_readers);
157 tpl_printf(vars, 0, "LBNFBREADERS", "%d",cfg->lb_nfb_readers);
158 tpl_printf(vars, 0, "LBMINECMCOUNT", "%d",cfg->lb_min_ecmcount);
159 tpl_printf(vars, 0, "LBMAXECEMCOUNT", "%d",cfg->lb_max_ecmcount);
160 tpl_printf(vars, 0, "LBREOPENSECONDS", "%d",cfg->lb_reopen_seconds);
161
162 fputs(tpl_getTpl(vars, "CONFIGLOADBALANCER"), f);
163
164}
165
166void send_oscam_config_camd33(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
167 int i;
168
169 if (strcmp(getParam(params, "action"), "execute") == 0) {
170 for(i = 0; i < (*params).paramcount; ++i) {
171 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
172 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
173 if (strcmp((*params).params[i], "nocrypt") == 0) {
174 clear_sip(&cfg->c33_plain);
175 }
176 //we use the same function as used for parsing the config tokens
177 chk_t_camd33((*params).params[i], (*params).values[i]);
178 }
179 }
180 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration camd33 done. You should restart Oscam now.</B><BR><BR>");
181 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
182 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
183 }
184
185 if (cfg->c33_port) {
186 tpl_printf(vars, 0, "PORT", "%d", cfg->c33_port);
187 if (cfg->c33_srvip != 0)
188 tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip));
189 if (cfg->c33_passive == 1)
190 tpl_addVar(vars, 0, "PASSIVE", "checked");
191
192 for (i = 0; i < (int) sizeof(cfg->c33_key); ++i) tpl_printf(vars, 1, "KEY", "%02X",cfg->c33_key[i]);
193 struct s_ip *cip;
194 char *dot="";
195 for (cip = cfg->c33_plain; cip; cip = cip->next) {
196 tpl_printf(vars, 1, "NOCRYPT", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
197 if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "NOCRYPT", "-%s", cs_inet_ntoa(cip->ip[1]));
198 dot=",";
199 }
200 }
201
202 fputs(tpl_getTpl(vars, "CONFIGCAMD33"), f);
203}
204
205void send_oscam_config_camd35(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
206 int i;
207 if ((strcmp(getParam(params, "action"),"execute") == 0) && (getParam(params, "port"))[0]) {
208 for(i = 0; i < (*params).paramcount; ++i) {
209 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
210 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
211 //we use the same function as used for parsing the config tokens
212 chk_t_camd35((*params).params[i], (*params).values[i]);
213 }
214 }
215 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration camd35 done. You should restart Oscam now.</B><BR><BR>");
216 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
217 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
218 }
219
220 if (cfg->c35_port) {
221 tpl_printf(vars, 0, "PORT", "%d", cfg->c35_port);
222 if (cfg->c35_srvip != 0)
223 tpl_addVar(vars, 1, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c35_srvip));
224
225 if (cfg->c35_suppresscmd08)
226 tpl_addVar(vars, 0, "SUPPRESSCMD08", "checked");
227 }
228 fputs(tpl_getTpl(vars, "CONFIGCAMD35"), f);
229}
230
231void send_oscam_config_camd35tcp(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
232 int i;
233 if ((strcmp(getParam(params, "action"),"execute") == 0) && (getParam(params, "port"))[0]) {
234 clear_ptab(&cfg->c35_tcp_ptab); /*clear Porttab*/
235 for(i = 0; i < (*params).paramcount; ++i) {
236 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
237 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
238 //we use the same function as used for parsing the config tokens
239 chk_t_camd35_tcp((*params).params[i], (*params).values[i]);
240 }
241 }
242 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration camd35 TCP done. You should restart Oscam now.</B><BR><BR>");
243 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
244 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
245 }
246
247 int j;
248 char *dot1, *dot2;
249 if ((cfg->c35_tcp_ptab.nports > 0) && (cfg->c35_tcp_ptab.ports[0].s_port > 0)) {
250 dot1 = "";
251 for(i = 0; i < cfg->c35_tcp_ptab.nports; ++i) {
252 tpl_printf(vars, 1, "PORT", "%s%d@%04X", dot1, cfg->c35_tcp_ptab.ports[i].s_port, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].caid);
253 if (cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 1) {
254 tpl_printf(vars, 1, "PORT", ":");
255 dot2 = "";
256 for (j = 0; j < cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j) {
257 tpl_printf(vars, 1, "PORT", "%s%lX", dot2, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]);
258 dot2 = ",";
259 }
260 }
261 dot1=";";
262 }
263
264 if (cfg->c35_tcp_srvip != 0)
265 tpl_addVar(vars, 1, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
266
267 }
268 fputs(tpl_getTpl(vars, "CONFIGCAMD35TCP"), f);
269}
270
271void send_oscam_config_newcamd(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
272 int i;
273 if (strcmp(getParam(params, "action"),"execute") == 0) {
274 clear_ptab(&cfg->ncd_ptab); /*clear Porttab*/
275 for(i = 0; i < (*params).paramcount; ++i) {
276 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
277 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
278 //we use the same function as used for parsing the config tokens
279 if (strcmp((*params).params[i], "allowed") == 0) {
280 clear_sip(&cfg->ncd_allowed);
281 }
282 chk_t_newcamd((*params).params[i], (*params).values[i]);
283 }
284 }
285 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Newcamd done. You should restart Oscam now.</B><BR><BR>");
286 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
287 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
288 }
289 int j;
290 char *dot1, *dot2;
291 if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)) {
292 dot1 = "";
293 for(i = 0; i < cfg->ncd_ptab.nports; ++i) {
294 tpl_printf(vars, 1, "PORT", "%s%d@%04X", dot1, cfg->ncd_ptab.ports[i].s_port, cfg->ncd_ptab.ports[i].ftab.filts[0].caid);
295
296 // separate DES Key
297 if(cfg->ncd_ptab.ports[i].ncd_key_is_set){
298 int k;
299 tpl_printf(vars, 1, "PORT", "{");
300 for (k = 0; k < 14; k++)
301 tpl_printf(vars, 1, "PORT", "%02X", cfg->ncd_ptab.ports[i].ncd_key[k]);
302 tpl_printf(vars, 1, "PORT", "}");
303 }
304
305 if (cfg->ncd_ptab.ports[i].ftab.filts[0].nprids > 0) {
306 tpl_printf(vars, 1, "PORT", ":");
307 dot2 = "";
308 for (j = 0; j < cfg->ncd_ptab.ports[i].ftab.filts[0].nprids; ++j) {
309 tpl_printf(vars, 1, "PORT", "%s%06X", dot2, cfg->ncd_ptab.ports[i].ftab.filts[0].prids[j]);
310 dot2 = ",";
311 }
312 }
313 dot1=";";
314 }
315
316
317 if (cfg->ncd_srvip != 0)
318 tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->ncd_srvip));
319
320 for (i=0;i<14;i++) tpl_printf(vars, 1, "KEY", "%02X", cfg->ncd_key[i]);
321
322 struct s_ip *cip;
323 char *dot="";
324 for (cip = cfg->ncd_allowed; cip; cip = cip->next) {
325 tpl_printf(vars, 1, "ALLOWED", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
326 if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "ALLOWED", "-%s", cs_inet_ntoa(cip->ip[1]));
327 dot=",";
328 }
329
330 if (cfg->ncd_keepalive)
331 tpl_addVar(vars, 0, "KEEPALIVE", "checked");
332 if (cfg->ncd_mgclient)
333 tpl_addVar(vars, 0, "MGCLIENTCHK", "checked");
334 }
335 fputs(tpl_getTpl(vars, "CONFIGNEWCAMD"), f);
336}
337
338void send_oscam_config_radegast(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
339 int i;
340 if (strcmp(getParam(params, "action"),"execute") == 0) {
341 for(i = 0; i < (*params).paramcount; ++i) {
342 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
343 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
344 if (strcmp((*params).params[i], "allowed") == 0) {
345 clear_sip(&cfg->rad_allowed);
346 }
347 //we use the same function as used for parsing the config tokens
348 chk_t_radegast((*params).params[i], (*params).values[i]);
349 }
350 }
351 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Radegast done. You should restart Oscam now.</B><BR><BR>");
352 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
353 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
354 }
355 tpl_printf(vars, 0, "PORT", "%d", cfg->rad_port);
356 if (cfg->rad_srvip != 0)
357 tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->rad_srvip));
358 tpl_addVar(vars, 0, "USER", cfg->rad_usr);
359
360 struct s_ip *cip;
361 char *dot="";
362 for (cip=cfg->rad_allowed; cip; cip=cip->next) {
363 tpl_printf(vars, 1, "ALLOWED", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
364 if (cip->ip[0] != cip->ip[1])
365 tpl_printf(vars, 1, "ALLOWED", "-%s", cs_inet_ntoa(cip->ip[1]));
366 dot=",";
367 }
368
369 fputs(tpl_getTpl(vars, "CONFIGRADEGAST"), f);
370}
371
372void send_oscam_config_cccam(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
373 int i;
374 if (strcmp(getParam(params, "action"),"execute") == 0) {
375 for(i = 0; i < (*params).paramcount; ++i) {
376 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
377 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
378 //we use the same function as used for parsing the config tokens
379 chk_t_cccam((*params).params[i], (*params).values[i]);
380 }
381 }
382 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
383 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
384 }
385
386 tpl_printf(vars, 1, "PORT", "%d", cfg->cc_port);
387 tpl_printf(vars, 0, "RESHARE", "%d", cfg->cc_reshare);
388
389 if (!strcmp((char*)cfg->cc_version,"2.0.11")) {
390 tpl_addVar(vars, 0, "VERSIONSELECTED0", "selected");
391 } else if (!strcmp((char*)cfg->cc_version,"2.1.1")) {
392 tpl_addVar(vars, 0, "VERSIONSELECTED1", "selected");
393 } else if (!strcmp((char*)cfg->cc_version,"2.1.2")) {
394 tpl_addVar(vars, 0, "VERSIONSELECTED2", "selected");
395 } else if (!strcmp((char*)cfg->cc_version,"2.1.3")) {
396 tpl_addVar(vars, 0, "VERSIONSELECTED3", "selected");
397 } else if (!strcmp((char*)cfg->cc_version,"2.1.4")) {
398 tpl_addVar(vars, 0, "VERSIONSELECTED4", "selected");
399 }
400
401 tpl_printf(vars, 0, "UPDATEINTERVAL", "%d", cfg->cc_update_interval);
402
403 tpl_printf(vars, 0, "TMP", "MINIMIZECARDSELECTED%d", cfg->cc_minimize_cards);
404 tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
405
406 fputs(tpl_getTpl(vars, "CONFIGCCCAM"), f);
407}
408
409#ifdef CS_WITH_GBOX
410void send_oscam_config_gbox(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
411 int i;
412 if (strcmp(getParam(params, "action"),"execute") == 0) {
413 for(i = 0; i < (*params).paramcount; ++i) {
414 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
415 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
416 //we use the same function as used for parsing the config tokens
417 chk_t_gbox((*params).params[i], (*params).values[i]);
418 }
419 }
420 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Gbox done. You should restart Oscam now.</B><BR><BR>");
421 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
422 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
423 }
424 tpl_printf(vars, 0, "MAXDIST", "%d", cfg->maxdist);
425 for (i=0;i<4;i++) tpl_printf(vars, 1, "PASSWORD", "%02X", cfg->gbox_pwd[i]);
426 tpl_addVar(vars, 0, "IGNORELIST", (char *)cfg->ignorefile);
427 tpl_addVar(vars, 0, "ONLINEINFOS", (char *)cfg->gbxShareOnl);
428 tpl_addVar(vars, 0, "CARDINFOS", (char *)cfg->cardfile);
429 char *dot = "";
430 for (i = 0; i < cfg->num_locals; i++) {
431 tpl_printf(vars, 1, "LOCALS", "%s%06lX", dot, cfg->locals[i]);
432 dot=";";
433 }
434 fputs(tpl_getTpl(vars, "CONFIGGBOX"), f);
435}
436#endif
437
438void send_oscam_config_monitor(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
439 int i;
440 if (strcmp(getParam(params, "action"),"execute") == 0) {
441
442 //cleanup
443 clear_sip(&cfg->mon_allowed);
444 clear_sip(&cfg->http_allowed);
445
446 for(i = 0; i < (*params).paramcount; ++i) {
447 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
448 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
449
450 //we use the same function as used for parsing the config tokens
451 if (strstr((*params).params[i], "http")) {
452 chk_t_webif((*params).params[i], (*params).values[i]);
453 } else {
454 chk_t_monitor((*params).params[i], (*params).values[i]);
455 }
456 }
457 }
458 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Monitor done. You should restart Oscam now.</B><BR><BR>");
459 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
460 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
461 }
462 tpl_printf(vars, 0, "MONPORT", "%d", cfg->mon_port);
463 if (cfg->mon_srvip != 0)
464 tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip));
465 tpl_printf(vars, 0, "AULOW", "%d", cfg->mon_aulow);
466 tpl_printf(vars, 0, "HIDECLIENTTO", "%d", cfg->mon_hideclient_to);
467 if(cfg->mon_appendchaninfo)
468 tpl_addVar(vars, 0, "APPENDCHANINFO", "checked");
469 tpl_printf(vars, 0, "HTTPPORT", "%d", cfg->http_port);
470 tpl_addVar(vars, 0, "HTTPUSER", cfg->http_user);
471 tpl_addVar(vars, 0, "HTTPPASSWORD", cfg->http_pwd);
472
473 // css style selector
474 if(strlen(cfg->http_css) == 0) {
475 tpl_addVar(vars, 0, "CSSOPTIONS", "<option value=\"\" selected>embedded</option>\n");
476 } else {
477 tpl_addVar(vars, 0, "CSSOPTIONS", "<option value=\"\">embedded</option>\n");
478 }
479
480 DIR *hdir;
481 struct dirent *entry;
482 hdir = opendir(cs_confdir);
483 do {
484 entry = readdir(hdir);
485 if ((entry) && (strstr(entry->d_name, ".css"))) {
486 if (strstr(cfg->http_css, entry->d_name)) {
487 tpl_printf(vars, 1, "CSSOPTIONS", "<option value=\"%s%s\" selected>%s%s</option>\n",cs_confdir,entry->d_name,cs_confdir,entry->d_name);
488 } else {
489 tpl_printf(vars, 1, "CSSOPTIONS", "<option value=\"%s%s\">%s%s</option>\n",cs_confdir,entry->d_name,cs_confdir,entry->d_name);
490 }
491 }
492 } while (entry);
493 closedir(hdir);
494
495 tpl_printf(vars, 0, "HTTPREFRESH", "%d", cfg->http_refresh);
496 tpl_addVar(vars, 0, "HTTPTPL", cfg->http_tpl);
497 tpl_addVar(vars, 0, "HTTPSCRIPT", cfg->http_script);
498 if (cfg->http_hide_idle_clients > 0) tpl_addVar(vars, 0, "CHECKED", "checked");
499
500 struct s_ip *cip;
501 char *dot="";
502 for (cip = cfg->mon_allowed; cip; cip = cip->next) {
503 tpl_printf(vars, 1, "NOCRYPT", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
504 if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "NOCRYPT", "-%s", cs_inet_ntoa(cip->ip[1]));
505 dot=",";
506 }
507
508 dot="";
509 for (cip = cfg->http_allowed; cip; cip = cip->next) {
510 tpl_printf(vars, 1, "HTTPALLOW", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
511 if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "HTTPALLOW", "-%s", cs_inet_ntoa(cip->ip[1]));
512 dot=",";
513 }
514
515 tpl_printf(vars, 0, "HTTPDYNDNS", "%s", cfg->http_dyndns);
516
517 //Monlevel selector
518 tpl_printf(vars, 0, "TMP", "MONSELECTED%d", cfg->mon_level);
519 tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
520
521 fputs(tpl_getTpl(vars, "CONFIGMONITOR"), f);
522}
523
524void send_oscam_config_serial(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
525 int i;
526 if (strcmp(getParam(params, "action"),"execute") == 0) {
527 //cfg->ser_device[0]='\0';
528 memset(cfg->ser_device, 0, sizeof(cfg->ser_device));
529 for(i = 0; i < (*params).paramcount; ++i) {
530 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
531 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
532 //we use the same function as used for parsing the config tokens
533 if((*params).values[i][0])
534 chk_t_serial((*params).params[i], (*params).values[i]);
535 }
536 }
537 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Serial done. You should restart Oscam now.</B><BR><BR>");
538 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
539 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
540 }
541
542 if (cfg->ser_device[0]){
543 char sdevice[512];
544 cs_strncpy(sdevice, cfg->ser_device, sizeof(sdevice));
545 char *ptr;
546 char delimiter[2]; delimiter[0] = 1; delimiter[1] = '\0';
547 ptr = strtok(sdevice, delimiter);
548 while(ptr != NULL) {
549 tpl_printf(vars, 0, "SERIALDEVICE", "%s", ptr);
550 tpl_addVar(vars, 1, "DEVICES", tpl_getTpl(vars, "CONFIGSERIALDEVICEBIT"));
551 ptr = strtok(NULL, delimiter);
552 }
553 }
554
555 tpl_printf(vars, 0, "SERIALDEVICE", "%s", "");
556 tpl_addVar(vars, 1, "DEVICES", tpl_getTpl(vars, "CONFIGSERIALDEVICEBIT"));
557
558 fputs(tpl_getTpl(vars, "CONFIGSERIAL"), f);
559}
560
561#ifdef HAVE_DVBAPI
562void send_oscam_config_dvbapi(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
563 int i;
564 if (strcmp(getParam(params, "action"),"execute") == 0) {
565 //clear tables
566 clear_caidtab(&cfg->dvbapi_prioritytab);
567 clear_caidtab(&cfg->dvbapi_ignoretab);
568 clear_caidtab(&cfg->dvbapi_delaytab);
569 for(i = 0; i < (*params).paramcount; ++i) {
570 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
571 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
572 //we use the same function as used for parsing the config tokens
573 chk_t_dvbapi((*params).params[i], (*params).values[i]);
574 }
575 }
576 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration DVB Api done. You should restart Oscam now.</B><BR><BR>");
577 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
578 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
579 }
580
581 if (cfg->dvbapi_enabled > 0)
582 tpl_addVar(vars, 0, "ENABLEDCHECKED", "checked");
583
584 if (cfg->dvbapi_au > 0)
585 tpl_addVar(vars, 0, "AUCHECKED", "checked");
586
587 tpl_printf(vars, 0, "BOXTYPE", "<option value=\"\"%s>None</option>\n", cfg->dvbapi_boxtype == 0 ? " selected" : "");
588 for (i=1; i<=BOXTYPES; i++) {
589 tpl_printf(vars, 1, "BOXTYPE", "<option%s>%s</option>\n", cfg->dvbapi_boxtype == i ? " selected" : "", boxdesc[i]);
590 }
591
592 if(cfg->dvbapi_usr[0])
593 tpl_addVar(vars, 0, "USER", cfg->dvbapi_usr);
594
595 //PMT Mode
596 tpl_printf(vars, 0, "TMP", "PMTMODESELECTED%d", cfg->dvbapi_pmtmode);
597 tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
598
599 i = 0;
600 char *dot = "";
601 ulong provid = 0;
602 while(cfg->dvbapi_prioritytab.caid[i]) {
603 tpl_printf(vars, 1, "PRIORITY", "%s%04X", dot, cfg->dvbapi_prioritytab.caid[i]);
604 if(cfg->dvbapi_prioritytab.mask[i]){
605 provid = (cfg->dvbapi_prioritytab.cmap[i] << 8 | cfg->dvbapi_prioritytab.mask[i]);
606 tpl_printf(vars, 1, "PRIORITY", ":%06lX", provid);
607 }
608 dot = ",";
609 i++;
610 }
611
612 i = 0;
613 dot = "";
614 provid = 0;
615 while(cfg->dvbapi_ignoretab.caid[i]) {
616 tpl_printf(vars, 1, "IGNORE", "%s%04X", dot, cfg->dvbapi_ignoretab.caid[i]);
617 if(cfg->dvbapi_ignoretab.mask[i]) {
618 provid = (cfg->dvbapi_ignoretab.cmap[i] << 8 | cfg->dvbapi_ignoretab.mask[i]);
619 tpl_printf(vars, 1, "IGNORE", ":%06lX", provid);
620 }
621 dot = ",";
622 i++;
623 }
624
625 i = 0;
626 dot = "";
627 while(cfg->dvbapi_delaytab.caid[i]) {
628 tpl_printf(vars, 1, "CWDELAY", "%s%04X", dot, cfg->dvbapi_delaytab.caid[i]);
629 tpl_printf(vars, 1, "CWDELAY", ":%d", cfg->dvbapi_delaytab.mask[i]);
630 dot = ",";
631 i++;
632 }
633
634 fputs(tpl_getTpl(vars, "CONFIGDVBAPI"), f);
635}
636#endif
637
638#ifdef CS_ANTICASC
639void send_oscam_config_anticasc(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
640 int i;
641 if (strcmp(getParam(params, "action"),"execute") == 0) {
642 for(i = 0; i < (*params).paramcount; ++i) {
643 if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))) {
644 tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
645 //we use the same function as used for parsing the config tokens
646 chk_t_ac((*params).params[i], (*params).values[i]);
647 }
648 }
649 tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Anticascading done. You should restart Oscam now.</B><BR><BR>");
650 refresh_oscam(REFR_ANTICASC, in);
651 if(write_config()==0) refresh_oscam(REFR_SERVER, in);
652 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
653 }
654 if (cfg->ac_enabled > 0) tpl_addVar(vars, 0, "CHECKED", "checked");
655 tpl_printf(vars, 0, "NUMUSERS", "%d", cfg->ac_users);
656 tpl_printf(vars, 0, "SAMPLETIME", "%d", cfg->ac_stime);
657 tpl_printf(vars, 0, "SAMPLES", "%d", cfg->ac_samples);
658 tpl_printf(vars, 0, "PENALTY", "%d", cfg->ac_penalty);
659 tpl_addVar(vars, 0, "ACLOGFILE", cfg->ac_logfile);
660 tpl_printf(vars, 0, "FAKEDELAY", "%d", cfg->ac_fakedelay);
661 tpl_printf(vars, 0, "DENYSAMPLES", "%d", cfg->ac_denysamples);
662 fputs(tpl_getTpl(vars, "CONFIGANTICASC"), f);
663}
664#endif
665
666void send_oscam_config(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
667 char *part = getParam(params, "part");
668 if (!strcmp(part,"camd33")) send_oscam_config_camd33(vars, f, params, in);
669 else if (!strcmp(part,"camd35")) send_oscam_config_camd35(vars, f, params, in);
670 else if (!strcmp(part,"camd35tcp")) send_oscam_config_camd35tcp(vars, f, params, in);
671 else if (!strcmp(part,"newcamd")) send_oscam_config_newcamd(vars, f, params, in);
672 else if (!strcmp(part,"radegast")) send_oscam_config_radegast(vars, f, params, in);
673 else if (!strcmp(part,"cccam")) send_oscam_config_cccam(vars, f, params, in);
674#ifdef CS_WITH_GBOX
675 else if (!strcmp(part,"gbox")) send_oscam_config_gbox(vars, f, params, in);
676#endif
677#ifdef HAVE_DVBAPI
678 else if (!strcmp(part,"dvbapi")) send_oscam_config_dvbapi(vars, f, params, in);
679#endif
680#ifdef CS_ANTICASC
681 else if (!strcmp(part,"anticasc")) send_oscam_config_anticasc(vars, f, params, in);
682#endif
683 else if (!strcmp(part,"monitor")) send_oscam_config_monitor(vars, f, params, in);
684 else if (!strcmp(part,"serial")) send_oscam_config_serial(vars, f, params, in);
685 else if (!strcmp(part,"loadbalancer")) send_oscam_config_loadbalancer(vars, f, params, in);
686 else send_oscam_config_global(vars, f, params, in);
687}
688
689void send_oscam_reader(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
690 int readeridx, isphysical = 0;
691 char *ctyp;
692 int i;
693 //uchar dummy[1]={0x00};
694
695 if (strcmp(getParam(params, "action"), "delete") == 0) {
696 reader[atoi(getParam(params, "reader"))].deleted = 1;
697 if(write_server()==0) {
698 refresh_oscam(REFR_READERS, in);
699 //printf("would kill now PID %d\n", reader[atoi(getParam(params, "reader"))].pid);
700 if(reader[atoi(getParam(params, "reader"))].pid)
701 kill(reader[atoi(getParam(params, "reader"))].pid, SIGQUIT);
702 }
703 else
704 tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
705 }
706
707 if (strcmp(getParam(params, "action"), "reread") == 0) {
708 readeridx = atoi(getParam(params, "ridx"));
709 //reset the counters
710 for (i = 0; i < 4; i++) {
711 reader[readeridx].emmerror[i] = 0;
712 reader[readeridx].emmwritten[i] = 0;
713 reader[readeridx].emmskipped[i] = 0;
714 reader[readeridx].emmblocked[i] = 0;
715 }
716 //write_to_pipe(client[reader[readeridx].cs_idx)].fd_m2c, PIP_ID_CIN, dummy, 1); // do not work for whatever reason
717 refresh_oscam(REFR_READERS, in); // refresh all reader because write pipe seams not work from here
718 }
719
720 for(readeridx = 0; readeridx < CS_MAXREADER && reader[readeridx].label[0]; readeridx++);
721 tpl_printf(vars, 0, "NEXTREADER", "Reader-%d", readeridx); //Next Readername
722
723 for(readeridx = 0; readeridx < CS_MAXREADER; readeridx++) {
724 isphysical = 0;
725
726 if(reader[readeridx].label[0] && reader[readeridx].typ && !reader[readeridx].deleted) {
727
728 tpl_printf(vars, 0, "READERIDX", "%d", readeridx);
729 tpl_addVar(vars, 0, "READERNAME", reader[readeridx].label);
730 tpl_addVar(vars, 0, "READERNAMEENC", tpl_addTmp(vars, urlencode(reader[readeridx].label)));
731
732 switch(reader[readeridx].typ) {
733 case R_MP35 :
734 ctyp = "mp35";
735 isphysical = 1;
736 break;
737 case R_MOUSE :
738 ctyp = "mouse";
739 isphysical = 1;
740 break;
741 case R_INTERNAL:
742 ctyp = "intern";
743 isphysical = 1;
744 break;
745 case R_SMART :
746 ctyp = "smartreader";
747 isphysical = 1;
748 break;
749 case R_SERIAL :
750 ctyp = "serial";
751 isphysical = 1;
752 break;
753 case R_DB2COM1 :
754 ctyp = "dbox COM1";
755 isphysical = 1;
756 break;
757 case R_DB2COM2 :
758 ctyp = "dbox COM2";
759 isphysical = 1;
760 break;
761 case R_CAMD35 : ctyp="camd 3.5x";break;
762 case R_CAMD33 : ctyp="camd 3.3x";break;
763 case R_NEWCAMD : ctyp="newcamd"; break;
764 case R_RADEGAST: ctyp="radegast"; break;
765#ifdef CS_WITH_GBOX
766 case R_GBOX : ctyp="gbox"; break;
767#endif
768#ifdef HAVE_PCSC
769 case R_PCSC :
770 ctyp="pcsc";
771 isphysical = 1;
772 break;
773#endif
774 case R_CCCAM : ctyp="cccam"; break;
775 case R_CS378X : ctyp="cs378x"; break;
776 default : ctyp="unknown"; break;
777 }
778
779 tpl_printf(vars, 0, "EMMERRORUK", "%d", reader[readeridx].emmerror[UNKNOWN]);
780 tpl_printf(vars, 0, "EMMERRORG", "%d", reader[readeridx].emmerror[GLOBAL]);
781 tpl_printf(vars, 0, "EMMERRORS", "%d", reader[readeridx].emmerror[SHARED]);
782 tpl_printf(vars, 0, "EMMERRORUQ", "%d", reader[readeridx].emmerror[UNIQUE]);
783
784 tpl_printf(vars, 0, "EMMWRITTENUK", "%d", reader[readeridx].emmwritten[UNKNOWN]);
785 tpl_printf(vars, 0, "EMMWRITTENG", "%d", reader[readeridx].emmwritten[GLOBAL]);
786 tpl_printf(vars, 0, "EMMWRITTENS", "%d", reader[readeridx].emmwritten[SHARED]);
787 tpl_printf(vars, 0, "EMMWRITTENUQ", "%d", reader[readeridx].emmwritten[UNIQUE]);
788
789 tpl_printf(vars, 0, "EMMSKIPPEDUK", "%d", reader[readeridx].emmskipped[UNKNOWN]);
790 tpl_printf(vars, 0, "EMMSKIPPEDG", "%d", reader[readeridx].emmskipped[GLOBAL]);
791 tpl_printf(vars, 0, "EMMSKIPPEDS", "%d", reader[readeridx].emmskipped[SHARED]);
792 tpl_printf(vars, 0, "EMMSKIPPEDUQ", "%d", reader[readeridx].emmskipped[UNIQUE]);
793
794 tpl_printf(vars, 0, "EMMBLOCKEDUK", "%d", reader[readeridx].emmblocked[UNKNOWN]);
795 tpl_printf(vars, 0, "EMMBLOCKEDG", "%d", reader[readeridx].emmblocked[GLOBAL]);
796 tpl_printf(vars, 0, "EMMBLOCKEDS", "%d", reader[readeridx].emmblocked[SHARED]);
797 tpl_printf(vars, 0, "EMMBLOCKEDUQ", "%d", reader[readeridx].emmblocked[UNIQUE]);
798
799 tpl_addVar(vars, 0, "DELICO", ICDEL);
800
801 //call stats
802 tpl_addVar(vars, 0, "STATICO", ICSTA);
803 tpl_printf(vars, 0, "READERID", "%d", readeridx);
804
805 if (isphysical == 1) {
806 tpl_printf(vars, 0, "RIDX", "%d", readeridx);
807 tpl_addVar(vars, 0, "REFRICO", ICREF);
808 tpl_addVar(vars, 0, "READERREFRESH", tpl_getTpl(vars, "READERREFRESHBIT"));
809
810 tpl_addVar(vars, 0, "ENTICO", ICENT);
811 tpl_addVar(vars, 0, "ENTITLEMENT", tpl_getTpl(vars, "READERENTITLEBIT"));
812
813 } else {
814 tpl_printf(vars, 0, "RIDX", "");
815 tpl_addVar(vars, 0, "READERREFRESH","");
816 if (reader[readeridx].typ == R_CCCAM) {
817 tpl_addVar(vars, 0, "ENTICO", ICENT);
818 tpl_addVar(vars, 0, "ENTITLEMENT", tpl_getTpl(vars, "READERENTITLEBIT"));
819 } else {
820 tpl_addVar(vars, 0, "ENTITLEMENT","");
821 }
822
823 }
824
825 tpl_addVar(vars, 0, "CTYP", ctyp);
826 tpl_addVar(vars, 0, "EDIICO", ICEDI);
827 tpl_addVar(vars, 1, "READERLIST", tpl_getTpl(vars, "READERSBIT"));
828 }
829 }
830 fputs(tpl_getTpl(vars, "READERS"), f);
831}
832
833void send_oscam_reader_config(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
834 int i, ridx=0;
835 char *reader_ = getParam(params, "reader");
836 char *value;
837
838 for(ridx = 0; ridx < CS_MAXREADER && reader[ridx].label[0]; ridx++); //last reader
839
840 if(strcmp(getParam(params, "action"), "Add") == 0) {
841 // Add new reader
842 memset(&reader[ridx], 0, sizeof(struct s_reader));
843 reader[ridx].enable = 1;
844 reader[ridx].tcp_rto = 30;
845 reader[ridx].show_cls = 10;
846 reader[ridx].maxqlen = CS_MAXQLEN;
847 reader[ridx].mhz = 357;
848 reader[ridx].cardmhz = 357;
849 reader[ridx].deprecated = 0;
850 reader[ridx].cachecm = 1;
851 strcpy(reader[ridx].pincode, "none");
852 reader[ridx].ndsversion = 0;
853 for (i = 1; i < CS_MAXCAIDTAB; reader[ridx].ctab.mask[i++] = 0xffff);
854 for (i = 0; i < (*params).paramcount; ++i) {
855 if (strcmp((*params).params[i], "action"))
856 chk_reader((*params).params[i], (*params).values[i], &reader[ridx]);
857 }
858 reader_ = reader[ridx].label;
859
860 } else if(strcmp(getParam(params, "action"), "Save") == 0) {
861 for(ridx = 0; ridx < CS_MAXREADER && strcmp(reader_, reader[ridx].label) != 0; ++ridx);
862 char servicelabels[255]="";
863
864 clear_caidtab(&reader[ridx].ctab);
865 clear_ftab(&reader[ridx].ftab);
866 clear_ftab(&reader[ridx].fchid);
867
868 reader[ridx].grp = 0;
869 reader[ridx].auprovid = 0;
870 for(i = 0; i < (*params).paramcount; ++i) {
871 if ((strcmp((*params).params[i], "reader")) && (strcmp((*params).params[i], "action"))) {
872 if (!strcmp((*params).params[i], "services"))
873 snprintf(servicelabels + strlen(servicelabels), sizeof(servicelabels), "%s,", (*params).values[i]);
874 else
875 if(strlen((*params).values[i]) > 0)
876 chk_reader((*params).params[i], (*params).values[i], &reader[ridx]);
877 }
878 //printf("param %s value %s\n",(*params).params[i], (*params).values[i]);
879 }
880 chk_reader("services", servicelabels, &reader[ridx]);
881 if(write_server()==0) refresh_oscam(REFR_READERS, in);
882 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
883 }
884
885 for(ridx = 0; ridx < CS_MAXREADER && strcmp(reader_, reader[ridx].label) != 0; ++ridx);
886
887 tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
888 if(reader[ridx].enable)
889 tpl_addVar(vars, 0, "ENABLED", "checked");
890
891 tpl_printf(vars, 0, "ACCOUNT", "%s,%s\n", reader[ridx].r_usr, reader[ridx].r_pwd);
892 for (i=0; i<14; i++) tpl_printf(vars, 1, "NCD_KEY", "%02X", reader[ridx].ncd_key[i]);
893 tpl_addVar(vars, 0, "PINCODE", reader[ridx].pincode);
894 //tpl_addVar(vars, 0, "EMMFILE", (char *)reader[ridx].emmfile);
895 tpl_printf(vars, 0, "INACTIVITYTIMEOUT", "%d", reader[ridx].tcp_ito);
896 tpl_printf(vars, 0, "RECEIVETIMEOUT", "%d", reader[ridx].tcp_rto);
897 tpl_printf(vars, 0, "DISABLESERVERFILTER", "%d", reader[ridx].ncd_disable_server_filt);
898 if(reader[ridx].fallback)
899 tpl_addVar(vars, 0, "FALLBACKCHECKED", "checked");
900 tpl_printf(vars, 0, "LOGPORT", "%d", reader[ridx].log_port);
901 tpl_printf(vars, 0, "BOXID", "%08X", reader[ridx].boxid);
902 tpl_addVar(vars, 0, "USER", reader[ridx].r_usr);
903 tpl_addVar(vars, 0, "PASS", reader[ridx].r_pwd);
904
905 if(reader[ridx].audisabled)
906 tpl_addVar(vars, 0, "AUDISABLED", "checked");
907
908 if(reader[ridx].auprovid)
909 tpl_printf(vars, 0, "AUPROVID", "%06lX", reader[ridx].auprovid);
910
911 if(reader[ridx].force_irdeto)
912 tpl_addVar(vars, 0, "FORCEIRDETOCHECKED", "checked");
913
914 //check for tiger
915 int tigerkey = 0;
916 for (i=64;i<120;i++) {
917 if(reader[ridx].rsa_mod[i] > 0) {
918 tigerkey = 1;
919 break;
920 }
921 }
922
923 if(reader[ridx].has_rsa) {
924 if (!tigerkey) {
925 for (i = 0; i < 64; i++) tpl_printf(vars, 1, "RSAKEY", "%02X", reader[ridx].rsa_mod[i]);
926 for (i = 0; i < 8 ; i++) tpl_printf(vars, 1, "BOXKEY", "%02X", reader[ridx].nagra_boxkey[i]);
927 }
928 }
929 if (tigerkey) {
930 for (i = 0; i < 120; i++) tpl_printf(vars, 1, "TIGERRSAKEY", "%02X", reader[ridx].rsa_mod[i]);
931 for (i = 0; i < 8 ; i++) tpl_printf(vars, 1, "BOXKEY", "%02X", reader[ridx].nagra_boxkey[i]);
932 }
933
934 if ( reader[ridx].atr[0])
935 for (i = 0; i < reader[ridx].atrlen/2; i++)
936 tpl_printf(vars, 1, "ATR", "%02X", reader[ridx].atr[i]);
937
938 if(reader[ridx].smargopatch)
939 tpl_addVar(vars, 0, "SMARGOPATCHCHECKED", "checked");
940
941 if (reader[ridx].detect&0x80)
942 tpl_printf(vars, 0, "DETECT", "!%s", RDR_CD_TXT[reader[ridx].detect&0x7f]);
943 else
944 tpl_printf(vars, 0, "DETECT", "%s", RDR_CD_TXT[reader[ridx].detect&0x7f]);
945
946 tpl_printf(vars, 0, "MHZ", "%d", reader[ridx].mhz);
947 tpl_printf(vars, 0, "CARDMHZ", "%d", reader[ridx].cardmhz);
948
949#ifdef CS_WITH_GBOX
950 tpl_addVar(vars, 0, "GBOXPWD", (char *)reader[ridx].gbox_pwd);
951 tpl_addVar(vars, 0, "PREMIUM", reader[ridx].gbox_prem);
952#endif
953
954 tpl_printf(vars, 0, "DEVICE", "%s", reader[ridx].device);
955 if(reader[ridx].r_port)
956 tpl_printf(vars, 1, "DEVICE", ",%d", reader[ridx].r_port);
957 if(reader[ridx].l_port) {
958 if(reader[ridx].r_port)
959 tpl_printf(vars, 1, "DEVICE", ",%d", reader[ridx].l_port);
960 else
961 tpl_printf(vars, 1, "DEVICE", ",,%d", reader[ridx].l_port);
962 }
963
964 //group
965 value = mk_t_group((ulong*)reader[ridx].grp);
966 tpl_printf(vars, 0, "GRP", "%s", value);
967 free(value);
968
969 if(reader[ridx].lb_weight)
970 tpl_printf(vars, 0, "LBWEIGHT", "%d", reader[ridx].lb_weight);
971
972 //services
973 char sidok[33];
974 long2bitchar(reader[ridx].sidtabok, sidok);
975 char sidno[33];
976 long2bitchar(reader[ridx].sidtabno,sidno);
977 struct s_sidtab *sidtab = cfg->sidtab;
978 //build matrix
979 i = 0;
980 while(sidtab != NULL) {
981 tpl_addVar(vars, 0, "SIDLABEL", sidtab->label);
982 if(sidok[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
983 else tpl_addVar(vars, 0, "CHECKED", "");
984 tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDOKBIT"));
985 if(sidno[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
986 else tpl_addVar(vars, 0, "CHECKED", "");
987 tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDNOBIT"));
988 sidtab=sidtab->next;
989 i++;
990 }
991
992 // CAID
993 value = mk_t_caidtab(&reader[ridx].ctab);
994 tpl_addVar(vars, 0, "CAIDS", value);
995 free(value);
996
997 //ident
998 value = mk_t_ftab(&reader[ridx].ftab);
999 tpl_printf(vars, 0, "IDENTS", "%s", value);
1000 free(value);
1001
1002 //CHID
1003 value = mk_t_ftab(&reader[ridx].fchid);
1004 tpl_printf(vars, 0, "CHIDS", "%s", value);
1005 free(value);
1006
1007 //class
1008 CLASSTAB *clstab = &reader[ridx].cltab;
1009 char *dot="";
1010 for(i = 0; i < clstab->an; ++i) {
1011 tpl_printf(vars, 1, "CLASS", "%s%02x", dot, (int)clstab->aclass[i]);
1012 dot=",";
1013 }
1014
1015 for(i = 0; i < clstab->bn; ++i) {
1016 tpl_printf(vars, 0, "CLASS", "%s!%02x", dot, (int)clstab->bclass[i]);
1017 dot=",";
1018 }
1019
1020 tpl_printf(vars, 0, "SHOWCLS", "%d", reader[ridx].show_cls);
1021 tpl_printf(vars, 0, "MAXQLEN", "%d", reader[ridx].maxqlen);
1022
1023 if(reader[ridx].cachemm)
1024 tpl_printf(vars, 0, "EMMCACHE", "%d,%d,%d", reader[ridx].cachemm, reader[ridx].rewritemm, reader[ridx].logemm);
1025
1026 //savenano
1027 int all = 1;
1028 dot="";
1029 for(i = 0; i < 256; ++i) {
1030 if(!(reader[ridx].b_nano[i] & 0x02)) {
1031 all = 0;
1032 break;
1033 }
1034 }
1035 if (all == 1) tpl_addVar(vars, 0, "SAVENANO", "all");
1036 else {
1037 for(i = 0; i < 256; ++i) {
1038 if(reader[ridx].b_nano[i] & 0x02) tpl_printf(vars, 1, "SAVENANO", "%s%02x\n", dot, i);
1039 dot=",";
1040 }
1041 }
1042
1043 //blocknano
1044 dot="";
1045 for(i = 0; i < 256; ++i) {
1046 if(!(reader[ridx].b_nano[i] & 0x01)) {
1047 all = 0;
1048 break;
1049 }
1050 }
1051 if (all == 1) tpl_addVar(vars, 0, "BLOCKNANO", "all");
1052 else {
1053 for(i = 0; i < 256; ++i) {
1054 if(reader[ridx].b_nano[i] & 0x01) tpl_printf(vars, 1, "BLOCKNANO", "%s%02x\n", dot, i);
1055 dot=",";
1056 }
1057 }
1058
1059 if (reader[ridx].cachecm)
1060 tpl_addVar(vars, 0, "ECMCACHECHECKED", "checked");
1061
1062 if (reader[ridx].blockemm_unknown)
1063 tpl_addVar(vars, 0, "BLOCKEMMUNKNOWNCHK", "checked");
1064 if (reader[ridx].blockemm_u)
1065 tpl_addVar(vars, 0, "BLOCKEMMUNIQCHK", "checked");
1066 if (reader[ridx].blockemm_s)
1067 tpl_addVar(vars, 0, "BLOCKEMMSHAREDCHK", "checked");
1068 if (reader[ridx].blockemm_g)
1069 tpl_addVar(vars, 0, "BLOCKEMMGLOBALCHK", "checked");
1070
1071 if (reader[ridx].deprecated)
1072 tpl_addVar(vars, 0, "DEPRECATEDCHCHECKED", "checked");
1073
1074 if (!strcmp(reader[ridx].cc_version, "2.0.11")) {
1075 tpl_addVar(vars, 0, "CCCVERSIONSELECTED0", "selected");
1076 } else if (!strcmp(reader[ridx].cc_version, "2.1.1")) {
1077 tpl_addVar(vars, 0, "CCCVERSIONSELECTED1", "selected");
1078 } else if (!strcmp(reader[ridx].cc_version, "2.1.2")) {
1079 tpl_addVar(vars, 0, "CCCVERSIONSELECTED2", "selected");
1080 } else if (!strcmp(reader[ridx].cc_version, "2.1.3")) {
1081 tpl_addVar(vars, 0, "CCCVERSIONSELECTED3", "selected");
1082 } else if (!strcmp(reader[ridx].cc_version, "2.1.4")) {
1083 tpl_addVar(vars, 0, "CCCVERSIONSELECTED4", "selected");
1084 }
1085
1086 tpl_printf(vars, 0, "TMP", "NDSVERSION%d", reader[ridx].ndsversion);
1087 tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
1088
1089 tpl_printf(vars, 0, "CCCMAXHOP", "%d", reader[ridx].cc_maxhop);
1090 if (reader[ridx].cc_disable_retry_ecm)
1091 tpl_addVar(vars, 0, "CCCDISABLERETRYECMCHECKED", "checked");
1092 if (reader[ridx].cc_disable_auto_block)
1093 tpl_addVar(vars, 0, "CCCDISABLEAUTOBLOCKCHECKED", "checked");
1094 if(reader[ridx].cc_want_emu)
1095 tpl_addVar(vars, 0, "CCCWANTEMUCHECKED", "checked");
1096
1097 if(reader[ridx].cc_keepalive)
1098 tpl_addVar(vars, 0, "KEEPALIVECHECKED", "selected");
1099
1100 // Show only parameters which needed for the reader
1101 switch (reader[ridx].typ) {
1102 case R_CONSTCW:
1103 tpl_addVar(vars, 0, "PROTOCOL", "constcw");
1104 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
1105 break;
1106 case R_DB2COM1:
1107 case R_DB2COM2:
1108 case R_MOUSE :
1109 tpl_addVar(vars, 0, "PROTOCOL", "mouse");
1110 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
1111 break;
1112 case R_MP35:
1113 tpl_addVar(vars, 0, "PROTOCOL", "mp35");
1114 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
1115 break;
1116 case R_SC8in1 :
1117 tpl_addVar(vars, 0, "PROTOCOL", "sc8in1");
1118 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
1119 break;
1120 case R_SMART :
1121 tpl_addVar(vars, 0, "PROTOCOL", "smartreader");
1122 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
1123 break;
1124 case R_INTERNAL:
1125 tpl_addVar(vars, 0, "PROTOCOL", "internal");
1126 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
1127 break;
1128 case R_SERIAL :
1129 tpl_addVar(vars, 0, "PROTOCOL", "serial");
1130 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
1131 break;
1132 case R_CAMD35 :
1133 tpl_addVar(vars, 0, "PROTOCOL", "camd35");
1134 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGCAMD35BIT"));
1135 break;
1136 case R_CS378X :
1137 tpl_addVar(vars, 0, "PROTOCOL", "cs378x");
1138 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGCS378XBIT"));
1139 break;
1140 case R_RADEGAST:
1141 tpl_addVar(vars, 0, "PROTOCOL", "radegast");
1142 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGRADEGASTBIT"));
1143 break;
1144 case R_NEWCAMD :
1145 if ( reader[ridx].ncd_proto == NCD_525 ){
1146 tpl_addVar(vars, 0, "PROTOCOL", "newcamd525");
1147 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGNCD525BIT"));
1148 } else if ( reader[ridx].ncd_proto == NCD_524 ) {
1149 tpl_addVar(vars, 0, "PROTOCOL", "newcamd524");
1150 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGNCD524BIT"));
1151 }
1152 break;
1153 case R_CCCAM :
1154 tpl_addVar(vars, 0, "PROTOCOL", "cccam");
1155 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGCCCAMBIT"));
1156 break;
1157#ifdef CS_WITH_GBOX
1158 case R_GBOX :
1159 tpl_addVar(vars, 0, "PROTOCOL", "gbox");
1160 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGGBOXBIT"));
1161 break;
1162#endif
1163#ifdef HAVE_PCSC
1164 case R_PCSC :
1165 tpl_addVar(vars, 0, "PROTOCOL", "pcsc");
1166 tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSTDHWREADERBIT"));
1167 break;
1168#endif
1169 default :
1170 tpl_addVar(vars, 1, "MESSAGE", "<b>Error: protocol not resolvable</b><BR>");
1171 tpl_printf(vars, 1, "MESSAGE", "<b>Error: protocol number: %d readername: %s readeridx: %d</b><BR>", reader[ridx].typ, reader[ridx].label, ridx);
1172 break;
1173
1174 }
1175 //READERCONFIGMOUSEBIT
1176 fputs(tpl_getTpl(vars, "READERCONFIG"), f);
1177}
1178
1179void send_oscam_reader_stats(struct templatevars *vars, FILE *f, struct uriparams *params) {
1180 int readeridx = atoi(getParam(params, "reader"));
1181
1182 tpl_printf(vars, 0, "READERNAME", "%s",reader[readeridx].label);
1183
1184 char *stxt[]={"found", "cache1", "cache2", "emu",
1185 "not found", "timeout", "sleeping",
1186 "fake", "invalid", "corrupt", "no card", "expdate", "disabled", "stopped"};
1187
1188 char fname[40];
1189 sprintf(fname, "%s/stat.%d", get_tmp_dir(), readeridx);
1190 FILE *file = fopen(fname, "r");
1191 if (file){
1192
1193 int i = 0;
1194 int rc, caid, servid, time_avg, ecm_count;
1195 long prid, last_received;
1196 struct s_srvid *srvid = cfg->srvid;
1197
1198 do
1199 {
1200 i = fscanf(file, "rc %d caid %04X prid %06lX srvid %04X time avg %dms ecms %d last %ld\n",
1201 &rc, &caid, &prid, &servid, &time_avg, &ecm_count, &last_received);
1202
1203 if (i > 4) {
1204 tpl_printf(vars, 0, "CHANNEL", "%04X:%06lX:%04X", caid, prid, servid);
1205
1206 int j, found = 0;
1207 srvid = cfg->srvid;
1208
1209 while (srvid != NULL) {
1210 if (srvid->srvid == servid) {
1211 for (j=0; j < srvid->ncaid; j++) {
1212 if (srvid->caid[j] == caid) {
1213 found = 1;
1214 break;
1215 }
1216 }
1217 }
1218 if (found == 1)
1219 break;
1220 else
1221 srvid = srvid->next;
1222 }
1223
1224 if (found == 1)
1225 tpl_printf(vars, 0, "CHANNELNAME","%s : %s", srvid->prov, srvid->name);
1226 else
1227 tpl_addVar(vars, 0, "CHANNELNAME","unknown");
1228
1229
1230 tpl_printf(vars, 0, "RC", "%s", stxt[rc]);
1231 tpl_printf(vars, 0, "TIME", "%dms", time_avg);
1232 tpl_printf(vars, 0, "COUNT", "%d", ecm_count);
1233
1234 if(last_received) {
1235 struct tm *lt = localtime(&last_received);
1236 tpl_printf(vars, 0, "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);
1237 } else {
1238 tpl_addVar(vars, 0, "LAST","never");
1239 }
1240
1241
1242 tpl_addVar(vars, 1, "READERSTATSROW", tpl_getTpl(vars, "READERSTATSBIT"));
1243 }
1244
1245 } while(i != EOF && i > 0);
1246 fclose(file);
1247
1248 } else {
1249 tpl_addVar(vars, 1, "READERSTATSROW","<TR><TD colspan=\"6\"> No statisticsfile found </TD></TR>");
1250 }
1251
1252 fputs(tpl_getTpl(vars, "READERSTATS"), f);
1253}
1254
1255void send_oscam_user_config_edit(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
1256 struct s_auth *account, *ptr;
1257 char user[128];
1258
1259 if (strcmp(getParam(params, "action"), "Save As") == 0) cs_strncpy(user, getParam(params, "newuser"), sizeof(user)/sizeof(char));
1260 else cs_strncpy(user, getParam(params, "user"), sizeof(user)/sizeof(char));
1261
1262 int i;
1263
1264 for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
1265
1266 // Create a new user if it doesn't yet
1267 if (account == NULL) {
1268 i = 1;
1269 while(strlen(user) < 1) {
1270 snprintf(user, sizeof(user)/sizeof(char) - 1, "NEWUSER%d", i);
1271 for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
1272 if(account != NULL) user[0] = '\0';
1273 ++i;
1274 }
1275 if (!(account=malloc(sizeof(struct s_auth)))) {
1276 cs_log("Error allocating memory (errno=%d)", errno);
1277 return;
1278 }
1279 if(cfg->account == NULL) cfg->account = account;
1280 else {
1281 for (ptr = cfg->account; ptr != NULL && ptr->next != NULL; ptr = ptr->next);
1282 ptr->next = account;
1283 }
1284 memset(account, 0, sizeof(struct s_auth));
1285 cs_strncpy((char *)account->usr, user, sizeof(account->usr));
1286 account->au=(-1);
1287 account->monlvl=cfg->mon_level;
1288 account->tosleep=cfg->tosleep;
1289 for (i=1; i<CS_MAXCAIDTAB; account->ctab.mask[i++]=0xffff);
1290 for (i=1; i<CS_MAXTUNTAB; account->ttab.bt_srvid[i++]=0x0000);
1291 account->expirationdate=(time_t)NULL;
1292#ifdef CS_ANTICASC
1293 account->ac_users=cfg->ac_users;
1294 account->ac_penalty=cfg->ac_penalty;
1295 account->ac_idx = account->ac_idx + 1;
1296#endif
1297 tpl_addVar(vars, 1, "MESSAGE", "<b>New user has been added with default settings</b><BR>");
1298 refresh_oscam(REFR_ACCOUNTS, in);
1299 // need to reget account as writing to disk changes account!
1300 for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
1301 }
1302
1303 if((strcmp(getParam(params, "action"), "Save") == 0) || (strcmp(getParam(params, "action"), "Save As") == 0)) {
1304 char servicelabels[255]="";
1305 //clear group
1306 account->grp = 0;
1307 //clear caidtab before it re-readed by chk_t
1308 clear_caidtab(&account->ctab);
1309 //clear Betatunnel before it re-readed by chk_t
1310 clear_tuntab(&account->ttab);
1311 //clear ident before it re-readed by chk_t
1312 clear_ftab(&account->ftab);
1313 //clear CHID before it re-readed by chk_t
1314 clear_ftab(&account->fchid);
1315
1316 for(i=0;i<(*params).paramcount;i++) {
1317 if ((strcmp((*params).params[i], "action")) && (strcmp((*params).params[i], "user")) && (strcmp((*params).params[i], "newuser"))) {
1318 if (!strcmp((*params).params[i], "expdate"))
1319 account->expirationdate=(time_t)NULL;
1320 if (!strcmp((*params).params[i], "services"))
1321 snprintf(servicelabels + strlen(servicelabels), sizeof(servicelabels), "%s,", (*params).values[i]);
1322 else
1323 chk_account((*params).params[i], (*params).values[i], account);
1324 }
1325 }
1326 chk_account("services", servicelabels, account);
1327 tpl_addVar(vars, 1, "MESSAGE", "<B>Settings updated</B><BR><BR>");
1328 refresh_oscam(REFR_ACCOUNTS, in);
1329 }
1330 for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
1331
1332 tpl_addVar(vars, 0, "USERNAME", account->usr);
1333 tpl_addVar(vars, 0, "PASSWORD", account->pwd);
1334
1335 //Disabled
1336 if(account->disabled)
1337 tpl_addVar(vars, 0, "DISABLEDCHECKED", "selected");
1338
1339 //Expirationdate
1340 struct tm * timeinfo = localtime (&account->expirationdate);
1341 char buf [80];
1342 strftime (buf,80,"%Y-%m-%d",timeinfo);
1343 if(strcmp(buf,"1970-01-01")) tpl_addVar(vars, 0, "EXPDATE", buf);
1344
1345 if(account->allowedtimeframe[0] && account->allowedtimeframe[1]) {
1346 tpl_printf(vars, 0, "ALLOWEDTIMEFRAME", "%02d:%02d-%02d:%02d",
1347 account->allowedtimeframe[0]/60,
1348 account->allowedtimeframe[0]%60,
1349 account->allowedtimeframe[1]/60,
1350 account->allowedtimeframe[1]%60 );
1351 }
1352
1353 //Group
1354 char *value = mk_t_group((ulong*)account->grp);
1355 tpl_addVar(vars, 0, "GROUPS", value);
1356 free(value);
1357
1358 //Hostname
1359 tpl_addVar(vars, 0, "DYNDNS", (char *)account->dyndns);
1360
1361 //Uniq
1362 tpl_printf(vars, 0, "TMP", "UNIQSELECTED%d", account->uniq);
1363 tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
1364
1365 //Sleep
1366 if(!account->tosleep) tpl_addVar(vars, 0, "SLEEP", "0");
1367 else tpl_printf(vars, 0, "SLEEP", "%d", account->tosleep);
1368 //Monlevel selector
1369 tpl_printf(vars, 0, "TMP", "MONSELECTED%d", account->monlvl);
1370 tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
1371
1372 //AU Selector
1373 if (!account->au) tpl_addVar(vars, 0, "AUSELECTED", "selected");
1374 if (account->autoau == 1) tpl_addVar(vars, 0, "AUTOAUSELECTED", "selected");
1375 int ridx;
1376 for (ridx=0; ridx<CS_MAXREADER; ridx++) {
1377 if(!reader[ridx].device[0]) break;
1378 tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
1379 if (account->au == ridx) tpl_addVar(vars, 0, "SELECTED", "selected");
1380 else tpl_addVar(vars, 0, "SELECTED", "");
1381 tpl_addVar(vars, 1, "RDROPTION", tpl_getTpl(vars, "USEREDITRDRSELECTED"));
1382 }
1383
1384 /* SERVICES */
1385 //services - first we have to move the long sidtabok/sidtabno to a binary array
1386 char sidok[33];
1387 long2bitchar(account->sidtabok,sidok);
1388 char sidno[33];
1389 long2bitchar(account->sidtabno,sidno);
1390 struct s_sidtab *sidtab = cfg->sidtab;
1391 //build matrix
1392 i=0;
1393 while(sidtab != NULL) {
1394 tpl_addVar(vars, 0, "SIDLABEL", sidtab->label);
1395 if(sidok[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
1396 else tpl_addVar(vars, 0, "CHECKED", "");
1397 tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "USEREDITSIDOKBIT"));
1398 if(sidno[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
1399 else tpl_addVar(vars, 0, "CHECKED", "");
1400 tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "USEREDITSIDNOBIT"));
1401 sidtab=sidtab->next;
1402 i++;
1403 }
1404
1405 // CAID
1406 value = mk_t_caidtab(&account->ctab);
1407 tpl_addVar(vars, 0, "CAIDS", value);
1408 free(value);
1409
1410 //ident
1411 value = mk_t_ftab(&account->ftab);
1412 tpl_printf(vars, 0, "IDENTS", "%s", value);
1413 free(value);
1414
1415 //CHID
1416 value = mk_t_ftab(&account->fchid);
1417 tpl_printf(vars, 0, "CHIDS", "%s", value);
1418 free(value);
1419
1420 //Betatunnel
1421 value = mk_t_tuntab(&account->ttab);
1422 tpl_addVar(vars, 0, "BETATUNNELS", value);
1423 free(value);
1424
1425 //SUPPRESSCMD08
1426 if (account->c35_suppresscmd08)
1427 tpl_addVar(vars, 0, "SUPPRESSCMD08", "selected");
1428
1429 //Sleepsend
1430 tpl_printf(vars, 0, "SLEEPSEND", "%d", account->c35_sleepsend);
1431
1432 //Keepalive
1433 if (account->ncd_keepalive)
1434 tpl_addVar(vars, 0, "KEEPALIVE", "selected");
1435
1436#ifdef CS_ANTICASC
1437 tpl_printf(vars, 0, "AC_USERS", "%d", account->ac_users);
1438 tpl_printf(vars, 0, "AC_PENALTY", "%d", account->ac_penalty);
1439#endif
1440
1441 tpl_printf(vars, 0, "CCCMAXHOPS", "%d", account->cccmaxhops);
1442 tpl_printf(vars, 0, "CCCRESHARE", "%d", account->cccreshare);
1443
1444 fputs(tpl_getTpl(vars, "USEREDIT"), f);
1445}
1446
1447void send_oscam_user_config(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
1448 struct s_auth *account, *account2;
1449 char *user = getParam(params, "user");
1450 int i, found = 0;
1451 int hideclient = 10;
1452
1453 if (cfg->mon_hideclient_to > 10)
1454 hideclient = cfg->mon_hideclient_to;
1455
1456 if (strcmp(getParam(params, "action"), "reinit") == 0) {
1457 if(!cfg->http_readonly)
1458 refresh_oscam(REFR_ACCOUNTS, in);
1459 }
1460
1461 if (strcmp(getParam(params, "action"), "delete") == 0) {
1462 if(cfg->http_readonly) {
1463 tpl_addVar(vars, 1, "MESSAGE", "<b>Webif is in readonly mode. No deletion will be made!</b><BR>");
1464 } else {
1465 account = cfg->account;
1466 if(strcmp(account->usr, user) == 0) {
1467 cfg->account = account->next;
1468 free(account);
1469 found = 1;
1470 } else if (account->next != NULL) {
1471 do {
1472 if(strcmp(account->next->usr, user) == 0) {
1473 account2 = account->next;
1474 account->next = account2->next;
1475 free(account2);
1476 found = 1;
1477 break;
1478 }
1479 }while ((account = account->next) && (account->next != NULL));
1480 }
1481
1482 if (found > 0) {
1483 tpl_addVar(vars, 1, "MESSAGE", "<b>Account has been deleted!</b><BR>");
1484 refresh_oscam(REFR_ACCOUNTS, in);
1485 } else tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
1486 }
1487 }
1488
1489
1490
1491 if ((strcmp(getParam(params, "action"), "disable") == 0) || (strcmp(getParam(params, "action"), "enable") == 0)) {
1492 for (account=cfg->account; (account); account=account->next) {
1493 if(strcmp(getParam(params, "user"), account->usr) == 0) {
1494 if(strcmp(getParam(params, "action"), "disable") == 0)
1495 account->disabled = 1;
1496 else
1497 account->disabled = 0;
1498 found = 1;
1499 }
1500 }
1501
1502 if (found > 0) {
1503 tpl_addVar(vars, 1, "MESSAGE", "<b>Account has been switched!</b><BR>");
1504 refresh_oscam(REFR_ACCOUNTS, in);
1505 } else tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
1506 }
1507
1508 /* List accounts*/
1509 char *status = "offline";
1510 char *expired = "";
1511 char *classname="offline";
1512 char *lastchan="&nbsp;";
1513 time_t now = time((time_t)0);
1514 int isec = 0, isonline = 0;
1515
1516 //for (account=cfg->account; (account); account=account->next) {
1517 for (account=cfg->account; (account); account=account->next) {
1518 //clear for next client
1519 expired = ""; classname = "offline"; status = "offline";
1520 isonline = 0;
1521 tpl_addVar(vars, 0, "CWOK", "");
1522 tpl_addVar(vars, 0, "CWNOK", "");
1523 tpl_addVar(vars, 0, "CWIGN", "");
1524 tpl_addVar(vars, 0, "CWTOUT", "");
1525 tpl_addVar(vars, 0, "CWCACHE", "");
1526 tpl_addVar(vars, 0, "CWTUN", "");
1527 tpl_addVar(vars, 0, "CLIENTPROTO","");
1528 tpl_addVar(vars, 0, "IDLESECS","");
1529 tpl_addVar(vars, 0, "CWLASTRESPONSET","");
1530 tpl_addVar(vars, 0, "EMMOK","");
1531 tpl_addVar(vars, 0, "EMMNOK","");
1532 tpl_addVar(vars, 0, "CLIENTPROTO","");
1533 tpl_addVar(vars, 0, "LASTCHANNEL", "");
1534
1535 if(account->expirationdate && account->expirationdate<time(NULL)) {
1536 expired = " (expired)";
1537 classname = "expired";
1538 }
1539 if(account->disabled != 0) {
1540 expired = " (disabled)";
1541 classname = "disabled";
1542 tpl_addVar(vars, 0, "SWITCHICO", ICENA);
1543 tpl_addVar(vars, 0, "SWITCHTITLE", "enable this account");
1544 tpl_addVar(vars, 0, "SWITCH", "enable");
1545 } else {
1546 tpl_addVar(vars, 0, "SWITCHICO", ICDIS);
1547 tpl_addVar(vars, 0, "SWITCHTITLE", "disable this account");
1548 tpl_addVar(vars, 0, "SWITCH", "disable");
1549 }
1550
1551 //search account in active clients
1552 int cwok = 0, cwnok = 0, cwign = 0, cwtout = 0, cwcache = 0, cwtun = 0, emmok = 0, emmnok = 0;
1553 int secs = 0, fullmins =0, mins =0, hours =0, lastresponsetm = 0;
1554 char *proto = "";
1555
1556 for (i=0; i<CS_MAXPID; i++)
1557 if (!strcmp(client[i].usr, account->usr)) {
1558 //set client to offline depending on hideclient_to
1559 if ((now - client[i].lastecm) < hideclient) {
1560 status = "<b>online</b>"; classname="online";
1561 isonline = 1;
1562 proto = monitor_get_proto(i);
1563 lastchan = get_servicename(client[i].last_srvid, client[i].last_caid);
1564 lastresponsetm = client[i].cwlastresptime;
1565 isec = now - client[i].last;
1566 if(isec > 0) {
1567 secs = isec % 60;
1568 if (isec > 60) {
1569 fullmins = isec / 60;
1570 mins = fullmins % 60;
1571 if(fullmins > 60) hours = fullmins / 60;
1572 }
1573 }
1574 }
1575
1576 cwok += client[i].cwfound;
1577 cwnok += client[i].cwnot;
1578 cwign += client[i].cwignored;
1579 cwtout += client[i].cwtout;
1580 cwcache += client[i].cwcache;
1581 cwtun += client[i].cwtun;
1582 emmok += client[i].emmok;
1583 emmnok += client[i].emmnok;
1584 }
1585
1586 if ( isonline > 0 ) {
1587 tpl_printf(vars, 0, "CWOK", "%d", cwok);
1588 tpl_printf(vars, 0, "CWNOK", "%d", cwnok);
1589 tpl_printf(vars, 0, "CWIGN", "%d", cwign);
1590 tpl_printf(vars, 0, "CWTOUT", "%d", cwtout);
1591 tpl_printf(vars, 0, "CWCACHE", "%d", cwcache);
1592 tpl_printf(vars, 0, "CWTUN", "%d", cwtun);
1593 tpl_printf(vars, 0, "EMMOK", "%d", emmok);
1594 tpl_printf(vars, 0, "EMMNOK", "%d", emmnok);
1595 tpl_addVar(vars, 0, "LASTCHANNEL", lastchan);
1596 tpl_printf(vars, 0, "CWLASTRESPONSET", "%d", lastresponsetm);
1597 tpl_addVar(vars, 0, "CLIENTPROTO", proto);
1598 tpl_printf(vars, 0, "IDLESECS", "%02d:%02d:%02d", hours, mins, secs);
1599
1600 }
1601
1602 tpl_addVar(vars, 0, "CLASSNAME", classname);
1603 tpl_addVar(vars, 0, "USER", account->usr);
1604 tpl_addVar(vars, 0, "USERENC", tpl_addTmp(vars, urlencode(account->usr)));
1605 tpl_addVar(vars, 0, "STATUS", status);
1606 tpl_addVar(vars, 0, "EXPIRED", expired);
1607 tpl_addVar(vars, 0, "DELICO", ICDEL);
1608 tpl_addVar(vars, 0, "EDIICO", ICEDI);
1609
1610 tpl_addVar(vars, 1, "USERCONFIGS", tpl_getTpl(vars, "USERCONFIGLISTBIT"));
1611 isec = 0;
1612 lastchan = "&nbsp;";
1613 }
1614
1615 if ((strcmp(getParam(params, "part"), "adduser") == 0) && (!cfg->http_readonly)) {
1616 tpl_addVar(vars, 1, "NEWUSERFORM", tpl_getTpl(vars, "ADDNEWUSER"));
1617 } else {
1618 if(cfg->http_refresh > 0) {
1619 tpl_printf(vars, 0, "REFRESHTIME", "%d", cfg->http_refresh);
1620 tpl_addVar(vars, 0, "REFRESHURL", "userconfig.html");
1621 tpl_addVar(vars, 0, "REFRESH", tpl_getTpl(vars, "REFRESH"));
1622 }
1623 }
1624
1625 fputs(tpl_getTpl(vars, "USERCONFIGLIST"), f);
1626}
1627
1628void send_oscam_entitlement(struct templatevars *vars, FILE *f, struct uriparams *params) {
1629 /* build entitlements from reader init history */
1630 int ridx;
1631 char *reader_ = getParam(params, "reader");
1632
1633 if (cfg->saveinithistory && strlen(reader_) > 0) {
1634 for (ridx = 0; ridx < CS_MAXREADER && strcmp(reader_,
1635 reader[ridx].label) != 0; ridx++)
1636 ;
1637
1638 if (reader[ridx].typ == R_CCCAM) {
1639
1640 int caidcount = 0;
1641
1642 char *provider = "";
1643
1644 struct cc_card *card;
1645 struct s_client *rc = &client[reader[ridx].cidx];
1646 struct cc_data *rcc = rc->cc;
1647
1648 if (rcc && rcc->cards) {
1649 pthread_mutex_lock(&rcc->cards_busy);
1650
1651 LLIST_ITR itr;
1652 card = llist_itr_init(rcc->cards, &itr);
1653 while (card) {
1654
1655 tpl_printf(vars, 1, "LOGHISTORY",
1656 "caid: %04X hop: %d<BR>\n", card->caid, card->hop);
1657
1658 int provcount = 0;
1659 LLIST_ITR itr;
1660 struct cc_provider *prov = llist_itr_init(card->providers,
1661 &itr);
1662 while (prov) {
1663 provider = get_provider(card->caid, prov->prov);
1664
1665 provcount++;
1666 tpl_printf(vars, 1, "LOGHISTORY",
1667 "&nbsp;&nbsp;-- Provider %d: %06X -- %s<BR>\n",
1668 provcount, prov->prov, provider);
1669 prov = llist_itr_next(&itr);
1670 }
1671
1672 tpl_addVar(vars, 1, "LOGHISTORY", "<BR>\n");
1673 caidcount++;
1674 card = llist_itr_next(&itr);
1675 }
1676 pthread_mutex_unlock(&rcc->cards_busy);
1677
1678 if (caidcount)
1679 tpl_printf(vars, 1, "LOGSUMMARY",
1680 "<BR>%d caid found on this reader<BR><BR>\n", caidcount);
1681
1682 tpl_printf(vars, 1, "LOGHISTORY", "cardfile end<BR>\n");
1683 } else {
1684 tpl_printf(vars, 1, "LOGHISTORY", "no cardfile found<BR>\n");
1685 }
1686
1687 } else {
1688
1689 // normal non-cccam reader
1690 FILE *fp;
1691 char filename[32];
1692 char buffer[128];
1693 snprintf(filename, sizeof(filename), "%s/reader%d", get_tmp_dir(), client[cs_idx].ridx);
1694 fp = fopen(filename, "r");
1695
1696 if (fp) {
1697 while (fgets(buffer, 128, fp) != NULL) {
1698 tpl_printf(vars, 1, "LOGHISTORY", "%s<BR>\n", buffer);
1699 }
1700 fclose(fp);
1701 }
1702 tpl_addVar(vars, 0, "READERNAME", reader_);
1703 }
1704
1705 } else {
1706 tpl_addVar(vars, 0, "LOGHISTORY",
1707 "You have to set saveinithistory=1 in your config to see Entitlements!<BR>\n");
1708 }
1709
1710 fputs(tpl_getTpl(vars, "ENTITLEMENTS"), f);
1711}
1712
1713void send_oscam_status(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
1714 int i;
1715 char *usr;
1716 int lsec, isec, cnr, con, cau;
1717 time_t now = time((time_t)0);
1718 struct tm *lt;
1719
1720 if (strcmp(getParam(params, "action"), "kill") == 0)
1721 kill(atoi(getParam(params, "pid")), SIGQUIT);
1722
1723 if (strcmp(getParam(params, "action"), "restart") == 0)
1724 for (i = 0; i < CS_MAXREADER; i++)
1725 if (reader[i].pid == atoi(getParam(params, "pid")))
1726 send_restart_cardreader(i, 1);
1727
1728 if (strcmp(getParam(params, "action"), "resetstat") == 0)
1729 for (i = 0; i < CS_MAXREADER; i++)
1730 if (reader[i].pid == atoi(getParam(params, "pid")))
1731 send_clear_reader_stat(i);
1732
1733 char *debuglvl = getParam(params, "debug");
1734 if(strlen(debuglvl) > 0)
1735 cs_dblevel = atoi(debuglvl);
1736
1737 char *hideidx = getParam(params, "hide");
1738 if(strlen(hideidx) > 0)
1739 client[atoi(hideidx)].wihidden = 1;
1740
1741 char *hideidle = getParam(params, "hideidle");
1742 if(strlen(hideidle) > 0) {
1743 if (atoi(hideidle) == 2) {
1744 for (i=0; i<CS_MAXPID; i++)
1745 client[i].wihidden = 0;
1746 } else {
1747 int oldval = cfg->http_hide_idle_clients;
1748 chk_t_webif("httphideidleclients", hideidle);
1749 if(oldval != cfg->http_hide_idle_clients) {
1750 refresh_oscam(REFR_SERVER, in);
1751 }
1752 }
1753 }
1754
1755 if(cfg->http_hide_idle_clients > 0) tpl_addVar(vars, 0, "HIDEIDLECLIENTSSELECTED1", "selected");
1756 else tpl_addVar(vars, 0, "HIDEIDLECLIENTSSELECTED0", "selected");
1757
1758 for (i=0; i<CS_MAXPID; i++) {
1759
1760 // Reset template variables
1761 tpl_addVar(vars, 0, "CLIENTLBVALUE","");
1762
1763 if (client[i].pid && client[i].wihidden != 1) {
1764
1765 if((cfg->http_hide_idle_clients == 1) && (client[i].typ == 'c') && ((now - client[i].lastecm) > cfg->mon_hideclient_to)) continue;
1766
1767 lsec=now-client[i].login;
1768 isec=now-client[i].last;
1769 usr=client[i].usr;
1770
1771 if (((client[i].typ=='r') || (client[i].typ=='p')) && (con=cs_idx2ridx(i))>=0) usr=reader[con].label;
1772
1773 if (((client[i].typ!='r') || (client[i].typ!='p')) && (client[i].lastreader[0]))
1774 tpl_printf(vars, 0, "CLIENTLBVALUE", "%s", client[i].lastreader);
1775
1776 if (client[i].dup) con=2;
1777 else if ((client[i].tosleep) && (now-client[i].lastswitch>client[i].tosleep)) con=1;
1778 else con=0;
1779
1780 if (i-cdiff>0) cnr=i-cdiff;
1781 else cnr=(i>1) ? i-1 : 0;
1782
1783 if( (cau=client[i].au+1) && (now-client[i].lastemm)/60 > cfg->mon_aulow) cau=-cau;
1784
1785 lt=localtime(&client[i].login);
1786
1787 tpl_printf(vars, 0, "HIDEIDX", "%d", i);
1788 tpl_addVar(vars, 0, "HIDEICON", ICHID);
1789 if(client[i].typ == 'c' && !cfg->http_readonly) {
1790 tpl_printf(vars, 0, "CLIENTPID", "%d&nbsp;", client[i].pid);
1791 tpl_printf(vars, 1, "CLIENTPID", "<A HREF=\"status.html?action=kill&pid=%d\" TITLE=\"Kill this client\"><IMG SRC=\"%s\" ALT=\"Kill\" STYLE=\"float:right\"></A>", client[i].pid, ICKIL);
1792 }
1793 else if((client[i].typ == 'r' || client[i].typ == 'p') && !cfg->http_readonly) {
1794 tpl_printf(vars, 0, "CLIENTPID", "%d&nbsp;", client[i].pid);
1795 tpl_printf(vars, 1, "CLIENTPID", "<A HREF=\"status.html?action=restart&pid=%d\" TITLE=\"Restart this reader/ proxy\"><IMG SRC=\"%s\" ALT=\"Kill\" STYLE=\"float:right\"></A>", client[i].pid, ICKIL);
1796 }
1797 else {
1798 tpl_printf(vars, 0, "CLIENTPID", "%d&nbsp;", client[i].pid);
1799 }
1800
1801 tpl_printf(vars, 0, "CLIENTTYPE", "%c", client[i].typ);
1802 tpl_printf(vars, 0, "CLIENTCNR", "%d", cnr);
1803 tpl_addVar(vars, 0, "CLIENTUSER", usr);
1804 tpl_printf(vars, 0, "CLIENTCAU", "%d", cau);
1805 tpl_printf(vars, 0, "CLIENTCRYPTED", "%d", client[i].crypted);
1806 tpl_printf(vars, 0, "CLIENTIP", "%s", cs_inet_ntoa(client[i].ip));
1807 tpl_printf(vars, 0, "CLIENTPORT", "%d", client[i].port);
1808 tpl_addVar(vars, 0, "CLIENTPROTO", monitor_get_proto(i));
1809 tpl_printf(vars, 0, "CLIENTLOGINDATE", "%02d.%02d.%02d", lt->tm_mday, lt->tm_mon+1, lt->tm_year%100);
1810 tpl_printf(vars, 0, "CLIENTLOGINTIME", "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
1811
1812 int secs = 0, fullmins =0, mins =0, fullhours =0, hours =0, days =0;
1813 if(lsec > 0) {
1814 secs = lsec % 60;
1815 if (lsec > 60) {
1816 fullmins = lsec / 60;
1817 mins = fullmins % 60;
1818 if(fullmins > 60) {
1819 fullhours = fullmins / 60;
1820 hours = fullhours % 24;
1821 days = fullhours / 24;
1822 }
1823 }
1824 }
1825 if(days == 0)
1826 tpl_printf(vars, 0, "CLIENTLOGINSECS", "%02d:%02d:%02d", hours, mins, secs);
1827 else
1828 tpl_printf(vars, 0, "CLIENTLOGINSECS", "%02dd %02d:%02d:%02d", days, hours, mins, secs);
1829
1830 tpl_printf(vars, 0, "CLIENTCAID", "%04X", client[i].last_caid);
1831 tpl_printf(vars, 0, "CLIENTSRVID", "%04X", client[i].last_srvid);
1832
1833 int j, found = 0;
1834 struct s_srvid *srvid = cfg->srvid;
1835
1836 while (srvid != NULL) {
1837 if (srvid->srvid == client[i].last_srvid) {
1838 for (j=0; j < srvid->ncaid; j++) {
1839 if (srvid->caid[j] == client[i].last_caid) {
1840 found = 1;
1841 break;
1842 }
1843 }
1844 }
1845 if (found == 1)
1846 break;
1847 else
1848 srvid = srvid->next;
1849 }
1850
1851 if (found == 1) {
1852 tpl_printf(vars, 0, "CLIENTSRVPROVIDER","%s : ", srvid->prov);
1853 tpl_addVar(vars, 0, "CLIENTSRVNAME", srvid->name);
1854 tpl_addVar(vars, 0, "CLIENTSRVTYPE", srvid->type);
1855 tpl_addVar(vars, 0, "CLIENTSRVDESCRIPTION", srvid->desc);
1856 } else {
1857 tpl_addVar(vars, 0, "CLIENTSRVPROVIDER","");
1858 tpl_printf(vars, 0, "CLIENTSRVNAME","");
1859 tpl_addVar(vars, 0, "CLIENTSRVTYPE","");
1860 tpl_addVar(vars, 0, "CLIENTSRVDESCRIPTION","");
1861 }
1862
1863 secs = 0, fullmins =0, mins =0, fullhours =0, hours =0, days =0;
1864 if(isec > 0) {
1865 secs = isec % 60;
1866 if (isec > 60) {
1867 fullmins = isec / 60;
1868 mins = fullmins % 60;
1869 if(fullmins > 60) {
1870 fullhours = fullmins / 60;
1871 hours = fullhours % 24;
1872 days = fullhours / 24;
1873 }
1874 }
1875 }
1876 if(days == 0)
1877 tpl_printf(vars, 0, "CLIENTIDLESECS", "%02d:%02d:%02d", hours, mins, secs);
1878 else
1879 tpl_printf(vars, 0, "CLIENTIDLESECS", "%02dd %02d:%02d:%02d", days, hours, mins, secs);
1880 if(con == 2) tpl_printf(vars, 0, "CLIENTCON", "Duplicate");
1881 else if (con == 1) tpl_printf(vars, 0, "CLIENTCON", "Sleep");
1882 else
1883 {
1884 char *txt = "OK";
1885 if (client[i].typ == 'r' || client[i].typ == 'p') //reader or proxy
1886 {
1887 int ridx;
1888 for (ridx = 0; ridx < CS_MAXREADER; ridx++)
1889 {
1890 if(ridx == client[i].ridx)
1891 {
1892 if (reader[ridx].lbvalue)
1893 tpl_printf(vars, 0, "CLIENTLBVALUE", "<A HREF=\"status.html?action=resetstat&pid=%d\" TITLE=\"Reset statistics for this reader/ proxy\">%d</A>", reader[ridx].pid, reader[ridx].lbvalue);
1894
1895 switch(reader[ridx].card_status)
1896 {
1897 case NO_CARD: txt = "OFF"; break;
1898 case CARD_NEED_INIT: txt = "NEEDINIT"; break;
1899 case CARD_INSERTED:
1900 if (client[i].typ=='p')
1901 txt = "CONNECTED";
1902 else
1903 txt = "CARDOK";
1904 break;
1905 case CARD_FAILURE: txt = "ERROR"; break;
1906 default: txt = "UNDEF";
1907 }
1908 }
1909 }
1910
1911 }
1912 tpl_printf(vars, 0, "CLIENTCON", txt);
1913 }
1914 tpl_addVar(vars, 1, "CLIENTSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
1915 }
1916 }
1917
1918#ifdef CS_LOGHISTORY
1919 for (i=(*loghistidx+3) % CS_MAXLOGHIST; i!=*loghistidx; i=(i+1) % CS_MAXLOGHIST) {
1920 char *p_usr, *p_txt;
1921 p_usr=(char *)(loghist+(i*CS_LOGHISTSIZE));
1922 p_txt=p_usr+32;
1923 if (p_txt[0]) tpl_printf(vars, 1, "LOGHISTORY", "%s<BR>\n", p_txt+8);
1924 }
1925#else
1926 tpl_addVar(vars, 0, "LOGHISTORY", "the flag CS_LOGHISTORY is not set in your binary<BR>\n");
1927#endif
1928
1929 tpl_printf(vars, 0, "SDEBUG", "<SPAN CLASS=\"debugt\"> %s&nbsp;%d to&nbsp;</SPAN>\n", "Switch Debug from", cs_dblevel);
1930 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"status.html?debug=0\" title=\"no debugging (default)\">0</A>&nbsp;\n");
1931 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"status.html?debug=1\" title=\"detailed error messages\">1</A>&nbsp;\n");
1932 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"status.html?debug=2\" title=\"ATR parsing info, ECM dumps, CW dumps\">2</A>&nbsp;\n");
1933 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"status.html?debug=4\" title=\"traffic from/to the reader\">4</A>&nbsp;\n");
1934 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"status.html?debug=8\" title=\"traffic from/to the clients\">8</A>&nbsp;\n");
1935 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"status.html?debug=16\" title=\"traffic to the reader-device on IFD layer\">16</A>&nbsp;\n");
1936 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"status.html?debug=32\" title=\"traffic to the reader-device on I/O layer\">32</A>&nbsp;\n");
1937 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"status.html?debug=64\" title=\"EMM logging\">64</A>&nbsp;\n");
1938 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"status.html?debug=255\" title=\"debug all\">255</A>\n");
1939
1940 fputs(tpl_getTpl(vars, "STATUS"), f);
1941}
1942
1943void send_oscam_services_edit(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
1944 struct s_sidtab *sidtab,*ptr;
1945 char label[128];
1946 int i;
1947
1948 cs_strncpy(label, strtolower(getParam(params, "service")), sizeof(label)/sizeof(char));
1949
1950 for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
1951
1952 if (sidtab == NULL) {
1953 i = 1;
1954 while(strlen(label) < 1) {
1955 snprintf(label, sizeof(label)/sizeof(char) - 1, "newservice%d", i);
1956 for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab = sidtab->next);
1957 if(sidtab != NULL) label[0] = '\0';
1958 ++i;
1959 }
1960 if (!(sidtab=malloc(sizeof(struct s_sidtab)))) {
1961 cs_log("Error allocating memory (errno=%d)", errno);
1962 return;
1963 }
1964
1965 if(cfg->sidtab == NULL) cfg->sidtab = sidtab;
1966 else {
1967 for (ptr = cfg->sidtab; ptr != NULL && ptr->next != NULL; ptr = ptr->next);
1968 ptr->next = sidtab;
1969 }
1970 memset(sidtab, 0, sizeof(struct s_sidtab));
1971 cs_strncpy((char *)sidtab->label, label, sizeof(sidtab->label));
1972
1973 tpl_addVar(vars, 1, "MESSAGE", "<b>New service has been added</b><BR>");
1974 if (write_services()==0) refresh_oscam(REFR_SERVICES, in);
1975 else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing services to disk failed!</b><BR>");
1976
1977 for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
1978 }
1979
1980 if (strcmp(getParam(params, "action"), "Save") == 0) {
1981 for(i=0;i<(*params).paramcount;i++) {
1982 if ((strcmp((*params).params[i], "action")) && (strcmp((*params).params[i], "service"))) {
1983 chk_sidtab((*params).params[i], (*params).values[i], sidtab);
1984 }
1985 }
1986 tpl_addVar(vars, 1, "MESSAGE", "<B>Services updated</B><BR><BR>");
1987 if (write_services()==0) refresh_oscam(REFR_SERVICES, in);
1988 else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
1989
1990 for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
1991 }
1992
1993 tpl_addVar(vars, 0, "LABEL", sidtab->label);
1994 tpl_addVar(vars, 0, "LABELENC", urlencode(sidtab->label));
1995
1996 for (i=0; i<sidtab->num_caid; i++) {
1997 if (i==0) tpl_printf(vars, 0, "CAIDS", "%04X", sidtab->caid[i]);
1998 else tpl_printf(vars, 1, "CAIDS", ",%04X", sidtab->caid[i]);
1999 }
2000 for (i=0; i<sidtab->num_provid; i++) {
2001 if (i==0) tpl_printf(vars, 0, "PROVIDS", "%06lX", sidtab->provid[i]);
2002 else tpl_printf(vars, 1, "PROVIDS", ",%06lX", sidtab->provid[i]);
2003 }
2004 for (i=0; i<sidtab->num_srvid; i++) {
2005 if (i==0) tpl_printf(vars, 0, "SRVIDS", "%04X", sidtab->srvid[i]);
2006 else tpl_printf(vars, 1, "SRVIDS", ",%04X", sidtab->srvid[i]);
2007 }
2008 fputs(tpl_getTpl(vars, "SERVICEEDIT"), f);
2009}
2010
2011void send_oscam_services(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
2012 struct s_sidtab *sidtab, *sidtab2;
2013 char *service = getParam(params, "service");
2014 int i, found = 0;
2015
2016 if (strcmp(getParam(params, "action"), "delete") == 0) {
2017 if(cfg->http_readonly) {
2018 tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry, Webif is in readonly mode. No deletion will be made!</b><BR>");
2019 } else {
2020 sidtab=cfg->sidtab;
2021 if(strcmp(sidtab->label, service) == 0) {
2022 cfg->sidtab = sidtab->next;
2023 free(sidtab);
2024 found = 1;
2025 } else if (sidtab->next != NULL) {
2026 do {
2027 if(strcmp(sidtab->next->label, service) == 0) {
2028 sidtab2 = sidtab->next;
2029 sidtab->next = sidtab2->next;
2030 free(sidtab2);
2031 found = 1;
2032 break;
2033 }
2034 } while ((sidtab = sidtab->next) && (sidtab->next != NULL));
2035 }
2036 if (found > 0) {
2037 tpl_addVar(vars, 1, "MESSAGE", "<b>Service has been deleted!</b><BR>");
2038 if (write_services() == 0) refresh_oscam(REFR_SERVICES, in);
2039 else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing services to disk failed!</b><BR>");
2040 } else tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry but the specified service doesn't exist. No deletion will be made!</b><BR>");
2041 }
2042 }
2043
2044 sidtab = cfg->sidtab;
2045 // Show List
2046 while(sidtab != NULL) {
2047 tpl_printf(vars, 0, "SID","");
2048 if ((strcmp(getParam(params, "service"), sidtab->label) == 0) && (strcmp(getParam(params, "action"), "list") == 0) ) {
2049 tpl_printf(vars, 0, "SIDCLASS","sidlist");
2050 tpl_printf(vars, 1, "SID", "<div style=\"float:right;background-color:red;color:white\"><A HREF=\"services.html\" style=\"color:white;text-decoration:none\">X</A></div>");
2051 for (i=0; i<sidtab->num_srvid; i++) {
2052 tpl_printf(vars, 1, "SID", "%04X : %s<BR>", sidtab->srvid[i], get_servicename(sidtab->srvid[i], sidtab->caid[0]));
2053 }
2054 } else {
2055 tpl_printf(vars, 0, "SIDCLASS","");
2056 tpl_printf(vars, 0, "SID","<A HREF=\"services.html?service=%s&action=list\">Show Services</A>",tpl_addTmp(vars, urlencode(sidtab->label)));
2057 }
2058 tpl_addVar(vars, 0, "LABELENC", tpl_addTmp(vars, urlencode(sidtab->label)));
2059 tpl_addVar(vars, 0, "LABEL", sidtab->label);
2060 tpl_addVar(vars, 0, "SIDLIST", tpl_getTpl(vars, "SERVICECONFIGSIDBIT"));
2061 tpl_addVar(vars, 0, "EDIICO", ICEDI);
2062 tpl_addVar(vars, 0, "DELICO", ICDEL);
2063 tpl_addVar(vars, 1, "SERVICETABS", tpl_getTpl(vars, "SERVICECONFIGLISTBIT"));
2064 sidtab=sidtab->next;
2065 }
2066 fputs(tpl_getTpl(vars, "SERVICECONFIGLIST"), f);
2067}
2068
2069void send_oscam_savetpls(struct templatevars *vars, FILE *f) {
2070 if(strlen(cfg->http_tpl) > 0) {
2071 tpl_printf(vars, 0, "CNT", "%d", tpl_saveIncludedTpls(cfg->http_tpl));
2072 tpl_addVar(vars, 0, "PATH", cfg->http_tpl);
2073 } else tpl_addVar(vars, 0, "CNT", "0");
2074 fputs(tpl_getTpl(vars, "SAVETEMPLATES"), f);
2075}
2076
2077void send_oscam_shutdown(struct templatevars *vars, FILE *f, struct uriparams *params) {
2078 if (strcmp(getParam(params, "action"), "Shutdown") == 0) {
2079 tpl_addVar(vars, 0, "STYLESHEET", CSS);
2080 tpl_printf(vars, 0, "REFRESHTIME", "%d", SHUTDOWNREFRESH);
2081 tpl_addVar(vars, 0, "REFRESHURL", "status.html");
2082 tpl_addVar(vars, 0, "REFRESH", tpl_getTpl(vars, "REFRESH"));
2083 tpl_printf(vars, 0, "SECONDS", "%d", SHUTDOWNREFRESH);
2084 fputs(tpl_getTpl(vars, "SHUTDOWN"), f);
2085 running = 0;
2086 cs_exit(SIGQUIT);
2087 kill(client[0].pid, SIGQUIT); // Test because running=0 seems to have no effect in server loop while socket is blocked/listen
2088 } else {
2089 fputs(tpl_getTpl(vars, "PRESHUTDOWN"), f);
2090 }
2091}
2092
2093void send_oscam_script(struct templatevars *vars, FILE *f) {
2094
2095 char *result = "not found";
2096 int rc = 0;
2097 if(!cfg->http_readonly) {
2098 if(cfg->http_script[0]) {
2099 tpl_addVar(vars, 0, "SCRIPTNAME",cfg->http_script);
2100 rc = system(cfg->http_script);
2101 if(rc == -1) {
2102 result = "done";
2103 } else {
2104 result = "failed";
2105 }
2106 } else {
2107 tpl_addVar(vars, 0, "SCRIPTNAME", "no script defined");
2108 }
2109 tpl_addVar(vars, 0, "SCRIPTRESULT", result);
2110 tpl_printf(vars, 0, "CODE", "%d", rc);
2111 } else {
2112 tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry, Webif is in readonly mode. No script execution possible!</b><BR>");
2113 }
2114 fputs(tpl_getTpl(vars, "SCRIPT"), f);
2115
2116}
2117
2118void send_oscam_scanusb(struct templatevars *vars, FILE *f) {
2119 FILE *fp;
2120 int err=0;
2121 char path[1035];
2122
2123 fp = popen("lsusb -v | egrep '^Bus|^ *iSerial|^ *iProduct'", "r");
2124 if (fp == NULL) {
2125 tpl_addVar(vars, 0, "USBENTRY", "Failed to run lusb");
2126 tpl_printf(vars, 0, "USBENTRY", "%s", path);
2127 tpl_addVar(vars, 1, "USBBIT", tpl_getTpl(vars, "SCANUSBBIT"));
2128 err = 1;
2129 }
2130
2131 if(!err) {
2132 while (fgets(path, sizeof(path)-1, fp) != NULL) {
2133 tpl_addVar(vars, 0, "USBENTRYCLASS", "");
2134 if (strstr(path,"Bus ")) {
2135 tpl_printf(vars, 0, "USBENTRY", "%s", path);
2136 tpl_addVar(vars, 0, "USBENTRYCLASS", "CLASS=\"scanusbsubhead\"");
2137 } else {
2138 tpl_printf(vars, 0, "USBENTRY", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s", path);
2139 }
2140 tpl_addVar(vars, 1, "USBBIT", tpl_getTpl(vars, "SCANUSBBIT"));
2141 }
2142 }
2143 pclose(fp);
2144 fputs(tpl_getTpl(vars, "SCANUSB"), f);
2145}
2146
2147void send_oscam_files(struct templatevars *vars, FILE *f, struct uriparams *params) {
2148
2149 char *stoplog = getParam(params, "stoplog");
2150 if(strlen(stoplog) > 0)
2151 cfg->disablelog = atoi(stoplog);
2152
2153 char *stopusrlog = getParam(params, "stopusrlog");
2154 if(strlen(stopusrlog) > 0)
2155 cfg->disableuserfile = atoi(stopusrlog);
2156
2157 char *debuglvl = getParam(params, "debug");
2158 if(strlen(debuglvl) > 0)
2159 cs_dblevel = atoi(debuglvl);
2160
2161 char targetfile[256];
2162
2163 if (strcmp(getParam(params, "part"), "conf") == 0)
2164 snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.conf");
2165 else if (strcmp(getParam(params, "part"), "version") == 0)
2166 snprintf(targetfile, 255,"%s%s", get_tmp_dir(), "/oscam.version");
2167 else if (strcmp(getParam(params, "part"), "user") == 0)
2168 snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.user");
2169 else if (strcmp(getParam(params, "part"), "server") == 0)
2170 snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.server");
2171 else if (strcmp(getParam(params, "part"), "services") == 0)
2172 snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.services");
2173 else if (strcmp(getParam(params, "part"), "srvid") == 0)
2174 snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.srvid");
2175 else if (strcmp(getParam(params, "part"), "provid") == 0)
2176 snprintf(targetfile, 255,"%s%s", cs_confdir, "oscam.provid");
2177 else if (strcmp(getParam(params, "part"), "logfile") == 0) {
2178 snprintf(targetfile, 255,"%s", cfg->logfile);
2179
2180 if (strcmp(getParam(params, "clear"), "logfile") == 0) {
2181 if(strlen(targetfile) > 0) {
2182 FILE *file = fopen(targetfile,"w");
2183 fclose(file);
2184 }
2185 }
2186
2187 tpl_printf(vars, 0, "SDEBUG", "<SPAN CLASS=\"debugt\"> %s&nbsp;%d to&nbsp;</SPAN>\n", "Switch Debug from", cs_dblevel);
2188 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&debug=0\" title=\"no debugging (default)\">0</A>&nbsp;\n");
2189 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&debug=1\" title=\"detailed error messages\">1</A>&nbsp;\n");
2190 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&debug=2\" title=\"ATR parsing info, ECM dumps, CW dumps\">2</A>&nbsp;\n");
2191 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&debug=4\" title=\"traffic from/to the reader\">4</A>&nbsp;\n");
2192 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&debug=8\" title=\"traffic from/to the clients\">8</A>&nbsp;\n");
2193 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&debug=16\" title=\"traffic to the reader-device on IFD layer\">16</A>&nbsp;\n");
2194 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&debug=32\" title=\"traffic to the reader-device on I/O layer\">32</A>&nbsp;\n");
2195 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&debug=64\" title=\"EMM logging\">64</A>&nbsp;\n");
2196 tpl_addVar(vars, 1, "SDEBUG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&debug=255\" title=\"debug all\">255</A><SPAN CLASS=\"debugt\">&nbsp;&nbsp;|</SPAN>\n");
2197
2198 if(!cfg->disablelog)
2199 tpl_printf(vars, 0, "SLOG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&stoplog=%d\">%s</A><SPAN CLASS=\"debugt\">&nbsp;&nbsp;|&nbsp;&nbsp;</SPAN>\n", 1, "Stop Log");
2200 else
2201 tpl_printf(vars, 0, "SLOG", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&stoplog=%d\">%s</A><SPAN CLASS=\"debugt\">&nbsp;&nbsp;|&nbsp;&nbsp;</SPAN>\n", 0, "Start Log");
2202
2203 tpl_printf(vars, 0, "SCLEAR", "<A CLASS=\"debugl\" HREF=\"files.html?part=logfile&clear=logfile\">%s</A><BR><BR>\n", "Clear Log");
2204 }
2205 else if (strcmp(getParam(params, "part"), "userfile") == 0) {
2206 snprintf(targetfile, 255,"%s", cfg->usrfile);
2207 if (strcmp(getParam(params, "clear"), "usrfile") == 0) {
2208 if(strlen(targetfile) > 0) {
2209 FILE *file = fopen(targetfile,"w");
2210 fclose(file);
2211 }
2212 }
2213
2214 if(!cfg->disableuserfile)
2215 tpl_printf(vars, 0, "SLOG", "<A HREF=\"files.html?part=userfile&stopusrlog=%d\">%s</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n", 1, "Stop Log");
2216 else
2217 tpl_printf(vars, 0, "SLOG", "<A HREF=\"files.html?part=userfile&stopusrlog=%d\">%s</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n", 0, "Start Log");
2218
2219 tpl_printf(vars, 0, "SCLEAR", "<A HREF=\"files.html?part=userfile&clear=usrfile\">%s</A><BR><BR>\n", "Clear Log");
2220 tpl_addVar(vars, 0, "FILTER", "<FORM ACTION=\"files.html\" method=\"get\">\n");
2221 tpl_addVar(vars, 1, "FILTER", "<INPUT name=\"part\" type=\"hidden\" value=\"userfile\">\n");
2222 tpl_addVar(vars, 1, "FILTER", "<SELECT name=\"filter\">\n");
2223 tpl_printf(vars, 1, "FILTER", "<OPTION value=\"%s\">%s</OPTION>\n", "all", "all");
2224
2225 struct s_auth *account = cfg->account;
2226 do {
2227 tpl_printf(vars, 1, "FILTER", "<OPTION value=\"%s\" %s>%s</OPTION>\n", account->usr, strcmp(getParam(params, "filter"), account->usr) ? "":"selected", account->usr);
2228 } while ((account = account->next) && (account->next != NULL));
2229
2230 tpl_addVar(vars, 1, "FILTER", "</SELECT><input type=\"submit\" name=\"action\" value=\"Filter\" title=\"Filter for a specific user\"></FORM>\n");
2231
2232 }
2233#ifdef CS_ANTICASC
2234 else if (strcmp(getParam(params, "part"), "anticasc") == 0)
2235 snprintf(targetfile, 255,"%s", cfg->ac_logfile);
2236#endif
2237
2238 if (!strstr(targetfile, "/dev/")) {
2239 if((strlen(targetfile) > 0) && (file_exists(targetfile) == 1)) {
2240 FILE *fp;
2241 char buffer[256];
2242
2243 if((fp = fopen(targetfile,"r")) == NULL) return;
2244 while (fgets(buffer, sizeof(buffer), fp) != NULL)
2245 if (!strcmp(getParam(params, "filter"), "all"))
2246 tpl_printf(vars, 1, "FILECONTENT", "%s", buffer);
2247 else
2248 if(strstr(buffer,getParam(params, "filter")))
2249 tpl_printf(vars, 1, "FILECONTENT", "%s", buffer);
2250 fclose (fp);
2251 } else {
2252 tpl_addVar(vars, 1, "FILECONTENT", "File not exist");
2253 }
2254 } else {
2255 tpl_addVar(vars, 1, "FILECONTENT", "File not valid");
2256 }
2257
2258 fputs(tpl_getTpl(vars, "FILE"), f);
2259}
2260
2261int process_request(FILE *f, struct in_addr in) {
2262
2263 client[cs_idx].last = time((time_t)0); //reset last busy time
2264
2265 int ok=0;
2266 struct s_ip *p_ip;
2267 in_addr_t addr = cs_inet_order(in.s_addr);
2268
2269 for (p_ip = cfg->http_allowed; (p_ip) && (!ok); p_ip = p_ip->next)
2270 ok =((addr >= p_ip->ip[0]) && (addr <= p_ip->ip[1]));
2271
2272 if (!ok && cfg->http_dyndns[0]) {
2273 if(cfg->http_dynip == addr) {
2274 ok = 1;
2275 } else {
2276 pthread_mutex_lock(&gethostbyname_lock);
2277 struct hostent *rht;
2278 struct sockaddr_in udp_sa;
2279
2280 rht = gethostbyname((const char *) cfg->http_dyndns);
2281 if (rht) {
2282 memcpy(&udp_sa.sin_addr, rht->h_addr, sizeof(udp_sa.sin_addr));
2283 cfg->http_dynip = cs_inet_order(udp_sa.sin_addr.s_addr);
2284 if (cfg->http_dynip == addr)
2285 ok = 1;
2286 }
2287 pthread_mutex_unlock(&gethostbyname_lock);
2288 }
2289 }
2290
2291 if (!ok) {
2292 send_error(f, 403, "Forbidden", NULL, "Access denied.");
2293 cs_log("unauthorized access from %s", inet_ntoa(*(struct in_addr *)&in));
2294 return 0;
2295 }
2296
2297 char buf[4096];
2298 char tmp[4096];
2299
2300 int authok = 0;
2301 char expectednonce[64];
2302
2303 char *method;
2304 char *path;
2305 char *protocol;
2306 char *pch;
2307 char *pch2;
2308 /* List of possible pages */
2309 char *pages[]= {
2310 "/config.html",
2311 "/readers.html",
2312 "/entitlements.html",
2313 "/status.html",
2314 "/userconfig.html",
2315 "/readerconfig.html",
2316 "/services.html",
2317 "/user_edit.html",
2318 "/site.css",
2319 "/services_edit.html",
2320 "/savetemplates.html",
2321 "/shutdown.html",
2322 "/script.html",
2323 "/scanusb.html",
2324 "/files.html",
2325 "/readerstats.html"};
2326
2327 int pagescnt = sizeof(pages)/sizeof(char *); // Calculate the amount of items in array
2328
2329 int pgidx = -1;
2330 int i;
2331 int parsemode = 1;
2332 struct uriparams params;
2333 params.paramcount = 0;
2334
2335 /* First line always includes the GET/POST request */
2336 if (!fgets(buf, sizeof(buf), f)) return -1;
2337 method = strtok(buf, " ");
2338 path = strtok(NULL, " ");
2339 protocol = strtok(NULL, "\r");
2340 if(method == NULL || path == NULL || protocol == NULL) return -1;
2341
2342 pch=path;
2343 /* advance pointer to beginning of query string */
2344 while(pch[0] != '?' && pch[0] != '\0') ++pch;
2345 if(pch[0] == '?') {
2346 pch[0] = '\0';
2347 ++pch;
2348 }
2349
2350 /* Map page to our static page definitions */
2351 for (i=0; i<pagescnt; i++) {
2352 if (!strcmp(path, pages[i])) pgidx = i;
2353 }
2354
2355 /* Parse url parameters; parsemode = 1 means parsing next param, parsemode = -1 parsing next
2356 value; pch2 points to the beginning of the currently parsed string, pch is the current position */
2357 pch2=pch;
2358 while(pch[0] != '\0') {
2359 if((parsemode == 1 && pch[0] == '=') || (parsemode == -1 && pch[0] == '&')) {
2360 pch[0] = '\0';
2361 urldecode(pch2);
2362 if(parsemode == 1) {
2363 if(params.paramcount >= MAXGETPARAMS) break;
2364 ++params.paramcount;
2365 params.params[params.paramcount-1] = pch2;
2366 } else {
2367 params.values[params.paramcount-1] = pch2;
2368 }
2369 parsemode = -parsemode;
2370 pch2 = pch + 1;
2371 }
2372 ++pch;
2373 }
2374 /* last value wasn't processed in the loop yet... */
2375 if(parsemode == -1 && params.paramcount <= MAXGETPARAMS) {
2376 urldecode(pch2);
2377 params.values[params.paramcount-1] = pch2;
2378 }
2379
2380 if(strlen(cfg->http_user) == 0 || strlen(cfg->http_pwd) == 0) authok = 1;
2381 else calculate_nonce(expectednonce, sizeof(expectednonce)/sizeof(char));
2382
2383 /* Read remaining request (we're only interested in auth header) */
2384 while (fgets(tmp, sizeof(tmp), f)) {
2385 if (tmp[0] == '\r' && tmp[1] == '\n') break;
2386 else if(authok == 0 && strlen(tmp) > 50 && strncmp(tmp, "Authorization:", 14) == 0 && strstr(tmp, "Digest") != NULL) {
2387 authok = check_auth(tmp, method, path, expectednonce);
2388 }
2389 }
2390
2391 //cs_debug("%s %d\n", path, pgidx);
2392 //for(i=0; i < params.paramcount; ++i) cs_debug("%s : %s\n", params.params[i], params.values[i]);
2393
2394 fseek(f, 0, SEEK_CUR); // Force change of stream direction
2395
2396 if(authok != 1) {
2397 strcpy(tmp, "WWW-Authenticate: Digest algorithm=\"MD5\", realm=\"");
2398 strcat(tmp, AUTHREALM);
2399 strcat(tmp, "\", qop=\"auth\", opaque=\"\", nonce=\"");
2400 strcat(tmp, expectednonce);
2401 strcat(tmp, "\"");
2402 if(authok == 2) strcat(tmp, ", stale=true");
2403 send_headers(f, 401, "Unauthorized", tmp, "text/html");
2404 return 0;
2405 }
2406
2407 /*build page*/
2408 send_headers(f, 200, "OK", NULL, "text/html");
2409 if(pgidx == 8) send_css(f);
2410 else {
2411 time_t t;
2412 struct templatevars *vars = tpl_create();
2413 struct tm *lt;
2414 struct tm *st;
2415 time(&t);
2416
2417 lt = localtime(&t);
2418
2419 tpl_addVar(vars, 0, "CS_VERSION", CS_VERSION);
2420 tpl_addVar(vars, 0, "CS_SVN_VERSION", CS_SVN_VERSION);
2421 tpl_addVar(vars, 0, "ICO", ICMAI);
2422 if(cfg->http_refresh > 0 && (pgidx == 3 || pgidx == -1)) {
2423 tpl_printf(vars, 0, "REFRESHTIME", "%d", cfg->http_refresh);
2424 tpl_addVar(vars, 0, "REFRESHURL", "status.html");
2425 tpl_addVar(vars, 0, "REFRESH", tpl_getTpl(vars, "REFRESH"));
2426 }
2427 tpl_printf(vars, 0, "CURDATE", "%02d.%02d.%02d", lt->tm_mday, lt->tm_mon+1, lt->tm_year%100);
2428 tpl_printf(vars, 0, "CURTIME", "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
2429 st = localtime(&client[0].login);
2430 tpl_printf(vars, 0, "STARTDATE", "%02d.%02d.%02d", st->tm_mday, st->tm_mon+1, st->tm_year%100);
2431 tpl_printf(vars, 0, "STARTTIME", "%02d:%02d:%02d", st->tm_hour, st->tm_min, st->tm_sec);
2432
2433 time_t now = time((time_t)0);
2434 int lsec = now - client[0].login;
2435 int secs = 0, fullmins = 0, mins = 0, fullhours = 0, hours = 0, days = 0;
2436 if(lsec > 0) {
2437 secs = lsec % 60;
2438 if (lsec > 60) {
2439 fullmins = lsec / 60;
2440 mins = fullmins % 60;
2441 if(fullmins > 60) {
2442 fullhours = fullmins / 60;
2443 hours = fullhours % 24;
2444 days = fullhours / 24;
2445 }
2446 }
2447 }
2448 if(days == 0)
2449 tpl_printf(vars, 0, "UPTIME", "%02d:%02d:%02d", hours, mins, secs);
2450 else
2451 tpl_printf(vars, 0, "UPTIME", "%02dd %02d:%02d:%02d", days, hours, mins, secs);
2452
2453 tpl_printf(vars, 0, "CURIP", "%s", inet_ntoa(*(struct in_addr *)&in));
2454 if(cfg->http_readonly)
2455 tpl_addVar(vars, 1, "BTNDISABLED", "DISABLED");
2456
2457 switch(pgidx) {
2458 case 0: send_oscam_config(vars, f, &params, in); break;
2459 case 1: send_oscam_reader(vars, f, &params, in); break;
2460 case 2: send_oscam_entitlement(vars, f, &params); break;
2461 case 3: send_oscam_status(vars, f, &params, in); break;
2462 case 4: send_oscam_user_config(vars, f, &params, in); break;
2463 case 5: send_oscam_reader_config(vars, f, &params, in); break;
2464 case 6: send_oscam_services(vars, f, &params, in); break;
2465 case 7: send_oscam_user_config_edit(vars, f, &params, in); break;
2466 //case 8: css file
2467 case 9: send_oscam_services_edit(vars, f, &params, in); break;
2468 case 10: send_oscam_savetpls(vars, f); break;
2469 case 11: send_oscam_shutdown(vars, f, &params); break;
2470 case 12: send_oscam_script(vars, f); break;
2471 case 13: send_oscam_scanusb(vars, f); break;
2472 case 14: send_oscam_files(vars, f, &params); break;
2473 case 15: send_oscam_reader_stats(vars, f, &params); break;
2474 default: send_oscam_status(vars, f, &params, in); break;
2475 }
2476 tpl_clear(vars);
2477 }
2478 return 0;
2479}
2480
2481void http_srv() {
2482 int i,sock, reuse = 1;
2483 struct sockaddr_in sin;
2484 struct sockaddr_in remote;
2485 socklen_t len = sizeof(remote);
2486 char *tmp;
2487
2488 /* Prepare lookup array for conversion between ascii and hex */
2489 tmp = malloc(3 * sizeof(char));
2490 for(i = 0; i < 256; i++) {
2491 snprintf(tmp, 3,"%02x", i);
2492 memcpy(hex2ascii[i], tmp, 2);
2493 }
2494 free(tmp);
2495 /* Create random string for nonce value generation */
2496 srand(time(NULL));
2497 create_rand_str(noncekey,32);
2498
2499 /* Startup server */
2500 if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
2501 cs_log("HTTP Server: Creating socket failed! (errno=%d)", errno);
2502 return;
2503 }
2504 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) {
2505 cs_log("HTTP Server: Setting SO_REUSEADDR via setsockopt failed! (errno=%d)", errno);
2506 }
2507
2508 memset(&sin, 0, sizeof sin);
2509 sin.sin_family = AF_INET;
2510 sin.sin_addr.s_addr = INADDR_ANY;
2511 sin.sin_port = htons(cfg->http_port);
2512 if((bind(sock, (struct sockaddr *) &sin, sizeof(sin))) < 0) {
2513 cs_log("HTTP Server couldn't bind on port %d (errno=%d). Not starting HTTP!", cfg->http_port, errno);
2514 close(sock);
2515 return;
2516 }
2517 if (listen(sock, SOMAXCONN) < 0) {
2518 cs_log("HTTP Server: Call to listen() failed! (errno=%d)", errno);
2519 close(sock);
2520 return;
2521 }
2522 cs_log("HTTP Server listening on port %d", cfg->http_port);
2523 struct pollfd pfd2[1];
2524 int rc;
2525 pfd2[0].fd = sock;
2526 pfd2[0].events = (POLLIN | POLLPRI);
2527
2528 while (running) {
2529 int s;
2530 FILE *f;
2531
2532 rc = poll(pfd2, 1, 1000);
2533
2534 if (rc > 0) {
2535 if((s = accept(sock, (struct sockaddr *) &remote, &len)) < 0) {
2536 cs_log("HTTP Server: Error calling accept() (errno=%d).", errno);
2537 break;
2538 }
2539
2540 f = fdopen(s, "r+");
2541 process_request(f, remote.sin_addr);
2542 fflush(f);
2543 fclose(f);
2544 shutdown(s, SHUT_WR);
2545 close(s);
2546 }
2547 }
2548
2549 cs_log("HTTP Server: Shutdown requested from %s", inet_ntoa(*(struct in_addr *)&remote.sin_addr));
2550 close(sock);
2551 kill(client[0].pid, SIGQUIT);
2552}
2553#endif
Note: See TracBrowser for help on using the repository browser.