1 | //
|
---|
2 | // OSCam HTTP server module
|
---|
3 | //
|
---|
4 | #include "oscam-http-helpers.c"
|
---|
5 | #include <stdio.h>
|
---|
6 | #include <string.h>
|
---|
7 | #include <time.h>
|
---|
8 | #include <sys/stat.h>
|
---|
9 | #include <dirent.h>
|
---|
10 | #include <sys/socket.h>
|
---|
11 |
|
---|
12 | void refresh_oscam(enum refreshtypes refreshtype){
|
---|
13 | int i;
|
---|
14 | switch (refreshtype){
|
---|
15 | case REFR_ACCOUNTS:
|
---|
16 | cs_log("Refresh Accounts requested by WebIF");
|
---|
17 | init_userdb();
|
---|
18 | cs_reinit_clients();
|
---|
19 | #ifdef CS_ANTICASC
|
---|
20 | for (i=0; i<CS_MAXPID; i++)
|
---|
21 | if (client[i].typ=='a') {
|
---|
22 | kill(client[i].pid, SIGHUP);
|
---|
23 | break;
|
---|
24 | }
|
---|
25 | #endif
|
---|
26 | break;
|
---|
27 |
|
---|
28 | case REFR_READERS:
|
---|
29 | cs_log("Refresh Reader");
|
---|
30 | //todo how I can refresh the readers
|
---|
31 | break;
|
---|
32 |
|
---|
33 | case REFR_SERVER:
|
---|
34 | cs_log("Refresh Server requested by WebIF");
|
---|
35 | //kill(client[0].pid, SIGHUP);
|
---|
36 | //todo how I can refresh the server after global settings
|
---|
37 | break;
|
---|
38 |
|
---|
39 | case REFR_SERVICES:
|
---|
40 | cs_log("Refresh Services requested by WebIF");
|
---|
41 | init_sidtab();
|
---|
42 | break;
|
---|
43 |
|
---|
44 | #ifdef CS_ANTICASC
|
---|
45 | case REFR_ANTICASC:
|
---|
46 | cs_log("Refresh Anticascading requested by WebIF");
|
---|
47 | for (i=0; i<CS_MAXPID; i++)
|
---|
48 | if (client[i].typ=='a') {
|
---|
49 | kill(client[i].pid, SIGHUP);
|
---|
50 | break;
|
---|
51 | }
|
---|
52 | break;
|
---|
53 | #endif
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | void send_oscam_config_global(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
58 | int i;
|
---|
59 |
|
---|
60 | if (strcmp(getParam(params, "action"), "execute") == 0){
|
---|
61 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
62 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
63 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
64 | //we use the same function as used for parsing the config tokens
|
---|
65 | chk_t_global((*params).params[i], (*params).values[i]);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Global *DONE*</B><BR><BR>");
|
---|
69 | /*if(write_config()==0) */refresh_oscam(REFR_SERVER);
|
---|
70 | }
|
---|
71 | tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->srvip));
|
---|
72 | tpl_addVar(vars, 0, "LOGFILE", logfile);
|
---|
73 | tpl_addVar(vars, 0, "PIDFILE", cfg->pidfile);
|
---|
74 | tpl_addVar(vars, 0, "USERFILE", cfg->usrfile);
|
---|
75 | tpl_addVar(vars, 0, "CWLOGDIR", cfg->cwlogdir);
|
---|
76 | tpl_printf(vars, 0, "CLIENTTIMEOUT", "%ld", cfg->ctimeout/1000);
|
---|
77 | tpl_printf(vars, 0, "FALLBACKTIMEOUT", "%ld", cfg->ftimeout/1000);
|
---|
78 | tpl_printf(vars, 0, "CLIENTMAXIDLE", "%d", cfg->cmaxidle);
|
---|
79 | tpl_printf(vars, 0, "CACHEDELAY", "%ld", cfg->delay/1000);
|
---|
80 | tpl_printf(vars, 0, "BINDWAIT", "%d", cfg->bindwait);
|
---|
81 | tpl_printf(vars, 0, "NETPRIO", "%ld", cfg->netprio);
|
---|
82 | tpl_printf(vars, 0, "RESOLVEDELAY", "%d", cfg->resolvedelay);
|
---|
83 | tpl_printf(vars, 0, "SLEEP", "%d", cfg->tosleep);
|
---|
84 | tpl_printf(vars, 0, "UNLOCKPARENTAL", "%d", cfg->ulparent);
|
---|
85 | tpl_printf(vars, 0, "NICE", "%d", cfg->nice);
|
---|
86 | tpl_printf(vars, 0, "SERIALTIMEOUT", "%d", cfg->srtimeout);
|
---|
87 | tpl_printf(vars, 0, "MAXLOGSIZE", "%d", cfg->max_log_size);
|
---|
88 | tpl_printf(vars, 0, "SHOWECMDW", "%d", cfg->show_ecm_dw);
|
---|
89 | tpl_printf(vars, 0, "WAITFORCARDS", "%d", cfg->waitforcards);
|
---|
90 | tpl_printf(vars, 0, "PREFERLOCALCARDS", "%d", cfg->preferlocalcards);
|
---|
91 |
|
---|
92 | fputs(tpl_getTpl(vars, "CONFIGGLOBAL"), f);
|
---|
93 | }
|
---|
94 |
|
---|
95 | void send_oscam_config_camd33(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
96 | int i;
|
---|
97 |
|
---|
98 | if (strcmp(getParam(params, "action"), "execute") == 0){
|
---|
99 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
100 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
101 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
102 | if (strcmp((*params).params[i], "nocrypt") == 0){
|
---|
103 | clear_sip(&cfg->c33_plain);
|
---|
104 | }
|
---|
105 | //we use the same function as used for parsing the config tokens
|
---|
106 | chk_t_camd33((*params).params[i], (*params).values[i]);
|
---|
107 | }
|
---|
108 | }
|
---|
109 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration camd33 *DONE*</B><BR><BR>");
|
---|
110 | refresh_oscam(REFR_SERVER);
|
---|
111 | }
|
---|
112 | tpl_printf(vars, 0, "PORT", "%d", cfg->c33_port);
|
---|
113 | tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip));
|
---|
114 | tpl_printf(vars, 0, "PASSIVE", "%d", cfg->c33_passive);
|
---|
115 |
|
---|
116 | for (i = 0; i < sizeof(cfg->c33_key); ++i) tpl_printf(vars, 1, "KEY", "%02X",cfg->c33_key[i]);
|
---|
117 | struct s_ip *cip;
|
---|
118 | char *dot="";
|
---|
119 | for (cip = cfg->c33_plain; cip; cip = cip->next){
|
---|
120 | tpl_printf(vars, 1, "NOCRYPT", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
121 | if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "NOCRYPT", "-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
122 | dot=",";
|
---|
123 | }
|
---|
124 |
|
---|
125 | fputs(tpl_getTpl(vars, "CONFIGCAMD33"), f);
|
---|
126 | }
|
---|
127 |
|
---|
128 | void send_oscam_config_camd35(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
129 | int i;
|
---|
130 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
131 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
132 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
133 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
134 | //we use the same function as used for parsing the config tokens
|
---|
135 | chk_t_camd35((*params).params[i], (*params).values[i]);
|
---|
136 | }
|
---|
137 | }
|
---|
138 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration camd35 *DONE*</B><BR><BR>");
|
---|
139 | refresh_oscam(REFR_SERVER);
|
---|
140 | }
|
---|
141 | tpl_printf(vars, 0, "PORT", "%d", cfg->c35_port);
|
---|
142 | tpl_addVar(vars, 1, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
|
---|
143 |
|
---|
144 | fputs(tpl_getTpl(vars, "CONFIGCAMD35"), f);
|
---|
145 | }
|
---|
146 |
|
---|
147 | void send_oscam_config_camd35tcp(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
148 | int i;
|
---|
149 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
150 | clear_ptab(&cfg->c35_tcp_ptab); /*clear Porttab*/
|
---|
151 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
152 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
153 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
154 | //we use the same function as used for parsing the config tokens
|
---|
155 | chk_t_camd35_tcp((*params).params[i], (*params).values[i]);
|
---|
156 | }
|
---|
157 | }
|
---|
158 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration camd35 TCP *DONE*</B><BR><BR>");
|
---|
159 | refresh_oscam(REFR_SERVER);
|
---|
160 | }
|
---|
161 |
|
---|
162 | int j;
|
---|
163 | char *dot1, *dot2;
|
---|
164 | if ((cfg->c35_tcp_ptab.nports > 0) && (cfg->c35_tcp_ptab.ports[0].s_port > 0)){
|
---|
165 | dot1 = "";
|
---|
166 | for(i = 0; i < cfg->c35_tcp_ptab.nports; ++i){
|
---|
167 | 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);
|
---|
168 | if (cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 0){
|
---|
169 | tpl_printf(vars, 1, "PORT", ":");
|
---|
170 | dot2 = "";
|
---|
171 | for (j = 0; j < cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j){
|
---|
172 | tpl_printf(vars, 1, "PORT", "%s%lX", dot2, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]);
|
---|
173 | dot2 = ",";
|
---|
174 | }
|
---|
175 | }
|
---|
176 | dot1=";";
|
---|
177 | }
|
---|
178 | }
|
---|
179 | tpl_addVar(vars, 1, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
|
---|
180 |
|
---|
181 | fputs(tpl_getTpl(vars, "CONFIGCAMD35TCP"), f);
|
---|
182 | }
|
---|
183 |
|
---|
184 | void send_oscam_config_newcamd(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
185 | int i;
|
---|
186 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
187 | clear_ptab(&cfg->ncd_ptab); /*clear Porttab*/
|
---|
188 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
189 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
190 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
191 | //we use the same function as used for parsing the config tokens
|
---|
192 | chk_t_newcamd((*params).params[i], (*params).values[i]);
|
---|
193 | }
|
---|
194 | }
|
---|
195 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Newcamd *DONE*</B><BR><BR>");
|
---|
196 | refresh_oscam(REFR_SERVER);
|
---|
197 | }
|
---|
198 | int j;
|
---|
199 | char *dot1, *dot2;
|
---|
200 | if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)){
|
---|
201 | dot1 = "";
|
---|
202 | for(i = 0; i < cfg->ncd_ptab.nports; ++i){
|
---|
203 | 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);
|
---|
204 | if (cfg->ncd_ptab.ports[i].ftab.filts[0].nprids > 0){
|
---|
205 | tpl_printf(vars, 1, "PORT", ":");
|
---|
206 | dot2 = "";
|
---|
207 | for (j = 0; j < cfg->ncd_ptab.ports[i].ftab.filts[0].nprids; ++j){
|
---|
208 | tpl_printf(vars, 1, "PORT", "%s%lX", dot2, cfg->ncd_ptab.ports[i].ftab.filts[0].prids[j]);
|
---|
209 | dot2 = ",";
|
---|
210 | }
|
---|
211 | }
|
---|
212 | dot1=";";
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->ncd_srvip));
|
---|
217 | for (i=0;i<14;i++) tpl_printf(vars, 1, "KEY", "%02X", cfg->ncd_key[i]);
|
---|
218 |
|
---|
219 | fputs(tpl_getTpl(vars, "CONFIGNEWCAMD"), f);
|
---|
220 | }
|
---|
221 |
|
---|
222 | void send_oscam_config_radegast(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
223 | int i;
|
---|
224 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
225 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
226 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
227 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
228 | if (strcmp((*params).params[i], "allowed") == 0){
|
---|
229 | clear_sip(&cfg->rad_allowed);
|
---|
230 | }
|
---|
231 | //we use the same function as used for parsing the config tokens
|
---|
232 | chk_t_radegast((*params).params[i], (*params).values[i]);
|
---|
233 | }
|
---|
234 | }
|
---|
235 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Radegast *DONE*</B><BR><BR>");
|
---|
236 | refresh_oscam(REFR_SERVER);
|
---|
237 | }
|
---|
238 | tpl_printf(vars, 0, "PORT", "%d", cfg->rad_port);
|
---|
239 | tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->rad_srvip));
|
---|
240 | tpl_addVar(vars, 0, "USER", cfg->rad_usr);
|
---|
241 |
|
---|
242 | struct s_ip *cip;
|
---|
243 | char *dot="";
|
---|
244 | for (cip=cfg->rad_allowed; cip; cip=cip->next){
|
---|
245 | tpl_printf(vars, 1, "ALLOWED", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
246 | if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "ALLOWED", "-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
247 | dot=",";
|
---|
248 | }
|
---|
249 |
|
---|
250 | fputs(tpl_getTpl(vars, "CONFIGRADEGAST"), f);
|
---|
251 | }
|
---|
252 |
|
---|
253 | void send_oscam_config_cccam(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
254 | int i;
|
---|
255 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
256 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
257 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
258 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
259 | //we use the same function as used for parsing the config tokens
|
---|
260 | chk_t_cccam((*params).params[i], (*params).values[i]);
|
---|
261 | }
|
---|
262 | }
|
---|
263 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR>Configuration Cccam Do not yet implemented<BR><BR>");
|
---|
264 | refresh_oscam(REFR_SERVER);
|
---|
265 | }
|
---|
266 | fputs(tpl_getTpl(vars, "CONFIGCCCAM"), f);
|
---|
267 | }
|
---|
268 |
|
---|
269 | void send_oscam_config_gbox(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
270 | int i;
|
---|
271 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
272 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
273 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
274 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
275 | //we use the same function as used for parsing the config tokens
|
---|
276 | chk_t_gbox((*params).params[i], (*params).values[i]);
|
---|
277 | }
|
---|
278 | }
|
---|
279 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Gbox *DONE*</B><BR><BR>");
|
---|
280 | refresh_oscam(REFR_SERVER);
|
---|
281 | }
|
---|
282 | tpl_printf(vars, 0, "MAXDIST", "%d", cfg->maxdist);
|
---|
283 | for (i=0;i<4;i++) tpl_printf(vars, 1, "PASSWORD", "%02X", cfg->gbox_pwd[i]);
|
---|
284 | tpl_addVar(vars, 0, "IGNORELIST", (char *)cfg->ignorefile);
|
---|
285 | tpl_addVar(vars, 0, "ONLINEINFOS", (char *)cfg->gbxShareOnl);
|
---|
286 | tpl_addVar(vars, 0, "CARDINFOS", (char *)cfg->cardfile);
|
---|
287 | char *dot = "";
|
---|
288 | for (i = 0; i < cfg->num_locals; i++){
|
---|
289 | tpl_printf(vars, 1, "LOCALS", "%s%06lX", dot, cfg->locals[i]);
|
---|
290 | dot=";";
|
---|
291 | }
|
---|
292 | fputs(tpl_getTpl(vars, "CONFIGGBOX"), f);
|
---|
293 | }
|
---|
294 |
|
---|
295 | void send_oscam_config_monitor(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
296 | int i;
|
---|
297 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
298 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
299 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
300 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
301 | if (strcmp((*params).params[i], "nocrypt") == 0){
|
---|
302 | clear_sip(&cfg->mon_allowed);
|
---|
303 | }
|
---|
304 | //we use the same function as used for parsing the config tokens
|
---|
305 | chk_t_monitor((*params).params[i], (*params).values[i]);
|
---|
306 | }
|
---|
307 | }
|
---|
308 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Monitor *DONE*</B><BR><BR>");
|
---|
309 | refresh_oscam(REFR_SERVER);
|
---|
310 | }
|
---|
311 | tpl_printf(vars, 0, "MONPORT", "%d", cfg->mon_port);
|
---|
312 | tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip));
|
---|
313 | tpl_printf(vars, 0, "AULOW", "%d", cfg->mon_aulow);
|
---|
314 | tpl_printf(vars, 0, "HIDECLIENTTO", "%d", cfg->mon_hideclient_to);
|
---|
315 | tpl_printf(vars, 0, "HTTPPORT", "%d", cfg->http_port);
|
---|
316 | tpl_addVar(vars, 0, "HTTPUSER", cfg->http_user);
|
---|
317 | tpl_addVar(vars, 0, "HTTPPASSWORD", cfg->http_pwd);
|
---|
318 | tpl_addVar(vars, 0, "HTTPCSS", cfg->http_css);
|
---|
319 | tpl_printf(vars, 0, "HTTPREFRESH", "%d", cfg->http_refresh);
|
---|
320 | tpl_addVar(vars, 0, "HTTPTPL", cfg->http_tpl);
|
---|
321 | if (cfg->http_hide_idle_clients > 0) tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
322 |
|
---|
323 | struct s_ip *cip;
|
---|
324 | char *dot="";
|
---|
325 | for (cip = cfg->mon_allowed; cip; cip = cip->next){
|
---|
326 | tpl_printf(vars, 1, "NOCRYPT", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
327 | if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "NOCRYPT", "-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
328 | dot=",";
|
---|
329 | }
|
---|
330 |
|
---|
331 | //Monlevel selector
|
---|
332 | tpl_printf(vars, 0, "TMP", "MONSELECTED%d", cfg->mon_level);
|
---|
333 | tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
|
---|
334 |
|
---|
335 | fputs(tpl_getTpl(vars, "CONFIGMONITOR"), f);
|
---|
336 | }
|
---|
337 |
|
---|
338 | void send_oscam_config_serial(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
339 | int i;
|
---|
340 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
341 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
342 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
343 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
344 | //we use the same function as used for parsing the config tokens
|
---|
345 | chk_t_serial((*params).params[i], (*params).values[i]);
|
---|
346 | }
|
---|
347 | }
|
---|
348 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Serial *DONE*</B><BR><BR>");
|
---|
349 | refresh_oscam(REFR_SERVER);
|
---|
350 | }
|
---|
351 |
|
---|
352 | tpl_addVar(vars, 0, "SERIALDEVICE", cfg->ser_device);
|
---|
353 |
|
---|
354 | fputs(tpl_getTpl(vars, "CONFIGSERIAL"), f);
|
---|
355 | }
|
---|
356 |
|
---|
357 | #ifdef HAVE_DVBAPI_3
|
---|
358 | void send_oscam_config_dvbapi(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
359 | int i;
|
---|
360 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
361 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
362 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
363 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
364 | //we use the same function as used for parsing the config tokens
|
---|
365 | chk_t_dvbapi((*params).params[i], (*params).values[i]);
|
---|
366 | }
|
---|
367 | }
|
---|
368 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration DVB Api *DONE*</B><BR><BR>");
|
---|
369 | refresh_oscam(REFR_SERVER);
|
---|
370 | }
|
---|
371 |
|
---|
372 | if (cfg->dvbapi_enabled > 0) tpl_addVar(vars, 0, "ENABLEDCHECKED", "checked");
|
---|
373 | if (cfg->dvbapi_au > 0) tpl_addVar(vars, 0, "AUCHECKED", "checked");
|
---|
374 | tpl_addVar(vars, 0, "BOXTYPE", cfg->dvbapi_boxtype);
|
---|
375 | tpl_addVar(vars, 0, "USER", cfg->dvbapi_usr);
|
---|
376 |
|
---|
377 | fputs(tpl_getTpl(vars, "CONFIGDVBAPI"), f);
|
---|
378 | }
|
---|
379 | #endif
|
---|
380 |
|
---|
381 | #ifdef CS_ANTICASC
|
---|
382 | void send_oscam_config_anticasc(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
383 | int i;
|
---|
384 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
385 | for(i = 0; i < (*params).paramcount; ++i){
|
---|
386 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
387 | tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s<BR>\n", (*params).params[i], (*params).values[i]);
|
---|
388 | //we use the same function as used for parsing the config tokens
|
---|
389 | chk_t_ac((*params).params[i], (*params).values[i]);
|
---|
390 | }
|
---|
391 | }
|
---|
392 | tpl_addVar(vars, 1, "MESSAGE", "<BR><BR><B>Configuration Anticascading *DONE*</B><BR><BR>");
|
---|
393 | refresh_oscam(REFR_ANTICASC);
|
---|
394 | }
|
---|
395 | if (cfg->ac_enabled > 0) tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
396 | tpl_printf(vars, 0, "NUMUSERS", "%d", cfg->ac_users);
|
---|
397 | tpl_printf(vars, 0, "SAMPLETIME", "%d", cfg->ac_stime);
|
---|
398 | tpl_printf(vars, 0, "SAMPLES", "%d", cfg->ac_samples);
|
---|
399 | tpl_printf(vars, 0, "PENALTY", "%d", cfg->ac_penalty);
|
---|
400 | tpl_addVar(vars, 0, "ACLOGFILE", cfg->ac_logfile);
|
---|
401 | tpl_printf(vars, 0, "FAKEDELAY", "%d", cfg->ac_fakedelay);
|
---|
402 | tpl_printf(vars, 0, "DENYSAMPLES", "%d", cfg->ac_denysamples);
|
---|
403 | fputs(tpl_getTpl(vars, "CONFIGANTICASC"), f);
|
---|
404 | }
|
---|
405 | #endif
|
---|
406 |
|
---|
407 | void send_oscam_config(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
408 | char *part = getParam(params, "part");
|
---|
409 | if (!strcmp(part,"camd33")) send_oscam_config_camd33(vars, f, params);
|
---|
410 | else if (!strcmp(part,"camd35")) send_oscam_config_camd35(vars, f, params);
|
---|
411 | else if (!strcmp(part,"camd35tcp")) send_oscam_config_camd35tcp(vars, f, params);
|
---|
412 | else if (!strcmp(part,"newcamd")) send_oscam_config_newcamd(vars, f, params);
|
---|
413 | else if (!strcmp(part,"radegast")) send_oscam_config_radegast(vars, f, params);
|
---|
414 | else if (!strcmp(part,"cccam")) send_oscam_config_cccam(vars, f, params);
|
---|
415 | else if (!strcmp(part,"gbox")) send_oscam_config_gbox(vars, f, params);
|
---|
416 | #ifdef HAVE_DVBAPI_3
|
---|
417 | else if (!strcmp(part,"dvbapi")) send_oscam_config_dvbapi(vars, f, params);
|
---|
418 | #endif
|
---|
419 | #ifdef CS_ANTICASC
|
---|
420 | else if (!strcmp(part,"anticasc")) send_oscam_config_anticasc(vars, f, params);
|
---|
421 | #endif
|
---|
422 | else if (!strcmp(part,"monitor")) send_oscam_config_monitor(vars, f, params);
|
---|
423 | else if (!strcmp(part,"serial")) send_oscam_config_serial(vars, f, params);
|
---|
424 | else send_oscam_config_global(vars, f, params);
|
---|
425 | }
|
---|
426 |
|
---|
427 | void send_oscam_reader(struct templatevars *vars, FILE *f) {
|
---|
428 | int ridx;
|
---|
429 | char *ctyp;
|
---|
430 |
|
---|
431 | for(ridx=0;ridx<CS_MAXREADER;ridx++){
|
---|
432 | if(!reader[ridx].device[0]) break;
|
---|
433 | switch(reader[ridx].typ){
|
---|
434 | case R_MOUSE : ctyp="mouse"; break;
|
---|
435 | case R_INTERNAL: ctyp="intern"; break;
|
---|
436 | case R_SMART : ctyp="smartreader"; break;
|
---|
437 | case R_CAMD35 : ctyp="camd 3.5x";break;
|
---|
438 | case R_CAMD33 : ctyp="camd 3.3x";break;
|
---|
439 | case R_NEWCAMD : ctyp="newcamd"; break;
|
---|
440 | case R_RADEGAST: ctyp="radegast"; break;
|
---|
441 | case R_SERIAL : ctyp="serial"; break;
|
---|
442 | case R_GBOX : ctyp="gbox"; break;
|
---|
443 | #ifdef HAVE_PCSC
|
---|
444 | case R_PCSC : ctyp="pcsc"; break;
|
---|
445 | #endif
|
---|
446 | case R_CCCAM : ctyp="cccam"; break;
|
---|
447 | case R_CS378X : ctyp="cs378x"; break;
|
---|
448 | default : ctyp="unknown"; break;
|
---|
449 | }
|
---|
450 | tpl_addVar(vars, 0, "CTYP", ctyp);
|
---|
451 | tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
|
---|
452 | tpl_addVar(vars, 0, "READERNAMEENC", tpl_addTmp(vars, urlencode(reader[ridx].label)));
|
---|
453 | tpl_addVar(vars, 1, "READERLIST", tpl_getTpl(vars, "READERSBIT"));
|
---|
454 | }
|
---|
455 | fputs(tpl_getTpl(vars, "READERS"), f);
|
---|
456 | }
|
---|
457 |
|
---|
458 | void send_oscam_reader_config(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
459 | int ridx;
|
---|
460 | char *reader_ = getParam(params, "reader");
|
---|
461 | for(ridx = 0; ridx < CS_MAXREADER && strcmp(reader_, reader[ridx].label) != 0; ++ridx);
|
---|
462 | if(ridx == CS_MAXREADER){
|
---|
463 | tpl_addVar(vars, 0, "MESSAGE", "<BR><BR>Reader not found<BR><BR>");
|
---|
464 | } else if(strcmp(getParam(params, "action"), "execute") == 0){
|
---|
465 | tpl_addVar(vars, 0, "MESSAGE", "<BR><BR>Saving not yet implemented<BR><BR>");
|
---|
466 | refresh_oscam(REFR_READERS);
|
---|
467 | }
|
---|
468 | int i;
|
---|
469 | tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
|
---|
470 | tpl_addVar(vars, 0, "DEVICE", reader[ridx].device);
|
---|
471 | tpl_addVar(vars, 0, "NCD_KEY", (char *)reader[ridx].ncd_key);
|
---|
472 | tpl_addVar(vars, 0, "PINCODE", reader[ridx].pincode);
|
---|
473 | tpl_addVar(vars, 0, "EMMFILE", (char *)reader[ridx].emmfile);
|
---|
474 | tpl_addVar(vars, 0, "GBOXPWD", (char *)reader[ridx].gbox_pwd);
|
---|
475 | tpl_printf(vars, 0, "INACTIVITYTIMEOUT", "%d", reader[ridx].tcp_ito);
|
---|
476 | tpl_printf(vars, 0, "RECEIVETIMEOUT", "%d", reader[ridx].tcp_rto);
|
---|
477 | tpl_printf(vars, 0, "DISABLESERVERFILTER", "%d", reader[ridx].ncd_disable_server_filt);
|
---|
478 | tpl_printf(vars, 0, "FALLBACK", "%d", reader[ridx].fallback);
|
---|
479 | tpl_printf(vars, 0, "LOGPORT", "%d", reader[ridx].log_port);
|
---|
480 | tpl_printf(vars, 0, "BOXID", "%ld", reader[ridx].boxid);
|
---|
481 |
|
---|
482 | if(reader[ridx].r_port) tpl_printf(vars, 0, "R_PORT", ",%d", reader[ridx].r_port);
|
---|
483 | if(reader[ridx].l_port) {
|
---|
484 | if(reader[ridx].r_port) tpl_printf(vars, 0, "L_PORT", ",%d", reader[ridx].l_port);
|
---|
485 | else tpl_printf(vars, 0, "L_PORT", ",,%d", reader[ridx].l_port);
|
---|
486 | }
|
---|
487 |
|
---|
488 | //Group
|
---|
489 | /*restore the settings format of group from long over bitarray*/
|
---|
490 | char *dot = ""; //flag for comma
|
---|
491 | char grpbit[33];
|
---|
492 | long2bitchar(reader[ridx].grp, grpbit);
|
---|
493 | for(i = 0; i < 32; i++){
|
---|
494 | if (grpbit[i] == '1'){
|
---|
495 | tpl_printf(vars, 1, "GRP", "%s%d", dot, i+1);
|
---|
496 | dot = ",";
|
---|
497 | }
|
---|
498 | }
|
---|
499 |
|
---|
500 | //services
|
---|
501 | char sidok[33];
|
---|
502 | long2bitchar(reader[ridx].sidtabok, sidok);
|
---|
503 | char sidno[33];
|
---|
504 | long2bitchar(reader[ridx].sidtabno,sidno);
|
---|
505 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
506 | //build matrix
|
---|
507 | i = 0;
|
---|
508 | while(sidtab != NULL){
|
---|
509 | tpl_addVar(vars, 0, "SIDLABEL", sidtab->label);
|
---|
510 | if(sidok[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
511 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
512 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDOKBIT"));
|
---|
513 | if(sidno[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
514 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
515 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDNOBIT"));
|
---|
516 | sidtab=sidtab->next;
|
---|
517 | i++;
|
---|
518 | }
|
---|
519 |
|
---|
520 | // CAID
|
---|
521 | i = 0;
|
---|
522 | CAIDTAB *ctab = &reader[ridx].ctab;
|
---|
523 | while(ctab->caid[i]) {
|
---|
524 | if (i == 0) tpl_printf(vars, 1, "CAIDS", "%04X", ctab->caid[i]);
|
---|
525 | else tpl_printf(vars, 1, "CAIDS", ",%04X", ctab->caid[i]);;
|
---|
526 | if(ctab->mask[i]) tpl_printf(vars, 1, "CAIDS", "&%04X", ctab->mask[i]);
|
---|
527 | i++;
|
---|
528 | }
|
---|
529 | fputs(tpl_getTpl(vars, "READERCONFIG"), f);
|
---|
530 | }
|
---|
531 |
|
---|
532 | void send_oscam_user_config_edit(struct templatevars *vars, FILE *f, struct uriparams *params){
|
---|
533 | struct s_auth *account, *ptr;
|
---|
534 | char user[128];
|
---|
535 |
|
---|
536 | if (strcmp(getParam(params, "action"), "Save As") == 0) strncpy(user, getParam(params, "newuser"), sizeof(user)/sizeof(char) - 1);
|
---|
537 | else strncpy(user, getParam(params, "user"), sizeof(user)/sizeof(char) - 1);
|
---|
538 | user[sizeof(user)/sizeof(char) - 1] = '\0';
|
---|
539 |
|
---|
540 | int i, j;
|
---|
541 |
|
---|
542 | for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
543 |
|
---|
544 | // Create a new user if it doesn't yet
|
---|
545 | if (account == NULL){
|
---|
546 | i = 1;
|
---|
547 | while(strlen(user) < 1){
|
---|
548 | snprintf(user, sizeof(user)/sizeof(char) - 1, "NEWUSER%d", i);
|
---|
549 | for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
550 | if(account != NULL) user[0] = '\0';
|
---|
551 | ++i;
|
---|
552 | }
|
---|
553 | if (!(account=malloc(sizeof(struct s_auth)))){
|
---|
554 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
555 | return;
|
---|
556 | }
|
---|
557 | if(cfg->account == NULL) cfg->account = account;
|
---|
558 | else {
|
---|
559 | for (ptr = cfg->account; ptr != NULL && ptr->next != NULL; ptr = ptr->next);
|
---|
560 | ptr->next = account;
|
---|
561 | }
|
---|
562 | memset(account, 0, sizeof(struct s_auth));
|
---|
563 | strncpy((char *)account->usr, user, sizeof(account->usr)-1);
|
---|
564 | account->au=(-1);
|
---|
565 | account->monlvl=cfg->mon_level;
|
---|
566 | account->tosleep=cfg->tosleep;
|
---|
567 | for (i=1; i<CS_MAXCAIDTAB; account->ctab.mask[i++]=0xffff);
|
---|
568 | for (i=1; i<CS_MAXTUNTAB; account->ttab.bt_srvid[i++]=0x0000);
|
---|
569 | #ifdef CS_ANTICASC
|
---|
570 | account->ac_users=cfg->ac_users;
|
---|
571 | account->ac_penalty=cfg->ac_penalty;
|
---|
572 | account->ac_idx = account->ac_idx + 1;
|
---|
573 | #endif
|
---|
574 | tpl_addVar(vars, 1, "MESSAGE", "<b>New user has been added with default settings</b><BR>");
|
---|
575 | if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS);
|
---|
576 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing configuration to disk failed!</b><BR>");
|
---|
577 | // need to reget account as writing to disk changes account!
|
---|
578 | for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
579 | }
|
---|
580 |
|
---|
581 | if((strcmp(getParam(params, "action"), "Save") == 0) || (strcmp(getParam(params, "action"), "Save As") == 0)){
|
---|
582 | char servicelabels[255]="";
|
---|
583 | //clear group
|
---|
584 | account->grp = 0;
|
---|
585 |
|
---|
586 | for(i=0;i<(*params).paramcount;i++){
|
---|
587 | if ((strcmp((*params).params[i], "action")) && (strcmp((*params).params[i], "user")) && (strcmp((*params).params[i], "newuser"))){
|
---|
588 | if (!strcmp((*params).params[i], "services"))
|
---|
589 | sprintf(servicelabels + strlen(servicelabels), "%s,", (*params).values[i]);
|
---|
590 | else
|
---|
591 | chk_account((*params).params[i], (*params).values[i], account);
|
---|
592 | }
|
---|
593 | }
|
---|
594 | chk_account("services", servicelabels, account);
|
---|
595 | tpl_addVar(vars, 1, "MESSAGE", "<B>Settings updated</B><BR><BR>");
|
---|
596 | if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS);
|
---|
597 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
598 | }
|
---|
599 |
|
---|
600 | tpl_addVar(vars, 0, "USERNAME", account->usr);
|
---|
601 | tpl_addVar(vars, 0, "PASSWORD", account->pwd);
|
---|
602 |
|
---|
603 | //Expirationdate
|
---|
604 | struct tm * timeinfo = localtime (&account->expirationdate);
|
---|
605 | char buf [80];
|
---|
606 | strftime (buf,80,"%Y-%m-%d",timeinfo);
|
---|
607 | if(strcmp(buf,"1970-01-01")) tpl_addVar(vars, 0, "EXPDATE", buf);
|
---|
608 | //Group
|
---|
609 | /*restore the settings format of group from long over bitarray*/
|
---|
610 | char *dot = ""; //flag for comma
|
---|
611 | char grpbit[33];
|
---|
612 | long2bitchar(account->grp, grpbit);
|
---|
613 | for(i = 0; i < 32; i++){
|
---|
614 | if (grpbit[i] == '1'){
|
---|
615 | tpl_printf(vars, 1, "GROUPS", "%s%d", dot, i+1);
|
---|
616 | dot = ",";
|
---|
617 | }
|
---|
618 | }
|
---|
619 | //Hostname
|
---|
620 | tpl_addVar(vars, 0, "DYNDNS", (char *)account->dyndns);
|
---|
621 |
|
---|
622 | //Uniq
|
---|
623 | tpl_printf(vars, 0, "TMP", "UNIQSELECTED%d", account->uniq);
|
---|
624 | tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
|
---|
625 |
|
---|
626 | //Sleep
|
---|
627 | if(!account->tosleep) tpl_addVar(vars, 0, "SLEEP", "0");
|
---|
628 | else tpl_printf(vars, 0, "SLEEP", "%d", account->tosleep);
|
---|
629 | //Monlevel selector
|
---|
630 | tpl_printf(vars, 0, "TMP", "MONSELECTED%d", account->monlvl);
|
---|
631 | tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
|
---|
632 |
|
---|
633 | //AU Selector
|
---|
634 | if (!account->au) tpl_addVar(vars, 0, "AUSELECTED", "selected");
|
---|
635 | if (account->autoau == 1) tpl_addVar(vars, 0, "AUTOAUSELECTED", "selected");
|
---|
636 | int ridx;
|
---|
637 | for (ridx=0; ridx<CS_MAXREADER; ridx++){
|
---|
638 | if(!reader[ridx].device[0]) break;
|
---|
639 | tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
|
---|
640 | if (account->au == ridx) tpl_addVar(vars, 0, "SELECTED", "selected");
|
---|
641 | else tpl_addVar(vars, 0, "SELECTED", "");
|
---|
642 | tpl_addVar(vars, 1, "RDROPTION", tpl_getTpl(vars, "USEREDITRDRSELECTED"));
|
---|
643 | }
|
---|
644 |
|
---|
645 | /* SERVICES */
|
---|
646 | //services - first we have to move the long sidtabok/sidtabno to a binary array
|
---|
647 | char sidok[33];
|
---|
648 | long2bitchar(account->sidtabok,sidok);
|
---|
649 | char sidno[33];
|
---|
650 | long2bitchar(account->sidtabno,sidno);
|
---|
651 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
652 | //build matrix
|
---|
653 | i=0;
|
---|
654 | while(sidtab != NULL){
|
---|
655 | tpl_addVar(vars, 0, "SIDLABEL", sidtab->label);
|
---|
656 | if(sidok[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
657 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
658 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "USEREDITSIDOKBIT"));
|
---|
659 | if(sidno[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
660 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
661 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "USEREDITSIDNOBIT"));
|
---|
662 | sidtab=sidtab->next;
|
---|
663 | i++;
|
---|
664 | }
|
---|
665 | /* CAID */
|
---|
666 | dot="";
|
---|
667 | i = 0;
|
---|
668 | CAIDTAB *ctab = &account->ctab;
|
---|
669 | while(ctab->caid[i]) {
|
---|
670 | tpl_printf(vars, 1, "CAIDS", "%s%04X", dot, ctab->caid[i]);
|
---|
671 | if(ctab->mask[i]) tpl_printf(vars, 1, "CAIDS", "&%04X", ctab->mask[i]);
|
---|
672 | if(ctab->cmap[i]) tpl_printf(vars, 1, "CAIDS", ":%04X", ctab->cmap[i]);
|
---|
673 | dot=",";
|
---|
674 | ++i;
|
---|
675 | }
|
---|
676 |
|
---|
677 | /*IDENT*/
|
---|
678 | dot="";
|
---|
679 | FTAB *ftab = &account->ftab;
|
---|
680 | for (i = 0; i < ftab->nfilts; ++i){
|
---|
681 | tpl_printf(vars, 1, "IDENTS", "%s%04X", dot, ftab->filts[i].caid);
|
---|
682 | dot=":";
|
---|
683 | for (j = 0; j < ftab->filts[i].nprids; ++j) {
|
---|
684 | tpl_printf(vars, 1, "IDENTS", "%s%06lX", dot, ftab->filts[i].prids[j]);
|
---|
685 | dot=",";
|
---|
686 | }
|
---|
687 | dot=";";
|
---|
688 | }
|
---|
689 |
|
---|
690 | /*Betatunnel*/
|
---|
691 | dot="";
|
---|
692 | i = 0;
|
---|
693 | TUNTAB *ttab = &account->ttab;
|
---|
694 | while(ttab->bt_caidfrom[i]) {
|
---|
695 | tpl_printf(vars, 1, "BETATUNNELS", "%s%04X", dot, ttab->bt_caidfrom[i]);
|
---|
696 | if(ttab->bt_srvid[i]) tpl_printf(vars, 1, "BETATUNNELS", ".%04X", ttab->bt_srvid[i]);
|
---|
697 | if(ttab->bt_caidto[i]) tpl_printf(vars, 1, "BETATUNNELS", ":%04X", ttab->bt_caidto[i]);
|
---|
698 | dot=",";
|
---|
699 | ++i;
|
---|
700 | }
|
---|
701 |
|
---|
702 | #ifdef CS_ANTICASC
|
---|
703 | tpl_printf(vars, 0, "AC_USERS", "%d", account->ac_users);
|
---|
704 | tpl_printf(vars, 0, "AC_PENALTY", "%d", account->ac_penalty);
|
---|
705 | #endif
|
---|
706 | fputs(tpl_getTpl(vars, "USEREDIT"), f);
|
---|
707 | }
|
---|
708 |
|
---|
709 | void send_oscam_user_config(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
710 | struct s_auth *account, *account2;
|
---|
711 | char *user = getParam(params, "user");
|
---|
712 | int i, found = 0;
|
---|
713 |
|
---|
714 | if (strcmp(getParam(params, "action"), "delete") == 0){
|
---|
715 | account=cfg->account;
|
---|
716 | if(strcmp(account->usr, user) == 0){
|
---|
717 | cfg->account = account->next;
|
---|
718 | free(account);
|
---|
719 | found = 1;
|
---|
720 | } else if (account->next != NULL){
|
---|
721 | do{
|
---|
722 | if(strcmp(account->next->usr, user) == 0){
|
---|
723 | account2 = account->next;
|
---|
724 | account->next = account2->next;
|
---|
725 | free(account2);
|
---|
726 | found = 1;
|
---|
727 | break;
|
---|
728 | }
|
---|
729 | } while ((account = account->next) && (account->next != NULL));
|
---|
730 | }
|
---|
731 |
|
---|
732 | if (found > 0){
|
---|
733 | tpl_addVar(vars, 1, "MESSAGE", "<b>Account has been deleted!</b><BR>");
|
---|
734 | if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS);
|
---|
735 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing configuration to disk failed!</b><BR>");
|
---|
736 | } else tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
|
---|
737 | }
|
---|
738 | /* List accounts*/
|
---|
739 | char *status = "offline";
|
---|
740 | char *expired = "";
|
---|
741 | char *classname="offline";
|
---|
742 | char *lastchan=" ";
|
---|
743 | time_t now = time((time_t)0);
|
---|
744 | int isec=0;
|
---|
745 |
|
---|
746 | for (account=cfg->account; (account) ; account=account->next){
|
---|
747 | expired = ""; classname="offline";
|
---|
748 | if(account->expirationdate && account->expirationdate<time(NULL)){
|
---|
749 | expired = " (expired)";
|
---|
750 | classname = "expired";
|
---|
751 | }
|
---|
752 | status="offline";
|
---|
753 |
|
---|
754 | //search account in active clients
|
---|
755 | for (i=0; i<CS_MAXPID; i++)
|
---|
756 | if (!strcmp(client[i].usr, account->usr)){
|
---|
757 | //30 secs without ecm is offline
|
---|
758 | if ((now - client[i].lastecm) < 30){
|
---|
759 | status = "<b>online</b>";classname="online";
|
---|
760 | lastchan = monitor_get_srvname(client[i].last_srvid);
|
---|
761 | isec = now - client[i].last;
|
---|
762 | }
|
---|
763 | }
|
---|
764 | tpl_addVar(vars, 0, "CLASSNAME", classname);
|
---|
765 | tpl_addVar(vars, 0, "USER", account->usr);
|
---|
766 | tpl_addVar(vars, 0, "USERENC", tpl_addTmp(vars, urlencode(account->usr)));
|
---|
767 | tpl_addVar(vars, 0, "STATUS", status);
|
---|
768 | tpl_addVar(vars, 0, "EXPIRED", expired);
|
---|
769 | tpl_addVar(vars, 0, "LASTCHANNEL", lastchan);
|
---|
770 | tpl_printf(vars, 0, "IDLESECS", "%d", isec);
|
---|
771 | tpl_addVar(vars, 1, "USERCONFIGS", tpl_getTpl(vars, "USERCONFIGLISTBIT"));
|
---|
772 | isec = 0;
|
---|
773 | lastchan = " ";
|
---|
774 | }
|
---|
775 | fputs(tpl_getTpl(vars, "USERCONFIGLIST"), f);
|
---|
776 | }
|
---|
777 |
|
---|
778 | void send_oscam_entitlement(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
779 | /* build entitlements from reader init history */
|
---|
780 | #ifdef CS_RDR_INIT_HIST
|
---|
781 | int ridx;
|
---|
782 | char *p;
|
---|
783 | char *reader_ = getParam(params, "reader");
|
---|
784 | if(strlen(reader_) > 0){
|
---|
785 | for (ridx=0; ridx<CS_MAXREADER && strcmp(reader_, reader[ridx].label) != 0; ridx++);
|
---|
786 | if(ridx<CS_MAXREADER){
|
---|
787 | for (p=(char *)reader[ridx].init_history; *p; p+=strlen(p)+1){
|
---|
788 | tpl_printf(vars, 1, "LOGHISTORY", "%s<BR>\n", p);
|
---|
789 | }
|
---|
790 | }
|
---|
791 | tpl_addVar(vars, 0, "READERNAME", reader_);
|
---|
792 | }
|
---|
793 | #else
|
---|
794 | tpl_addVar(vars, 0, "LOGHISTORY", "Your binary has not been compiled with the \
|
---|
795 | CS_RDR_INIT_HIST flag (some architectures disable this \
|
---|
796 | per default to save ressources). Please recompile if you \
|
---|
797 | need this feature! This is not a bug!<BR>\n");
|
---|
798 | #endif
|
---|
799 | fputs(tpl_getTpl(vars, "ENTITLEMENTS"), f);
|
---|
800 | }
|
---|
801 |
|
---|
802 | void send_oscam_status(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
803 | int i;
|
---|
804 | char *usr;
|
---|
805 | int lsec, isec, cnr, con, cau;
|
---|
806 | time_t now = time((time_t)0);
|
---|
807 | struct tm *lt;
|
---|
808 |
|
---|
809 | char *hideidle = getParam(params, "hideidle");
|
---|
810 | if(strlen(hideidle) > 0){
|
---|
811 | int oldval = cfg->http_hide_idle_clients;
|
---|
812 | chk_t_monitor("httphideidleclients", hideidle);
|
---|
813 | if(oldval != cfg->http_hide_idle_clients){
|
---|
814 | refresh_oscam(REFR_SERVER);
|
---|
815 | }
|
---|
816 | }
|
---|
817 |
|
---|
818 | if(cfg->http_hide_idle_clients > 0) tpl_addVar(vars, 0, "HIDEIDLECLIENTSSELECTED1", "selected");
|
---|
819 | else tpl_addVar(vars, 0, "HIDEIDLECLIENTSSELECTED0", "selected");
|
---|
820 |
|
---|
821 | for (i=0; i<CS_MAXPID; i++) {
|
---|
822 | if (client[i].pid) {
|
---|
823 |
|
---|
824 | if((cfg->http_hide_idle_clients == 1) && (client[i].typ == 'c') && ((now - client[i].lastecm) > cfg->mon_hideclient_to)) continue;
|
---|
825 |
|
---|
826 | lsec=now-client[i].login;
|
---|
827 | isec=now-client[i].last;
|
---|
828 | usr=client[i].usr;
|
---|
829 |
|
---|
830 | if (((client[i].typ=='r') || (client[i].typ=='p')) && (con=cs_idx2ridx(i))>=0) usr=reader[con].label;
|
---|
831 |
|
---|
832 | if (client[i].dup) con=2;
|
---|
833 | else if ((client[i].tosleep) && (now-client[i].lastswitch>client[i].tosleep)) con=1;
|
---|
834 | else con=0;
|
---|
835 |
|
---|
836 | if (i-cdiff>0) cnr=i-cdiff;
|
---|
837 | else cnr=(i>1) ? i-1 : 0;
|
---|
838 |
|
---|
839 | if( (cau=client[i].au+1) && (now-client[i].lastemm)/60 > cfg->mon_aulow) cau=-cau;
|
---|
840 |
|
---|
841 | lt=localtime(&client[i].login);
|
---|
842 |
|
---|
843 | tpl_printf(vars, 0, "CLIENTPID", "%d", client[i].pid);
|
---|
844 | tpl_printf(vars, 0, "CLIENTTYPE", "%c", client[i].typ);
|
---|
845 | tpl_printf(vars, 0, "CLIENTCNR", "%d", cnr);
|
---|
846 | tpl_addVar(vars, 0, "CLIENTUSER", usr);
|
---|
847 | tpl_printf(vars, 0, "CLIENTCAU", "%d", cau);
|
---|
848 | tpl_printf(vars, 0, "CLIENTCRYPTED", "%d", client[i].crypted);
|
---|
849 | tpl_printf(vars, 0, "CLIENTIP", "%s", cs_inet_ntoa(client[i].ip));
|
---|
850 | tpl_printf(vars, 0, "CLIENTPORT", "%d", client[i].port);
|
---|
851 | tpl_addVar(vars, 0, "CLIENTPROTO", monitor_get_proto(i));
|
---|
852 | tpl_printf(vars, 0, "CLIENTLOGINDATE", "%02d.%02d.%02d", lt->tm_mday, lt->tm_mon+1, lt->tm_year%100);
|
---|
853 | tpl_printf(vars, 0, "CLIENTLOGINTIME", "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
|
---|
854 |
|
---|
855 | int secs = 0, fullmins =0, mins =0, hours =0;
|
---|
856 | if(lsec > 0){
|
---|
857 | secs = lsec % 60;
|
---|
858 | if (lsec > 60){
|
---|
859 | fullmins = lsec / 60;
|
---|
860 | mins = fullmins % 60;
|
---|
861 | if(fullmins > 60) hours = fullmins / 60;
|
---|
862 | }
|
---|
863 | }
|
---|
864 |
|
---|
865 | tpl_printf(vars, 0, "CLIENTLOGINSECS", "%02d:%02d:%02d", hours, mins, secs);
|
---|
866 | tpl_printf(vars, 0, "CLIENTCAID", "%04X", client[i].last_caid);
|
---|
867 | tpl_printf(vars, 0, "CLIENTSRVID", "%04X", client[i].last_srvid);
|
---|
868 | tpl_addVar(vars, 0, "CLIENTSRVNAME", monitor_get_srvname(client[i].last_srvid));
|
---|
869 |
|
---|
870 | secs = 0; fullmins =0; mins =0; hours =0;
|
---|
871 | if(isec > 0){
|
---|
872 | secs = isec % 60;
|
---|
873 | if (isec > 60){
|
---|
874 | fullmins = isec / 60;
|
---|
875 | mins = fullmins % 60;
|
---|
876 | if(fullmins > 60) hours = fullmins / 60;
|
---|
877 | }
|
---|
878 | }
|
---|
879 |
|
---|
880 | tpl_printf(vars, 0, "CLIENTIDLESECS", "%02d:%02d:%02d", hours, mins, secs);
|
---|
881 | if(con == 2) tpl_printf(vars, 0, "CLIENTCON", "Duplicate");
|
---|
882 | else if (con == 1) tpl_printf(vars, 0, "CLIENTCON", "Sleep");
|
---|
883 | else tpl_printf(vars, 0, "CLIENTCON", "OK");
|
---|
884 | tpl_printf(vars, 0, "CWOK", "%d", client[i].cwfound);
|
---|
885 | tpl_printf(vars, 0, "CWNOK", "%d", client[i].cwnot);
|
---|
886 | tpl_addVar(vars, 1, "CLIENTSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
|
---|
887 | }
|
---|
888 | }
|
---|
889 |
|
---|
890 | #ifdef CS_LOGHISTORY
|
---|
891 | for (i=(*loghistidx+3) % CS_MAXLOGHIST; i!=*loghistidx; i=(i+1) % CS_MAXLOGHIST){
|
---|
892 | char *p_usr, *p_txt;
|
---|
893 | p_usr=(char *)(loghist+(i*CS_LOGHISTSIZE));
|
---|
894 | p_txt=p_usr+32;
|
---|
895 | if (p_txt[0]) tpl_printf(vars, 1, "LOGHISTORY", "%s<BR>\n", p_txt+8);
|
---|
896 | }
|
---|
897 | #else
|
---|
898 | tpl_addVar(vars, 0, "LOGHISTORY", "the flag CS_LOGHISTORY is not set in your binary<BR>\n");
|
---|
899 | #endif
|
---|
900 |
|
---|
901 | fputs(tpl_getTpl(vars, "STATUS"), f);
|
---|
902 | }
|
---|
903 |
|
---|
904 | void send_oscam_services_edit(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
905 | struct s_sidtab *sidtab,*ptr;
|
---|
906 | char label[128];
|
---|
907 | int i;
|
---|
908 |
|
---|
909 | strncpy(label, strtolower(getParam(params, "service")), sizeof(label)/sizeof(char) - 1);
|
---|
910 | label[sizeof(label)/sizeof(char) - 1] = '\0';
|
---|
911 |
|
---|
912 | for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
|
---|
913 |
|
---|
914 | if (sidtab == NULL){
|
---|
915 | i = 1;
|
---|
916 | while(strlen(label) < 1){
|
---|
917 | snprintf(label, sizeof(label)/sizeof(char) - 1, "newservice%d", i);
|
---|
918 | for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab = sidtab->next);
|
---|
919 | if(sidtab != NULL) label[0] = '\0';
|
---|
920 | ++i;
|
---|
921 | }
|
---|
922 | if (!(sidtab=malloc(sizeof(struct s_sidtab)))){
|
---|
923 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
924 | return;
|
---|
925 | }
|
---|
926 |
|
---|
927 | if(cfg->sidtab == NULL) cfg->sidtab = sidtab;
|
---|
928 | else {
|
---|
929 | for (ptr = cfg->sidtab; ptr != NULL && ptr->next != NULL; ptr = ptr->next);
|
---|
930 | ptr->next = sidtab;
|
---|
931 | }
|
---|
932 | memset(sidtab, 0, sizeof(struct s_sidtab));
|
---|
933 | strncpy((char *)sidtab->label, label, sizeof(sidtab->label)-1);
|
---|
934 |
|
---|
935 | tpl_addVar(vars, 1, "MESSAGE", "<b>New service has been added</b><BR>");
|
---|
936 | if (write_services()==0) refresh_oscam(REFR_SERVICES);
|
---|
937 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing services to disk failed!</b><BR>");
|
---|
938 |
|
---|
939 | for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
|
---|
940 | }
|
---|
941 |
|
---|
942 | if (strcmp(getParam(params, "action"), "Save") == 0){
|
---|
943 | for(i=0;i<(*params).paramcount;i++){
|
---|
944 | if ((strcmp((*params).params[i], "action")) && (strcmp((*params).params[i], "service"))){
|
---|
945 | chk_sidtab((*params).params[i], (*params).values[i], sidtab);
|
---|
946 | }
|
---|
947 | }
|
---|
948 | tpl_addVar(vars, 1, "MESSAGE", "<B>Services updated</B><BR><BR>");
|
---|
949 | if (write_services()==0) refresh_oscam(REFR_SERVICES);
|
---|
950 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
951 |
|
---|
952 | for (sidtab = cfg->sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
|
---|
953 | }
|
---|
954 |
|
---|
955 | tpl_addVar(vars, 0, "LABEL", sidtab->label);
|
---|
956 | tpl_addVar(vars, 0, "LABELENC", urlencode(sidtab->label));
|
---|
957 |
|
---|
958 | for (i=0; i<sidtab->num_caid; i++){
|
---|
959 | if (i==0) tpl_printf(vars, 0, "CAIDS", "%04X", sidtab->caid[i]);
|
---|
960 | else tpl_printf(vars, 1, "CAIDS", ",%04X", sidtab->caid[i]);
|
---|
961 | }
|
---|
962 | for (i=0; i<sidtab->num_provid; i++){
|
---|
963 | if (i==0) tpl_printf(vars, 0, "PROVIDS", "%08lX", sidtab->provid[i]);
|
---|
964 | else tpl_printf(vars, 1, "PROVIDS", ",%08lX", sidtab->provid[i]);
|
---|
965 | }
|
---|
966 | for (i=0; i<sidtab->num_srvid; i++){
|
---|
967 | if (i==0) tpl_printf(vars, 0, "SRVIDS", "%04X", sidtab->srvid[i]);
|
---|
968 | else tpl_printf(vars, 1, "SRVIDS", ",%04X", sidtab->srvid[i]);
|
---|
969 | }
|
---|
970 | fputs(tpl_getTpl(vars, "SERVICEEDIT"), f);
|
---|
971 | }
|
---|
972 |
|
---|
973 | void send_oscam_services(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
974 | struct s_sidtab *sidtab, *sidtab2;
|
---|
975 | char *service = getParam(params, "service");
|
---|
976 | int i, found = 0;
|
---|
977 |
|
---|
978 | if (strcmp(getParam(params, "action"), "delete") == 0){
|
---|
979 | sidtab=cfg->sidtab;
|
---|
980 | if(strcmp(sidtab->label, service) == 0){
|
---|
981 | cfg->sidtab = sidtab->next;
|
---|
982 | free(sidtab);
|
---|
983 | found = 1;
|
---|
984 | } else if (sidtab->next != NULL){
|
---|
985 | do{
|
---|
986 | if(strcmp(sidtab->next->label, service) == 0){
|
---|
987 | sidtab2 = sidtab->next;
|
---|
988 | sidtab->next = sidtab2->next;
|
---|
989 | free(sidtab2);
|
---|
990 | found = 1;
|
---|
991 | break;
|
---|
992 | }
|
---|
993 | } while ((sidtab = sidtab->next) && (sidtab->next != NULL));
|
---|
994 | }
|
---|
995 | if (found > 0){
|
---|
996 | tpl_addVar(vars, 1, "MESSAGE", "<b>Service has been deleted!</b><BR>");
|
---|
997 | if (write_services()==0) refresh_oscam(REFR_SERVICES);
|
---|
998 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing services to disk failed!</b><BR>");
|
---|
999 | } else tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry but the specified service doesn't exist. No deletion will be made!</b><BR>");
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 | sidtab=cfg->sidtab;
|
---|
1003 | // Show List
|
---|
1004 | while(sidtab != NULL){
|
---|
1005 | tpl_printf(vars, 0, "SID","");
|
---|
1006 | if ((strcmp(getParam(params, "service"), sidtab->label) == 0) && (strcmp(getParam(params, "action"), "list") == 0) ){
|
---|
1007 | tpl_printf(vars, 0, "SIDCLASS","sidlist");
|
---|
1008 | for (i=0; i<sidtab->num_srvid; i++){
|
---|
1009 | tpl_printf(vars, 1, "SID", "%04X : %s<BR>", sidtab->srvid[i], monitor_get_srvname(sidtab->srvid[i]));
|
---|
1010 | }
|
---|
1011 | } else {
|
---|
1012 | tpl_printf(vars, 0, "SIDCLASS","");
|
---|
1013 | tpl_printf(vars, 0, "SID","<A HREF=\"services.html?service=%s&action=list\">Show Services</A>",tpl_addTmp(vars, urlencode(sidtab->label)));
|
---|
1014 | }
|
---|
1015 | tpl_addVar(vars, 0, "LABELENC", tpl_addTmp(vars, urlencode(sidtab->label)));
|
---|
1016 | tpl_addVar(vars, 0, "LABEL", sidtab->label);
|
---|
1017 | tpl_addVar(vars, 0, "SIDLIST", tpl_getTpl(vars, "SERVICECONFIGSIDBIT"));
|
---|
1018 | tpl_addVar(vars, 1, "SERVICETABS", tpl_getTpl(vars, "SERVICECONFIGLISTBIT"));
|
---|
1019 | sidtab=sidtab->next;
|
---|
1020 | }
|
---|
1021 | fputs(tpl_getTpl(vars, "SERVICECONFIGLIST"), f);
|
---|
1022 | }
|
---|
1023 |
|
---|
1024 | void send_oscam_savetpls(struct templatevars *vars, FILE *f){
|
---|
1025 | if(strlen(cfg->http_tpl) > 0){
|
---|
1026 | tpl_printf(vars, 0, "CNT", "%d", tpl_saveIncludedTpls(cfg->http_tpl));
|
---|
1027 | tpl_addVar(vars, 0, "PATH", cfg->http_tpl);
|
---|
1028 | } else tpl_addVar(vars, 0, "CNT", "0");
|
---|
1029 | fputs(tpl_getTpl(vars, "SAVETEMPLATES"), f);
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | int process_request(FILE *f, struct in_addr in) {
|
---|
1033 | char buf[4096];
|
---|
1034 | char tmp[4096];
|
---|
1035 |
|
---|
1036 | int authok = 0;
|
---|
1037 | char expectednonce[64];
|
---|
1038 |
|
---|
1039 | char *method;
|
---|
1040 | char *path;
|
---|
1041 | char *protocol;
|
---|
1042 | char *pch;
|
---|
1043 | char *pch2;
|
---|
1044 | /* List of possible pages */
|
---|
1045 | char *pages[]={
|
---|
1046 | "/config.html",
|
---|
1047 | "/readers.html",
|
---|
1048 | "/entitlements.html",
|
---|
1049 | "/status.html",
|
---|
1050 | "/userconfig.html",
|
---|
1051 | "/readerconfig.html",
|
---|
1052 | "/services.html",
|
---|
1053 | "/user_edit.html",
|
---|
1054 | "/site.css",
|
---|
1055 | "/services_edit.html",
|
---|
1056 | "/savetemplates.html"};
|
---|
1057 | int pagescnt = sizeof(pages)/sizeof(char *); // Calculate the amount of items in array
|
---|
1058 |
|
---|
1059 | int pgidx = -1;
|
---|
1060 | int i;
|
---|
1061 | int parsemode = 1;
|
---|
1062 | struct uriparams params;
|
---|
1063 | params.paramcount = 0;
|
---|
1064 |
|
---|
1065 | /* First line always includes the GET/POST request */
|
---|
1066 | if (!fgets(buf, sizeof(buf), f)) return -1;
|
---|
1067 | method = strtok(buf, " ");
|
---|
1068 | path = strtok(NULL, " ");
|
---|
1069 | protocol = strtok(NULL, "\r");
|
---|
1070 | if(method == NULL || path == NULL || protocol == NULL) return -1;
|
---|
1071 |
|
---|
1072 | pch=path;
|
---|
1073 | /* advance pointer to beginning of query string */
|
---|
1074 | while(pch[0] != '?' && pch[0] != '\0') ++pch;
|
---|
1075 | if(pch[0] == '?'){
|
---|
1076 | pch[0] = '\0';
|
---|
1077 | ++pch;
|
---|
1078 | }
|
---|
1079 |
|
---|
1080 | /* Map page to our static page definitions */
|
---|
1081 | for (i=0; i<pagescnt; i++){
|
---|
1082 | if (!strcmp(path, pages[i])) pgidx = i;
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 | /* Parse url parameters; parsemode = 1 means parsing next param, parsemode = -1 parsing next
|
---|
1086 | value; pch2 points to the beginning of the currently parsed string, pch is the current position */
|
---|
1087 | pch2=pch;
|
---|
1088 | while(pch[0] != '\0'){
|
---|
1089 | if((parsemode == 1 && pch[0] == '=') || (parsemode == -1 && pch[0] == '&')){
|
---|
1090 | pch[0] = '\0';
|
---|
1091 | urldecode(pch2);
|
---|
1092 | if(parsemode == 1) {
|
---|
1093 | if(params.paramcount >= MAXGETPARAMS) break;
|
---|
1094 | ++params.paramcount;
|
---|
1095 | params.params[params.paramcount-1] = pch2;
|
---|
1096 | } else {
|
---|
1097 | params.values[params.paramcount-1] = pch2;
|
---|
1098 | }
|
---|
1099 | parsemode = -parsemode;
|
---|
1100 | pch2 = pch + 1;
|
---|
1101 | }
|
---|
1102 | ++pch;
|
---|
1103 | }
|
---|
1104 | /* last value wasn't processed in the loop yet... */
|
---|
1105 | if(parsemode == -1 && params.paramcount <= MAXGETPARAMS){
|
---|
1106 | urldecode(pch2);
|
---|
1107 | params.values[params.paramcount-1] = pch2;
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | if(strlen(cfg->http_user) == 0 || strlen(cfg->http_pwd) == 0) authok = 1;
|
---|
1111 | else calculate_nonce(expectednonce, sizeof(expectednonce)/sizeof(char));
|
---|
1112 |
|
---|
1113 | /* Read remaining request (we're only interested in auth header) */
|
---|
1114 | while (fgets(tmp, sizeof(tmp), f)) {
|
---|
1115 | if (tmp[0] == '\r' && tmp[1] == '\n') break;
|
---|
1116 | else if(authok == 0 && strlen(tmp) > 50 && strncmp(tmp, "Authorization:", 14) == 0 && strstr(tmp, "Digest") != NULL) {
|
---|
1117 | authok = check_auth(tmp, method, path, expectednonce);
|
---|
1118 | }
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | //cs_debug("%s %d\n", path, pgidx);
|
---|
1122 | //for(i=0; i < params.paramcount; ++i) cs_debug("%s : %s\n", params.params[i], params.values[i]);
|
---|
1123 |
|
---|
1124 | fseek(f, 0, SEEK_CUR); // Force change of stream direction
|
---|
1125 |
|
---|
1126 | if(authok != 1){
|
---|
1127 | strcpy(tmp, "WWW-Authenticate: Digest algorithm=\"MD5\", realm=\"");
|
---|
1128 | strcat(tmp, AUTHREALM);
|
---|
1129 | strcat(tmp, "\", qop=\"auth\", opaque=\"\", nonce=\"");
|
---|
1130 | strcat(tmp, expectednonce);
|
---|
1131 | strcat(tmp, "\"");
|
---|
1132 | if(authok == 2) strcat(tmp, ", stale=true");
|
---|
1133 | send_headers(f, 401, "Unauthorized", tmp, "text/html");
|
---|
1134 | return 0;
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | /*build page*/
|
---|
1138 | send_headers(f, 200, "OK", NULL, "text/html");
|
---|
1139 | if(pgidx == 8) send_css(f);
|
---|
1140 | else {
|
---|
1141 | time_t t;
|
---|
1142 | struct templatevars *vars = tpl_create();
|
---|
1143 | struct tm *lt;
|
---|
1144 | time(&t);
|
---|
1145 |
|
---|
1146 | lt=localtime(&t);
|
---|
1147 | tpl_addVar(vars, 0, "CS_VERSION", CS_VERSION);
|
---|
1148 | tpl_addVar(vars, 0, "CS_SVN_VERSION", CS_SVN_VERSION);
|
---|
1149 | if(cfg->http_refresh > 0 && (pgidx == 3 || pgidx == -1)){
|
---|
1150 | tpl_printf(vars, 0, "REFRESHTIME", "%d", cfg->http_refresh);
|
---|
1151 | tpl_addVar(vars, 0, "REFRESH", tpl_getTpl(vars, "REFRESH"));
|
---|
1152 | }
|
---|
1153 | tpl_printf(vars, 0, "CURDATE", "%02d.%02d.%02d", lt->tm_mday, lt->tm_mon+1, lt->tm_year%100);
|
---|
1154 | tpl_printf(vars, 0, "CURTIME", "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
|
---|
1155 | switch(pgidx){
|
---|
1156 | case 0: send_oscam_config(vars, f, ¶ms); break;
|
---|
1157 | case 1: send_oscam_reader(vars, f); break;
|
---|
1158 | case 2: send_oscam_entitlement(vars, f, ¶ms); break;
|
---|
1159 | case 3: send_oscam_status(vars, f, ¶ms); break;
|
---|
1160 | case 4: send_oscam_user_config(vars, f, ¶ms); break;
|
---|
1161 | case 5: send_oscam_reader_config(vars, f, ¶ms); break;
|
---|
1162 | case 6: send_oscam_services(vars, f, ¶ms); break;
|
---|
1163 | case 7: send_oscam_user_config_edit(vars, f, ¶ms); break;
|
---|
1164 | case 9: send_oscam_services_edit(vars, f, ¶ms); break;
|
---|
1165 | case 10: send_oscam_savetpls(vars, f); break;
|
---|
1166 | default: send_oscam_status(vars, f, ¶ms); break;
|
---|
1167 | }
|
---|
1168 | tpl_clear(vars);
|
---|
1169 | }
|
---|
1170 | return 0;
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | void http_srv() {
|
---|
1174 | int i,sock, reuse =1;
|
---|
1175 | struct sockaddr_in sin;
|
---|
1176 | struct sockaddr_in remote;
|
---|
1177 | socklen_t len = sizeof(remote);
|
---|
1178 | char *tmp;
|
---|
1179 |
|
---|
1180 | /* Prepare lookup array for conversion between ascii and hex */
|
---|
1181 | tmp = malloc(3*sizeof(char));
|
---|
1182 | for(i=0; i<256; i++) {
|
---|
1183 | snprintf(tmp, 3,"%02x", i);
|
---|
1184 | memcpy(hex2ascii[i], tmp, 2);
|
---|
1185 | }
|
---|
1186 | free(tmp);
|
---|
1187 | /* Create random string for nonce value generation */
|
---|
1188 | srand(time(NULL));
|
---|
1189 | create_rand_str(noncekey,32);
|
---|
1190 |
|
---|
1191 | /* Startup server */
|
---|
1192 | if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
|
---|
1193 | cs_log("HTTP Server: Creating socket failed! (errno=%d)", errno);
|
---|
1194 | return;
|
---|
1195 | }
|
---|
1196 | if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0){
|
---|
1197 | cs_log("HTTP Server: Setting SO_REUSEADDR via setsockopt failed! (errno=%d)", errno);
|
---|
1198 | }
|
---|
1199 |
|
---|
1200 | memset(&sin, 0, sizeof sin);
|
---|
1201 | sin.sin_family = AF_INET;
|
---|
1202 | sin.sin_addr.s_addr = INADDR_ANY;
|
---|
1203 | sin.sin_port = htons(cfg->http_port);
|
---|
1204 | if((bind(sock, (struct sockaddr *) &sin, sizeof(sin))) < 0) {
|
---|
1205 | cs_log("HTTP Server couldn't bind on port %d (errno=%d). Not starting HTTP!", cfg->http_port, errno);
|
---|
1206 | close(sock);
|
---|
1207 | return;
|
---|
1208 | }
|
---|
1209 | if (listen(sock, SOMAXCONN) < 0){
|
---|
1210 | cs_log("HTTP Server: Call to listen() failed! (errno=%d)", errno);
|
---|
1211 | close(sock);
|
---|
1212 | return;
|
---|
1213 | }
|
---|
1214 | cs_log("HTTP Server listening on port %d", cfg->http_port);
|
---|
1215 | while (1)
|
---|
1216 | {
|
---|
1217 | int s;
|
---|
1218 | FILE *f;
|
---|
1219 | if((s = accept(sock, (struct sockaddr *) &remote, &len)) < 0){
|
---|
1220 | cs_log("HTTP Server: Error calling accept() (errno=%d).", errno);
|
---|
1221 | break;
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | f = fdopen(s, "r+");
|
---|
1225 | process_request(f, remote.sin_addr);
|
---|
1226 | fflush(f);
|
---|
1227 | fclose(f);
|
---|
1228 | shutdown(s, SHUT_WR);
|
---|
1229 | close(s);
|
---|
1230 | }
|
---|
1231 | close(sock);
|
---|
1232 | }
|
---|