1 | #ifdef WEBIF
|
---|
2 | //
|
---|
3 | // OSCam HTTP server module
|
---|
4 | //
|
---|
5 | #include "oscam-http-helpers.c"
|
---|
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 |
|
---|
13 | static int running = 1;
|
---|
14 |
|
---|
15 | void refresh_oscam(enum refreshtypes refreshtype, struct in_addr in){
|
---|
16 | int i;
|
---|
17 | switch (refreshtype){
|
---|
18 | case REFR_ACCOUNTS:
|
---|
19 | cs_log("Refresh Accounts requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
|
---|
20 | kill(client[0].pid, SIGHUP);
|
---|
21 | #ifdef CS_ANTICASC
|
---|
22 | for (i=0; i<CS_MAXPID; i++)
|
---|
23 | if (client[i].typ=='a') {
|
---|
24 | kill(client[i].pid, SIGHUP);
|
---|
25 | break;
|
---|
26 | }
|
---|
27 | #endif
|
---|
28 | break;
|
---|
29 |
|
---|
30 | case REFR_READERS:
|
---|
31 | #ifdef CS_RDR_INIT_HIST
|
---|
32 | kill(client[0].pid, SIGUSR2);
|
---|
33 | cs_log("Refresh Reader/Tiers requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
|
---|
34 | #endif
|
---|
35 | break;
|
---|
36 |
|
---|
37 | case REFR_SERVER:
|
---|
38 | cs_log("Refresh Server requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
|
---|
39 | //kill(client[0].pid, SIGHUP);
|
---|
40 | //todo how I can refresh the server after global settings
|
---|
41 | break;
|
---|
42 |
|
---|
43 | case REFR_SERVICES:
|
---|
44 | cs_log("Refresh Services requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
|
---|
45 | //init_sidtab();
|
---|
46 | kill(client[0].pid, SIGHUP);
|
---|
47 | break;
|
---|
48 |
|
---|
49 | #ifdef CS_ANTICASC
|
---|
50 | case REFR_ANTICASC:
|
---|
51 | cs_log("Refresh Anticascading requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
|
---|
52 | for (i=0; i<CS_MAXPID; i++)
|
---|
53 | if (client[i].typ=='a') {
|
---|
54 | kill(client[i].pid, SIGHUP);
|
---|
55 | break;
|
---|
56 | }
|
---|
57 | break;
|
---|
58 | #endif
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | void send_oscam_config_global(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
63 | int i;
|
---|
64 |
|
---|
65 | if (strcmp(getParam(params, "action"), "execute") == 0){
|
---|
66 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
67 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
68 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
69 | //we use the same function as used for parsing the config tokens
|
---|
70 |
|
---|
71 | chk_t_global((*params).params[i], (*params).values[i]);
|
---|
72 | }
|
---|
73 | }
|
---|
74 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Global done. You should restart Oscam now.</B><BR><BR>");
|
---|
75 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
76 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
77 | }
|
---|
78 | if (cfg->srvip != 0)
|
---|
79 | tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->srvip));
|
---|
80 | if (cfg->pidfile != NULL) tpl_addVar(vars, 0, "PIDFILE", cfg->pidfile);
|
---|
81 | if (cfg->usrfile != NULL) tpl_addVar(vars, 0, "USERFILE", cfg->usrfile);
|
---|
82 | if (cfg->logfile != NULL) tpl_addVar(vars, 0, "LOGFILE", cfg->logfile);
|
---|
83 | if (cfg->cwlogdir != NULL) tpl_addVar(vars, 0, "CWLOGDIR", cfg->cwlogdir);
|
---|
84 | tpl_printf(vars, 0, "USERFILEFLAG", "%d", cfg->usrfileflag);
|
---|
85 | tpl_printf(vars, 0, "CLIENTTIMEOUT", "%ld", cfg->ctimeout/1000);
|
---|
86 | tpl_printf(vars, 0, "FALLBACKTIMEOUT", "%ld", cfg->ftimeout/1000);
|
---|
87 | tpl_printf(vars, 0, "CLIENTMAXIDLE", "%d", cfg->cmaxidle);
|
---|
88 | tpl_printf(vars, 0, "CACHEDELAY", "%ld", cfg->delay);
|
---|
89 | tpl_printf(vars, 0, "BINDWAIT", "%d", cfg->bindwait);
|
---|
90 | tpl_printf(vars, 0, "NETPRIO", "%ld", cfg->netprio);
|
---|
91 | tpl_printf(vars, 0, "RESOLVEDELAY", "%d", cfg->resolvedelay);
|
---|
92 | tpl_printf(vars, 0, "SLEEP", "%d", cfg->tosleep);
|
---|
93 | tpl_printf(vars, 0, "UNLOCKPARENTAL", "%d", cfg->ulparent);
|
---|
94 | tpl_printf(vars, 0, "NICE", "%d", cfg->nice);
|
---|
95 | tpl_printf(vars, 0, "SERIALTIMEOUT", "%d", cfg->srtimeout);
|
---|
96 | tpl_printf(vars, 0, "MAXLOGSIZE", "%d", cfg->max_log_size);
|
---|
97 | tpl_printf(vars, 0, "WAITFORCARDS", "%d", cfg->waitforcards);
|
---|
98 | tpl_printf(vars, 0, "PREFERLOCALCARDS", "%d", cfg->preferlocalcards);
|
---|
99 |
|
---|
100 | fputs(tpl_getTpl(vars, "CONFIGGLOBAL"), f);
|
---|
101 | }
|
---|
102 |
|
---|
103 | void send_oscam_config_camd33(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
104 | int i;
|
---|
105 |
|
---|
106 | if (strcmp(getParam(params, "action"), "execute") == 0){
|
---|
107 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
108 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
109 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
110 | if (strcmp((*params).params[i], "nocrypt") == 0){
|
---|
111 | clear_sip(&cfg->c33_plain);
|
---|
112 | }
|
---|
113 | //we use the same function as used for parsing the config tokens
|
---|
114 | chk_t_camd33((*params).params[i], (*params).values[i]);
|
---|
115 | }
|
---|
116 | }
|
---|
117 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration camd33 done. You should restart Oscam now.</B><BR><BR>");
|
---|
118 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
119 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
120 | }
|
---|
121 | tpl_printf(vars, 0, "PORT", "%d", cfg->c33_port);
|
---|
122 | if (cfg->c33_srvip != 0)
|
---|
123 | tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip));
|
---|
124 | tpl_printf(vars, 0, "PASSIVE", "%d", cfg->c33_passive);
|
---|
125 |
|
---|
126 | for (i = 0; i < (int) sizeof(cfg->c33_key); ++i) tpl_printf(vars, 1, "KEY", "%02X",cfg->c33_key[i]);
|
---|
127 | struct s_ip *cip;
|
---|
128 | char *dot="";
|
---|
129 | for (cip = cfg->c33_plain; cip; cip = cip->next){
|
---|
130 | tpl_printf(vars, 1, "NOCRYPT", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
131 | if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "NOCRYPT", "-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
132 | dot=",";
|
---|
133 | }
|
---|
134 |
|
---|
135 | fputs(tpl_getTpl(vars, "CONFIGCAMD33"), f);
|
---|
136 | }
|
---|
137 |
|
---|
138 | void send_oscam_config_camd35(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
139 | int i;
|
---|
140 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
141 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
142 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
143 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
144 | //we use the same function as used for parsing the config tokens
|
---|
145 | chk_t_camd35((*params).params[i], (*params).values[i]);
|
---|
146 | }
|
---|
147 | }
|
---|
148 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration camd35 done. You should restart Oscam now.</B><BR><BR>");
|
---|
149 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
150 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
151 | }
|
---|
152 | tpl_printf(vars, 0, "PORT", "%d", cfg->c35_port);
|
---|
153 | if (cfg->c35_tcp_srvip != 0)
|
---|
154 | tpl_addVar(vars, 1, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
|
---|
155 |
|
---|
156 | if (cfg->c35_suppresscmd08)
|
---|
157 | tpl_addVar(vars, 0, "SUPPRESSCMD08", "checked");
|
---|
158 |
|
---|
159 | fputs(tpl_getTpl(vars, "CONFIGCAMD35"), f);
|
---|
160 | }
|
---|
161 |
|
---|
162 | void send_oscam_config_camd35tcp(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
163 | int i;
|
---|
164 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
165 | clear_ptab(&cfg->c35_tcp_ptab); /*clear Porttab*/
|
---|
166 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
167 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
168 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
169 | //we use the same function as used for parsing the config tokens
|
---|
170 | chk_t_camd35_tcp((*params).params[i], (*params).values[i]);
|
---|
171 | }
|
---|
172 | }
|
---|
173 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration camd35 TCP done. You should restart Oscam now.</B><BR><BR>");
|
---|
174 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
175 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
176 | }
|
---|
177 |
|
---|
178 | int j;
|
---|
179 | char *dot1, *dot2;
|
---|
180 | if ((cfg->c35_tcp_ptab.nports > 0) && (cfg->c35_tcp_ptab.ports[0].s_port > 0)){
|
---|
181 | dot1 = "";
|
---|
182 | for(i = 0; i < cfg->c35_tcp_ptab.nports; ++i){
|
---|
183 | 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);
|
---|
184 | if (cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 0){
|
---|
185 | tpl_printf(vars, 1, "PORT", ":");
|
---|
186 | dot2 = "";
|
---|
187 | for (j = 0; j < cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j){
|
---|
188 | tpl_printf(vars, 1, "PORT", "%s%lX", dot2, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]);
|
---|
189 | dot2 = ",";
|
---|
190 | }
|
---|
191 | }
|
---|
192 | dot1=";";
|
---|
193 | }
|
---|
194 | }
|
---|
195 | if (cfg->c35_tcp_srvip != 0)
|
---|
196 | tpl_addVar(vars, 1, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
|
---|
197 |
|
---|
198 | fputs(tpl_getTpl(vars, "CONFIGCAMD35TCP"), f);
|
---|
199 | }
|
---|
200 |
|
---|
201 | void send_oscam_config_newcamd(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
202 | int i;
|
---|
203 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
204 | clear_ptab(&cfg->ncd_ptab); /*clear Porttab*/
|
---|
205 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
206 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
207 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
208 | //we use the same function as used for parsing the config tokens
|
---|
209 | if (strcmp((*params).params[i], "allowed") == 0){
|
---|
210 | clear_sip(&cfg->ncd_allowed);
|
---|
211 | }
|
---|
212 | chk_t_newcamd((*params).params[i], (*params).values[i]);
|
---|
213 | }
|
---|
214 | }
|
---|
215 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Newcamd done. You should restart Oscam now.</B><BR><BR>");
|
---|
216 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
217 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
218 | }
|
---|
219 | int j;
|
---|
220 | char *dot1, *dot2;
|
---|
221 | if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)){
|
---|
222 | dot1 = "";
|
---|
223 | for(i = 0; i < cfg->ncd_ptab.nports; ++i){
|
---|
224 | 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);
|
---|
225 | if (cfg->ncd_ptab.ports[i].ftab.filts[0].nprids > 0){
|
---|
226 | tpl_printf(vars, 1, "PORT", ":");
|
---|
227 | dot2 = "";
|
---|
228 | for (j = 0; j < cfg->ncd_ptab.ports[i].ftab.filts[0].nprids; ++j){
|
---|
229 | tpl_printf(vars, 1, "PORT", "%s%06X", dot2, cfg->ncd_ptab.ports[i].ftab.filts[0].prids[j]);
|
---|
230 | dot2 = ",";
|
---|
231 | }
|
---|
232 | }
|
---|
233 | dot1=";";
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | if (cfg->ncd_srvip != 0)
|
---|
238 | tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->ncd_srvip));
|
---|
239 | for (i=0;i<14;i++) tpl_printf(vars, 1, "KEY", "%02X", cfg->ncd_key[i]);
|
---|
240 |
|
---|
241 | struct s_ip *cip;
|
---|
242 | char *dot="";
|
---|
243 | for (cip = cfg->ncd_allowed; cip; cip = cip->next){
|
---|
244 | tpl_printf(vars, 1, "ALLOWED", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
245 | if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "ALLOWED", "-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
246 | dot=",";
|
---|
247 | }
|
---|
248 |
|
---|
249 | if (cfg->ncd_keepalive)
|
---|
250 | tpl_addVar(vars, 0, "KEEPALIVE", "checked");
|
---|
251 |
|
---|
252 | fputs(tpl_getTpl(vars, "CONFIGNEWCAMD"), f);
|
---|
253 | }
|
---|
254 |
|
---|
255 | void send_oscam_config_radegast(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
256 | int i;
|
---|
257 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
258 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
259 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
260 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
261 | if (strcmp((*params).params[i], "allowed") == 0){
|
---|
262 | clear_sip(&cfg->rad_allowed);
|
---|
263 | }
|
---|
264 | //we use the same function as used for parsing the config tokens
|
---|
265 | chk_t_radegast((*params).params[i], (*params).values[i]);
|
---|
266 | }
|
---|
267 | }
|
---|
268 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Radegast done. You should restart Oscam now.</B><BR><BR>");
|
---|
269 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
270 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
271 | }
|
---|
272 | tpl_printf(vars, 0, "PORT", "%d", cfg->rad_port);
|
---|
273 | if (cfg->rad_srvip != 0)
|
---|
274 | tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->rad_srvip));
|
---|
275 | tpl_addVar(vars, 0, "USER", cfg->rad_usr);
|
---|
276 |
|
---|
277 | struct s_ip *cip;
|
---|
278 | char *dot="";
|
---|
279 | for (cip=cfg->rad_allowed; cip; cip=cip->next){
|
---|
280 | tpl_printf(vars, 1, "ALLOWED", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
281 | if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "ALLOWED", "-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
282 | dot=",";
|
---|
283 | }
|
---|
284 |
|
---|
285 | fputs(tpl_getTpl(vars, "CONFIGRADEGAST"), f);
|
---|
286 | }
|
---|
287 |
|
---|
288 | void send_oscam_config_cccam(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 | //we use the same function as used for parsing the config tokens
|
---|
295 | chk_t_cccam((*params).params[i], (*params).values[i]);
|
---|
296 | }
|
---|
297 | }
|
---|
298 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
299 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
300 | }
|
---|
301 |
|
---|
302 | tpl_printf(vars, 1, "PORT", "%d", cfg->cc_port);
|
---|
303 | tpl_printf(vars, 0, "RESHARE", "%d", cfg->cc_reshare);
|
---|
304 | tpl_printf(vars, 0, "VERSION", "%s", cfg->cc_version);
|
---|
305 | tpl_printf(vars, 0, "BUILD", "%s", cfg->cc_build);
|
---|
306 |
|
---|
307 | fputs(tpl_getTpl(vars, "CONFIGCCCAM"), f);
|
---|
308 | }
|
---|
309 |
|
---|
310 | #ifdef CS_WITH_GBOX
|
---|
311 | void send_oscam_config_gbox(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
312 | int i;
|
---|
313 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
314 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
315 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
316 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
317 | //we use the same function as used for parsing the config tokens
|
---|
318 | chk_t_gbox((*params).params[i], (*params).values[i]);
|
---|
319 | }
|
---|
320 | }
|
---|
321 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Gbox done. You should restart Oscam now.</B><BR><BR>");
|
---|
322 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
323 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
324 | }
|
---|
325 | tpl_printf(vars, 0, "MAXDIST", "%d", cfg->maxdist);
|
---|
326 | for (i=0;i<4;i++) tpl_printf(vars, 1, "PASSWORD", "%02X", cfg->gbox_pwd[i]);
|
---|
327 | tpl_addVar(vars, 0, "IGNORELIST", (char *)cfg->ignorefile);
|
---|
328 | tpl_addVar(vars, 0, "ONLINEINFOS", (char *)cfg->gbxShareOnl);
|
---|
329 | tpl_addVar(vars, 0, "CARDINFOS", (char *)cfg->cardfile);
|
---|
330 | char *dot = "";
|
---|
331 | for (i = 0; i < cfg->num_locals; i++){
|
---|
332 | tpl_printf(vars, 1, "LOCALS", "%s%06lX", dot, cfg->locals[i]);
|
---|
333 | dot=";";
|
---|
334 | }
|
---|
335 | fputs(tpl_getTpl(vars, "CONFIGGBOX"), f);
|
---|
336 | }
|
---|
337 | #endif
|
---|
338 |
|
---|
339 | void send_oscam_config_monitor(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
340 | int i;
|
---|
341 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
342 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
343 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
344 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
345 | if (strcmp((*params).params[i], "nocrypt") == 0){
|
---|
346 | clear_sip(&cfg->mon_allowed);
|
---|
347 | }
|
---|
348 | //we use the same function as used for parsing the config tokens
|
---|
349 | chk_t_monitor((*params).params[i], (*params).values[i]);
|
---|
350 | }
|
---|
351 | }
|
---|
352 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Monitor done. You should restart Oscam now.</B><BR><BR>");
|
---|
353 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
354 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
355 | }
|
---|
356 | tpl_printf(vars, 0, "MONPORT", "%d", cfg->mon_port);
|
---|
357 | if (cfg->mon_srvip != 0)
|
---|
358 | tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip));
|
---|
359 | tpl_printf(vars, 0, "AULOW", "%d", cfg->mon_aulow);
|
---|
360 | tpl_printf(vars, 0, "HIDECLIENTTO", "%d", cfg->mon_hideclient_to);
|
---|
361 | tpl_printf(vars, 0, "HTTPPORT", "%d", cfg->http_port);
|
---|
362 | tpl_addVar(vars, 0, "HTTPUSER", cfg->http_user);
|
---|
363 | tpl_addVar(vars, 0, "HTTPPASSWORD", cfg->http_pwd);
|
---|
364 | tpl_addVar(vars, 0, "HTTPCSS", cfg->http_css);
|
---|
365 | tpl_printf(vars, 0, "HTTPREFRESH", "%d", cfg->http_refresh);
|
---|
366 | tpl_addVar(vars, 0, "HTTPTPL", cfg->http_tpl);
|
---|
367 | tpl_addVar(vars, 0, "HTTPSCRIPT", cfg->http_script);
|
---|
368 | if (cfg->http_hide_idle_clients > 0) tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
369 |
|
---|
370 | struct s_ip *cip;
|
---|
371 | char *dot="";
|
---|
372 | for (cip = cfg->mon_allowed; cip; cip = cip->next){
|
---|
373 | tpl_printf(vars, 1, "NOCRYPT", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
374 | if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "NOCRYPT", "-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
375 | dot=",";
|
---|
376 | }
|
---|
377 |
|
---|
378 | //Monlevel selector
|
---|
379 | tpl_printf(vars, 0, "TMP", "MONSELECTED%d", cfg->mon_level);
|
---|
380 | tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
|
---|
381 |
|
---|
382 | fputs(tpl_getTpl(vars, "CONFIGMONITOR"), f);
|
---|
383 | }
|
---|
384 |
|
---|
385 | void send_oscam_config_serial(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
386 | int i;
|
---|
387 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
388 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
389 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
390 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
391 | //we use the same function as used for parsing the config tokens
|
---|
392 | //chk_t_serial((*params).params[i], (*params).values[i]);
|
---|
393 | }
|
---|
394 | }
|
---|
395 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Serial Not yet implemented</B><BR><BR>");
|
---|
396 | refresh_oscam(REFR_SERVER, in);
|
---|
397 | }
|
---|
398 |
|
---|
399 | tpl_addVar(vars, 0, "SERIALDEVICE", cfg->ser_device);
|
---|
400 |
|
---|
401 | fputs(tpl_getTpl(vars, "CONFIGSERIAL"), f);
|
---|
402 | }
|
---|
403 |
|
---|
404 | #ifdef HAVE_DVBAPI
|
---|
405 | void send_oscam_config_dvbapi(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
406 | int i;
|
---|
407 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
408 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
409 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
410 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
411 | //we use the same function as used for parsing the config tokens
|
---|
412 | chk_t_dvbapi((*params).params[i], (*params).values[i]);
|
---|
413 | }
|
---|
414 | }
|
---|
415 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration DVB Api done. You should restart Oscam now.</B><BR><BR>");
|
---|
416 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
417 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
418 | }
|
---|
419 |
|
---|
420 | if (cfg->dvbapi_enabled > 0) tpl_addVar(vars, 0, "ENABLEDCHECKED", "checked");
|
---|
421 | if (cfg->dvbapi_au > 0) tpl_addVar(vars, 0, "AUCHECKED", "checked");
|
---|
422 | tpl_addVar(vars, 0, "BOXTYPE", cfg->dvbapi_boxtype);
|
---|
423 | tpl_addVar(vars, 0, "USER", cfg->dvbapi_usr);
|
---|
424 |
|
---|
425 | fputs(tpl_getTpl(vars, "CONFIGDVBAPI"), f);
|
---|
426 | }
|
---|
427 | #endif
|
---|
428 |
|
---|
429 | #ifdef CS_ANTICASC
|
---|
430 | void send_oscam_config_anticasc(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
431 | int i;
|
---|
432 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
433 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
434 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
435 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
436 | //we use the same function as used for parsing the config tokens
|
---|
437 | chk_t_ac((*params).params[i], (*params).values[i]);
|
---|
438 | }
|
---|
439 | }
|
---|
440 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Anticascading done. You should restart Oscam now.</B><BR><BR>");
|
---|
441 | refresh_oscam(REFR_ANTICASC, in);
|
---|
442 | if(write_config()==0) refresh_oscam(REFR_SERVER, in);
|
---|
443 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
444 | }
|
---|
445 | if (cfg->ac_enabled > 0) tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
446 | tpl_printf(vars, 0, "NUMUSERS", "%d", cfg->ac_users);
|
---|
447 | tpl_printf(vars, 0, "SAMPLETIME", "%d", cfg->ac_stime);
|
---|
448 | tpl_printf(vars, 0, "SAMPLES", "%d", cfg->ac_samples);
|
---|
449 | tpl_printf(vars, 0, "PENALTY", "%d", cfg->ac_penalty);
|
---|
450 | tpl_addVar(vars, 0, "ACLOGFILE", cfg->ac_logfile);
|
---|
451 | tpl_printf(vars, 0, "FAKEDELAY", "%d", cfg->ac_fakedelay);
|
---|
452 | tpl_printf(vars, 0, "DENYSAMPLES", "%d", cfg->ac_denysamples);
|
---|
453 | fputs(tpl_getTpl(vars, "CONFIGANTICASC"), f);
|
---|
454 | }
|
---|
455 | #endif
|
---|
456 |
|
---|
457 | void send_oscam_config(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
458 | char *part = getParam(params, "part");
|
---|
459 | if (!strcmp(part,"camd33")) send_oscam_config_camd33(vars, f, params, in);
|
---|
460 | else if (!strcmp(part,"camd35")) send_oscam_config_camd35(vars, f, params, in);
|
---|
461 | else if (!strcmp(part,"camd35tcp")) send_oscam_config_camd35tcp(vars, f, params, in);
|
---|
462 | else if (!strcmp(part,"newcamd")) send_oscam_config_newcamd(vars, f, params, in);
|
---|
463 | else if (!strcmp(part,"radegast")) send_oscam_config_radegast(vars, f, params, in);
|
---|
464 | else if (!strcmp(part,"cccam")) send_oscam_config_cccam(vars, f, params, in);
|
---|
465 | #ifdef CS_WITH_GBOX
|
---|
466 | else if (!strcmp(part,"gbox")) send_oscam_config_gbox(vars, f, params, in);
|
---|
467 | #endif
|
---|
468 | #ifdef HAVE_DVBAPI
|
---|
469 | else if (!strcmp(part,"dvbapi")) send_oscam_config_dvbapi(vars, f, params, in);
|
---|
470 | #endif
|
---|
471 | #ifdef CS_ANTICASC
|
---|
472 | else if (!strcmp(part,"anticasc")) send_oscam_config_anticasc(vars, f, params, in);
|
---|
473 | #endif
|
---|
474 | else if (!strcmp(part,"monitor")) send_oscam_config_monitor(vars, f, params, in);
|
---|
475 | else if (!strcmp(part,"serial")) send_oscam_config_serial(vars, f, params, in);
|
---|
476 | else send_oscam_config_global(vars, f, params, in);
|
---|
477 | }
|
---|
478 |
|
---|
479 | void send_oscam_reader(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
480 | int readeridx, isphysical = 0;
|
---|
481 | char *ctyp;
|
---|
482 | //uchar dummy[1]={0x00};
|
---|
483 |
|
---|
484 | if (strcmp(getParam(params, "action"), "reread") == 0){
|
---|
485 | readeridx = atoi(getParam(params, "ridx"));
|
---|
486 | //reset the counters
|
---|
487 | reader[readeridx].emmerror = 0;
|
---|
488 | reader[readeridx].emmwritten = 0;
|
---|
489 | reader[readeridx].emmskipped = 0;
|
---|
490 | reader[readeridx].emmblocked = 0;
|
---|
491 | //write_to_pipe(client[reader[readeridx].cs_idx)].fd_m2c, PIP_ID_CIN, dummy, 1); // do not work for whatever reason
|
---|
492 | refresh_oscam(REFR_READERS, in); // refresh all reader because write pipe seams not work from here
|
---|
493 | }
|
---|
494 |
|
---|
495 | for(readeridx = 0; readeridx < CS_MAXREADER; readeridx++){
|
---|
496 | isphysical = 0;
|
---|
497 |
|
---|
498 | if(!reader[readeridx].device[0]) break;
|
---|
499 |
|
---|
500 | tpl_addVar(vars, 0, "READERNAME", reader[readeridx].label);
|
---|
501 | tpl_addVar(vars, 0, "READERNAMEENC", tpl_addTmp(vars, urlencode(reader[readeridx].label)));
|
---|
502 |
|
---|
503 | switch(reader[readeridx].typ){
|
---|
504 | case R_MOUSE :
|
---|
505 | ctyp = "mouse";
|
---|
506 | isphysical = 1;
|
---|
507 | break;
|
---|
508 | case R_INTERNAL:
|
---|
509 | ctyp = "intern";
|
---|
510 | isphysical = 1;
|
---|
511 | break;
|
---|
512 | case R_SMART :
|
---|
513 | ctyp = "smartreader";
|
---|
514 | isphysical = 1;
|
---|
515 | break;
|
---|
516 | case R_SERIAL :
|
---|
517 | ctyp = "serial";
|
---|
518 | isphysical = 1;
|
---|
519 | break;
|
---|
520 | case R_DB2COM1 :
|
---|
521 | ctyp = "dbox COM1";
|
---|
522 | isphysical = 1;
|
---|
523 | break;
|
---|
524 | case R_DB2COM2 :
|
---|
525 | ctyp = "dbox COM2";
|
---|
526 | isphysical = 1;
|
---|
527 | break;
|
---|
528 | case R_CAMD35 : ctyp="camd 3.5x";break;
|
---|
529 | case R_CAMD33 : ctyp="camd 3.3x";break;
|
---|
530 | case R_NEWCAMD : ctyp="newcamd"; break;
|
---|
531 | case R_RADEGAST: ctyp="radegast"; break;
|
---|
532 | #ifdef CS_WITH_GBOX
|
---|
533 | case R_GBOX : ctyp="gbox"; break;
|
---|
534 | #endif
|
---|
535 | #ifdef HAVE_PCSC
|
---|
536 | case R_PCSC :
|
---|
537 | ctyp="pcsc";
|
---|
538 | isphysical = 1;
|
---|
539 | break;
|
---|
540 | #endif
|
---|
541 | case R_CCCAM : ctyp="cccam"; break;
|
---|
542 | case R_CS378X : ctyp="cs378x"; break;
|
---|
543 | default : ctyp="unknown"; break;
|
---|
544 | }
|
---|
545 |
|
---|
546 | if (isphysical == 1) {
|
---|
547 | tpl_printf(vars, 0, "RIDX", "%d", readeridx);
|
---|
548 | tpl_printf(vars, 0, "EMMERROR", "%d", reader[readeridx].emmerror);
|
---|
549 | tpl_printf(vars, 0, "EMMWRITTEN", "%d", reader[readeridx].emmwritten);
|
---|
550 | tpl_printf(vars, 0, "EMMSKIPPED", "%d", reader[readeridx].emmskipped);
|
---|
551 | tpl_printf(vars, 0, "EMMBLOCKED", "%d", reader[readeridx].emmblocked);
|
---|
552 | tpl_addVar(vars, 0, "REFRICO", ICREF);
|
---|
553 | tpl_addVar(vars, 0, "READERREFRESH", tpl_getTpl(vars, "READERREFRESHBIT"));
|
---|
554 | #ifdef CS_RDR_INIT_HIST
|
---|
555 | tpl_addVar(vars, 0, "ENTICO", ICENT);
|
---|
556 | tpl_addVar(vars, 0, "ENTITLEMENT", tpl_getTpl(vars, "READERENTITLEBIT"));
|
---|
557 | #endif
|
---|
558 | } else {
|
---|
559 | tpl_printf(vars, 0, "RIDX", "");
|
---|
560 | tpl_addVar(vars, 0, "EMMERROR", "");
|
---|
561 | tpl_addVar(vars, 0, "EMMWRITTEN", "");
|
---|
562 | tpl_addVar(vars, 0, "EMMSKIPPED", "");
|
---|
563 | tpl_addVar(vars, 0, "EMMBLOCKED", "");
|
---|
564 | tpl_addVar(vars, 0, "READERREFRESH","");
|
---|
565 | #ifdef CS_RDR_INIT_HIST
|
---|
566 | tpl_addVar(vars, 0, "ENTITLEMENT","");
|
---|
567 | #endif
|
---|
568 | }
|
---|
569 |
|
---|
570 | tpl_addVar(vars, 0, "CTYP", ctyp);
|
---|
571 | tpl_addVar(vars, 0, "EDIICO", ICEDI);
|
---|
572 | tpl_addVar(vars, 1, "READERLIST", tpl_getTpl(vars, "READERSBIT"));
|
---|
573 |
|
---|
574 | }
|
---|
575 | fputs(tpl_getTpl(vars, "READERS"), f);
|
---|
576 | }
|
---|
577 |
|
---|
578 | void send_oscam_reader_config(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
579 | int ridx;
|
---|
580 | char *reader_ = getParam(params, "reader");
|
---|
581 | for(ridx = 0; ridx < CS_MAXREADER && strcmp(reader_, reader[ridx].label) != 0; ++ridx);
|
---|
582 | if(ridx == CS_MAXREADER){
|
---|
583 | tpl_addVar(vars, 0, "MESSAGE", "<BR><BR>Reader not found<BR><BR>");
|
---|
584 | } else if(strcmp(getParam(params, "action"), "execute") == 0){
|
---|
585 | tpl_addVar(vars, 0, "MESSAGE", "<BR><BR>Saving not yet implemented<BR><BR>");
|
---|
586 | refresh_oscam(REFR_READERS, in);
|
---|
587 | }
|
---|
588 | int i;
|
---|
589 |
|
---|
590 | tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
|
---|
591 | tpl_printf(vars, 0, "DEVICE", "%s", reader[ridx].device);
|
---|
592 | tpl_addVar(vars, 0, "NCD_KEY", (char *)reader[ridx].ncd_key);
|
---|
593 | tpl_addVar(vars, 0, "PINCODE", reader[ridx].pincode);
|
---|
594 | //tpl_addVar(vars, 0, "EMMFILE", (char *)reader[ridx].emmfile);
|
---|
595 | tpl_printf(vars, 0, "INACTIVITYTIMEOUT", "%d", reader[ridx].tcp_ito);
|
---|
596 | tpl_printf(vars, 0, "RECEIVETIMEOUT", "%d", reader[ridx].tcp_rto);
|
---|
597 | tpl_printf(vars, 0, "DISABLESERVERFILTER", "%d", reader[ridx].ncd_disable_server_filt);
|
---|
598 | tpl_printf(vars, 0, "FALLBACK", "%d", reader[ridx].fallback);
|
---|
599 | tpl_printf(vars, 0, "LOGPORT", "%d", reader[ridx].log_port);
|
---|
600 | tpl_printf(vars, 0, "BOXID", "%ld", reader[ridx].boxid);
|
---|
601 | tpl_addVar(vars, 0, "USER", reader[ridx].r_usr);
|
---|
602 | tpl_addVar(vars, 0, "PASS", reader[ridx].r_pwd);
|
---|
603 | tpl_addVar(vars, 0, "RSAKEY", (char *)reader[ridx].rsa_mod);
|
---|
604 | tpl_addVar(vars, 0, "BOXKEY", (char *)reader[ridx].nagra_boxkey);
|
---|
605 |
|
---|
606 | if (reader[ridx].detect&0x80)
|
---|
607 | tpl_printf(vars, 0, "DETECT", "!%s", RDR_CD_TXT[reader[ridx].detect&0x7f]);
|
---|
608 | else
|
---|
609 | tpl_printf(vars, 0, "DETECT", "%s", RDR_CD_TXT[reader[ridx].detect&0x7f]);
|
---|
610 |
|
---|
611 | tpl_printf(vars, 0, "MHZ", "%d", reader[ridx].mhz);
|
---|
612 | tpl_printf(vars, 0, "CARDMHZ", "%d", reader[ridx].cardmhz);
|
---|
613 |
|
---|
614 |
|
---|
615 | #ifdef CS_WITH_GBOX
|
---|
616 | tpl_addVar(vars, 0, "GBOXPWD", (char *)reader[ridx].gbox_pwd);
|
---|
617 | tpl_addVar(vars, 0, "PREMIUM", reader[ridx].gbox_prem);
|
---|
618 | #endif
|
---|
619 |
|
---|
620 | if(reader[ridx].r_port) tpl_printf(vars, 0, "R_PORT", ",%d", reader[ridx].r_port);
|
---|
621 | if(reader[ridx].l_port) {
|
---|
622 | if(reader[ridx].r_port) tpl_printf(vars, 0, "L_PORT", ",%d", reader[ridx].l_port);
|
---|
623 | else tpl_printf(vars, 0, "L_PORT", ",,%d", reader[ridx].l_port);
|
---|
624 | }
|
---|
625 |
|
---|
626 | //group
|
---|
627 | char *value = mk_t_group((ulong*)reader[ridx].grp);
|
---|
628 | tpl_printf(vars, 0, "GRP", "%s", value);
|
---|
629 | free(value);
|
---|
630 |
|
---|
631 | //services
|
---|
632 | char sidok[33];
|
---|
633 | long2bitchar(reader[ridx].sidtabok, sidok);
|
---|
634 | char sidno[33];
|
---|
635 | long2bitchar(reader[ridx].sidtabno,sidno);
|
---|
636 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
637 | //build matrix
|
---|
638 | i = 0;
|
---|
639 | while(sidtab != NULL){
|
---|
640 | tpl_addVar(vars, 0, "SIDLABEL", sidtab->label);
|
---|
641 | if(sidok[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
642 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
643 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDOKBIT"));
|
---|
644 | if(sidno[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
645 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
646 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDNOBIT"));
|
---|
647 | sidtab=sidtab->next;
|
---|
648 | i++;
|
---|
649 | }
|
---|
650 |
|
---|
651 | // CAID
|
---|
652 | value = mk_t_caidtab(&reader[ridx].ctab);
|
---|
653 | tpl_addVar(vars, 0, "CAIDS", value);
|
---|
654 | free(value);
|
---|
655 |
|
---|
656 | //ident
|
---|
657 | value = mk_t_ftab(&reader[ridx].ftab);
|
---|
658 | tpl_printf(vars, 0, "IDENTS", "%s\n", value);
|
---|
659 | free(value);
|
---|
660 |
|
---|
661 | //class
|
---|
662 | CLASSTAB *clstab = &reader[ridx].cltab;
|
---|
663 | char *dot="";
|
---|
664 | for(i = 0; i < clstab->an; ++i){
|
---|
665 | tpl_printf(vars, 1, "CLASS", "%s%02x", dot, (int)clstab->aclass[i]);
|
---|
666 | dot=",";
|
---|
667 | }
|
---|
668 | for(i = 0; i < clstab->bn; ++i){
|
---|
669 | tpl_printf(vars, 0, "CLASS", "%s!%02x", dot, (int)clstab->bclass[i]);
|
---|
670 | dot=",";
|
---|
671 | }
|
---|
672 |
|
---|
673 | //chid
|
---|
674 | int j;
|
---|
675 | dot="";
|
---|
676 | FTAB *ftab = &reader[ridx].fchid;
|
---|
677 | for (i = 0; i < ftab->nfilts; ++i){
|
---|
678 | tpl_printf(vars, 1, "CHIDS", "%s%04X", dot, ftab->filts[i].caid);
|
---|
679 | dot=":";
|
---|
680 | for (j = 0; j < ftab->filts[i].nprids; ++j) {
|
---|
681 | tpl_printf(vars, 1, "CHIDS", "%s%06lX", dot, ftab->filts[i].prids[j]);
|
---|
682 | dot=",";
|
---|
683 | }
|
---|
684 | dot=";";
|
---|
685 | }
|
---|
686 |
|
---|
687 | tpl_printf(vars, 0, "SHOWCLS", "%d", reader[ridx].show_cls);
|
---|
688 | tpl_printf(vars, 0, "MAXQLEN", "%d", reader[ridx].maxqlen);
|
---|
689 | tpl_printf(vars, 0, "EMMCACHE", "%d,%d,&d", reader[ridx].cachemm, reader[ridx].rewritemm, reader[ridx].logemm);
|
---|
690 |
|
---|
691 | //savenano
|
---|
692 | int all = 1;
|
---|
693 | dot="";
|
---|
694 | for(i = 0; i < 256; ++i){
|
---|
695 | if(!(reader[ridx].b_nano[i] & 0x02)){
|
---|
696 | all = 0;
|
---|
697 | break;
|
---|
698 | }
|
---|
699 | }
|
---|
700 | if (all == 1) tpl_printf(vars, 0, "SAVENANO", "all", reader[ridx].maxqlen);
|
---|
701 | else {
|
---|
702 | for(i = 0; i < 256; ++i){
|
---|
703 | if(reader[ridx].b_nano[i] & 0x02) tpl_printf(vars, 1, "SAVENANO", "%s%02x\n", dot, i);
|
---|
704 | dot=",";
|
---|
705 | }
|
---|
706 | }
|
---|
707 |
|
---|
708 | //blocknano
|
---|
709 | dot="";
|
---|
710 | for(i = 0; i < 256; ++i){
|
---|
711 | if(!(reader[ridx].b_nano[i] & 0x01)){
|
---|
712 | all = 0;
|
---|
713 | break;
|
---|
714 | }
|
---|
715 | }
|
---|
716 | if (all == 1) tpl_printf(vars, 0, "BLOCKNANO", "all", reader[ridx].maxqlen);
|
---|
717 | else {
|
---|
718 | for(i = 0; i < 256; ++i){
|
---|
719 | if(reader[ridx].b_nano[i] & 0x01) tpl_printf(vars, 1, "BLOCKNANO", "%s%02x\n", dot, i);
|
---|
720 | dot=",";
|
---|
721 | }
|
---|
722 | }
|
---|
723 |
|
---|
724 | tpl_addVar(vars, 0, "CCCVERSION", reader[ridx].cc_version);
|
---|
725 | tpl_addVar(vars, 0, "CCCBUILD", reader[ridx].cc_build);
|
---|
726 | tpl_printf(vars, 0, "CCCMAXHOP", "%d", reader[ridx].cc_maxhop);
|
---|
727 |
|
---|
728 |
|
---|
729 | // Show only parameters which needed for the reader
|
---|
730 | switch (reader[ridx].typ) {
|
---|
731 |
|
---|
732 | case R_MOUSE :
|
---|
733 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGMOUSEBIT"));
|
---|
734 | break;
|
---|
735 | case R_SMART :
|
---|
736 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSMARTBIT"));
|
---|
737 | break;
|
---|
738 | case R_INTERNAL:
|
---|
739 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGINTERNALBIT"));
|
---|
740 | break;
|
---|
741 | case R_SERIAL :
|
---|
742 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSERIALBIT"));
|
---|
743 | break;
|
---|
744 | case R_CAMD35 :
|
---|
745 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGCAMD35BIT"));
|
---|
746 | break;
|
---|
747 | case R_CS378X :
|
---|
748 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGCS378XBIT"));
|
---|
749 | break;
|
---|
750 | case R_RADEGAST:
|
---|
751 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGRADEGASTBIT"));
|
---|
752 | break;
|
---|
753 | case R_NEWCAMD :
|
---|
754 | if ( reader[ridx].ncd_proto == NCD_525 )
|
---|
755 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGNCD525BIT"));
|
---|
756 | else if ( reader[ridx].ncd_proto == NCD_524 )
|
---|
757 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGNCD524BIT"));
|
---|
758 | break;
|
---|
759 | #ifdef CS_WITH_GBOX
|
---|
760 | case R_GBOX :
|
---|
761 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGGBOXBIT"));
|
---|
762 | break;
|
---|
763 | #endif
|
---|
764 | #ifdef HAVE_PCSC
|
---|
765 | case R_PCSC :
|
---|
766 | tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGPCSCBIT"));
|
---|
767 | break;
|
---|
768 | #endif
|
---|
769 |
|
---|
770 |
|
---|
771 | }
|
---|
772 | //READERCONFIGMOUSEBIT
|
---|
773 | fputs(tpl_getTpl(vars, "READERCONFIG"), f);
|
---|
774 | }
|
---|
775 |
|
---|
776 | void send_oscam_user_config_edit(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in){
|
---|
777 | struct s_auth *account, *ptr;
|
---|
778 | char user[128];
|
---|
779 |
|
---|
780 | if (strcmp(getParam(params, "action"), "Save As") == 0) cs_strncpy(user, getParam(params, "newuser"), sizeof(user)/sizeof(char));
|
---|
781 | else cs_strncpy(user, getParam(params, "user"), sizeof(user)/sizeof(char));
|
---|
782 |
|
---|
783 | int i;
|
---|
784 |
|
---|
785 | for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
786 |
|
---|
787 | // Create a new user if it doesn't yet
|
---|
788 | if (account == NULL){
|
---|
789 | i = 1;
|
---|
790 | while(strlen(user) < 1){
|
---|
791 | snprintf(user, sizeof(user)/sizeof(char) - 1, "NEWUSER%d", i);
|
---|
792 | for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
793 | if(account != NULL) user[0] = '\0';
|
---|
794 | ++i;
|
---|
795 | }
|
---|
796 | if (!(account=malloc(sizeof(struct s_auth)))){
|
---|
797 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
798 | return;
|
---|
799 | }
|
---|
800 | if(cfg->account == NULL) cfg->account = account;
|
---|
801 | else {
|
---|
802 | for (ptr = cfg->account; ptr != NULL && ptr->next != NULL; ptr = ptr->next);
|
---|
803 | ptr->next = account;
|
---|
804 | }
|
---|
805 | memset(account, 0, sizeof(struct s_auth));
|
---|
806 | cs_strncpy((char *)account->usr, user, sizeof(account->usr));
|
---|
807 | account->au=(-1);
|
---|
808 | account->monlvl=cfg->mon_level;
|
---|
809 | account->tosleep=cfg->tosleep;
|
---|
810 | for (i=1; i<CS_MAXCAIDTAB; account->ctab.mask[i++]=0xffff);
|
---|
811 | for (i=1; i<CS_MAXTUNTAB; account->ttab.bt_srvid[i++]=0x0000);
|
---|
812 | account->expirationdate=(time_t)NULL;
|
---|
813 | #ifdef CS_ANTICASC
|
---|
814 | account->ac_users=cfg->ac_users;
|
---|
815 | account->ac_penalty=cfg->ac_penalty;
|
---|
816 | account->ac_idx = account->ac_idx + 1;
|
---|
817 | #endif
|
---|
818 | tpl_addVar(vars, 1, "MESSAGE", "<b>New user has been added with default settings</b><BR>");
|
---|
819 | if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS, in);
|
---|
820 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing configuration to disk failed!</b><BR>");
|
---|
821 | // need to reget account as writing to disk changes account!
|
---|
822 | for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
823 | }
|
---|
824 |
|
---|
825 | if((strcmp(getParam(params, "action"), "Save") == 0) || (strcmp(getParam(params, "action"), "Save As") == 0)){
|
---|
826 | char servicelabels[255]="";
|
---|
827 | //clear group
|
---|
828 | account->grp = 0;
|
---|
829 |
|
---|
830 | for(i=0;i<(*params).paramcount;i++){
|
---|
831 | if ((strcmp((*params).params[i], "action")) && (strcmp((*params).params[i], "user")) && (strcmp((*params).params[i], "newuser"))){
|
---|
832 | if (!strcmp((*params).params[i], "expdate"))
|
---|
833 | account->expirationdate=(time_t)NULL;
|
---|
834 | if (!strcmp((*params).params[i], "services"))
|
---|
835 | sprintf(servicelabels + strlen(servicelabels), "%s,", (*params).values[i]);
|
---|
836 | else
|
---|
837 | chk_account((*params).params[i], (*params).values[i], account);
|
---|
838 | }
|
---|
839 | }
|
---|
840 | chk_account("services", servicelabels, account);
|
---|
841 | tpl_addVar(vars, 1, "MESSAGE", "<B>Settings updated</B><BR><BR>");
|
---|
842 | if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS, in);
|
---|
843 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
844 | }
|
---|
845 | for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
846 |
|
---|
847 | tpl_addVar(vars, 0, "USERNAME", account->usr);
|
---|
848 | tpl_addVar(vars, 0, "PASSWORD", account->pwd);
|
---|
849 |
|
---|
850 | //Disabled
|
---|
851 | if(account->disabled)
|
---|
852 | tpl_addVar(vars, 0, "DISABLEDCHECKED", "checked");
|
---|
853 |
|
---|
854 | //Expirationdate
|
---|
855 | struct tm * timeinfo = localtime (&account->expirationdate);
|
---|
856 | char buf [80];
|
---|
857 | strftime (buf,80,"%Y-%m-%d",timeinfo);
|
---|
858 | if(strcmp(buf,"1970-01-01")) tpl_addVar(vars, 0, "EXPDATE", buf);
|
---|
859 |
|
---|
860 | //Group
|
---|
861 | char *value = mk_t_group((ulong*)account->grp);
|
---|
862 | tpl_addVar(vars, 0, "GROUPS", value);
|
---|
863 | free(value);
|
---|
864 |
|
---|
865 | //Hostname
|
---|
866 | tpl_addVar(vars, 0, "DYNDNS", (char *)account->dyndns);
|
---|
867 |
|
---|
868 | //Uniq
|
---|
869 | tpl_printf(vars, 0, "TMP", "UNIQSELECTED%d", account->uniq);
|
---|
870 | tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
|
---|
871 |
|
---|
872 | //Sleep
|
---|
873 | if(!account->tosleep) tpl_addVar(vars, 0, "SLEEP", "0");
|
---|
874 | else tpl_printf(vars, 0, "SLEEP", "%d", account->tosleep);
|
---|
875 | //Monlevel selector
|
---|
876 | tpl_printf(vars, 0, "TMP", "MONSELECTED%d", account->monlvl);
|
---|
877 | tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
|
---|
878 |
|
---|
879 | //AU Selector
|
---|
880 | if (!account->au) tpl_addVar(vars, 0, "AUSELECTED", "selected");
|
---|
881 | if (account->autoau == 1) tpl_addVar(vars, 0, "AUTOAUSELECTED", "selected");
|
---|
882 | int ridx;
|
---|
883 | for (ridx=0; ridx<CS_MAXREADER; ridx++){
|
---|
884 | if(!reader[ridx].device[0]) break;
|
---|
885 | tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
|
---|
886 | if (account->au == ridx) tpl_addVar(vars, 0, "SELECTED", "selected");
|
---|
887 | else tpl_addVar(vars, 0, "SELECTED", "");
|
---|
888 | tpl_addVar(vars, 1, "RDROPTION", tpl_getTpl(vars, "USEREDITRDRSELECTED"));
|
---|
889 | }
|
---|
890 |
|
---|
891 | /* SERVICES */
|
---|
892 | //services - first we have to move the long sidtabok/sidtabno to a binary array
|
---|
893 | char sidok[33];
|
---|
894 | long2bitchar(account->sidtabok,sidok);
|
---|
895 | char sidno[33];
|
---|
896 | long2bitchar(account->sidtabno,sidno);
|
---|
897 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
898 | //build matrix
|
---|
899 | i=0;
|
---|
900 | while(sidtab != NULL){
|
---|
901 | tpl_addVar(vars, 0, "SIDLABEL", sidtab->label);
|
---|
902 | if(sidok[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
903 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
904 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "USEREDITSIDOKBIT"));
|
---|
905 | if(sidno[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
906 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
907 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "USEREDITSIDNOBIT"));
|
---|
908 | sidtab=sidtab->next;
|
---|
909 | i++;
|
---|
910 | }
|
---|
911 |
|
---|
912 | // CAID
|
---|
913 | value = mk_t_caidtab(&account->ctab);
|
---|
914 | tpl_addVar(vars, 0, "CAIDS", value);
|
---|
915 | free(value);
|
---|
916 |
|
---|
917 | //ident
|
---|
918 | value = mk_t_ftab(&account->ftab);
|
---|
919 | tpl_printf(vars, 0, "IDENTS", "%s\n", value);
|
---|
920 | free(value);
|
---|
921 |
|
---|
922 | //Betatunnel
|
---|
923 | value = mk_t_tuntab(&account->ttab);
|
---|
924 | tpl_addVar(vars, 0, "BETATUNNELS", value);
|
---|
925 | free(value);
|
---|
926 |
|
---|
927 | //SUPPRESSCMD08
|
---|
928 | if (account->c35_suppresscmd08)
|
---|
929 | tpl_addVar(vars, 0, "SUPPRESSCMD08", "checked");
|
---|
930 |
|
---|
931 | //Keepalive
|
---|
932 | if (account->ncd_keepalive)
|
---|
933 | tpl_addVar(vars, 0, "KEEPALIVE", "checked");
|
---|
934 |
|
---|
935 | #ifdef CS_ANTICASC
|
---|
936 | tpl_printf(vars, 0, "AC_USERS", "%d", account->ac_users);
|
---|
937 | tpl_printf(vars, 0, "AC_PENALTY", "%d", account->ac_penalty);
|
---|
938 | #endif
|
---|
939 | fputs(tpl_getTpl(vars, "USEREDIT"), f);
|
---|
940 | }
|
---|
941 |
|
---|
942 | void send_oscam_user_config(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
943 | struct s_auth *account, *account2;
|
---|
944 | char *user = getParam(params, "user");
|
---|
945 | int i, found = 0;
|
---|
946 | int hideclient = 10;
|
---|
947 |
|
---|
948 | if (cfg->mon_hideclient_to > 10)
|
---|
949 | hideclient = cfg->mon_hideclient_to;
|
---|
950 |
|
---|
951 | if (strcmp(getParam(params, "action"), "delete") == 0){
|
---|
952 | account=cfg->account;
|
---|
953 | if(strcmp(account->usr, user) == 0){
|
---|
954 | cfg->account = account->next;
|
---|
955 | free(account);
|
---|
956 | found = 1;
|
---|
957 | } else if (account->next != NULL){
|
---|
958 | do{
|
---|
959 | if(strcmp(account->next->usr, user) == 0){
|
---|
960 | account2 = account->next;
|
---|
961 | account->next = account2->next;
|
---|
962 | free(account2);
|
---|
963 | found = 1;
|
---|
964 | break;
|
---|
965 | }
|
---|
966 | } while ((account = account->next) && (account->next != NULL));
|
---|
967 | }
|
---|
968 |
|
---|
969 | if (found > 0){
|
---|
970 | tpl_addVar(vars, 1, "MESSAGE", "<b>Account has been deleted!</b><BR>");
|
---|
971 | if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS, in);
|
---|
972 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing configuration to disk failed!</b><BR>");
|
---|
973 | } else tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
|
---|
974 | }
|
---|
975 |
|
---|
976 | if ((strcmp(getParam(params, "action"), "disable") == 0) || (strcmp(getParam(params, "action"), "enable") == 0)){
|
---|
977 | for (account=cfg->account; (account) ; account=account->next){
|
---|
978 | if(strcmp(getParam(params, "user"), account->usr) == 0){
|
---|
979 | if(strcmp(getParam(params, "action"), "disable") == 0)
|
---|
980 | account->disabled = 1;
|
---|
981 | else
|
---|
982 | account->disabled = 0;
|
---|
983 | found = 1;
|
---|
984 | }
|
---|
985 | }
|
---|
986 |
|
---|
987 | if (found > 0){
|
---|
988 | tpl_addVar(vars, 1, "MESSAGE", "<b>Account has been switched!</b><BR>");
|
---|
989 | if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS, in);
|
---|
990 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing configuration to disk failed!</b><BR>");
|
---|
991 | } else tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
|
---|
992 | }
|
---|
993 |
|
---|
994 | /* List accounts*/
|
---|
995 | char *status = "offline";
|
---|
996 | char *expired = "";
|
---|
997 | char *classname="offline";
|
---|
998 | char *lastchan=" ";
|
---|
999 | time_t now = time((time_t)0);
|
---|
1000 | int isec = 0, isonline = 0;
|
---|
1001 |
|
---|
1002 | for (account=cfg->account; (account) ; account=account->next){
|
---|
1003 | //clear for next client
|
---|
1004 | expired = ""; classname = "offline"; status = "offline";
|
---|
1005 | isonline = 0;
|
---|
1006 | tpl_addVar(vars, 0, "CWOK", "");
|
---|
1007 | tpl_addVar(vars, 0, "CWNOK", "");
|
---|
1008 | tpl_addVar(vars, 0, "CWIGN", "");
|
---|
1009 | tpl_addVar(vars, 0, "CWTOUT", "");
|
---|
1010 | tpl_addVar(vars, 0, "CWCACHE", "");
|
---|
1011 | tpl_addVar(vars, 0, "CWTUN", "");
|
---|
1012 | tpl_addVar(vars, 0, "CLIENTPROTO","");
|
---|
1013 | tpl_addVar(vars, 0, "IDLESECS","");
|
---|
1014 | tpl_addVar(vars, 0, "CWLASTRESPONSET","");
|
---|
1015 | tpl_addVar(vars, 0, "EMMOK","");
|
---|
1016 | tpl_addVar(vars, 0, "EMMNOK","");
|
---|
1017 | tpl_addVar(vars, 0, "CLIENTPROTO","");
|
---|
1018 | tpl_addVar(vars, 0, "LASTCHANNEL", "");
|
---|
1019 |
|
---|
1020 | if(account->expirationdate && account->expirationdate<time(NULL)){
|
---|
1021 | expired = " (expired)";
|
---|
1022 | classname = "expired";
|
---|
1023 | }
|
---|
1024 | if(account->disabled != 0){
|
---|
1025 | expired = " (disabled)";
|
---|
1026 | classname = "disabled";
|
---|
1027 | tpl_addVar(vars, 0, "SWITCHICO", ICENA);
|
---|
1028 | tpl_addVar(vars, 0, "SWITCHTITLE", "enable this account");
|
---|
1029 | tpl_addVar(vars, 0, "SWITCH", "enable");
|
---|
1030 | }else{
|
---|
1031 | tpl_addVar(vars, 0, "SWITCHICO", ICDIS);
|
---|
1032 | tpl_addVar(vars, 0, "SWITCHTITLE", "disable this account");
|
---|
1033 | tpl_addVar(vars, 0, "SWITCH", "disable");
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | //search account in active clients
|
---|
1037 | int cwok = 0, cwnok = 0, cwign = 0, cwtout = 0, cwcache = 0, cwtun = 0, emmok = 0, emmnok = 0;
|
---|
1038 | int secs = 0, fullmins =0, mins =0, hours =0, lastresponsetm = 0;
|
---|
1039 | char *proto = "";
|
---|
1040 |
|
---|
1041 | for (i=0; i<CS_MAXPID; i++)
|
---|
1042 | if (!strcmp(client[i].usr, account->usr)){
|
---|
1043 | //set client to offline depending on hideclient_to
|
---|
1044 | if ((now - client[i].lastecm) < hideclient){
|
---|
1045 | status = "<b>online</b>"; classname="online";
|
---|
1046 | isonline = 1;
|
---|
1047 | proto = monitor_get_proto(i);
|
---|
1048 | lastchan = monitor_get_srvname(client[i].last_srvid, client[i].last_caid);
|
---|
1049 | lastresponsetm = client[i].cwlastresptime;
|
---|
1050 | isec = now - client[i].last;
|
---|
1051 | if(isec > 0){
|
---|
1052 | secs = isec % 60;
|
---|
1053 | if (isec > 60){
|
---|
1054 | fullmins = isec / 60;
|
---|
1055 | mins = fullmins % 60;
|
---|
1056 | if(fullmins > 60) hours = fullmins / 60;
|
---|
1057 | }
|
---|
1058 | }
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | cwok += client[i].cwfound;
|
---|
1062 | cwnok += client[i].cwnot;
|
---|
1063 | cwign += client[i].cwignored;
|
---|
1064 | cwtout += client[i].cwtout;
|
---|
1065 | cwcache += client[i].cwcache;
|
---|
1066 | cwtun += client[i].cwtun;
|
---|
1067 | emmok += client[i].emmok;
|
---|
1068 | emmnok += client[i].emmnok;
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | if ( isonline > 0 ) {
|
---|
1072 | tpl_printf(vars, 0, "CWOK", "%d", cwok);
|
---|
1073 | tpl_printf(vars, 0, "CWNOK", "%d", cwnok);
|
---|
1074 | tpl_printf(vars, 0, "CWIGN", "%d", cwign);
|
---|
1075 | tpl_printf(vars, 0, "CWTOUT", "%d", cwtout);
|
---|
1076 | tpl_printf(vars, 0, "CWCACHE", "%d", cwcache);
|
---|
1077 | tpl_printf(vars, 0, "CWTUN", "%d", cwtun);
|
---|
1078 | tpl_printf(vars, 0, "EMMOK", "%d", emmok);
|
---|
1079 | tpl_printf(vars, 0, "EMMNOK", "%d", emmnok);
|
---|
1080 | tpl_addVar(vars, 0, "LASTCHANNEL", lastchan);
|
---|
1081 | tpl_printf(vars, 0, "CWLASTRESPONSET", "%d", lastresponsetm);
|
---|
1082 | tpl_addVar(vars, 0, "CLIENTPROTO", proto);
|
---|
1083 | tpl_printf(vars, 0, "IDLESECS", "%02d:%02d:%02d", hours, mins, secs);
|
---|
1084 |
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 | tpl_addVar(vars, 0, "CLASSNAME", classname);
|
---|
1088 | tpl_addVar(vars, 0, "USER", account->usr);
|
---|
1089 | tpl_addVar(vars, 0, "USERENC", tpl_addTmp(vars, urlencode(account->usr)));
|
---|
1090 | tpl_addVar(vars, 0, "STATUS", status);
|
---|
1091 | tpl_addVar(vars, 0, "EXPIRED", expired);
|
---|
1092 | tpl_addVar(vars, 0, "DELICO", ICDEL);
|
---|
1093 | tpl_addVar(vars, 0, "EDIICO", ICEDI);
|
---|
1094 |
|
---|
1095 | tpl_addVar(vars, 1, "USERCONFIGS", tpl_getTpl(vars, "USERCONFIGLISTBIT"));
|
---|
1096 | isec = 0;
|
---|
1097 | lastchan = " ";
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | if (strcmp(getParam(params, "part"), "adduser") == 0){
|
---|
1101 | tpl_addVar(vars, 1, "NEWUSERFORM", tpl_getTpl(vars, "ADDNEWUSER"));
|
---|
1102 | } else {
|
---|
1103 | if(cfg->http_refresh > 0){
|
---|
1104 | tpl_printf(vars, 0, "REFRESHTIME", "%d", cfg->http_refresh);
|
---|
1105 | tpl_addVar(vars, 0, "REFRESHURL", "userconfig.html");
|
---|
1106 | tpl_addVar(vars, 0, "REFRESH", tpl_getTpl(vars, "REFRESH"));
|
---|
1107 | }
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 |
|
---|
1111 | fputs(tpl_getTpl(vars, "USERCONFIGLIST"), f);
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | void send_oscam_entitlement(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
1115 | /* build entitlements from reader init history */
|
---|
1116 | #ifdef CS_RDR_INIT_HIST
|
---|
1117 | int ridx;
|
---|
1118 | char *p;
|
---|
1119 | char *reader_ = getParam(params, "reader");
|
---|
1120 | if(strlen(reader_) > 0){
|
---|
1121 | for (ridx=0; ridx<CS_MAXREADER && strcmp(reader_, reader[ridx].label) != 0; ridx++);
|
---|
1122 | if(ridx<CS_MAXREADER){
|
---|
1123 | for (p=(char *)reader[ridx].init_history; *p; p+=strlen(p)+1){
|
---|
1124 | tpl_printf(vars, 1, "LOGHISTORY", "%s<BR>\n", p);
|
---|
1125 | }
|
---|
1126 | }
|
---|
1127 | tpl_addVar(vars, 0, "READERNAME", reader_);
|
---|
1128 | }
|
---|
1129 | #else
|
---|
1130 | tpl_addVar(vars, 0, "LOGHISTORY", "Your binary has not been compiled with the \
|
---|
1131 | CS_RDR_INIT_HIST flag (some architectures disable this \
|
---|
1132 | per default to save ressources). Please recompile if you \
|
---|
1133 | need this feature! This is not a bug!<BR>\n");
|
---|
1134 | #endif
|
---|
1135 | fputs(tpl_getTpl(vars, "ENTITLEMENTS"), f);
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | void send_oscam_status(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
1139 | int i;
|
---|
1140 | char *usr;
|
---|
1141 | int lsec, isec, cnr, con, cau;
|
---|
1142 | time_t now = time((time_t)0);
|
---|
1143 | struct tm *lt;
|
---|
1144 |
|
---|
1145 | char *hideidx = getParam(params, "hide");
|
---|
1146 | if(strlen(hideidx) > 0)
|
---|
1147 | client[atoi(hideidx)].wihidden = 1;
|
---|
1148 |
|
---|
1149 | char *hideidle = getParam(params, "hideidle");
|
---|
1150 | if(strlen(hideidle) > 0){
|
---|
1151 | if (atoi(hideidle) == 2){
|
---|
1152 | for (i=0; i<CS_MAXPID; i++)
|
---|
1153 | client[i].wihidden = 0;
|
---|
1154 | }else{
|
---|
1155 | int oldval = cfg->http_hide_idle_clients;
|
---|
1156 | chk_t_monitor("httphideidleclients", hideidle);
|
---|
1157 | if(oldval != cfg->http_hide_idle_clients){
|
---|
1158 | refresh_oscam(REFR_SERVER, in);
|
---|
1159 | }
|
---|
1160 | }
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | if(cfg->http_hide_idle_clients > 0) tpl_addVar(vars, 0, "HIDEIDLECLIENTSSELECTED1", "selected");
|
---|
1164 | else tpl_addVar(vars, 0, "HIDEIDLECLIENTSSELECTED0", "selected");
|
---|
1165 |
|
---|
1166 | for (i=0; i<CS_MAXPID; i++) {
|
---|
1167 | if (client[i].pid && client[i].wihidden != 1) {
|
---|
1168 |
|
---|
1169 | if((cfg->http_hide_idle_clients == 1) && (client[i].typ == 'c') && ((now - client[i].lastecm) > cfg->mon_hideclient_to)) continue;
|
---|
1170 |
|
---|
1171 | lsec=now-client[i].login;
|
---|
1172 | isec=now-client[i].last;
|
---|
1173 | usr=client[i].usr;
|
---|
1174 |
|
---|
1175 | if (((client[i].typ=='r') || (client[i].typ=='p')) && (con=cs_idx2ridx(i))>=0) usr=reader[con].label;
|
---|
1176 |
|
---|
1177 | if (client[i].dup) con=2;
|
---|
1178 | else if ((client[i].tosleep) && (now-client[i].lastswitch>client[i].tosleep)) con=1;
|
---|
1179 | else con=0;
|
---|
1180 |
|
---|
1181 | if (i-cdiff>0) cnr=i-cdiff;
|
---|
1182 | else cnr=(i>1) ? i-1 : 0;
|
---|
1183 |
|
---|
1184 | if( (cau=client[i].au+1) && (now-client[i].lastemm)/60 > cfg->mon_aulow) cau=-cau;
|
---|
1185 |
|
---|
1186 | lt=localtime(&client[i].login);
|
---|
1187 |
|
---|
1188 | tpl_printf(vars, 0, "HIDEIDX", "%d", i);
|
---|
1189 | tpl_addVar(vars, 0, "HIDEICON", ICHID);
|
---|
1190 | tpl_printf(vars, 0, "CLIENTPID", "%d", client[i].pid);
|
---|
1191 | tpl_printf(vars, 0, "CLIENTTYPE", "%c", client[i].typ);
|
---|
1192 | tpl_printf(vars, 0, "CLIENTCNR", "%d", cnr);
|
---|
1193 | tpl_addVar(vars, 0, "CLIENTUSER", usr);
|
---|
1194 | tpl_printf(vars, 0, "CLIENTCAU", "%d", cau);
|
---|
1195 | tpl_printf(vars, 0, "CLIENTCRYPTED", "%d", client[i].crypted);
|
---|
1196 | tpl_printf(vars, 0, "CLIENTIP", "%s", cs_inet_ntoa(client[i].ip));
|
---|
1197 | tpl_printf(vars, 0, "CLIENTPORT", "%d", client[i].port);
|
---|
1198 | tpl_addVar(vars, 0, "CLIENTPROTO", monitor_get_proto(i));
|
---|
1199 | tpl_printf(vars, 0, "CLIENTLOGINDATE", "%02d.%02d.%02d", lt->tm_mday, lt->tm_mon+1, lt->tm_year%100);
|
---|
1200 | tpl_printf(vars, 0, "CLIENTLOGINTIME", "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
|
---|
1201 |
|
---|
1202 | int secs = 0, fullmins =0, mins =0, fullhours =0, hours =0, days =0;
|
---|
1203 | if(lsec > 0){
|
---|
1204 | secs = lsec % 60;
|
---|
1205 | if (lsec > 60){
|
---|
1206 | fullmins = lsec / 60;
|
---|
1207 | mins = fullmins % 60;
|
---|
1208 | if(fullmins > 60){
|
---|
1209 | fullhours = fullmins / 60;
|
---|
1210 | hours = fullhours % 24;
|
---|
1211 | days = fullhours / 24;
|
---|
1212 | }
|
---|
1213 | }
|
---|
1214 | }
|
---|
1215 | if(days == 0)
|
---|
1216 | tpl_printf(vars, 0, "CLIENTLOGINSECS", "%02d:%02d:%02d", hours, mins, secs);
|
---|
1217 | else
|
---|
1218 | tpl_printf(vars, 0, "CLIENTLOGINSECS", "%02dd %02d:%02d:%02d", days, hours, mins, secs);
|
---|
1219 |
|
---|
1220 | tpl_printf(vars, 0, "CLIENTCAID", "%04X", client[i].last_caid);
|
---|
1221 | tpl_printf(vars, 0, "CLIENTSRVID", "%04X", client[i].last_srvid);
|
---|
1222 |
|
---|
1223 | int j, found = 0;
|
---|
1224 | struct s_srvid *srvid = cfg->srvid;
|
---|
1225 |
|
---|
1226 | while (srvid != NULL){
|
---|
1227 | if (srvid->srvid == client[i].last_srvid){
|
---|
1228 | for (j=0; j < srvid->ncaid; j++){
|
---|
1229 | if (srvid->caid[j] == client[i].last_caid){
|
---|
1230 | found = 1;
|
---|
1231 | break;
|
---|
1232 | }
|
---|
1233 | }
|
---|
1234 | }
|
---|
1235 | if (found == 1)
|
---|
1236 | break;
|
---|
1237 | else
|
---|
1238 | srvid = srvid->next;
|
---|
1239 | }
|
---|
1240 |
|
---|
1241 | if (found == 1){
|
---|
1242 | tpl_printf(vars, 0, "CLIENTSRVPROVIDER","%s : ", srvid->prov);
|
---|
1243 | tpl_addVar(vars, 0, "CLIENTSRVNAME", srvid->name);
|
---|
1244 | tpl_addVar(vars, 0, "CLIENTSRVTYPE", srvid->type);
|
---|
1245 | tpl_addVar(vars, 0, "CLIENTSRVDESCRIPTION", srvid->desc);
|
---|
1246 | }else{
|
---|
1247 | cs_debug("Srvid: %04X not found",client[i].last_srvid);
|
---|
1248 | tpl_addVar(vars, 0, "CLIENTSRVPROVIDER","");
|
---|
1249 | tpl_printf(vars, 0, "CLIENTSRVNAME","");
|
---|
1250 | tpl_addVar(vars, 0, "CLIENTSRVTYPE","");
|
---|
1251 | tpl_addVar(vars, 0, "CLIENTSRVDESCRIPTION","");
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | secs = 0, fullmins =0, mins =0, fullhours =0, hours =0, days =0;
|
---|
1255 | if(isec > 0){
|
---|
1256 | secs = isec % 60;
|
---|
1257 | if (isec > 60){
|
---|
1258 | fullmins = isec / 60;
|
---|
1259 | mins = fullmins % 60;
|
---|
1260 | if(fullmins > 60){
|
---|
1261 | fullhours = fullmins / 60;
|
---|
1262 | hours = fullhours % 24;
|
---|
1263 | days = fullhours / 24;
|
---|
1264 | }
|
---|
1265 | }
|
---|
1266 | }
|
---|
1267 | if(days == 0)
|
---|
1268 | tpl_printf(vars, 0, "CLIENTIDLESECS", "%02d:%02d:%02d", hours, mins, secs);
|
---|
1269 | else
|
---|
1270 | tpl_printf(vars, 0, "CLIENTIDLESECS", "%02dd %02d:%02d:%02d", days, hours, mins, secs);
|
---|
1271 | if(con == 2) tpl_printf(vars, 0, "CLIENTCON", "Duplicate");
|
---|
1272 | else if (con == 1) tpl_printf(vars, 0, "CLIENTCON", "Sleep");
|
---|
1273 | else tpl_printf(vars, 0, "CLIENTCON", "OK");
|
---|
1274 | tpl_addVar(vars, 1, "CLIENTSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
|
---|
1275 | }
|
---|
1276 | }
|
---|
1277 |
|
---|
1278 | #ifdef CS_LOGHISTORY
|
---|
1279 | for (i=(*loghistidx+3) % CS_MAXLOGHIST; i!=*loghistidx; i=(i+1) % CS_MAXLOGHIST){
|
---|
1280 | char *p_usr, *p_txt;
|
---|
1281 | p_usr=(char *)(loghist+(i*CS_LOGHISTSIZE));
|
---|
1282 | p_txt=p_usr+32;
|
---|
1283 | if (p_txt[0]) tpl_printf(vars, 1, "LOGHISTORY", "%s<BR>\n", p_txt+8);
|
---|
1284 | }
|
---|
1285 | #else
|
---|
1286 | tpl_addVar(vars, 0, "LOGHISTORY", "the flag CS_LOGHISTORY is not set in your binary<BR>\n");
|
---|
1287 | #endif
|
---|
1288 |
|
---|
1289 | fputs(tpl_getTpl(vars, "STATUS"), f);
|
---|
1290 | }
|
---|
1291 |
|
---|
1292 | void send_oscam_services_edit(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
1293 | struct s_sidtab *sidtab,*ptr;
|
---|
1294 | char label[128];
|
---|
1295 | int i;
|
---|
1296 |
|
---|
1297 | cs_strncpy(label, strtolower(getParam(params, "service")), sizeof(label)/sizeof(char));
|
---|
1298 |
|
---|
1299 | for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
|
---|
1300 |
|
---|
1301 | if (sidtab == NULL){
|
---|
1302 | i = 1;
|
---|
1303 | while(strlen(label) < 1){
|
---|
1304 | snprintf(label, sizeof(label)/sizeof(char) - 1, "newservice%d", i);
|
---|
1305 | for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab = sidtab->next);
|
---|
1306 | if(sidtab != NULL) label[0] = '\0';
|
---|
1307 | ++i;
|
---|
1308 | }
|
---|
1309 | if (!(sidtab=malloc(sizeof(struct s_sidtab)))){
|
---|
1310 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
1311 | return;
|
---|
1312 | }
|
---|
1313 |
|
---|
1314 | if(cfg->sidtab == NULL) cfg->sidtab = sidtab;
|
---|
1315 | else {
|
---|
1316 | for (ptr = cfg->sidtab; ptr != NULL && ptr->next != NULL; ptr = ptr->next);
|
---|
1317 | ptr->next = sidtab;
|
---|
1318 | }
|
---|
1319 | memset(sidtab, 0, sizeof(struct s_sidtab));
|
---|
1320 | cs_strncpy((char *)sidtab->label, label, sizeof(sidtab->label));
|
---|
1321 |
|
---|
1322 | tpl_addVar(vars, 1, "MESSAGE", "<b>New service has been added</b><BR>");
|
---|
1323 | if (write_services()==0) refresh_oscam(REFR_SERVICES, in);
|
---|
1324 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing services to disk failed!</b><BR>");
|
---|
1325 |
|
---|
1326 | for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 | if (strcmp(getParam(params, "action"), "Save") == 0){
|
---|
1330 | for(i=0;i<(*params).paramcount;i++){
|
---|
1331 | if ((strcmp((*params).params[i], "action")) && (strcmp((*params).params[i], "service"))){
|
---|
1332 | chk_sidtab((*params).params[i], (*params).values[i], sidtab);
|
---|
1333 | }
|
---|
1334 | }
|
---|
1335 | tpl_addVar(vars, 1, "MESSAGE", "<B>Services updated</B><BR><BR>");
|
---|
1336 | if (write_services()==0) refresh_oscam(REFR_SERVICES, in);
|
---|
1337 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
1338 |
|
---|
1339 | for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
|
---|
1340 | }
|
---|
1341 |
|
---|
1342 | tpl_addVar(vars, 0, "LABEL", sidtab->label);
|
---|
1343 | tpl_addVar(vars, 0, "LABELENC", urlencode(sidtab->label));
|
---|
1344 |
|
---|
1345 | for (i=0; i<sidtab->num_caid; i++){
|
---|
1346 | if (i==0) tpl_printf(vars, 0, "CAIDS", "%04X", sidtab->caid[i]);
|
---|
1347 | else tpl_printf(vars, 1, "CAIDS", ",%04X", sidtab->caid[i]);
|
---|
1348 | }
|
---|
1349 | for (i=0; i<sidtab->num_provid; i++){
|
---|
1350 | if (i==0) tpl_printf(vars, 0, "PROVIDS", "%06lX", sidtab->provid[i]);
|
---|
1351 | else tpl_printf(vars, 1, "PROVIDS", ",%06lX", sidtab->provid[i]);
|
---|
1352 | }
|
---|
1353 | for (i=0; i<sidtab->num_srvid; i++){
|
---|
1354 | if (i==0) tpl_printf(vars, 0, "SRVIDS", "%04X", sidtab->srvid[i]);
|
---|
1355 | else tpl_printf(vars, 1, "SRVIDS", ",%04X", sidtab->srvid[i]);
|
---|
1356 | }
|
---|
1357 | fputs(tpl_getTpl(vars, "SERVICEEDIT"), f);
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | void send_oscam_services(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
|
---|
1361 | struct s_sidtab *sidtab, *sidtab2;
|
---|
1362 | char *service = getParam(params, "service");
|
---|
1363 | int i, found = 0;
|
---|
1364 |
|
---|
1365 | if (strcmp(getParam(params, "action"), "delete") == 0){
|
---|
1366 | sidtab=cfg->sidtab;
|
---|
1367 | if(strcmp(sidtab->label, service) == 0){
|
---|
1368 | cfg->sidtab = sidtab->next;
|
---|
1369 | free(sidtab);
|
---|
1370 | found = 1;
|
---|
1371 | } else if (sidtab->next != NULL){
|
---|
1372 | do{
|
---|
1373 | if(strcmp(sidtab->next->label, service) == 0){
|
---|
1374 | sidtab2 = sidtab->next;
|
---|
1375 | sidtab->next = sidtab2->next;
|
---|
1376 | free(sidtab2);
|
---|
1377 | found = 1;
|
---|
1378 | break;
|
---|
1379 | }
|
---|
1380 | } while ((sidtab = sidtab->next) && (sidtab->next != NULL));
|
---|
1381 | }
|
---|
1382 | if (found > 0){
|
---|
1383 | tpl_addVar(vars, 1, "MESSAGE", "<b>Service has been deleted!</b><BR>");
|
---|
1384 | if (write_services()==0) refresh_oscam(REFR_SERVICES, in);
|
---|
1385 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing services to disk failed!</b><BR>");
|
---|
1386 | } else tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry but the specified service doesn't exist. No deletion will be made!</b><BR>");
|
---|
1387 | }
|
---|
1388 |
|
---|
1389 | sidtab=cfg->sidtab;
|
---|
1390 | // Show List
|
---|
1391 | while(sidtab != NULL){
|
---|
1392 | tpl_printf(vars, 0, "SID","");
|
---|
1393 | if ((strcmp(getParam(params, "service"), sidtab->label) == 0) && (strcmp(getParam(params, "action"), "list") == 0) ){
|
---|
1394 | tpl_printf(vars, 0, "SIDCLASS","sidlist");
|
---|
1395 | for (i=0; i<sidtab->num_srvid; i++){
|
---|
1396 | tpl_printf(vars, 1, "SID", "%04X : %s<BR>", sidtab->srvid[i], monitor_get_srvname(sidtab->srvid[i], sidtab->caid[0]));
|
---|
1397 | }
|
---|
1398 | } else {
|
---|
1399 | tpl_printf(vars, 0, "SIDCLASS","");
|
---|
1400 | tpl_printf(vars, 0, "SID","<A HREF=\"services.html?service=%s&action=list\">Show Services</A>",tpl_addTmp(vars, urlencode(sidtab->label)));
|
---|
1401 | }
|
---|
1402 | tpl_addVar(vars, 0, "LABELENC", tpl_addTmp(vars, urlencode(sidtab->label)));
|
---|
1403 | tpl_addVar(vars, 0, "LABEL", sidtab->label);
|
---|
1404 | tpl_addVar(vars, 0, "SIDLIST", tpl_getTpl(vars, "SERVICECONFIGSIDBIT"));
|
---|
1405 | tpl_addVar(vars, 0, "EDIICO", ICEDI);
|
---|
1406 | tpl_addVar(vars, 0, "DELICO", ICDEL);
|
---|
1407 | tpl_addVar(vars, 1, "SERVICETABS", tpl_getTpl(vars, "SERVICECONFIGLISTBIT"));
|
---|
1408 | sidtab=sidtab->next;
|
---|
1409 | }
|
---|
1410 | fputs(tpl_getTpl(vars, "SERVICECONFIGLIST"), f);
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 | void send_oscam_savetpls(struct templatevars *vars, FILE *f){
|
---|
1414 | if(strlen(cfg->http_tpl) > 0){
|
---|
1415 | tpl_printf(vars, 0, "CNT", "%d", tpl_saveIncludedTpls(cfg->http_tpl));
|
---|
1416 | tpl_addVar(vars, 0, "PATH", cfg->http_tpl);
|
---|
1417 | } else tpl_addVar(vars, 0, "CNT", "0");
|
---|
1418 | fputs(tpl_getTpl(vars, "SAVETEMPLATES"), f);
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | void send_oscam_shutdown(struct templatevars *vars, FILE *f, struct uriparams *params){
|
---|
1422 | if (strcmp(getParam(params, "action"), "Shutdown") == 0){
|
---|
1423 | tpl_addVar(vars, 0, "STYLESHEET", CSS);
|
---|
1424 | tpl_printf(vars, 0, "REFRESHTIME", "%d", SHUTDOWNREFRESH);
|
---|
1425 | tpl_addVar(vars, 0, "REFRESHURL", "status.html");
|
---|
1426 | tpl_addVar(vars, 0, "REFRESH", tpl_getTpl(vars, "REFRESH"));
|
---|
1427 | tpl_printf(vars, 0, "SECONDS", "%d", SHUTDOWNREFRESH);
|
---|
1428 | fputs(tpl_getTpl(vars, "SHUTDOWN"), f);
|
---|
1429 | running = 0;
|
---|
1430 | }else{
|
---|
1431 | fputs(tpl_getTpl(vars, "PRESHUTDOWN"), f);
|
---|
1432 | }
|
---|
1433 | }
|
---|
1434 |
|
---|
1435 | void send_oscam_script(struct templatevars *vars, FILE *f){
|
---|
1436 | char *result = "not found";
|
---|
1437 | int rc = 0;
|
---|
1438 | if(cfg->http_script[0]){
|
---|
1439 | tpl_addVar(vars, 0, "SCRIPTNAME",cfg->http_script);
|
---|
1440 | rc = system(cfg->http_script);
|
---|
1441 | if(rc == -1){
|
---|
1442 | result = "done";
|
---|
1443 | }else{
|
---|
1444 | result = "failed";
|
---|
1445 | }
|
---|
1446 | }else{
|
---|
1447 | tpl_addVar(vars, 0, "SCRIPTNAME", "no script defined");
|
---|
1448 | }
|
---|
1449 | tpl_addVar(vars, 0, "SCRIPTRESULT", result);
|
---|
1450 | tpl_printf(vars, 0, "CODE", "%d", rc);
|
---|
1451 | fputs(tpl_getTpl(vars, "SCRIPT"), f);
|
---|
1452 | }
|
---|
1453 |
|
---|
1454 | void send_oscam_scanusb(struct templatevars *vars, FILE *f){
|
---|
1455 | FILE *fp;
|
---|
1456 | int err=0;
|
---|
1457 | char path[1035];
|
---|
1458 |
|
---|
1459 | fp = popen("lsusb", "r");
|
---|
1460 | if (fp == NULL) {
|
---|
1461 | tpl_addVar(vars, 0, "USBENTRY", "Failed to run lusb");
|
---|
1462 | tpl_printf(vars, 0, "USBENTRY", "%s", path);
|
---|
1463 | tpl_addVar(vars, 1, "USBBIT", tpl_getTpl(vars, "SCANUSBBIT"));
|
---|
1464 | err = 1;
|
---|
1465 | }
|
---|
1466 |
|
---|
1467 | if(!err){
|
---|
1468 | while (fgets(path, sizeof(path)-1, fp) != NULL) {
|
---|
1469 | tpl_printf(vars, 0, "USBENTRY", "%s", path);
|
---|
1470 | tpl_addVar(vars, 1, "USBBIT", tpl_getTpl(vars, "SCANUSBBIT"));
|
---|
1471 | }
|
---|
1472 | }
|
---|
1473 | pclose(fp);
|
---|
1474 | fputs(tpl_getTpl(vars, "SCANUSB"), f);
|
---|
1475 | }
|
---|
1476 |
|
---|
1477 | int process_request(FILE *f, struct in_addr in) {
|
---|
1478 |
|
---|
1479 | client[cs_idx].last = time((time_t)0); //reset last busy time
|
---|
1480 |
|
---|
1481 | int ok=0;
|
---|
1482 | struct s_ip *p_ip;
|
---|
1483 | in_addr_t addr = cs_inet_order(in.s_addr);
|
---|
1484 |
|
---|
1485 | for (p_ip = cfg->mon_allowed; (p_ip) && (!ok); p_ip = p_ip->next)
|
---|
1486 | ok =((addr >= p_ip->ip[0]) && (addr <= p_ip->ip[1]));
|
---|
1487 | if (!ok){
|
---|
1488 | send_error(f, 403, "Forbidden", NULL, "Access denied.");
|
---|
1489 | cs_log("unauthorized access from %s", inet_ntoa(*(struct in_addr *)&in));
|
---|
1490 | return 0;
|
---|
1491 | }
|
---|
1492 |
|
---|
1493 | char buf[4096];
|
---|
1494 | char tmp[4096];
|
---|
1495 |
|
---|
1496 | int authok = 0;
|
---|
1497 | char expectednonce[64];
|
---|
1498 |
|
---|
1499 | char *method;
|
---|
1500 | char *path;
|
---|
1501 | char *protocol;
|
---|
1502 | char *pch;
|
---|
1503 | char *pch2;
|
---|
1504 | /* List of possible pages */
|
---|
1505 | char *pages[]={
|
---|
1506 | "/config.html",
|
---|
1507 | "/readers.html",
|
---|
1508 | "/entitlements.html",
|
---|
1509 | "/status.html",
|
---|
1510 | "/userconfig.html",
|
---|
1511 | "/readerconfig.html",
|
---|
1512 | "/services.html",
|
---|
1513 | "/user_edit.html",
|
---|
1514 | "/site.css",
|
---|
1515 | "/services_edit.html",
|
---|
1516 | "/savetemplates.html",
|
---|
1517 | "/shutdown.html",
|
---|
1518 | "/script.html",
|
---|
1519 | "/scanusb.html"};
|
---|
1520 |
|
---|
1521 | int pagescnt = sizeof(pages)/sizeof(char *); // Calculate the amount of items in array
|
---|
1522 |
|
---|
1523 | int pgidx = -1;
|
---|
1524 | int i;
|
---|
1525 | int parsemode = 1;
|
---|
1526 | struct uriparams params;
|
---|
1527 | params.paramcount = 0;
|
---|
1528 |
|
---|
1529 | /* First line always includes the GET/POST request */
|
---|
1530 | if (!fgets(buf, sizeof(buf), f)) return -1;
|
---|
1531 | method = strtok(buf, " ");
|
---|
1532 | path = strtok(NULL, " ");
|
---|
1533 | protocol = strtok(NULL, "\r");
|
---|
1534 | if(method == NULL || path == NULL || protocol == NULL) return -1;
|
---|
1535 |
|
---|
1536 | pch=path;
|
---|
1537 | /* advance pointer to beginning of query string */
|
---|
1538 | while(pch[0] != '?' && pch[0] != '\0') ++pch;
|
---|
1539 | if(pch[0] == '?'){
|
---|
1540 | pch[0] = '\0';
|
---|
1541 | ++pch;
|
---|
1542 | }
|
---|
1543 |
|
---|
1544 | /* Map page to our static page definitions */
|
---|
1545 | for (i=0; i<pagescnt; i++){
|
---|
1546 | if (!strcmp(path, pages[i])) pgidx = i;
|
---|
1547 | }
|
---|
1548 |
|
---|
1549 | /* Parse url parameters; parsemode = 1 means parsing next param, parsemode = -1 parsing next
|
---|
1550 | value; pch2 points to the beginning of the currently parsed string, pch is the current position */
|
---|
1551 | pch2=pch;
|
---|
1552 | while(pch[0] != '\0'){
|
---|
1553 | if((parsemode == 1 && pch[0] == '=') || (parsemode == -1 && pch[0] == '&')){
|
---|
1554 | pch[0] = '\0';
|
---|
1555 | urldecode(pch2);
|
---|
1556 | if(parsemode == 1) {
|
---|
1557 | if(params.paramcount >= MAXGETPARAMS) break;
|
---|
1558 | ++params.paramcount;
|
---|
1559 | params.params[params.paramcount-1] = pch2;
|
---|
1560 | } else {
|
---|
1561 | params.values[params.paramcount-1] = pch2;
|
---|
1562 | }
|
---|
1563 | parsemode = -parsemode;
|
---|
1564 | pch2 = pch + 1;
|
---|
1565 | }
|
---|
1566 | ++pch;
|
---|
1567 | }
|
---|
1568 | /* last value wasn't processed in the loop yet... */
|
---|
1569 | if(parsemode == -1 && params.paramcount <= MAXGETPARAMS){
|
---|
1570 | urldecode(pch2);
|
---|
1571 | params.values[params.paramcount-1] = pch2;
|
---|
1572 | }
|
---|
1573 |
|
---|
1574 | if(strlen(cfg->http_user) == 0 || strlen(cfg->http_pwd) == 0) authok = 1;
|
---|
1575 | else calculate_nonce(expectednonce, sizeof(expectednonce)/sizeof(char));
|
---|
1576 |
|
---|
1577 | /* Read remaining request (we're only interested in auth header) */
|
---|
1578 | while (fgets(tmp, sizeof(tmp), f)) {
|
---|
1579 | if (tmp[0] == '\r' && tmp[1] == '\n') break;
|
---|
1580 | else if(authok == 0 && strlen(tmp) > 50 && strncmp(tmp, "Authorization:", 14) == 0 && strstr(tmp, "Digest") != NULL) {
|
---|
1581 | authok = check_auth(tmp, method, path, expectednonce);
|
---|
1582 | }
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 | //cs_debug("%s %d\n", path, pgidx);
|
---|
1586 | //for(i=0; i < params.paramcount; ++i) cs_debug("%s : %s\n", params.params[i], params.values[i]);
|
---|
1587 |
|
---|
1588 | fseek(f, 0, SEEK_CUR); // Force change of stream direction
|
---|
1589 |
|
---|
1590 | if(authok != 1){
|
---|
1591 | strcpy(tmp, "WWW-Authenticate: Digest algorithm=\"MD5\", realm=\"");
|
---|
1592 | strcat(tmp, AUTHREALM);
|
---|
1593 | strcat(tmp, "\", qop=\"auth\", opaque=\"\", nonce=\"");
|
---|
1594 | strcat(tmp, expectednonce);
|
---|
1595 | strcat(tmp, "\"");
|
---|
1596 | if(authok == 2) strcat(tmp, ", stale=true");
|
---|
1597 | send_headers(f, 401, "Unauthorized", tmp, "text/html");
|
---|
1598 | return 0;
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 | /*build page*/
|
---|
1602 | send_headers(f, 200, "OK", NULL, "text/html");
|
---|
1603 | if(pgidx == 8) send_css(f);
|
---|
1604 | else {
|
---|
1605 | time_t t;
|
---|
1606 | struct templatevars *vars = tpl_create();
|
---|
1607 | struct tm *lt;
|
---|
1608 | time(&t);
|
---|
1609 |
|
---|
1610 | lt=localtime(&t);
|
---|
1611 | tpl_addVar(vars, 0, "CS_VERSION", CS_VERSION);
|
---|
1612 | tpl_addVar(vars, 0, "CS_SVN_VERSION", CS_SVN_VERSION);
|
---|
1613 | tpl_addVar(vars, 0, "ICO", ICMAI);
|
---|
1614 | if(cfg->http_refresh > 0 && (pgidx == 3 || pgidx == -1)){
|
---|
1615 | tpl_printf(vars, 0, "REFRESHTIME", "%d", cfg->http_refresh);
|
---|
1616 | tpl_addVar(vars, 0, "REFRESHURL", "status.html");
|
---|
1617 | tpl_addVar(vars, 0, "REFRESH", tpl_getTpl(vars, "REFRESH"));
|
---|
1618 | }
|
---|
1619 | tpl_printf(vars, 0, "CURDATE", "%02d.%02d.%02d", lt->tm_mday, lt->tm_mon+1, lt->tm_year%100);
|
---|
1620 | tpl_printf(vars, 0, "CURTIME", "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
|
---|
1621 | tpl_printf(vars, 0, "CURIP", "%s", inet_ntoa(*(struct in_addr *)&in));
|
---|
1622 | switch(pgidx){
|
---|
1623 | case 0: send_oscam_config(vars, f, ¶ms, in); break;
|
---|
1624 | case 1: send_oscam_reader(vars, f, ¶ms, in); break;
|
---|
1625 | case 2: send_oscam_entitlement(vars, f, ¶ms); break;
|
---|
1626 | case 3: send_oscam_status(vars, f, ¶ms, in); break;
|
---|
1627 | case 4: send_oscam_user_config(vars, f, ¶ms, in); break;
|
---|
1628 | case 5: send_oscam_reader_config(vars, f, ¶ms, in); break;
|
---|
1629 | case 6: send_oscam_services(vars, f, ¶ms, in); break;
|
---|
1630 | case 7: send_oscam_user_config_edit(vars, f, ¶ms, in); break;
|
---|
1631 | //case 8: css file
|
---|
1632 | case 9: send_oscam_services_edit(vars, f, ¶ms, in); break;
|
---|
1633 | case 10: send_oscam_savetpls(vars, f); break;
|
---|
1634 | case 11: send_oscam_shutdown(vars, f, ¶ms); break;
|
---|
1635 | case 12: send_oscam_script(vars, f); break;
|
---|
1636 | case 13: send_oscam_scanusb(vars, f); break;
|
---|
1637 | default: send_oscam_status(vars, f, ¶ms, in); break;
|
---|
1638 | }
|
---|
1639 | tpl_clear(vars);
|
---|
1640 | }
|
---|
1641 | return 0;
|
---|
1642 | }
|
---|
1643 |
|
---|
1644 | void http_srv() {
|
---|
1645 | int i,sock, reuse = 1;
|
---|
1646 | struct sockaddr_in sin;
|
---|
1647 | struct sockaddr_in remote;
|
---|
1648 | socklen_t len = sizeof(remote);
|
---|
1649 | char *tmp;
|
---|
1650 |
|
---|
1651 | /* Prepare lookup array for conversion between ascii and hex */
|
---|
1652 | tmp = malloc(3 * sizeof(char));
|
---|
1653 | for(i = 0; i < 256; i++) {
|
---|
1654 | snprintf(tmp, 3,"%02x", i);
|
---|
1655 | memcpy(hex2ascii[i], tmp, 2);
|
---|
1656 | }
|
---|
1657 | free(tmp);
|
---|
1658 | /* Create random string for nonce value generation */
|
---|
1659 | srand(time(NULL));
|
---|
1660 | create_rand_str(noncekey,32);
|
---|
1661 |
|
---|
1662 | /* Startup server */
|
---|
1663 | if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
|
---|
1664 | cs_log("HTTP Server: Creating socket failed! (errno=%d)", errno);
|
---|
1665 | return;
|
---|
1666 | }
|
---|
1667 | if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) {
|
---|
1668 | cs_log("HTTP Server: Setting SO_REUSEADDR via setsockopt failed! (errno=%d)", errno);
|
---|
1669 | }
|
---|
1670 |
|
---|
1671 | memset(&sin, 0, sizeof sin);
|
---|
1672 | sin.sin_family = AF_INET;
|
---|
1673 | sin.sin_addr.s_addr = INADDR_ANY;
|
---|
1674 | sin.sin_port = htons(cfg->http_port);
|
---|
1675 | if((bind(sock, (struct sockaddr *) &sin, sizeof(sin))) < 0) {
|
---|
1676 | cs_log("HTTP Server couldn't bind on port %d (errno=%d). Not starting HTTP!", cfg->http_port, errno);
|
---|
1677 | close(sock);
|
---|
1678 | return;
|
---|
1679 | }
|
---|
1680 | if (listen(sock, SOMAXCONN) < 0) {
|
---|
1681 | cs_log("HTTP Server: Call to listen() failed! (errno=%d)", errno);
|
---|
1682 | close(sock);
|
---|
1683 | return;
|
---|
1684 | }
|
---|
1685 | cs_log("HTTP Server listening on port %d", cfg->http_port);
|
---|
1686 | struct pollfd pfd[1];
|
---|
1687 | int rc;
|
---|
1688 | pfd[0].fd = sock;
|
---|
1689 | pfd[0].events = (POLLIN | POLLPRI);
|
---|
1690 |
|
---|
1691 | while (running) {
|
---|
1692 | int s;
|
---|
1693 | FILE *f;
|
---|
1694 |
|
---|
1695 | rc = poll(pfd, 1, 1000);
|
---|
1696 | if (master_pid != getppid())
|
---|
1697 | cs_exit(0);
|
---|
1698 |
|
---|
1699 | if (rc > 0) {
|
---|
1700 | if((s = accept(sock, (struct sockaddr *) &remote, &len)) < 0){
|
---|
1701 | cs_log("HTTP Server: Error calling accept() (errno=%d).", errno);
|
---|
1702 | break;
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 | f = fdopen(s, "r+");
|
---|
1706 | process_request(f, remote.sin_addr);
|
---|
1707 | fflush(f);
|
---|
1708 | fclose(f);
|
---|
1709 | shutdown(s, SHUT_WR);
|
---|
1710 | close(s);
|
---|
1711 | }
|
---|
1712 | }
|
---|
1713 |
|
---|
1714 | close(sock);
|
---|
1715 | kill(client[0].pid, SIGQUIT);
|
---|
1716 | }
|
---|
1717 | #endif
|
---|