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