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