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