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