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