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 | static 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 |
|
---|
20 | void refresh_oscam(enum refreshtypes refreshtype){
|
---|
21 | int 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 |
|
---|
60 | void 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> </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 |
|
---|
137 | void 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> </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 |
|
---|
197 | void 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> </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 |
|
---|
237 | void 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> </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 |
|
---|
301 | void 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> </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 |
|
---|
352 | void 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> </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 |
|
---|
389 | void 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> </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 |
|
---|
444 | void 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> </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 |
|
---|
510 | //Tablefoot and finish form
|
---|
511 | fprintf(f,"</TABLE>\r\n");
|
---|
512 | fprintf(f,"<input type=\"submit\" value=\"OK\"></form>\r\n");
|
---|
513 | }
|
---|
514 | }
|
---|
515 |
|
---|
516 | #ifdef CS_ANTICASC
|
---|
517 |
|
---|
518 | void send_oscam_config_anticasc(FILE *f, struct uriparams *params) {
|
---|
519 | int i;
|
---|
520 |
|
---|
521 | fprintf(f,"<BR><BR>");
|
---|
522 |
|
---|
523 | if (strcmp(getParam(params, "action"),"execute") == 0){
|
---|
524 | //we found the execute flag
|
---|
525 | for(i=0;i<(*params).paramcount;i++){
|
---|
526 | if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
|
---|
527 | fprintf(f,"Parameter: %s set to Value: %s<BR>\r\n", (*params).params[i], (*params).values[i]);
|
---|
528 | //we use the same function as used for parsing the config tokens
|
---|
529 | chk_t_ac((*params).params[i], (*params).values[i]);
|
---|
530 | }
|
---|
531 | }
|
---|
532 |
|
---|
533 | //Disclaimer
|
---|
534 | fprintf(f,"<BR><BR><B>Configuration Anticascading *DONE*</B><BR><BR>");
|
---|
535 | refresh_oscam(REFR_ANTICASC);
|
---|
536 | } else{
|
---|
537 |
|
---|
538 | //if nothing above matches we show the form
|
---|
539 | fprintf(f,"<form action=\"/config.html\" method=\"get\">\r\n");
|
---|
540 | fprintf(f,"<input name=\"part\" type=\"hidden\" value=\"anticasc\">\r\n");
|
---|
541 | fprintf(f,"<input name=\"action\" type=\"hidden\" value=\"execute\">\r\n");
|
---|
542 | fprintf(f,"<TABLE cellspacing=\"0\">");
|
---|
543 | fprintf(f,"\t<TH> </TH><TH>Edit Anticascading Config </TH>");
|
---|
544 |
|
---|
545 | //Port
|
---|
546 | char *checked="";
|
---|
547 | if (cfg->ac_enabled > 0) checked="checked";
|
---|
548 | fprintf(f,"\t<TR><TD>Enabled:</TD><TD><input name=\"enabled\" type=\"checkbox\" value=\"1\" %s>\r\n", checked);
|
---|
549 | //numusers
|
---|
550 | 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);
|
---|
551 | //sampletime
|
---|
552 | 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);
|
---|
553 | //samples
|
---|
554 | 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);
|
---|
555 | //penalty
|
---|
556 | 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);
|
---|
557 | //aclogfile
|
---|
558 | 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);
|
---|
559 | //fakedelay
|
---|
560 | 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);
|
---|
561 | //denysamples
|
---|
562 | 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);
|
---|
563 |
|
---|
564 | //Tablefoot and finish form
|
---|
565 | fprintf(f,"</TABLE>\r\n");
|
---|
566 | fprintf(f,"<input type=\"submit\" value=\"OK\"></form>\r\n");
|
---|
567 | }
|
---|
568 | }
|
---|
569 |
|
---|
570 | #endif
|
---|
571 |
|
---|
572 | void send_oscam_config(FILE *f, struct uriparams *params) {
|
---|
573 | fprintf(f,"<BR><BR>");
|
---|
574 |
|
---|
575 | /*create submenue*/
|
---|
576 | fprintf(f, "<TABLE border=0 class=\"menu\">\n");
|
---|
577 | fprintf(f, " <TR>\n");
|
---|
578 | fprintf(f, " <TD CLASS=\"menu\"><A HREF=\"config.html?part=global\">Global</TD>\n");
|
---|
579 | fprintf(f, " <TD CLASS=\"menu\"><A HREF=\"config.html?part=camd33\">Camd3.3</TD>\n");
|
---|
580 | fprintf(f, " <TD CLASS=\"menu\"><A HREF=\"config.html?part=camd35\">Camd3.5</TD>\n");
|
---|
581 | fprintf(f, " <TD CLASS=\"menu\"><A HREF=\"config.html?part=newcamd\">Newcamd</TD>\n");
|
---|
582 | fprintf(f, " <TD CLASS=\"menu\"><A HREF=\"config.html?part=radegast\">Radegast</TD>\n");
|
---|
583 | fprintf(f, " <TD CLASS=\"menu\"><A HREF=\"config.html?part=cccam\">Cccam</TD>\n");
|
---|
584 | fprintf(f, " <TD CLASS=\"menu\"><A HREF=\"config.html?part=gbox\">Gbox</TD>\n");
|
---|
585 | #ifdef CS_ANTICASC
|
---|
586 | fprintf(f, " <TD CLASS=\"menu\"><A HREF=\"config.html?part=anticasc\">Anticascading</TD>\n");
|
---|
587 | #endif
|
---|
588 | fprintf(f, " <TD CLASS=\"menu\"><A HREF=\"config.html?part=monitor\">Monitor</TD>\n");
|
---|
589 | fprintf(f, " </TR>\n");
|
---|
590 | fprintf(f, "</TABLE>\n");
|
---|
591 |
|
---|
592 | char *part = getParam(params, "part");
|
---|
593 | if (strlen(part) == 0)
|
---|
594 | send_oscam_config_global(f, params);
|
---|
595 | else {
|
---|
596 | if (!strcmp(part,"global"))
|
---|
597 | send_oscam_config_global(f, params);
|
---|
598 | else if (!strcmp(part,"camd33"))
|
---|
599 | send_oscam_config_camd33(f, params);
|
---|
600 | else if (!strcmp(part,"camd35"))
|
---|
601 | send_oscam_config_camd35(f, params);
|
---|
602 | else if (!strcmp(part,"newcamd"))
|
---|
603 | send_oscam_config_newcamd(f, params);
|
---|
604 | else if (!strcmp(part,"radegast"))
|
---|
605 | send_oscam_config_radegast(f, params);
|
---|
606 | else if (!strcmp(part,"cccam"))
|
---|
607 | send_oscam_config_cccam(f, params);
|
---|
608 | else if (!strcmp(part,"gbox"))
|
---|
609 | send_oscam_config_gbox(f, params);
|
---|
610 | #ifdef CS_ANTICASC
|
---|
611 | else if (!strcmp(part,"anticasc"))
|
---|
612 | send_oscam_config_anticasc(f, params);
|
---|
613 | #endif
|
---|
614 | else if (!strcmp(part,"monitor"))
|
---|
615 | send_oscam_config_monitor(f, params);
|
---|
616 | else
|
---|
617 | send_oscam_config_global(f, params);
|
---|
618 | }
|
---|
619 | }
|
---|
620 |
|
---|
621 | void send_oscam_reader(struct templatevars *vars, FILE *f) {
|
---|
622 | int ridx;
|
---|
623 | char *ctyp;
|
---|
624 |
|
---|
625 | for(ridx=0;ridx<CS_MAXREADER;ridx++){
|
---|
626 | if(!reader[ridx].device[0]) break;
|
---|
627 | switch(reader[ridx].typ){
|
---|
628 | case R_MOUSE : ctyp="mouse"; break;
|
---|
629 | case R_INTERNAL: ctyp="intern"; break;
|
---|
630 | case R_SMART : ctyp="smartreader"; break;
|
---|
631 | case R_CAMD35 : ctyp="camd 3.5x";break;
|
---|
632 | case R_CAMD33 : ctyp="camd 3.3x";break;
|
---|
633 | case R_NEWCAMD : ctyp="newcamd"; break;
|
---|
634 | case R_RADEGAST: ctyp="radegast"; break;
|
---|
635 | case R_SERIAL : ctyp="serial"; break;
|
---|
636 | case R_GBOX : ctyp="gbox"; break;
|
---|
637 | #ifdef HAVE_PCSC
|
---|
638 | case R_PCSC : ctyp="pcsc"; break;
|
---|
639 | #endif
|
---|
640 | case R_CCCAM : ctyp="cccam"; break;
|
---|
641 | case R_CS378X : ctyp="cs378x"; break;
|
---|
642 | default : ctyp="unknown"; break;
|
---|
643 | }
|
---|
644 | tpl_addVar(vars, 0, "CTYP", ctyp);
|
---|
645 | tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
|
---|
646 | tpl_addVar(vars, 0, "READERNAMEENC", tpl_addTmp(vars, urlencode(reader[ridx].label)));
|
---|
647 | tpl_addVar(vars, 1, "READERLIST", tpl_getTpl(vars, "READERSBIT"));
|
---|
648 | }
|
---|
649 | fputs(tpl_getTpl(vars, "READERS"), f);
|
---|
650 | }
|
---|
651 |
|
---|
652 | void send_oscam_reader_config(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
653 | int ridx;
|
---|
654 | char *reader_ = getParam(params, "reader");
|
---|
655 | for(ridx = 0; ridx < CS_MAXREADER && strcmp(reader_, reader[ridx].label) != 0; ++ridx);
|
---|
656 | if(ridx == CS_MAXREADER){
|
---|
657 | tpl_addVar(vars, 0, "MESSAGE", "<BR><BR>Reader not found<BR><BR>");
|
---|
658 | } else if(strcmp(getParam(params, "action"), "execute") == 0){
|
---|
659 | tpl_addVar(vars, 0, "MESSAGE", "<BR><BR>Saving not yet implemented<BR><BR>");
|
---|
660 | refresh_oscam(REFR_READERS);
|
---|
661 | }
|
---|
662 | int i;
|
---|
663 | tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
|
---|
664 | tpl_addVar(vars, 0, "DEVICE", reader[ridx].device);
|
---|
665 | tpl_addVar(vars, 0, "NCD_KEY", (char *)reader[ridx].ncd_key);
|
---|
666 | tpl_addVar(vars, 0, "PINCODE", reader[ridx].pincode);
|
---|
667 | tpl_addVar(vars, 0, "EMMFILE", (char *)reader[ridx].emmfile);
|
---|
668 | tpl_addVar(vars, 0, "GBOXPWD", (char *)reader[ridx].gbox_pwd);
|
---|
669 | tpl_printf(vars, 0, "INACTIVITYTIMEOUT", "%d", reader[ridx].tcp_ito);
|
---|
670 | tpl_printf(vars, 0, "RECEIVETIMEOUT", "%d", reader[ridx].tcp_rto);
|
---|
671 | tpl_printf(vars, 0, "DISABLESERVERFILTER", "%d", reader[ridx].ncd_disable_server_filt);
|
---|
672 | tpl_printf(vars, 0, "FALLBACK", "%d", reader[ridx].fallback);
|
---|
673 | tpl_printf(vars, 0, "LOGPORT", "%d", reader[ridx].log_port);
|
---|
674 | tpl_printf(vars, 0, "BOXID", "%ld", reader[ridx].boxid);
|
---|
675 |
|
---|
676 | if(reader[ridx].r_port) tpl_printf(vars, 0, "R_PORT", ",%d", reader[ridx].r_port);
|
---|
677 | if(reader[ridx].l_port) {
|
---|
678 | if(reader[ridx].r_port) tpl_printf(vars, 0, "L_PORT", ",%d", reader[ridx].l_port);
|
---|
679 | else tpl_printf(vars, 0, "L_PORT", ",,%d", reader[ridx].l_port);
|
---|
680 | }
|
---|
681 |
|
---|
682 | //Group
|
---|
683 | /*restore the settings format of group from long over bitarray*/
|
---|
684 | char *dot = ""; //flag for comma
|
---|
685 | char grpbit[33];
|
---|
686 | long2bitchar(reader[ridx].grp, grpbit);
|
---|
687 | for(i = 0; i < 32; i++){
|
---|
688 | if (grpbit[i] == '1'){
|
---|
689 | tpl_printf(vars, 1, "GRP", "%s%d", dot, i+1);
|
---|
690 | dot = ",";
|
---|
691 | }
|
---|
692 | }
|
---|
693 |
|
---|
694 | //services
|
---|
695 | char sidok[33];
|
---|
696 | long2bitchar(reader[ridx].sidtabok, sidok);
|
---|
697 | char sidno[33];
|
---|
698 | long2bitchar(reader[ridx].sidtabno,sidno);
|
---|
699 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
700 | //build matrix
|
---|
701 | while(sidtab != NULL){
|
---|
702 | tpl_addVar(vars, 0, "SIDLABEL", sidtab->label);
|
---|
703 | if(sidok[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
704 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
705 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDOKBIT"));
|
---|
706 | if(sidno[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
707 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
708 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDNOBIT"));
|
---|
709 | sidtab=sidtab->next;
|
---|
710 | }
|
---|
711 |
|
---|
712 | // CAID
|
---|
713 | i = 0;
|
---|
714 | CAIDTAB *ctab = &reader[ridx].ctab;
|
---|
715 | while(ctab->caid[i]) {
|
---|
716 | if (i == 0) tpl_printf(vars, 1, "CAIDS", "%04X", ctab->caid[i]);
|
---|
717 | else tpl_printf(vars, 1, "CAIDS", ",%04X", ctab->caid[i]);;
|
---|
718 | if(ctab->mask[i]) tpl_printf(vars, 1, "CAIDS", "&%04X", ctab->mask[i]);
|
---|
719 | i++;
|
---|
720 | }
|
---|
721 | fputs(tpl_getTpl(vars, "READERCONFIG"), f);
|
---|
722 | }
|
---|
723 |
|
---|
724 | void send_oscam_user_config_edit(struct templatevars *vars, FILE *f, struct uriparams *params){
|
---|
725 | struct s_auth *account, *ptr;
|
---|
726 | char *user = getParam(params, "user");
|
---|
727 | int i, j;
|
---|
728 |
|
---|
729 | for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
730 |
|
---|
731 | // Create a new user if it doesn't yet
|
---|
732 | if (account == NULL){
|
---|
733 | if (!(account=malloc(sizeof(struct s_auth)))){
|
---|
734 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
735 | return;
|
---|
736 | }
|
---|
737 | if(cfg->account == NULL) cfg->account = account;
|
---|
738 | else {
|
---|
739 | for (ptr = cfg->account; ptr != NULL && ptr->next != NULL; ptr = ptr->next);
|
---|
740 | ptr->next = account;
|
---|
741 | }
|
---|
742 | memset(account, 0, sizeof(struct s_auth));
|
---|
743 | strncpy((char *)account->usr, user, sizeof(account->usr)-1);
|
---|
744 | account->au=(-1);
|
---|
745 | account->monlvl=cfg->mon_level;
|
---|
746 | account->tosleep=cfg->tosleep;
|
---|
747 | for (i=1; i<CS_MAXCAIDTAB; account->ctab.mask[i++]=0xffff);
|
---|
748 | for (i=1; i<CS_MAXTUNTAB; account->ttab.bt_srvid[i++]=0x0000);
|
---|
749 | #ifdef CS_ANTICASC
|
---|
750 | account->ac_users=cfg->ac_users;
|
---|
751 | account->ac_penalty=cfg->ac_penalty;
|
---|
752 | account->ac_idx = account->ac_idx + 1;
|
---|
753 | #endif
|
---|
754 | tpl_addVar(vars, 1, "MESSAGE", "<b>New user has been added with default settings</b><BR>");
|
---|
755 | if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS);
|
---|
756 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing configuration to disk failed!</b><BR>");
|
---|
757 | // need to reget account as writing to disk changes account!
|
---|
758 | for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
|
---|
759 | }
|
---|
760 |
|
---|
761 | if(strcmp(getParam(params, "action"), "execute") == 0){
|
---|
762 | char servicelabels[255]="";
|
---|
763 | //clear group
|
---|
764 | account->grp = 0;
|
---|
765 |
|
---|
766 | for(i=0;i<(*params).paramcount;i++){
|
---|
767 | if ((strcmp((*params).params[i], "action")) && (strcmp((*params).params[i], "user"))){
|
---|
768 | if (!strcmp((*params).params[i], "services"))
|
---|
769 | sprintf(servicelabels + strlen(servicelabels), "%s,", (*params).values[i]);
|
---|
770 | else
|
---|
771 | chk_account((*params).params[i], (*params).values[i], account);
|
---|
772 | }
|
---|
773 | }
|
---|
774 | chk_account("services", servicelabels, account);
|
---|
775 | tpl_addVar(vars, 1, "MESSAGE", "<B>Settings updated</B><BR><BR>");
|
---|
776 | if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS);
|
---|
777 | else tpl_addVar(vars, 1, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
|
---|
778 | }
|
---|
779 |
|
---|
780 | tpl_addVar(vars, 0, "USERNAME", account->usr);
|
---|
781 | tpl_addVar(vars, 0, "PASSWORD", account->pwd);
|
---|
782 |
|
---|
783 | //Expirationdate
|
---|
784 | struct tm * timeinfo = localtime (&account->expirationdate);
|
---|
785 | char buf [80];
|
---|
786 | strftime (buf,80,"%Y-%m-%d",timeinfo);
|
---|
787 | if(strcmp(buf,"1970-01-01")) tpl_addVar(vars, 0, "EXPDATE", buf);
|
---|
788 | //Group
|
---|
789 | /*restore the settings format of group from long over bitarray*/
|
---|
790 | char *dot = ""; //flag for comma
|
---|
791 | char grpbit[33];
|
---|
792 | long2bitchar(account->grp, grpbit);
|
---|
793 | for(i = 0; i < 32; i++){
|
---|
794 | if (grpbit[i] == '1'){
|
---|
795 | tpl_printf(vars, 1, "GROUPS", "%s%d", dot, i+1);
|
---|
796 | dot = ",";
|
---|
797 | }
|
---|
798 | }
|
---|
799 | //Hostname
|
---|
800 | tpl_addVar(vars, 0, "DYNDNS", (char *)account->dyndns);
|
---|
801 |
|
---|
802 | //Uniq
|
---|
803 | tpl_printf(vars, 0, "TMP", "UNIQSELECTED%d", account->uniq);
|
---|
804 | tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
|
---|
805 |
|
---|
806 | //Sleep
|
---|
807 | if(!account->tosleep) tpl_addVar(vars, 0, "SLEEP", "0");
|
---|
808 | else tpl_printf(vars, 0, "SLEEP", "%d", account->tosleep);
|
---|
809 | //Monlevel selector
|
---|
810 | tpl_printf(vars, 0, "TMP", "MONSELECTED%d", account->monlvl);
|
---|
811 | tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
|
---|
812 |
|
---|
813 | //AU Selector
|
---|
814 | if (!account->au) tpl_addVar(vars, 0, "AUSELECTED", "selected");
|
---|
815 | if (account->autoau == 1) tpl_addVar(vars, 0, "AUTOAUSELECTED", "selected");
|
---|
816 | int ridx;
|
---|
817 | for (ridx=0; ridx<CS_MAXREADER; ridx++){
|
---|
818 | if(!reader[ridx].device[0]) break;
|
---|
819 | tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
|
---|
820 | if (account->au == ridx) tpl_addVar(vars, 0, "SELECTED", "selected");
|
---|
821 | else tpl_addVar(vars, 0, "SELECTED", "");
|
---|
822 | tpl_addVar(vars, 1, "RDROPTION", tpl_getTpl(vars, "USEREDITRDRSELECTED"));
|
---|
823 | }
|
---|
824 |
|
---|
825 | /* SERVICES */
|
---|
826 | //services - first we have to move the long sidtabok/sidtabno to a binary array
|
---|
827 | char sidok[33];
|
---|
828 | long2bitchar(account->sidtabok,sidok);
|
---|
829 | char sidno[33];
|
---|
830 | long2bitchar(account->sidtabno,sidno);
|
---|
831 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
832 | //build matrix
|
---|
833 | i=0;
|
---|
834 | while(sidtab != NULL){
|
---|
835 | tpl_addVar(vars, 0, "SIDLABEL", sidtab->label);
|
---|
836 | if(sidok[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
837 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
838 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "USEREDITSIDOKBIT"));
|
---|
839 | if(sidno[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
|
---|
840 | else tpl_addVar(vars, 0, "CHECKED", "");
|
---|
841 | tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "USEREDITSIDNOBIT"));
|
---|
842 | sidtab=sidtab->next;
|
---|
843 | i++;
|
---|
844 | }
|
---|
845 | /* CAID */
|
---|
846 | dot="";
|
---|
847 | i = 0;
|
---|
848 | CAIDTAB *ctab = &account->ctab;
|
---|
849 | while(ctab->caid[i]) {
|
---|
850 | tpl_printf(vars, 1, "CAIDS", "%s%04X", dot, ctab->caid[i]);
|
---|
851 | if(ctab->mask[i]) tpl_printf(vars, 1, "CAIDS", "&%04X", ctab->mask[i]);
|
---|
852 | if(ctab->cmap[i]) tpl_printf(vars, 1, "CAIDS", ":%04X", ctab->cmap[i]);
|
---|
853 | dot=",";
|
---|
854 | ++i;
|
---|
855 | }
|
---|
856 |
|
---|
857 | /*IDENT*/
|
---|
858 | dot="";
|
---|
859 | FTAB *ftab = &account->ftab;
|
---|
860 | for (i = 0; i < ftab->nfilts; ++i){
|
---|
861 | tpl_printf(vars, 1, "IDENTS", "%s%04X", dot, ftab->filts[i].caid);
|
---|
862 | dot=":";
|
---|
863 | for (j = 0; j < ftab->filts[i].nprids; ++j) {
|
---|
864 | tpl_printf(vars, 1, "IDENTS", "%s%06lX", dot, ftab->filts[i].prids[j]);
|
---|
865 | dot=",";
|
---|
866 | }
|
---|
867 | dot=";";
|
---|
868 | }
|
---|
869 |
|
---|
870 | /*Betatunnel*/
|
---|
871 | dot="";
|
---|
872 | i = 0;
|
---|
873 | TUNTAB *ttab = &account->ttab;
|
---|
874 | while(ttab->bt_caidfrom[i]) {
|
---|
875 | tpl_printf(vars, 1, "BETATUNNELS", "%s%04X", dot, ttab->bt_caidfrom[i]);
|
---|
876 | if(ttab->bt_srvid[i]) tpl_printf(vars, 1, "BETATUNNELS", ".%04X", ttab->bt_srvid[i]);
|
---|
877 | if(ttab->bt_caidto[i]) tpl_printf(vars, 1, "BETATUNNELS", ":%04X", ttab->bt_caidto[i]);
|
---|
878 | dot=",";
|
---|
879 | ++i;
|
---|
880 | }
|
---|
881 |
|
---|
882 | #ifdef CS_ANTICASC
|
---|
883 | tpl_printf(vars, 0, "AC_USERS", "%d", account->ac_users);
|
---|
884 | tpl_printf(vars, 0, "AC_PENALTY", "%d", account->ac_penalty);
|
---|
885 | #endif
|
---|
886 | fputs(tpl_getTpl(vars, "USEREDIT"), f);
|
---|
887 | }
|
---|
888 |
|
---|
889 | void send_oscam_user_config(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
890 | struct s_auth *account, *account2;
|
---|
891 | char *user = getParam(params, "user");
|
---|
892 | int i, found = 0;
|
---|
893 |
|
---|
894 | if (strcmp(getParam(params, "action"), "delete") == 0){
|
---|
895 | account=cfg->account;
|
---|
896 | if(strcmp(account->usr, user) == 0){
|
---|
897 | cfg->account = account->next;
|
---|
898 | free(account);
|
---|
899 | found = 1;
|
---|
900 | } else if (account->next != NULL){
|
---|
901 | do{
|
---|
902 | if(strcmp(account->next->usr, user) == 0){
|
---|
903 | account2 = account->next;
|
---|
904 | account->next = account2->next;
|
---|
905 | free(account2);
|
---|
906 | found = 1;
|
---|
907 | break;
|
---|
908 | }
|
---|
909 | } while ((account = account->next) && (account->next != NULL));
|
---|
910 | }
|
---|
911 |
|
---|
912 | if (found > 0){
|
---|
913 | tpl_addVar(vars, 1, "MESSAGE", "<b>Account has been deleted!</b><BR>");
|
---|
914 | if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS);
|
---|
915 | else tpl_addVar(vars, 1, "MESSAGE", "<b>Writing configuration to disk failed!</b><BR>");
|
---|
916 | } else tpl_addVar(vars, 1, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
|
---|
917 | }
|
---|
918 | /* List accounts*/
|
---|
919 | char *status = "offline";
|
---|
920 | char *expired = "";
|
---|
921 | char *classname="offline";
|
---|
922 | char *lastchan=" ";
|
---|
923 | time_t now = time((time_t)0);
|
---|
924 | int isec=0;
|
---|
925 |
|
---|
926 | for (account=cfg->account; (account) ; account=account->next){
|
---|
927 | expired = ""; classname="offline";
|
---|
928 | if(account->expirationdate && account->expirationdate<time(NULL)){
|
---|
929 | expired = " (expired)";
|
---|
930 | classname = "expired";
|
---|
931 | }
|
---|
932 | status="offline";
|
---|
933 |
|
---|
934 | //search account in active clients
|
---|
935 | for (i=0; i<CS_MAXPID; i++)
|
---|
936 | if (!strcmp(client[i].usr, account->usr)){
|
---|
937 | //30 secs without ecm is offline
|
---|
938 | if ((now - client[i].lastecm) < 30){
|
---|
939 | status = "<b>online</b>";classname="online";
|
---|
940 | lastchan = monitor_get_srvname(client[i].last_srvid);
|
---|
941 | isec = now - client[i].last;
|
---|
942 | }
|
---|
943 | }
|
---|
944 | tpl_addVar(vars, 0, "CLASSNAME", classname);
|
---|
945 | tpl_addVar(vars, 0, "USER", account->usr);
|
---|
946 | tpl_addVar(vars, 0, "USERENC", tpl_addTmp(vars, urlencode(account->usr)));
|
---|
947 | tpl_addVar(vars, 0, "STATUS", status);
|
---|
948 | tpl_addVar(vars, 0, "EXPIRED", expired);
|
---|
949 | tpl_addVar(vars, 0, "LASTCHANNEL", lastchan);
|
---|
950 | tpl_printf(vars, 0, "IDLESECS", "%d", isec);
|
---|
951 | tpl_addVar(vars, 1, "USERCONFIGS", tpl_getTpl(vars, "USERCONFIGLISTBIT"));
|
---|
952 | isec = 0;
|
---|
953 | lastchan = " ";
|
---|
954 | }
|
---|
955 | fputs(tpl_getTpl(vars, "USERCONFIGLIST"), f);
|
---|
956 | }
|
---|
957 |
|
---|
958 | void send_oscam_entitlement(struct templatevars *vars, FILE *f, struct uriparams *params) {
|
---|
959 | /* build entitlements from reader init history */
|
---|
960 | int ridx;
|
---|
961 | char *p;
|
---|
962 | char *reader_ = getParam(params, "reader");
|
---|
963 | if(strlen(reader_) > 0){
|
---|
964 | #ifdef CS_RDR_INIT_HIST
|
---|
965 | for (ridx=0; ridx<CS_MAXREADER && strcmp(reader_, reader[ridx].label) != 0; ridx++);
|
---|
966 | if(ridx<CS_MAXREADER){
|
---|
967 | for (p=(char *)reader[ridx].init_history; *p; p+=strlen(p)+1){
|
---|
968 | tpl_printf(vars, 1, "LOGHISTORY", "%s<BR>\n", p);
|
---|
969 | }
|
---|
970 | }
|
---|
971 | #else
|
---|
972 | tpl_addVar(vars, 0, "LOGHISTORY", "The flag CS_RDR_INIT_HIST is not set in your binary<BR>\n");
|
---|
973 | #endif
|
---|
974 | tpl_addVar(vars, 0, "READERNAME", reader_);
|
---|
975 | }
|
---|
976 | fputs(tpl_getTpl(vars, "ENTITLEMENTS"), f);
|
---|
977 | }
|
---|
978 |
|
---|
979 | void send_oscam_status(struct templatevars *vars, FILE *f) {
|
---|
980 | int i;
|
---|
981 | char *usr;
|
---|
982 | int lsec, isec, cnr, con, cau;
|
---|
983 | time_t now = time((time_t)0);
|
---|
984 | struct tm *lt;
|
---|
985 | for (i=0; i<CS_MAXPID; i++) {
|
---|
986 | if (client[i].pid) {
|
---|
987 | if ((cfg->mon_hideclient_to <= 0) || (((now-client[i].lastecm)/60)<cfg->mon_hideclient_to) ||
|
---|
988 | (((now-client[i].lastemm)/60)<cfg->mon_hideclient_to) || (client[i].typ!='c')){
|
---|
989 | lsec=now-client[i].login;
|
---|
990 | isec=now-client[i].last;
|
---|
991 | usr=client[i].usr;
|
---|
992 |
|
---|
993 | if (((client[i].typ=='r') || (client[i].typ=='p')) && (con=cs_idx2ridx(i))>=0) usr=reader[con].label;
|
---|
994 |
|
---|
995 | if (client[i].dup) con=2;
|
---|
996 | else if ((client[i].tosleep) && (now-client[i].lastswitch>client[i].tosleep)) con=1;
|
---|
997 | else con=0;
|
---|
998 |
|
---|
999 | if (i-cdiff>0) cnr=i-cdiff;
|
---|
1000 | else cnr=(i>1) ? i-1 : 0;
|
---|
1001 |
|
---|
1002 | if( (cau=client[i].au+1) && (now-client[i].lastemm)/60 > cfg->mon_aulow) cau=-cau;
|
---|
1003 |
|
---|
1004 | lt=localtime(&client[i].login);
|
---|
1005 |
|
---|
1006 | tpl_printf(vars, 0, "CLIENTPID", "%d", client[i].pid);
|
---|
1007 | tpl_printf(vars, 0, "CLIENTTYPE", "%c", client[i].typ);
|
---|
1008 | tpl_printf(vars, 0, "CLIENTCNR", "%d", cnr);
|
---|
1009 | tpl_addVar(vars, 0, "CLIENTUSER", usr);
|
---|
1010 | tpl_printf(vars, 0, "CLIENTCAU", "%d", cau);
|
---|
1011 | tpl_printf(vars, 0, "CLIENTCRYPTED", "%d", client[i].crypted);
|
---|
1012 | tpl_printf(vars, 0, "CLIENTIP", "%s", cs_inet_ntoa(client[i].ip));
|
---|
1013 | tpl_printf(vars, 0, "CLIENTPORT", "%d", client[i].port);
|
---|
1014 | tpl_addVar(vars, 0, "CLIENTPROTO", monitor_get_proto(i));
|
---|
1015 | tpl_printf(vars, 0, "CLIENTLOGINDATE", "%02d.%02d.%02d", lt->tm_mday, lt->tm_mon+1, lt->tm_year%100);
|
---|
1016 | tpl_printf(vars, 0, "CLIENTLOGINTIME", "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
|
---|
1017 | tpl_printf(vars, 0, "CLIENTLOGINSECS", "%d", lsec);
|
---|
1018 | tpl_printf(vars, 0, "CLIENTCAID", "%04X", client[i].last_caid);
|
---|
1019 | tpl_printf(vars, 0, "CLIENTSRVID", "%04X", client[i].last_srvid);
|
---|
1020 | tpl_addVar(vars, 0, "CLIENTSRVNAME", monitor_get_srvname(client[i].last_srvid));
|
---|
1021 | tpl_printf(vars, 0, "CLIENTIDLESECS", "%d", isec);
|
---|
1022 | tpl_printf(vars, 0, "CLIENTCON", "%d", con);
|
---|
1023 | tpl_printf(vars, 0, "CWOK", "%d", client[i].cwfound);
|
---|
1024 | tpl_printf(vars, 0, "CWNOK", "%d", client[i].cwnot);
|
---|
1025 | tpl_addVar(vars, 1, "CLIENTSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
|
---|
1026 | }
|
---|
1027 | }
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 | #ifdef CS_LOGHISTORY
|
---|
1031 | for (i=(*loghistidx+3) % CS_MAXLOGHIST; i!=*loghistidx; i=(i+1) % CS_MAXLOGHIST){
|
---|
1032 | char *p_usr, *p_txt;
|
---|
1033 | p_usr=(char *)(loghist+(i*CS_LOGHISTSIZE));
|
---|
1034 | p_txt=p_usr+32;
|
---|
1035 | if (p_txt[0]) tpl_printf(vars, 1, "LOGHISTORY", "%s<BR>\n", p_txt+8);
|
---|
1036 | }
|
---|
1037 | #else
|
---|
1038 | tpl_addVar(vars, 0, "LOGHISTORY", "the flag CS_LOGHISTORY is not set in your binary<BR>\n");
|
---|
1039 | #endif
|
---|
1040 |
|
---|
1041 | fputs(tpl_getTpl(vars, "STATUS"), f);
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | void send_oscam_services(struct templatevars *vars, FILE *f) {
|
---|
1045 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
1046 | int i;
|
---|
1047 |
|
---|
1048 | while(sidtab != NULL){
|
---|
1049 | for (i=0; i<sidtab->num_caid; i++){
|
---|
1050 | if (i==0) tpl_printf(vars, 0, "CAIDS", "%04X", sidtab->caid[i]);
|
---|
1051 | else tpl_printf(vars, 1, "CAIDS", ",%04X", sidtab->caid[i]);
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | for (i=0; i<sidtab->num_provid; i++){
|
---|
1055 | if (i==0) tpl_printf(vars, 0, "PROVIDS", "%ld08X", sidtab->provid[i]);
|
---|
1056 | else tpl_printf(vars, 1, "PROVIDS", ",%ld08X", sidtab->provid[i]);
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 | for (i=0; i<sidtab->num_srvid; i++){
|
---|
1060 | if (i==0) tpl_printf(vars, 0, "SRVIDS", "%04X", sidtab->srvid[i]);
|
---|
1061 | else tpl_printf(vars, 1, "SRVIDS", ",%04X", sidtab->srvid[i]);
|
---|
1062 | }
|
---|
1063 | tpl_addVar(vars, 0, "LABEL", sidtab->label);
|
---|
1064 | tpl_printf(vars, 0, "CAIDNUM", "%d", sidtab->num_caid);
|
---|
1065 | tpl_printf(vars, 0, "PROVIDNUM", "%d",sidtab->num_provid);
|
---|
1066 | tpl_printf(vars, 0, "SRVIDNUM", "%d", sidtab->num_srvid);
|
---|
1067 | tpl_addVar(vars, 1, "SIDTABS", tpl_getTpl(vars, "SIDTABBIT"));
|
---|
1068 | sidtab=sidtab->next;
|
---|
1069 | }
|
---|
1070 | fputs(tpl_getTpl(vars, "SIDTAB"), f);
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | int process_request(FILE *f, struct in_addr in) {
|
---|
1074 | char buf[4096];
|
---|
1075 | char tmp[4096];
|
---|
1076 |
|
---|
1077 | int authok = 0;
|
---|
1078 | char expectednonce[64];
|
---|
1079 |
|
---|
1080 | char *method;
|
---|
1081 | char *path;
|
---|
1082 | char *protocol;
|
---|
1083 | char *pch;
|
---|
1084 | char *pch2;
|
---|
1085 | /* List of possible pages */
|
---|
1086 | char *pages[]={ "/config.html",
|
---|
1087 | "/readers.html",
|
---|
1088 | "/entitlements.html",
|
---|
1089 | "/status.html",
|
---|
1090 | "/userconfig.html",
|
---|
1091 | "/readerconfig.html",
|
---|
1092 | "/services.html",
|
---|
1093 | "/user_edit.html",
|
---|
1094 | "/site.css"};
|
---|
1095 | int pagescnt = sizeof(pages)/sizeof(char *); // Calculate the amount of items in array
|
---|
1096 |
|
---|
1097 | int pgidx = -1;
|
---|
1098 | int i;
|
---|
1099 | int parsemode = 1;
|
---|
1100 | struct uriparams params;
|
---|
1101 | params.paramcount = 0;
|
---|
1102 |
|
---|
1103 | /* First line always includes the GET/POST request */
|
---|
1104 | if (!fgets(buf, sizeof(buf), f)) return -1;
|
---|
1105 | method = strtok(buf, " ");
|
---|
1106 | path = strtok(NULL, " ");
|
---|
1107 | protocol = strtok(NULL, "\r");
|
---|
1108 | if(method == NULL || path == NULL || protocol == NULL) return -1;
|
---|
1109 |
|
---|
1110 | pch=path;
|
---|
1111 | /* advance pointer to beginning of query string */
|
---|
1112 | while(pch[0] != '?' && pch[0] != '\0') ++pch;
|
---|
1113 | if(pch[0] == '?'){
|
---|
1114 | pch[0] = '\0';
|
---|
1115 | ++pch;
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | /* Map page to our static page definitions */
|
---|
1119 | for (i=0; i<pagescnt; i++){
|
---|
1120 | if (!strcmp(path, pages[i])) pgidx = i;
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | /* Parse url parameters; parsemode = 1 means parsing next param, parsemode = -1 parsing next
|
---|
1124 | value; pch2 points to the beginning of the currently parsed string, pch is the current position */
|
---|
1125 | pch2=pch;
|
---|
1126 | while(pch[0] != '\0'){
|
---|
1127 | if((parsemode == 1 && pch[0] == '=') || (parsemode == -1 && pch[0] == '&')){
|
---|
1128 | pch[0] = '\0';
|
---|
1129 | urldecode(pch2);
|
---|
1130 | if(parsemode == 1) {
|
---|
1131 | if(params.paramcount >= MAXGETPARAMS) break;
|
---|
1132 | ++params.paramcount;
|
---|
1133 | params.params[params.paramcount-1] = pch2;
|
---|
1134 | } else {
|
---|
1135 | params.values[params.paramcount-1] = pch2;
|
---|
1136 | }
|
---|
1137 | parsemode = -parsemode;
|
---|
1138 | pch2 = pch + 1;
|
---|
1139 | }
|
---|
1140 | ++pch;
|
---|
1141 | }
|
---|
1142 | /* last value wasn't processed in the loop yet... */
|
---|
1143 | if(parsemode == -1 && params.paramcount <= MAXGETPARAMS){
|
---|
1144 | urldecode(pch2);
|
---|
1145 | params.values[params.paramcount-1] = pch2;
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | if(strlen(cfg->http_user) == 0 || strlen(cfg->http_pwd) == 0) authok = 1;
|
---|
1149 | else calculate_nonce(expectednonce, sizeof(expectednonce)/sizeof(char));
|
---|
1150 |
|
---|
1151 | /* Read remaining request (we're only interested in auth header) */
|
---|
1152 | while (fgets(tmp, sizeof(tmp), f)) {
|
---|
1153 | if (tmp[0] == '\r' && tmp[1] == '\n') break;
|
---|
1154 | else if(authok == 0 && strlen(tmp) > 50 && strncmp(tmp, "Authorization:", 14) == 0 && strstr(tmp, "Digest") != NULL) {
|
---|
1155 | authok = check_auth(tmp, method, path, expectednonce);
|
---|
1156 | }
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | //cs_debug("%s %d\n", path, pgidx);
|
---|
1160 | //for(i=0; i < params.paramcount; ++i) cs_debug("%s : %s\n", params.params[i], params.values[i]);
|
---|
1161 |
|
---|
1162 | fseek(f, 0, SEEK_CUR); // Force change of stream direction
|
---|
1163 |
|
---|
1164 | if(authok != 1){
|
---|
1165 | strcpy(tmp, "WWW-Authenticate: Digest algorithm=\"MD5\", realm=\"");
|
---|
1166 | strcat(tmp, AUTHREALM);
|
---|
1167 | strcat(tmp, "\", qop=\"auth\", opaque=\"\", nonce=\"");
|
---|
1168 | strcat(tmp, expectednonce);
|
---|
1169 | strcat(tmp, "\"");
|
---|
1170 | if(authok == 2) strcat(tmp, ", stale=true");
|
---|
1171 | send_headers(f, 401, "Unauthorized", tmp, "text/html");
|
---|
1172 | return 0;
|
---|
1173 | }
|
---|
1174 |
|
---|
1175 | /*build page*/
|
---|
1176 | send_headers(f, 200, "OK", NULL, "text/html");
|
---|
1177 | if(pgidx == 8) send_css(f);
|
---|
1178 | else if(pgidx != 0){
|
---|
1179 | time_t t;
|
---|
1180 | struct templatevars *vars = tpl_create();
|
---|
1181 | struct tm *lt;
|
---|
1182 | time(&t);
|
---|
1183 |
|
---|
1184 | lt=localtime(&t);
|
---|
1185 | tpl_addVar(vars, 0, "CS_VERSION", CS_VERSION);
|
---|
1186 | tpl_addVar(vars, 0, "CS_SVN_VERSION", CS_SVN_VERSION);
|
---|
1187 | if(cfg->http_refresh > 0 && (pgidx == 3 || pgidx == -1)){
|
---|
1188 | tpl_printf(vars, 0, "REFRESHTIME", "%d", cfg->http_refresh);
|
---|
1189 | tpl_addVar(vars, 0, "REFRESH", tpl_getTpl(vars, "REFRESH"));
|
---|
1190 | }
|
---|
1191 | tpl_printf(vars, 0, "CURDATE", "%02d.%02d.%02d", lt->tm_mday, lt->tm_mon+1, lt->tm_year%100);
|
---|
1192 | tpl_printf(vars, 0, "CURTIME", "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
|
---|
1193 | switch(pgidx){
|
---|
1194 | case 0: break;
|
---|
1195 | case 1: send_oscam_reader(vars, f); break;
|
---|
1196 | case 2: send_oscam_entitlement(vars, f, ¶ms); break;
|
---|
1197 | case 3: send_oscam_status(vars, f); break;
|
---|
1198 | case 4: send_oscam_user_config(vars, f, ¶ms); break;
|
---|
1199 | case 5: send_oscam_reader_config(vars, f, ¶ms); break;
|
---|
1200 | case 6: send_oscam_services(vars, f); break;
|
---|
1201 | case 7: send_oscam_user_config_edit(vars, f, ¶ms); break;
|
---|
1202 | default: send_oscam_status(vars, f); break;
|
---|
1203 | }
|
---|
1204 | tpl_clear(vars);
|
---|
1205 | } else {
|
---|
1206 | send_htmlhead(f,0);
|
---|
1207 | send_oscam_menu(f);
|
---|
1208 | send_oscam_config(f, ¶ms);
|
---|
1209 | send_footer(f);
|
---|
1210 | fprintf(f, "</BODY></HTML>\r\n");
|
---|
1211 | }
|
---|
1212 | return 0;
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | void http_srv() {
|
---|
1216 | int i,sock, reuse =1;
|
---|
1217 | struct sockaddr_in sin;
|
---|
1218 | struct sockaddr_in remote;
|
---|
1219 | socklen_t len = sizeof(remote);
|
---|
1220 | char *tmp;
|
---|
1221 |
|
---|
1222 | /* Prepare lookup array for conversion between ascii and hex */
|
---|
1223 | tmp = malloc(3*sizeof(char));
|
---|
1224 | for(i=0; i<256; i++) {
|
---|
1225 | snprintf(tmp, 3,"%02x", i);
|
---|
1226 | memcpy(hex2ascii[i], tmp, 2);
|
---|
1227 | }
|
---|
1228 | free(tmp);
|
---|
1229 | /* Create random string for nonce value generation */
|
---|
1230 | srand(time(NULL));
|
---|
1231 | create_rand_str(noncekey,32);
|
---|
1232 |
|
---|
1233 | /* Startup server */
|
---|
1234 | if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
|
---|
1235 | cs_log("HTTP Server: Creating socket failed! (errno=%d)", errno);
|
---|
1236 | return;
|
---|
1237 | }
|
---|
1238 | if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0){
|
---|
1239 | cs_log("HTTP Server: Setting SO_REUSEADDR via setsockopt failed! (errno=%d)", errno);
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 | memset(&sin, 0, sizeof sin);
|
---|
1243 | sin.sin_family = AF_INET;
|
---|
1244 | sin.sin_addr.s_addr = INADDR_ANY;
|
---|
1245 | sin.sin_port = htons(cfg->http_port);
|
---|
1246 | if((bind(sock, (struct sockaddr *) &sin, sizeof(sin))) < 0) {
|
---|
1247 | cs_log("HTTP Server couldn't bind on port %d (errno=%d). Not starting HTTP!", cfg->http_port, errno);
|
---|
1248 | close(sock);
|
---|
1249 | return;
|
---|
1250 | }
|
---|
1251 | if (listen(sock, SOMAXCONN) < 0){
|
---|
1252 | cs_log("HTTP Server: Call to listen() failed! (errno=%d)", errno);
|
---|
1253 | close(sock);
|
---|
1254 | return;
|
---|
1255 | }
|
---|
1256 | cs_log("HTTP Server listening on port %d", cfg->http_port);
|
---|
1257 | while (1)
|
---|
1258 | {
|
---|
1259 | int s;
|
---|
1260 | FILE *f;
|
---|
1261 | if((s = accept(sock, (struct sockaddr *) &remote, &len)) < 0){
|
---|
1262 | cs_log("HTTP Server: Error calling accept() (errno=%d).", errno);
|
---|
1263 | break;
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | f = fdopen(s, "r+");
|
---|
1267 | process_request(f, remote.sin_addr);
|
---|
1268 | fflush(f);
|
---|
1269 | fclose(f);
|
---|
1270 | shutdown(s, SHUT_WR);
|
---|
1271 | close(s);
|
---|
1272 | }
|
---|
1273 | close(sock);
|
---|
1274 | }
|
---|