source: branches/monitor-improvement/oscam-http.c@ 1024

Last change on this file since 1024 was 1024, checked in by alno, 13 years ago

WebIF:
changelog:

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