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