1 | #include "globals.h"
|
---|
2 | #ifdef CS_WITH_BOXKEYS
|
---|
3 | # include "oscam-boxkeys.np"
|
---|
4 | #endif
|
---|
5 |
|
---|
6 | #define CONFVARWIDTH 20
|
---|
7 |
|
---|
8 | static char *cs_conf="oscam.conf";
|
---|
9 | static char *cs_user="oscam.user";
|
---|
10 | static char *cs_srvr="oscam.server";
|
---|
11 | static char *cs_srid="oscam.srvid";
|
---|
12 | static char *cs_l4ca="oscam.guess";
|
---|
13 | static char *cs_cert="oscam.cert";
|
---|
14 | static char *cs_sidt="oscam.services";
|
---|
15 | #ifdef CS_ANTICASC
|
---|
16 | static char *cs_ac="oscam.ac";
|
---|
17 | #endif
|
---|
18 |
|
---|
19 | static char token[4096];
|
---|
20 |
|
---|
21 | typedef enum cs_proto_type
|
---|
22 | {
|
---|
23 | TAG_GLOBAL, // must be first !
|
---|
24 | TAG_MONITOR, // monitor
|
---|
25 | TAG_CAMD33, // camd 3.3x
|
---|
26 | TAG_CAMD35, // camd 3.5x UDP
|
---|
27 | TAG_NEWCAMD, // newcamd
|
---|
28 | TAG_RADEGAST, // radegast
|
---|
29 | TAG_SERIAL, // serial (static)
|
---|
30 | TAG_CS357X, // camd 3.5x UDP
|
---|
31 | TAG_CS378X, // camd 3.5x TCP
|
---|
32 | TAG_GBOX, // gbox
|
---|
33 | TAG_CCCAM, // cccam
|
---|
34 | TAG_DVBAPI, // dvbapi
|
---|
35 | TAG_WEBIF, // webif
|
---|
36 | TAG_ANTICASC // anti-cascading
|
---|
37 | } cs_proto_type_t;
|
---|
38 |
|
---|
39 | static char *cctag[]={"global", "monitor", "camd33", "camd35", "newcamd", "radegast", "serial",
|
---|
40 | "cs357x", "cs378x", "gbox", "cccam", "dvbapi", "webif", "anticasc", NULL};
|
---|
41 |
|
---|
42 | #ifdef DEBUG_SIDTAB
|
---|
43 | static void show_sidtab(struct s_sidtab *sidtab)
|
---|
44 | {
|
---|
45 | for (; sidtab; sidtab=sidtab->next)
|
---|
46 | {
|
---|
47 | int i;
|
---|
48 | char buf[1024];
|
---|
49 | cs_log("label=%s", sidtab->label);
|
---|
50 | sprintf(buf, "caid(%d)=", sidtab->num_caid);
|
---|
51 | for (i=0; i<sidtab->num_caid; i++)
|
---|
52 | sprintf(buf+strlen(buf), "%04X ", sidtab->caid[i]);
|
---|
53 | cs_log("%s", buf);
|
---|
54 | sprintf(buf, "provider(%d)=", sidtab->num_provid);
|
---|
55 | for (i=0; i<sidtab->num_provid; i++)
|
---|
56 | sprintf(buf+strlen(buf), "%08X ", sidtab->provid[i]);
|
---|
57 | cs_log("%s", buf);
|
---|
58 | sprintf(buf, "services(%d)=", sidtab->num_srvid);
|
---|
59 | for (i=0; i<sidtab->num_srvid; i++)
|
---|
60 | sprintf(buf+strlen(buf), "%04X ", sidtab->srvid[i]);
|
---|
61 | cs_log("%s", buf);
|
---|
62 | }
|
---|
63 | }
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | void chk_iprange(char *value, struct s_ip **base)
|
---|
67 | {
|
---|
68 | int i = 0;
|
---|
69 | char *ptr1, *ptr2;
|
---|
70 | struct s_ip *lip, *cip;
|
---|
71 |
|
---|
72 | for (cip=lip=*base; cip; cip=cip->next)
|
---|
73 | lip = cip;
|
---|
74 | if (!(cip=malloc(sizeof(struct s_ip)))) {
|
---|
75 | fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
|
---|
76 | exit(1);
|
---|
77 | }
|
---|
78 | if (*base)
|
---|
79 | lip->next = cip;
|
---|
80 | else
|
---|
81 | *base = cip;
|
---|
82 |
|
---|
83 | memset(cip, 0, sizeof(struct s_ip));
|
---|
84 | for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) {
|
---|
85 | if (i == 0)
|
---|
86 | ++i;
|
---|
87 | else {
|
---|
88 | if (!(cip=malloc(sizeof(struct s_ip)))) {
|
---|
89 | fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
|
---|
90 | exit(1);
|
---|
91 | }
|
---|
92 | lip->next = cip;
|
---|
93 | memset(cip, 0, sizeof(struct s_ip));
|
---|
94 | }
|
---|
95 |
|
---|
96 | if( (ptr2=strchr(trim(ptr1), '-')) ) {
|
---|
97 | *ptr2++ ='\0';
|
---|
98 | cip->ip[0]=cs_inet_addr(trim(ptr1));
|
---|
99 | cip->ip[1]=cs_inet_addr(trim(ptr2));
|
---|
100 | } else {
|
---|
101 | cip->ip[0]=cip->ip[1]=cs_inet_addr(ptr1);
|
---|
102 | }
|
---|
103 | lip = cip;
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | void chk_caidtab(char *caidasc, CAIDTAB *ctab)
|
---|
108 | {
|
---|
109 | int i;
|
---|
110 | char *ptr1, *ptr2, *ptr3;
|
---|
111 |
|
---|
112 | for (i = 0, ptr1 = strtok(caidasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
|
---|
113 | ulong caid, mask, cmap;
|
---|
114 | if( (ptr3 = strchr(trim(ptr1), ':')) )
|
---|
115 | *ptr3++ = '\0';
|
---|
116 | else
|
---|
117 | ptr3 = "";
|
---|
118 |
|
---|
119 | if( (ptr2 = strchr(trim(ptr1), '&')) )
|
---|
120 | *ptr2++ = '\0';
|
---|
121 | else
|
---|
122 | ptr2 = "";
|
---|
123 |
|
---|
124 | if (((caid = a2i(ptr1, 2)) | (mask = a2i(ptr2,-2)) | (cmap = a2i(ptr3, 2))) < 0x10000) {
|
---|
125 | ctab->caid[i] = caid;
|
---|
126 | ctab->mask[i] = mask;
|
---|
127 | ctab->cmap[i++] = cmap;
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | void chk_tuntab(char *tunasc, TUNTAB *ttab)
|
---|
133 | {
|
---|
134 | int i;
|
---|
135 | char *ptr1, *ptr2, *ptr3;
|
---|
136 |
|
---|
137 | for (i = 0, ptr1 = strtok(tunasc, ","); (i < CS_MAXTUNTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
|
---|
138 | ulong bt_caidfrom, bt_caidto, bt_srvid;
|
---|
139 | if( (ptr3 = strchr(trim(ptr1), ':')) )
|
---|
140 | *ptr3++ = '\0';
|
---|
141 | else
|
---|
142 | ptr3 = "";
|
---|
143 |
|
---|
144 | if( (ptr2 = strchr(trim(ptr1), '.')) )
|
---|
145 | *ptr2++ = '\0';
|
---|
146 | else
|
---|
147 | ptr2 = "";
|
---|
148 |
|
---|
149 | if ((bt_caidfrom = a2i(ptr1, 2)) | (bt_srvid = a2i(ptr2,-2)) | (bt_caidto = a2i(ptr3, 2))) {
|
---|
150 | ttab->bt_caidfrom[i] = bt_caidfrom;
|
---|
151 | ttab->bt_caidto[i] = bt_caidto;
|
---|
152 | ttab->bt_srvid[i++] = bt_srvid;
|
---|
153 | }
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | void chk_services(char *labels, ulong *sidok, ulong *sidno)
|
---|
158 | {
|
---|
159 | int i;
|
---|
160 | char *ptr;
|
---|
161 | SIDTAB *sidtab;
|
---|
162 | *sidok = *sidno = 0;
|
---|
163 | for (ptr=strtok(labels, ","); ptr; ptr=strtok(NULL, ",")) {
|
---|
164 | for (trim(ptr), i = 0, sidtab = cfg->sidtab; sidtab; sidtab = sidtab->next, i++) {
|
---|
165 | if (!strcmp(sidtab->label, ptr)) *sidok|=(1<<i);
|
---|
166 | if ((ptr[0]=='!') && (!strcmp(sidtab->label, ptr+1))) *sidno|=(1<<i);
|
---|
167 | }
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName)
|
---|
172 | {
|
---|
173 | int i, j;
|
---|
174 | char *ptr1, *ptr2, *ptr3;
|
---|
175 | char *ptr[CS_MAXFILTERS] = {0};
|
---|
176 |
|
---|
177 | memset(ftab, 0, sizeof(FTAB));
|
---|
178 | for( i = 0, ptr1 = strtok(zFilterAsc, ";"); (i < CS_MAXFILTERS) && (ptr1); ptr1 = strtok(NULL, ";"), i++ ) {
|
---|
179 | ptr[i] = ptr1;
|
---|
180 | if( (ptr2 = strchr(trim(ptr1), ':')) ) {
|
---|
181 | *ptr2++ ='\0';
|
---|
182 | ftab->filts[i].caid = (ushort)a2i(ptr1, 4);
|
---|
183 | ptr[i] = ptr2;
|
---|
184 | }
|
---|
185 | else if (zFiltName && zFiltName[0] == 'c') {
|
---|
186 | cs_log("PANIC: CAID field not found in CHID parameter!");
|
---|
187 | cs_exit(1);
|
---|
188 | }
|
---|
189 | ftab->nfilts++;
|
---|
190 | }
|
---|
191 |
|
---|
192 | if( ftab->nfilts ) cs_debug("%s '%s' %s filter(s):", zType, zName, zFiltName);
|
---|
193 | for( i = 0; i < ftab->nfilts; i++ ) {
|
---|
194 | cs_debug("CAID #%d: %04X", i, ftab->filts[i].caid);
|
---|
195 | for( j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++ ) {
|
---|
196 | ftab->filts[i].prids[j] = a2i(ptr3,6);
|
---|
197 | ftab->filts[i].nprids++;
|
---|
198 | cs_debug("%s #%d: %06X", zFiltName, j, ftab->filts[i].prids[j]);
|
---|
199 | }
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | void chk_cltab(char *classasc, CLASSTAB *clstab)
|
---|
204 | {
|
---|
205 | int i;
|
---|
206 | char *ptr1;
|
---|
207 | for( i = 0, ptr1 = strtok(classasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",") ) {
|
---|
208 | ptr1 = trim(ptr1);
|
---|
209 | if( ptr1[0] == '!' )
|
---|
210 | clstab->bclass[clstab->bn++] = (uchar)a2i(ptr1+1, 2);
|
---|
211 | else
|
---|
212 | clstab->aclass[clstab->an++] = (uchar)a2i(ptr1, 2);
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | void chk_port_tab(char *portasc, PTAB *ptab)
|
---|
217 | {
|
---|
218 | int i, j, nfilts, ifilt, iport;
|
---|
219 | char *ptr1, *ptr2, *ptr3;
|
---|
220 | char *ptr[CS_MAXPORTS] = {0};
|
---|
221 | int port[CS_MAXPORTS] = {0};
|
---|
222 | int previous_nports = ptab->nports;
|
---|
223 |
|
---|
224 | for (nfilts = i = previous_nports, ptr1 = strtok(portasc, ";"); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ";"), i++) {
|
---|
225 | ptr[i] = ptr1;
|
---|
226 | if( (ptr2=strchr(trim(ptr1), '@')) ) {
|
---|
227 | *ptr2++ ='\0';
|
---|
228 | ptab->ports[i].s_port = atoi(ptr1);
|
---|
229 | ptr[i] = ptr2;
|
---|
230 | port[i] = ptab->ports[i].s_port;
|
---|
231 | ptab->nports++;
|
---|
232 | }
|
---|
233 | nfilts++;
|
---|
234 | }
|
---|
235 |
|
---|
236 | if( nfilts == 1 && strlen(portasc) < 6 && ptab->ports[0].s_port == 0 ) {
|
---|
237 | ptab->ports[0].s_port = atoi(portasc);
|
---|
238 | ptab->nports = 1;
|
---|
239 | }
|
---|
240 |
|
---|
241 | iport = ifilt = previous_nports;
|
---|
242 | for (i=previous_nports; i<nfilts; i++) {
|
---|
243 | if( port[i] != 0 )
|
---|
244 | iport = i;
|
---|
245 | for (j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++) {
|
---|
246 | if( (ptr2=strchr(trim(ptr3), ':')) ) {
|
---|
247 | *ptr2++='\0';
|
---|
248 | ptab->ports[iport].ftab.nfilts++;
|
---|
249 | ifilt = ptab->ports[iport].ftab.nfilts-1;
|
---|
250 | ptab->ports[iport].ftab.filts[ifilt].caid = (ushort)a2i(ptr3, 4);
|
---|
251 | ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6);
|
---|
252 | } else {
|
---|
253 | ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6);
|
---|
254 | }
|
---|
255 | ptab->ports[iport].ftab.filts[ifilt].nprids++;
|
---|
256 | }
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 | #ifdef NOTUSED
|
---|
261 | static void chk_srvip(char *value, in_addr_t *ip)
|
---|
262 | {
|
---|
263 | int i;
|
---|
264 | char *ptr;
|
---|
265 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
266 | if (i<8) ip[i++] = inet_addr(ptr);
|
---|
267 | }
|
---|
268 | #endif
|
---|
269 |
|
---|
270 | void chk_t_global(char *token, char *value)
|
---|
271 | {
|
---|
272 | if (!strcmp(token, "disablelog")) {
|
---|
273 | if (strlen(value) == 0) {
|
---|
274 | cfg->disablelog = 0;
|
---|
275 | return;
|
---|
276 | } else {
|
---|
277 | cfg->disablelog = atoi(value);
|
---|
278 | return;
|
---|
279 | }
|
---|
280 | }
|
---|
281 |
|
---|
282 | if (!strcmp(token, "serverip")) {
|
---|
283 | if (strlen(value) == 0) {
|
---|
284 | cfg->srvip = 0;
|
---|
285 | return;
|
---|
286 | } else {
|
---|
287 | cfg->srvip=inet_addr(value);
|
---|
288 | return;
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 | if (!strcmp(token, "logfile")) {
|
---|
293 | if (cfg->logfile != NULL) {
|
---|
294 | free(cfg->logfile);
|
---|
295 | cfg->logfile = NULL;
|
---|
296 | }
|
---|
297 | if (strlen(value) > 0)
|
---|
298 | asprintf(&(cfg->logfile), "%s", value);
|
---|
299 | return;
|
---|
300 | }
|
---|
301 |
|
---|
302 | if (!strcmp(token, "pidfile")) {
|
---|
303 | if (cfg->pidfile != NULL) {
|
---|
304 | free(cfg->pidfile);
|
---|
305 | cfg->pidfile = NULL;
|
---|
306 | }
|
---|
307 | if (strlen(value) > 0)
|
---|
308 | asprintf(&(cfg->pidfile), "%s", value);
|
---|
309 | return;
|
---|
310 | }
|
---|
311 |
|
---|
312 | if (!strcmp(token, "usrfile")) {
|
---|
313 | if (cfg->usrfile != NULL) {
|
---|
314 | free(cfg->usrfile);
|
---|
315 | cfg->usrfile = NULL;
|
---|
316 | }
|
---|
317 | if (strlen(value) > 0)
|
---|
318 | asprintf(&(cfg->usrfile), "%s", value);
|
---|
319 | return;
|
---|
320 | }
|
---|
321 |
|
---|
322 | if (!strcmp(token, "cwlogdir")) {
|
---|
323 | if (cfg->cwlogdir != NULL) {
|
---|
324 | free(cfg->cwlogdir);
|
---|
325 | cfg->cwlogdir = NULL;
|
---|
326 | }
|
---|
327 | if (strlen(value) > 0)
|
---|
328 | asprintf(&(cfg->cwlogdir), "%s", value);
|
---|
329 | return;
|
---|
330 | }
|
---|
331 |
|
---|
332 | if (!strcmp(token, "usrfileflag")) {
|
---|
333 | if (strlen(value) == 0) {
|
---|
334 | cfg->usrfileflag = 0;
|
---|
335 | return;
|
---|
336 | } else {
|
---|
337 | cfg->usrfileflag = atoi(value);
|
---|
338 | return;
|
---|
339 | }
|
---|
340 | }
|
---|
341 |
|
---|
342 | if (!strcmp(token, "clienttimeout")) {
|
---|
343 | if (strlen(value) == 0) {
|
---|
344 | cfg->ctimeout = CS_CLIENT_TIMEOUT;
|
---|
345 | return;
|
---|
346 | } else {
|
---|
347 | cfg->ctimeout = atoi(value);
|
---|
348 | if (cfg->ctimeout < 100)
|
---|
349 | cfg->ctimeout *= 1000;
|
---|
350 | return;
|
---|
351 | }
|
---|
352 | }
|
---|
353 |
|
---|
354 | if (!strcmp(token, "fallbacktimeout")) {
|
---|
355 | if (strlen(value) == 0) {
|
---|
356 | cfg->ftimeout = CS_CLIENT_TIMEOUT;
|
---|
357 | return;
|
---|
358 | } else {
|
---|
359 | cfg->ftimeout = atoi(value);
|
---|
360 | if (cfg->ftimeout < 100)
|
---|
361 | cfg->ftimeout *= 1000;
|
---|
362 | return;
|
---|
363 | }
|
---|
364 | }
|
---|
365 |
|
---|
366 | if (!strcmp(token, "clientmaxidle")) {
|
---|
367 | if (strlen(value) == 0) {
|
---|
368 | cfg->cmaxidle = CS_CLIENT_MAXIDLE;
|
---|
369 | return;
|
---|
370 | } else {
|
---|
371 | cfg->cmaxidle = atoi(value);
|
---|
372 | return;
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | if (!strcmp(token, "cachedelay")) {
|
---|
377 | if (strlen(value) == 0) {
|
---|
378 | cfg->delay = CS_DELAY;
|
---|
379 | return;
|
---|
380 | } else {
|
---|
381 | cfg->delay = atoi(value);
|
---|
382 | return;
|
---|
383 | }
|
---|
384 | }
|
---|
385 |
|
---|
386 | if (!strcmp(token, "bindwait")) {
|
---|
387 | if (strlen(value) == 0) {
|
---|
388 | cfg->bindwait = CS_BIND_TIMEOUT;
|
---|
389 | return;
|
---|
390 | } else {
|
---|
391 | cfg->bindwait = atoi(value);
|
---|
392 | return;
|
---|
393 | }
|
---|
394 | }
|
---|
395 |
|
---|
396 | if (!strcmp(token, "netprio")) {
|
---|
397 | if (strlen(value) == 0) {
|
---|
398 | cfg->netprio = 0;
|
---|
399 | return;
|
---|
400 | } else {
|
---|
401 | cfg->netprio = atoi(value);
|
---|
402 | return;
|
---|
403 | }
|
---|
404 | }
|
---|
405 |
|
---|
406 | if (!strcmp(token, "resolvedelay")) {
|
---|
407 | if (strlen(value) == 0) {
|
---|
408 | cfg->resolvedelay = CS_RESOLVE_DELAY;
|
---|
409 | return;
|
---|
410 | } else {
|
---|
411 | cfg->resolvedelay = atoi(value);
|
---|
412 | return;
|
---|
413 | }
|
---|
414 | }
|
---|
415 |
|
---|
416 | if (!strcmp(token, "sleep")) {
|
---|
417 | if (strlen(value) == 0) {
|
---|
418 | cfg->tosleep = 0;
|
---|
419 | return;
|
---|
420 | } else {
|
---|
421 | cfg->tosleep = atoi(value);
|
---|
422 | return;
|
---|
423 | }
|
---|
424 | }
|
---|
425 |
|
---|
426 | if (!strcmp(token, "unlockparental")) {
|
---|
427 | if (strlen(value) == 0) {
|
---|
428 | cfg->ulparent = 0;
|
---|
429 | return;
|
---|
430 | } else {
|
---|
431 | cfg->ulparent = atoi(value);
|
---|
432 | return;
|
---|
433 | }
|
---|
434 | }
|
---|
435 |
|
---|
436 | if (!strcmp(token, "nice")) {
|
---|
437 | if (strlen(value) == 0) {
|
---|
438 | cfg->nice = 99;
|
---|
439 | return;
|
---|
440 | } else {
|
---|
441 | cfg->nice = atoi(value);
|
---|
442 | if ((cfg->nice<-20) || (cfg->nice>20)) cfg->nice = 99;
|
---|
443 | if (cfg->nice != 99) cs_setpriority(cfg->nice); // ignore errors
|
---|
444 | return;
|
---|
445 | }
|
---|
446 | }
|
---|
447 |
|
---|
448 | if (!strcmp(token, "serialreadertimeout")) {
|
---|
449 | if (cfg->srtimeout < 100)
|
---|
450 | cfg->srtimeout = atoi(value) * 1000;
|
---|
451 | else
|
---|
452 | cfg->srtimeout = atoi(value);
|
---|
453 | if (cfg->srtimeout <= 0)
|
---|
454 | cfg->srtimeout = 1500;
|
---|
455 | return;
|
---|
456 | }
|
---|
457 |
|
---|
458 | if (!strcmp(token, "maxlogsize")) {
|
---|
459 | if (strlen(value) == 0) {
|
---|
460 | cfg->max_log_size = 10;
|
---|
461 | return;
|
---|
462 | } else {
|
---|
463 | cfg->max_log_size = atoi(value);
|
---|
464 | if( cfg->max_log_size <= 10 )
|
---|
465 | cfg->max_log_size = 10;
|
---|
466 | return;
|
---|
467 | }
|
---|
468 | }
|
---|
469 |
|
---|
470 | if( !strcmp(token, "waitforcards")) {
|
---|
471 | if (strlen(value) == 0) {
|
---|
472 | cfg->waitforcards = 0;
|
---|
473 | return;
|
---|
474 | } else {
|
---|
475 | cfg->waitforcards = atoi(value);
|
---|
476 | return;
|
---|
477 | }
|
---|
478 | }
|
---|
479 |
|
---|
480 | if( !strcmp(token, "preferlocalcards")) {
|
---|
481 | if (strlen(value) == 0) {
|
---|
482 | cfg->preferlocalcards = 0;
|
---|
483 | return;
|
---|
484 | } else {
|
---|
485 | cfg->preferlocalcards = atoi(value);
|
---|
486 | return;
|
---|
487 | }
|
---|
488 | }
|
---|
489 |
|
---|
490 | if (token[0] != '#')
|
---|
491 | cs_log("Warning: keyword '%s' in global section not recognized", token);
|
---|
492 | }
|
---|
493 |
|
---|
494 | #ifdef CS_ANTICASC
|
---|
495 | void chk_t_ac(char *token, char *value)
|
---|
496 | {
|
---|
497 | if (!strcmp(token, "enabled")) {
|
---|
498 | cfg->ac_enabled = atoi(value);
|
---|
499 | if( cfg->ac_enabled <= 0 )
|
---|
500 | cfg->ac_enabled = 0;
|
---|
501 | else
|
---|
502 | cfg->ac_enabled = 1;
|
---|
503 | return;
|
---|
504 | }
|
---|
505 |
|
---|
506 | if (!strcmp(token, "numusers")) {
|
---|
507 | cfg->ac_users = atoi(value);
|
---|
508 | if( cfg->ac_users < 0 )
|
---|
509 | cfg->ac_users = 0;
|
---|
510 | return;
|
---|
511 | }
|
---|
512 |
|
---|
513 | if (!strcmp(token, "sampletime")) {
|
---|
514 | cfg->ac_stime = atoi(value);
|
---|
515 | if( cfg->ac_stime < 0 )
|
---|
516 | cfg->ac_stime = 2;
|
---|
517 | return;
|
---|
518 | }
|
---|
519 |
|
---|
520 | if (!strcmp(token, "samples")) {
|
---|
521 | cfg->ac_samples = atoi(value);
|
---|
522 | if( cfg->ac_samples < 2 || cfg->ac_samples > 10)
|
---|
523 | cfg->ac_samples = 10;
|
---|
524 | return;
|
---|
525 | }
|
---|
526 |
|
---|
527 | if (!strcmp(token, "penalty")) {
|
---|
528 | cfg->ac_penalty = atoi(value);
|
---|
529 | if( cfg->ac_penalty < 0 )
|
---|
530 | cfg->ac_penalty = 0;
|
---|
531 | return;
|
---|
532 | }
|
---|
533 |
|
---|
534 | if (!strcmp(token, "aclogfile")) {
|
---|
535 | cs_strncpy(cfg->ac_logfile, value, sizeof(cfg->ac_logfile));
|
---|
536 | return;
|
---|
537 | }
|
---|
538 |
|
---|
539 | if( !strcmp(token, "fakedelay") ) {
|
---|
540 | cfg->ac_fakedelay = atoi(value);
|
---|
541 | if( cfg->ac_fakedelay < 100 || cfg->ac_fakedelay > 1000 )
|
---|
542 | cfg->ac_fakedelay = 1000;
|
---|
543 | return;
|
---|
544 | }
|
---|
545 |
|
---|
546 | if( !strcmp(token, "denysamples") ) {
|
---|
547 | cfg->ac_denysamples = atoi(value);
|
---|
548 | if( cfg->ac_denysamples < 2 || cfg->ac_denysamples > cfg->ac_samples - 1 )
|
---|
549 | cfg->ac_denysamples=cfg->ac_samples-1;
|
---|
550 | return;
|
---|
551 | }
|
---|
552 |
|
---|
553 | if (token[0] != '#')
|
---|
554 | cs_log("Warning: keyword '%s' in anticascading section not recognized",token);
|
---|
555 | }
|
---|
556 | #endif
|
---|
557 |
|
---|
558 | void chk_t_monitor(char *token, char *value)
|
---|
559 | {
|
---|
560 | if (!strcmp(token, "port")) {
|
---|
561 | if(strlen(value) == 0) {
|
---|
562 | cfg->mon_port = 0;
|
---|
563 | return;
|
---|
564 | } else {
|
---|
565 | cfg->mon_port=atoi(value);
|
---|
566 | return;
|
---|
567 | }
|
---|
568 | }
|
---|
569 |
|
---|
570 | if (!strcmp(token, "serverip")) {
|
---|
571 | if(strlen(value) == 0) {
|
---|
572 | cfg->mon_srvip = 0;
|
---|
573 | return;
|
---|
574 | } else {
|
---|
575 | cfg->mon_srvip=inet_addr(value);
|
---|
576 | return;
|
---|
577 | }
|
---|
578 | }
|
---|
579 |
|
---|
580 | if (!strcmp(token, "nocrypt")) {
|
---|
581 | if(strlen(value) == 0) {
|
---|
582 | clear_sip(&cfg->mon_allowed);
|
---|
583 | return;
|
---|
584 | } else {
|
---|
585 | chk_iprange(value, &cfg->mon_allowed);
|
---|
586 | return;
|
---|
587 | }
|
---|
588 | }
|
---|
589 |
|
---|
590 | if (!strcmp(token, "aulow")) {
|
---|
591 | if(strlen(value) == 0) {
|
---|
592 | cfg->mon_aulow = 0;
|
---|
593 | return;
|
---|
594 | } else {
|
---|
595 | cfg->mon_aulow = atoi(value);
|
---|
596 | return;
|
---|
597 | }
|
---|
598 | }
|
---|
599 |
|
---|
600 | if (!strcmp(token, "monlevel")) {
|
---|
601 | if(strlen(value) == 0) {
|
---|
602 | cfg->mon_level = 0;
|
---|
603 | return;
|
---|
604 | } else {
|
---|
605 | cfg->mon_level = atoi(value);
|
---|
606 | return;
|
---|
607 | }
|
---|
608 | }
|
---|
609 |
|
---|
610 | if (!strcmp(token, "hideclient_to")) {
|
---|
611 | if(strlen(value) == 0) {
|
---|
612 | cfg->mon_hideclient_to = 0;
|
---|
613 | return;
|
---|
614 | } else {
|
---|
615 | cfg->mon_hideclient_to = atoi(value);
|
---|
616 | return;
|
---|
617 | }
|
---|
618 | }
|
---|
619 |
|
---|
620 | if (token[0] != '#')
|
---|
621 | cs_log("Warning: keyword '%s' in monitor section not recognized",token);
|
---|
622 | }
|
---|
623 |
|
---|
624 | #ifdef WEBIF
|
---|
625 | void chk_t_webif(char *token, char *value)
|
---|
626 | {
|
---|
627 | if (!strcmp(token, "httpport")) {
|
---|
628 | if(strlen(value) == 0) {
|
---|
629 | cfg->http_port = 0;
|
---|
630 | return;
|
---|
631 | } else {
|
---|
632 | cfg->http_port = atoi(value);
|
---|
633 | return;
|
---|
634 | }
|
---|
635 | }
|
---|
636 |
|
---|
637 | if (!strcmp(token, "httpuser")) {
|
---|
638 | cs_strncpy(cfg->http_user, value, sizeof(cfg->http_user));
|
---|
639 | return;
|
---|
640 | }
|
---|
641 |
|
---|
642 | if (!strcmp(token, "httppwd")) {
|
---|
643 | cs_strncpy(cfg->http_pwd, value, sizeof(cfg->http_pwd));
|
---|
644 | return;
|
---|
645 | }
|
---|
646 |
|
---|
647 | if (!strcmp(token, "httpcss")) {
|
---|
648 | cs_strncpy(cfg->http_css, value, sizeof(cfg->http_css));
|
---|
649 | return;
|
---|
650 | }
|
---|
651 |
|
---|
652 | if (!strcmp(token, "httpscript")) {
|
---|
653 | cs_strncpy(cfg->http_script, value, sizeof(cfg->http_script));
|
---|
654 | return;
|
---|
655 | }
|
---|
656 |
|
---|
657 | if (!strcmp(token, "httptpl")) {
|
---|
658 | cs_strncpy(cfg->http_tpl, value, sizeof(cfg->http_tpl));
|
---|
659 | if(strlen(cfg->http_tpl) < (sizeof(cfg->http_tpl)-2) && cfg->http_tpl[strlen(cfg->http_tpl)-1] != '/') {
|
---|
660 | cfg->http_tpl[strlen(cfg->http_tpl)] = '/';
|
---|
661 | cfg->http_tpl[strlen(cfg->http_tpl)] = '\0';
|
---|
662 | }
|
---|
663 | return;
|
---|
664 | }
|
---|
665 |
|
---|
666 | if (!strcmp(token, "httprefresh")) {
|
---|
667 | if(strlen(value) == 0) {
|
---|
668 | cfg->http_refresh = 0;
|
---|
669 | return;
|
---|
670 | } else {
|
---|
671 | cfg->http_refresh = atoi(value);
|
---|
672 | return;
|
---|
673 | }
|
---|
674 | }
|
---|
675 |
|
---|
676 | if (!strcmp(token, "httphideidleclients")) {
|
---|
677 | if(strlen(value) == 0) {
|
---|
678 | cfg->http_hide_idle_clients = 0;
|
---|
679 | return;
|
---|
680 | } else {
|
---|
681 | cfg->http_hide_idle_clients=atoi(value);
|
---|
682 | return;
|
---|
683 | }
|
---|
684 | }
|
---|
685 |
|
---|
686 | if (!strcmp(token, "httpallowed")) {
|
---|
687 | if(strlen(value) == 0) {
|
---|
688 | clear_sip(&cfg->http_allowed);
|
---|
689 | return;
|
---|
690 | } else {
|
---|
691 | chk_iprange(value, &cfg->http_allowed);
|
---|
692 | return;
|
---|
693 | }
|
---|
694 | }
|
---|
695 |
|
---|
696 | if (token[0] != '#')
|
---|
697 | cs_log("Warning: keyword '%s' in webif section not recognized",token);
|
---|
698 | }
|
---|
699 | #endif
|
---|
700 |
|
---|
701 |
|
---|
702 | void chk_t_camd33(char *token, char *value)
|
---|
703 | {
|
---|
704 | if (!strcmp(token, "port")) {
|
---|
705 | if(strlen(value) == 0) {
|
---|
706 | cfg->c33_port = 0;
|
---|
707 | return;
|
---|
708 | } else {
|
---|
709 | cfg->c33_port = atoi(value);
|
---|
710 | return;
|
---|
711 | }
|
---|
712 | }
|
---|
713 |
|
---|
714 | if (!strcmp(token, "serverip")) {
|
---|
715 | if(strlen(value) == 0) {
|
---|
716 | cfg->c33_srvip = 0;
|
---|
717 | return;
|
---|
718 | } else {
|
---|
719 | cfg->c33_srvip = inet_addr(value);
|
---|
720 | return;
|
---|
721 | }
|
---|
722 | }
|
---|
723 |
|
---|
724 | if (!strcmp(token, "nocrypt")) {
|
---|
725 | if(strlen(value) == 0) {
|
---|
726 | return;
|
---|
727 | } else {
|
---|
728 | chk_iprange(value, &cfg->c33_plain);
|
---|
729 | return;
|
---|
730 | }
|
---|
731 | }
|
---|
732 |
|
---|
733 | if (!strcmp(token, "passive")) {
|
---|
734 | cfg->c33_passive = (value[0]!='0');
|
---|
735 | return;
|
---|
736 | }
|
---|
737 |
|
---|
738 | if (!strcmp(token, "key")) {
|
---|
739 | if (key_atob(value, cfg->c33_key)) {
|
---|
740 | fprintf(stderr, "Configuration camd3.3x: Error in Key\n");
|
---|
741 | exit(1);
|
---|
742 | }
|
---|
743 | cfg->c33_crypted=1;
|
---|
744 | return;
|
---|
745 | }
|
---|
746 |
|
---|
747 | if (token[0] != '#')
|
---|
748 | cs_log("Warning: keyword '%s' in camd33 section not recognized",token);
|
---|
749 | }
|
---|
750 |
|
---|
751 | void chk_t_camd35(char *token, char *value)
|
---|
752 | {
|
---|
753 | if (!strcmp(token, "port")) {
|
---|
754 | if(strlen(value) == 0) {
|
---|
755 | cfg->c35_port = 0;
|
---|
756 | return;
|
---|
757 | } else {
|
---|
758 | cfg->c35_port = atoi(value);
|
---|
759 | return;
|
---|
760 | }
|
---|
761 | }
|
---|
762 |
|
---|
763 | if (!strcmp(token, "serverip")) {
|
---|
764 | if(strlen(value) == 0) {
|
---|
765 | cfg->c35_tcp_srvip = 0;
|
---|
766 | return;
|
---|
767 | } else {
|
---|
768 | cfg->c35_tcp_srvip = inet_addr(value);
|
---|
769 | return;
|
---|
770 | }
|
---|
771 | }
|
---|
772 |
|
---|
773 | if (!strcmp(token, "suppresscmd08")) {
|
---|
774 | if(strlen(value) == 0) {
|
---|
775 | cfg->c35_suppresscmd08 = 0;
|
---|
776 | return;
|
---|
777 | } else {
|
---|
778 | cfg->c35_suppresscmd08=atoi(value);
|
---|
779 | return;
|
---|
780 | }
|
---|
781 | }
|
---|
782 |
|
---|
783 | if (token[0] != '#')
|
---|
784 | cs_log("Warning: keyword '%s' in camd35 section not recognized", token);
|
---|
785 | }
|
---|
786 |
|
---|
787 | void chk_t_camd35_tcp(char *token, char *value)
|
---|
788 | {
|
---|
789 | if (!strcmp(token, "port")) {
|
---|
790 | if(strlen(value) == 0) {
|
---|
791 | clear_ptab(&cfg->c35_tcp_ptab);
|
---|
792 | return;
|
---|
793 | } else {
|
---|
794 | chk_port_tab(value, &cfg->c35_tcp_ptab);
|
---|
795 | return;
|
---|
796 | }
|
---|
797 | }
|
---|
798 |
|
---|
799 | if (!strcmp(token, "serverip")) {
|
---|
800 | if(strlen(value) == 0) {
|
---|
801 | cfg->c35_tcp_srvip = 0;
|
---|
802 | return;
|
---|
803 | } else {
|
---|
804 | cfg->c35_tcp_srvip = inet_addr(value);
|
---|
805 | return;
|
---|
806 | }
|
---|
807 | }
|
---|
808 |
|
---|
809 | if (!strcmp(token, "suppresscmd08")) {
|
---|
810 | if(strlen(value) == 0) {
|
---|
811 | cfg->c35_suppresscmd08 = 0;
|
---|
812 | return;
|
---|
813 | } else {
|
---|
814 | cfg->c35_suppresscmd08 = atoi(value);
|
---|
815 | return;
|
---|
816 | }
|
---|
817 | }
|
---|
818 |
|
---|
819 | if (token[0] != '#')
|
---|
820 | cs_log("Warning: keyword '%s' in camd35 tcp section not recognized", token);
|
---|
821 | }
|
---|
822 |
|
---|
823 | void chk_t_newcamd(char *token, char *value)
|
---|
824 | {
|
---|
825 | if (!strcmp(token, "port")) {
|
---|
826 | if(strlen(value) == 0) {
|
---|
827 | clear_ptab(&cfg->ncd_ptab);
|
---|
828 | return;
|
---|
829 | } else {
|
---|
830 | chk_port_tab(value, &cfg->ncd_ptab);
|
---|
831 | return;
|
---|
832 | }
|
---|
833 | }
|
---|
834 |
|
---|
835 | if (!strcmp(token, "serverip")) {
|
---|
836 | if(strlen(value) == 0) {
|
---|
837 | cfg->ncd_srvip = 0;
|
---|
838 | return;
|
---|
839 | } else {
|
---|
840 | cfg->ncd_srvip = inet_addr(value);
|
---|
841 | return;
|
---|
842 | }
|
---|
843 | }
|
---|
844 |
|
---|
845 | if (!strcmp(token, "allowed")) {
|
---|
846 | if(strlen(value) == 0) {
|
---|
847 | clear_sip(&cfg->ncd_allowed);
|
---|
848 | return;
|
---|
849 | } else {
|
---|
850 | chk_iprange(value, &cfg->ncd_allowed);
|
---|
851 | return;
|
---|
852 | }
|
---|
853 | }
|
---|
854 |
|
---|
855 | if (!strcmp(token, "key")) {
|
---|
856 | if (key_atob14(value, cfg->ncd_key)) {
|
---|
857 | fprintf(stderr, "Configuration newcamd: Error in Key\n");
|
---|
858 | exit(1);
|
---|
859 | }
|
---|
860 | return;
|
---|
861 | }
|
---|
862 |
|
---|
863 | if (!strcmp(token, "keepalive")) {
|
---|
864 | if(strlen(value) == 0) {
|
---|
865 | cfg->ncd_keepalive = 1;
|
---|
866 | return;
|
---|
867 | } else {
|
---|
868 | cfg->ncd_keepalive = atoi(value);
|
---|
869 | return;
|
---|
870 | }
|
---|
871 | }
|
---|
872 |
|
---|
873 | if (token[0] != '#')
|
---|
874 | cs_log("Warning: keyword '%s' in newcamd section not recognized", token);
|
---|
875 | }
|
---|
876 |
|
---|
877 | void chk_t_cccam(char *token, char *value)
|
---|
878 | {
|
---|
879 | if (!strcmp(token, "port")) {
|
---|
880 | if(strlen(value) == 0) {
|
---|
881 | cfg->cc_port = 0;
|
---|
882 | return;
|
---|
883 | } else {
|
---|
884 | cfg->cc_port = atoi(value);
|
---|
885 | return;
|
---|
886 | }
|
---|
887 | }
|
---|
888 | //if (!strcmp(token, "serverip")) { cfg->cc_srvip=inet_addr(value); return; }
|
---|
889 |
|
---|
890 | if (!strcmp(token, "reshare")) {
|
---|
891 | if(strlen(value) == 0) {
|
---|
892 | cfg->cc_reshare = 0;
|
---|
893 | return;
|
---|
894 | } else {
|
---|
895 | cfg->cc_reshare=atoi(value);
|
---|
896 | return;
|
---|
897 | }
|
---|
898 | }
|
---|
899 | // cccam version
|
---|
900 | if (!strcmp(token, "version")) {
|
---|
901 | if (strlen(value) > sizeof(cfg->cc_version) - 1) {
|
---|
902 | fprintf(stderr, "cccam config: version too long\n");
|
---|
903 | exit(1);
|
---|
904 | }
|
---|
905 | memset(cfg->cc_version, 0, sizeof(cfg->cc_version));
|
---|
906 | strncpy((char*)cfg->cc_version, value, sizeof(cfg->cc_version) - 1);
|
---|
907 | return;
|
---|
908 | }
|
---|
909 | // cccam build number
|
---|
910 | if (!strcmp(token, "build")) {
|
---|
911 | if (strlen(value) > sizeof(cfg->cc_build) - 1) {
|
---|
912 | fprintf(stderr, "cccam config build number too long\n");
|
---|
913 | exit(1);
|
---|
914 | }
|
---|
915 | memset(cfg->cc_build, 0, sizeof(cfg->cc_build));
|
---|
916 | strncpy((char*)cfg->cc_build, value, sizeof(cfg->cc_build)-1);
|
---|
917 | return;
|
---|
918 | }
|
---|
919 |
|
---|
920 | if (token[0] != '#')
|
---|
921 | cs_log("Warning: keyword '%s' in cccam section not recognized",token);
|
---|
922 | }
|
---|
923 |
|
---|
924 | void chk_t_radegast(char *token, char *value)
|
---|
925 | {
|
---|
926 | if (!strcmp(token, "port")) {
|
---|
927 | if(strlen(value) == 0) {
|
---|
928 | cfg->rad_port = 0;
|
---|
929 | return;
|
---|
930 | } else {
|
---|
931 | cfg->rad_port = atoi(value);
|
---|
932 | return;
|
---|
933 | }
|
---|
934 | }
|
---|
935 |
|
---|
936 | if (!strcmp(token, "serverip")) {
|
---|
937 | if(strlen(value) == 0) {
|
---|
938 | cfg->rad_srvip = 0;
|
---|
939 | return;
|
---|
940 | } else {
|
---|
941 | cfg->rad_srvip = inet_addr(value);
|
---|
942 | return;
|
---|
943 | }
|
---|
944 | }
|
---|
945 |
|
---|
946 | if (!strcmp(token, "allowed")) {
|
---|
947 | if(strlen(value) == 0) {
|
---|
948 | clear_sip(&cfg->rad_allowed);
|
---|
949 | return;
|
---|
950 | } else {
|
---|
951 | chk_iprange(value, &cfg->rad_allowed);
|
---|
952 | return;
|
---|
953 | }
|
---|
954 | }
|
---|
955 |
|
---|
956 | if (!strcmp(token, "user")) {
|
---|
957 | cs_strncpy(cfg->rad_usr, value, sizeof(cfg->rad_usr));
|
---|
958 | return;
|
---|
959 | }
|
---|
960 |
|
---|
961 | if (token[0] != '#')
|
---|
962 | cs_log("Warning: keyword '%s' in radegast section not recognized", token);
|
---|
963 | }
|
---|
964 |
|
---|
965 | void chk_t_serial(char *token, char *value)
|
---|
966 | {
|
---|
967 | if (!strcmp(token, "device")) {
|
---|
968 | int l;
|
---|
969 | l = strlen(cfg->ser_device);
|
---|
970 | if (l)
|
---|
971 | cfg->ser_device[l++]=1; // use ctrl-a as delimiter
|
---|
972 | cs_strncpy(cfg->ser_device+l, value, sizeof(cfg->ser_device)-l);
|
---|
973 | return;
|
---|
974 | }
|
---|
975 | if (token[0] != '#')
|
---|
976 | cs_log("Warning: keyword '%s' in serial section not recognized", token);
|
---|
977 | }
|
---|
978 |
|
---|
979 | #ifdef CS_WITH_GBOX
|
---|
980 | static void chk_t_gbox(char *token, char *value)
|
---|
981 | {
|
---|
982 | //if (!strcmp(token, "password")) strncpy(cfg->gbox_pwd, i2b(4, a2i(value, 4)), 4);
|
---|
983 | if (!strcmp(token, "password")) {
|
---|
984 | cs_atob(cfg->gbox_pwd, value, 4);
|
---|
985 | return;
|
---|
986 | }
|
---|
987 |
|
---|
988 | if (!strcmp(token, "maxdist")) {
|
---|
989 | cfg->maxdist=atoi(value);
|
---|
990 | return;
|
---|
991 | }
|
---|
992 |
|
---|
993 | if (!strcmp(token, "ignorelist")) {
|
---|
994 | cs_strncpy((char *)cfg->ignorefile, value, sizeof(cfg->ignorefile));
|
---|
995 | return;
|
---|
996 | }
|
---|
997 |
|
---|
998 | if (!strcmp(token, "onlineinfos")) {
|
---|
999 | cs_strncpy((char *)cfg->gbxShareOnl, value, sizeof(cfg->gbxShareOnl));
|
---|
1000 | return;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | if (!strcmp(token, "cardinfos")) {
|
---|
1004 | cs_strncpy((char *)cfg->cardfile, value, sizeof(cfg->cardfile));
|
---|
1005 | return;
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | if (!strcmp(token, "locals"))
|
---|
1009 | {
|
---|
1010 | char *ptr1;
|
---|
1011 | int n = 0, i;
|
---|
1012 | for (i = 0, ptr1 = strtok(value, ","); (i < CS_MAXLOCALS) && (ptr1); ptr1 = strtok(NULL, ",")) {
|
---|
1013 | cfg->locals[n++] = a2i(ptr1, 8);
|
---|
1014 | //printf("%i %08X",n,cfg->locals[n-1]);
|
---|
1015 | }
|
---|
1016 | cfg->num_locals = n;
|
---|
1017 | return;
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | if (token[0] != '#')
|
---|
1021 | cs_log("Warning: keyword '%s' in gbox section not recognized",token);
|
---|
1022 | }
|
---|
1023 | #endif
|
---|
1024 |
|
---|
1025 | #ifdef HAVE_DVBAPI
|
---|
1026 | void chk_t_dvbapi(char *token, char *value)
|
---|
1027 | {
|
---|
1028 | if (!strcmp(token, "enabled")) {
|
---|
1029 | cfg->dvbapi_enabled = atoi(value);
|
---|
1030 | return;
|
---|
1031 | }
|
---|
1032 |
|
---|
1033 | if (!strcmp(token, "au")) {
|
---|
1034 | cfg->dvbapi_au = atoi(value);
|
---|
1035 | return;
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | if (!strcmp(token, "boxtype")) {
|
---|
1039 | cs_strncpy(cfg->dvbapi_boxtype, value, sizeof(cfg->dvbapi_boxtype));
|
---|
1040 | return;
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | if (!strcmp(token, "user")) {
|
---|
1044 | cs_strncpy(cfg->dvbapi_usr, value, sizeof(cfg->dvbapi_usr));
|
---|
1045 | return;
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | if (!strcmp(token, "priority")) {
|
---|
1049 | cs_strncpy(cfg->dvbapi_priority, value, sizeof(cfg->dvbapi_priority));
|
---|
1050 | return;
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | if (!strcmp(token, "ignore")) {
|
---|
1054 | cs_strncpy(cfg->dvbapi_ignore, value, sizeof(cfg->dvbapi_ignore));
|
---|
1055 | return;
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | if (token[0] != '#')
|
---|
1059 | cs_log("Warning: keyword '%s' in dvbapi section not recognized\n",token);
|
---|
1060 | }
|
---|
1061 | #endif
|
---|
1062 |
|
---|
1063 | static void chk_token(char *token, char *value, int tag)
|
---|
1064 | {
|
---|
1065 | switch(tag) {
|
---|
1066 | case TAG_GLOBAL : chk_t_global(token, value); break;
|
---|
1067 | case TAG_MONITOR : chk_t_monitor(token, value); break;
|
---|
1068 | case TAG_CAMD33 : chk_t_camd33(token, value); break;
|
---|
1069 | case TAG_CAMD35 :
|
---|
1070 | case TAG_CS357X : chk_t_camd35(token, value); break;
|
---|
1071 | case TAG_NEWCAMD : chk_t_newcamd(token, value); break;
|
---|
1072 | case TAG_RADEGAST: chk_t_radegast(token, value); break;
|
---|
1073 | case TAG_SERIAL : chk_t_serial(token, value); break;
|
---|
1074 | case TAG_CS378X : chk_t_camd35_tcp(token, value); break;
|
---|
1075 | case TAG_CCCAM : chk_t_cccam(token, value); break;
|
---|
1076 |
|
---|
1077 | #ifdef CS_WITH_GBOX
|
---|
1078 | case TAG_GBOX : chk_t_gbox(token, value); break;
|
---|
1079 | #else
|
---|
1080 | case TAG_GBOX : cs_log("Warning: OSCam compiled without gbox support."); break;
|
---|
1081 | #endif
|
---|
1082 |
|
---|
1083 |
|
---|
1084 | #ifdef HAVE_DVBAPI
|
---|
1085 | case TAG_DVBAPI : chk_t_dvbapi(token, value); break;
|
---|
1086 | #else
|
---|
1087 | case TAG_DVBAPI : cs_log("Warning: OSCam compiled without DVB API support."); break;
|
---|
1088 | #endif
|
---|
1089 |
|
---|
1090 |
|
---|
1091 | #ifdef WEBIF
|
---|
1092 | case TAG_WEBIF : chk_t_webif(token, value); break;
|
---|
1093 | #else
|
---|
1094 | case TAG_WEBIF : cs_log("Warning: OSCam compiled without Webinterface support."); break;
|
---|
1095 | #endif
|
---|
1096 |
|
---|
1097 |
|
---|
1098 | #ifdef CS_ANTICASC
|
---|
1099 | case TAG_ANTICASC: chk_t_ac(token, value); break;
|
---|
1100 | #else
|
---|
1101 | case TAG_ANTICASC: cs_log("Warning: OSCam compiled without anticascading support."); break;
|
---|
1102 | #endif
|
---|
1103 |
|
---|
1104 | }
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | void init_len4caid()
|
---|
1108 | {
|
---|
1109 | int nr;
|
---|
1110 | FILE *fp;
|
---|
1111 | char *value;
|
---|
1112 |
|
---|
1113 | memset(len4caid, 0, sizeof(ushort)<<8);
|
---|
1114 | sprintf(token, "%s%s", cs_confdir, cs_l4ca);
|
---|
1115 | if (!(fp = fopen(token, "r")))
|
---|
1116 | return;
|
---|
1117 | for(nr = 0; fgets(token, sizeof(token), fp);) {
|
---|
1118 | int i, c;
|
---|
1119 | char *ptr;
|
---|
1120 | if (!(value=strchr(token, ':')))
|
---|
1121 | continue;
|
---|
1122 | *value++ ='\0';
|
---|
1123 | if( (ptr = strchr(value, '#')) )
|
---|
1124 | *ptr = '\0';
|
---|
1125 | if (strlen(trim(token)) != 2)
|
---|
1126 | continue;
|
---|
1127 | if (strlen(trim(value)) != 4)
|
---|
1128 | continue;
|
---|
1129 | if ((i = byte_atob(token)) < 0)
|
---|
1130 | continue;
|
---|
1131 | if ((c = word_atob(value)) < 0)
|
---|
1132 | continue;
|
---|
1133 | len4caid[i] = c;
|
---|
1134 | nr++;
|
---|
1135 | }
|
---|
1136 | fclose(fp);
|
---|
1137 | cs_log("%d lengths for caid guessing loaded", nr);
|
---|
1138 | return;
|
---|
1139 | }
|
---|
1140 |
|
---|
1141 | int search_boxkey(ushort caid, char *key)
|
---|
1142 | {
|
---|
1143 | int i, rc = 0;
|
---|
1144 | FILE *fp;
|
---|
1145 | char c_caid[512];
|
---|
1146 |
|
---|
1147 | sprintf(c_caid, "%s%s", cs_confdir, cs_cert);
|
---|
1148 | fp = fopen(c_caid, "r");
|
---|
1149 | if (fp) {
|
---|
1150 | for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);) {
|
---|
1151 | char *c_provid, *c_key;
|
---|
1152 |
|
---|
1153 | c_provid = strchr(c_caid, '#');
|
---|
1154 | if (c_provid)
|
---|
1155 | *c_provid = '\0';
|
---|
1156 | if (!(c_provid = strchr(c_caid, ':')))
|
---|
1157 | continue;
|
---|
1158 | *c_provid++ ='\0';
|
---|
1159 | if (!(c_key = strchr(c_provid, ':')))
|
---|
1160 | continue;
|
---|
1161 | *c_key++ ='\0';
|
---|
1162 | if (word_atob(trim(c_caid))!=caid)
|
---|
1163 | continue;
|
---|
1164 | if ((i=(strlen(trim(c_key))>>1)) > 256)
|
---|
1165 | continue;
|
---|
1166 | if (cs_atob((uchar *)key, c_key, i) < 0) {
|
---|
1167 | cs_log("wrong key in \"%s\"", cs_cert);
|
---|
1168 | continue;
|
---|
1169 | }
|
---|
1170 | rc = 1;
|
---|
1171 | }
|
---|
1172 | fclose(fp);
|
---|
1173 | }
|
---|
1174 | #ifdef OSCAM_INBUILD_KEYS
|
---|
1175 | for(i=0; (!rc) && (npkey[i].keylen); i++)
|
---|
1176 | if (rc=((caid==npkey[i].caid) && (npkey[i].provid==0)))
|
---|
1177 | memcpy(key, npkey[i].key, npkey[i].keylen);
|
---|
1178 | #endif
|
---|
1179 | return(rc);
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | int init_config()
|
---|
1183 | {
|
---|
1184 | int tag=TAG_GLOBAL;
|
---|
1185 | FILE *fp;
|
---|
1186 | char *value;
|
---|
1187 |
|
---|
1188 | #ifndef CS_EMBEDDED
|
---|
1189 | #ifdef PRIO_PROCESS
|
---|
1190 | errno=0;
|
---|
1191 | if ((cfg->nice = getpriority(PRIO_PROCESS, 0)) == (-1))
|
---|
1192 | if (errno)
|
---|
1193 | #endif
|
---|
1194 | #endif
|
---|
1195 | cfg->nice = 99;
|
---|
1196 | cfg->ctimeout = CS_CLIENT_TIMEOUT;
|
---|
1197 | cfg->ftimeout = CS_CLIENT_TIMEOUT / 2;
|
---|
1198 | cfg->cmaxidle = CS_CLIENT_MAXIDLE;
|
---|
1199 | cfg->delay = CS_DELAY;
|
---|
1200 | cfg->bindwait = CS_BIND_TIMEOUT;
|
---|
1201 | cfg->resolvedelay = CS_RESOLVE_DELAY;
|
---|
1202 | cfg->mon_level = 2;
|
---|
1203 | cfg->mon_hideclient_to = 0;
|
---|
1204 | cfg->srtimeout = 1500;
|
---|
1205 | cfg->ulparent = 0;
|
---|
1206 | cfg->logfile = NULL;
|
---|
1207 | cfg->pidfile = NULL;
|
---|
1208 | cfg->usrfile = NULL;
|
---|
1209 | cfg->cwlogdir = NULL;
|
---|
1210 | #ifdef WEBIF
|
---|
1211 | strcpy(cfg->http_user, "");
|
---|
1212 | strcpy(cfg->http_pwd, "");
|
---|
1213 | strcpy(cfg->http_css, "");
|
---|
1214 | cfg->http_refresh = 0;
|
---|
1215 | cfg->http_hide_idle_clients = 0;
|
---|
1216 | strcpy(cfg->http_tpl, "");
|
---|
1217 | #endif
|
---|
1218 | cfg->ncd_keepalive = 1;
|
---|
1219 | #ifdef CS_ANTICASC
|
---|
1220 | cfg->ac_enabled = 0;
|
---|
1221 | cfg->ac_users = 0;
|
---|
1222 | cfg->ac_stime = 2;
|
---|
1223 | cfg->ac_samples = 10;
|
---|
1224 | cfg->ac_denysamples = 8;
|
---|
1225 | cfg->ac_fakedelay = 1000;
|
---|
1226 | strcpy(cfg->ac_logfile, "./oscam_ac.log");
|
---|
1227 | #endif
|
---|
1228 | sprintf(token, "%s%s", cs_confdir, cs_conf);
|
---|
1229 | if (!(fp = fopen(token, "r"))) {
|
---|
1230 | fprintf(stderr, "Cannot open config file '%s' (errno=%d)\n", token, errno);
|
---|
1231 | exit(1);
|
---|
1232 | }
|
---|
1233 | while (fgets(token, sizeof(token), fp)) {
|
---|
1234 | int i, l;
|
---|
1235 | //void *ptr;
|
---|
1236 | if ((l = strlen(trim(token))) < 3)
|
---|
1237 | continue;
|
---|
1238 | if ((token[0] == '[') && (token[l-1] == ']')) {
|
---|
1239 | for (token[l-1] = 0, tag = -1, i = TAG_GLOBAL; cctag[i]; i++)
|
---|
1240 | if (!strcmp(cctag[i], strtolower(token+1)))
|
---|
1241 | tag = i;
|
---|
1242 | continue;
|
---|
1243 | }
|
---|
1244 | if (!(value=strchr(token, '=')))
|
---|
1245 | continue;
|
---|
1246 | *value++ ='\0';
|
---|
1247 | chk_token(trim(strtolower(token)), trim(value), tag);
|
---|
1248 | }
|
---|
1249 | fclose(fp);
|
---|
1250 | #ifdef CS_LOGFILE
|
---|
1251 | if (cfg->logfile == NULL)
|
---|
1252 | asprintf(&(cfg->logfile), "%s", CS_LOGFILE);
|
---|
1253 | #endif
|
---|
1254 | cs_init_log(cfg->logfile);
|
---|
1255 | if (cfg->ftimeout >= cfg->ctimeout) {
|
---|
1256 | cfg->ftimeout = cfg->ctimeout - 100;
|
---|
1257 | cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be smaller than clienttimeout (%lu ms))", cfg->ftimeout, cfg->ctimeout);
|
---|
1258 | }
|
---|
1259 | if(cfg->ftimeout < cfg->srtimeout) {
|
---|
1260 | cfg->ftimeout = cfg->srtimeout + 100;
|
---|
1261 | cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ftimeout, cfg->srtimeout);
|
---|
1262 | }
|
---|
1263 | if(cfg->ctimeout < cfg->srtimeout) {
|
---|
1264 | cfg->ctimeout = cfg->srtimeout + 100;
|
---|
1265 | cs_log("WARNING: clienttimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ctimeout, cfg->srtimeout);
|
---|
1266 | }
|
---|
1267 | #ifdef CS_ANTICASC
|
---|
1268 | if( cfg->ac_denysamples+1 > cfg->ac_samples ) {
|
---|
1269 | cfg->ac_denysamples = cfg->ac_samples - 1;
|
---|
1270 | cs_log("WARNING: DenySamples adjusted to %d", cfg->ac_denysamples);
|
---|
1271 | }
|
---|
1272 | #endif
|
---|
1273 | return 0;
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | void chk_account(char *token, char *value, struct s_auth *account)
|
---|
1277 | {
|
---|
1278 | int i;
|
---|
1279 | char *ptr1;
|
---|
1280 |
|
---|
1281 | if (!strcmp(token, "user")) {
|
---|
1282 | cs_strncpy(account->usr, value, sizeof(account->usr));
|
---|
1283 | return;
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | if (!strcmp(token, "pwd")) {
|
---|
1287 | cs_strncpy(account->pwd, value, sizeof(account->pwd));
|
---|
1288 | return;
|
---|
1289 | }
|
---|
1290 |
|
---|
1291 | if (!strcmp(token, "hostname")) {
|
---|
1292 | cs_strncpy((char *)account->dyndns, value, sizeof(account->dyndns));
|
---|
1293 | return;
|
---|
1294 | }
|
---|
1295 |
|
---|
1296 | if (!strcmp(token, "betatunnel")) {
|
---|
1297 | if(strlen(value) == 0) {
|
---|
1298 | clear_tuntab(&account->ttab);
|
---|
1299 | return;
|
---|
1300 | } else {
|
---|
1301 | chk_tuntab(value, &account->ttab);
|
---|
1302 | return;
|
---|
1303 | }
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | if (!strcmp(token, "uniq")) {
|
---|
1307 | if(strlen(value) == 0) {
|
---|
1308 | account->uniq = 0;
|
---|
1309 | return;
|
---|
1310 | } else {
|
---|
1311 | account->uniq = atoi(value);
|
---|
1312 | return;
|
---|
1313 | }
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 | if (!strcmp(token, "sleep")) {
|
---|
1317 | if(strlen(value) == 0) {
|
---|
1318 | account->tosleep = 0;
|
---|
1319 | return;
|
---|
1320 | } else {
|
---|
1321 | account->tosleep=atoi(value);
|
---|
1322 | return;
|
---|
1323 | }
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 | if (!strcmp(token, "monlevel")) {
|
---|
1327 | if(strlen(value) == 0) {
|
---|
1328 | account->monlvl = 0;
|
---|
1329 | return;
|
---|
1330 | } else {
|
---|
1331 | account->monlvl = atoi(value);
|
---|
1332 | return;
|
---|
1333 | }
|
---|
1334 | }
|
---|
1335 |
|
---|
1336 | if (!strcmp(token, "caid")) {
|
---|
1337 | if(strlen(value) == 0) {
|
---|
1338 | clear_caidtab(&account->ctab);
|
---|
1339 | return;
|
---|
1340 | } else {
|
---|
1341 | chk_caidtab(value, &account->ctab);
|
---|
1342 | return;
|
---|
1343 | }
|
---|
1344 | }
|
---|
1345 |
|
---|
1346 | if (!strcmp(token, "disabled")) {
|
---|
1347 | if(strlen(value) == 0) {
|
---|
1348 | account->disabled = 0;
|
---|
1349 | return;
|
---|
1350 | } else {
|
---|
1351 | account->disabled = atoi(value);
|
---|
1352 | return;
|
---|
1353 | }
|
---|
1354 | }
|
---|
1355 |
|
---|
1356 | if (!strcmp(token, "suppresscmd08")) {
|
---|
1357 | if(strlen(value) == 0) {
|
---|
1358 | account->c35_suppresscmd08 = 0;
|
---|
1359 | return;
|
---|
1360 | } else {
|
---|
1361 | account->c35_suppresscmd08=atoi(value);
|
---|
1362 | return;
|
---|
1363 | }
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | if (!strcmp(token, "keepalive")) {
|
---|
1367 | if(strlen(value) == 0) {
|
---|
1368 | account->ncd_keepalive = 1;
|
---|
1369 | return;
|
---|
1370 | } else {
|
---|
1371 | account->ncd_keepalive = atoi(value);
|
---|
1372 | return;
|
---|
1373 | }
|
---|
1374 | }
|
---|
1375 | /*
|
---|
1376 | * case insensitive
|
---|
1377 | */
|
---|
1378 | strtolower(value);
|
---|
1379 |
|
---|
1380 | if (!strcmp(token, "au")) {
|
---|
1381 | //set default values for usage during runtime from Webif
|
---|
1382 | account->au=-1;
|
---|
1383 | account->autoau=0;
|
---|
1384 |
|
---|
1385 | if(value && value[0]=='1') account->autoau=1;
|
---|
1386 | for (i=0; i<CS_MAXREADER; i++)
|
---|
1387 | if ((reader[i].label[0]) && (!strncmp(reader[i].label, value, strlen(reader[i].label))))
|
---|
1388 | account->au=i;
|
---|
1389 | return;
|
---|
1390 | }
|
---|
1391 |
|
---|
1392 | if (!strcmp(token, "group")) {
|
---|
1393 | account->grp = 0;
|
---|
1394 | for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) {
|
---|
1395 | int g;
|
---|
1396 | g = atoi(ptr1);
|
---|
1397 | if ((g>0) && (g < 33)) account->grp|=(1<<(g-1));
|
---|
1398 | }
|
---|
1399 | return;
|
---|
1400 | }
|
---|
1401 |
|
---|
1402 | if(!strcmp(token, "services")) {
|
---|
1403 | chk_services(value, &account->sidtabok, &account->sidtabno);
|
---|
1404 | return;
|
---|
1405 | }
|
---|
1406 |
|
---|
1407 | if(!strcmp(token, "ident")) { /*ToDo ftab clear*/
|
---|
1408 | chk_ftab(value, &account->ftab, "user", account->usr, "provid");
|
---|
1409 | return;
|
---|
1410 | }
|
---|
1411 |
|
---|
1412 | if(!strcmp(token, "class")) {
|
---|
1413 | chk_cltab(value, &account->cltab);
|
---|
1414 | return;
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 | if(!strcmp(token, "chid")) {
|
---|
1418 | chk_ftab(value, &account->fchid, "user", account->usr, "chid");
|
---|
1419 | return;
|
---|
1420 | }
|
---|
1421 |
|
---|
1422 | if (!strcmp(token, "expdate")) {
|
---|
1423 | if (!value[0]) {
|
---|
1424 | account->expirationdate=(time_t)NULL;
|
---|
1425 | return;
|
---|
1426 | }
|
---|
1427 | struct tm cstime;
|
---|
1428 | memset(&cstime,0,sizeof(cstime));
|
---|
1429 | for (i=0, ptr1=strtok(value, "-/"); (i<3)&&(ptr1); ptr1=strtok(NULL, "-/"), i++) {
|
---|
1430 | switch(i) {
|
---|
1431 | case 0: cstime.tm_year=atoi(ptr1)-1900; break;
|
---|
1432 | case 1: cstime.tm_mon =atoi(ptr1)-1; break;
|
---|
1433 | case 2: cstime.tm_mday=atoi(ptr1); break;
|
---|
1434 | }
|
---|
1435 | }
|
---|
1436 | account->expirationdate=mktime(&cstime);
|
---|
1437 | return;
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | #ifdef CS_ANTICASC
|
---|
1441 | if( !strcmp(token, "numusers") ) {
|
---|
1442 | account->ac_users = atoi(value);
|
---|
1443 | return;
|
---|
1444 | }
|
---|
1445 |
|
---|
1446 | if( !strcmp(token, "penalty") ) {
|
---|
1447 | account->ac_penalty = atoi(value);
|
---|
1448 | return;
|
---|
1449 | }
|
---|
1450 | #endif
|
---|
1451 |
|
---|
1452 | if (token[0] != '#')
|
---|
1453 | cs_log("Warning: keyword '%s' in account section not recognized",token);
|
---|
1454 | }
|
---|
1455 |
|
---|
1456 | int write_services()
|
---|
1457 | {
|
---|
1458 | int i;
|
---|
1459 | FILE *f;
|
---|
1460 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
1461 | char tmpfile[256];
|
---|
1462 | char destfile[256];
|
---|
1463 | char bakfile[256];
|
---|
1464 |
|
---|
1465 | snprintf(destfile, 255,"%s%s", cs_confdir, cs_sidt);
|
---|
1466 | snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_sidt);
|
---|
1467 | snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_sidt);
|
---|
1468 |
|
---|
1469 | if (!(f=fopen(tmpfile, "w"))){
|
---|
1470 | cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
|
---|
1471 | return(1);
|
---|
1472 | }
|
---|
1473 | fprintf(f,"#oscam.services generated automatically\n\n");
|
---|
1474 |
|
---|
1475 | while(sidtab != NULL){
|
---|
1476 | fprintf(f,"[%s]\n", sidtab->label);
|
---|
1477 | fprintf_conf(f, CONFVARWIDTH, "caid", "");
|
---|
1478 | for (i=0; i<sidtab->num_caid; i++){
|
---|
1479 | if (i==0) fprintf(f,"%04X", sidtab->caid[i]);
|
---|
1480 | else fprintf(f,",%04X", sidtab->caid[i]);
|
---|
1481 | }
|
---|
1482 | fputc((int)'\n', f);
|
---|
1483 | fprintf_conf(f, CONFVARWIDTH, "provid", "");
|
---|
1484 | for (i=0; i<sidtab->num_provid; i++){
|
---|
1485 | if (i==0) fprintf(f,"%06lX", sidtab->provid[i]);
|
---|
1486 | else fprintf(f,",%06lX", sidtab->provid[i]);
|
---|
1487 | }
|
---|
1488 | fputc((int)'\n', f);
|
---|
1489 | fprintf_conf(f, CONFVARWIDTH, "srvid", "");
|
---|
1490 | for (i=0; i<sidtab->num_srvid; i++){
|
---|
1491 | if (i==0) fprintf(f,"%04X", sidtab->srvid[i]);
|
---|
1492 | else fprintf(f,",%04X", sidtab->srvid[i]);
|
---|
1493 | }
|
---|
1494 | fprintf(f,"\n\n");
|
---|
1495 | sidtab=sidtab->next;
|
---|
1496 | }
|
---|
1497 |
|
---|
1498 | fclose(f);
|
---|
1499 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
1500 | }
|
---|
1501 |
|
---|
1502 | int write_config()
|
---|
1503 | {
|
---|
1504 | int i,j;
|
---|
1505 | FILE *f;
|
---|
1506 | char *dot = "", *dot1 = "", *dot2 = ""; //flags for delimiters
|
---|
1507 | char tmpfile[256];
|
---|
1508 | char destfile[256];
|
---|
1509 | char bakfile[256];
|
---|
1510 |
|
---|
1511 | snprintf(destfile, 255,"%s%s", cs_confdir, cs_conf);
|
---|
1512 | snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_conf);
|
---|
1513 | snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_conf);
|
---|
1514 |
|
---|
1515 | if (!(f=fopen(tmpfile, "w"))){
|
---|
1516 | cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
|
---|
1517 | return(1);
|
---|
1518 | }
|
---|
1519 | fprintf(f,"#oscam.config generated automatically\n\n");
|
---|
1520 |
|
---|
1521 | /*global settings*/
|
---|
1522 | fprintf(f,"[global]\n");
|
---|
1523 | if (cfg->srvip != 0)
|
---|
1524 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->srvip));
|
---|
1525 | if (cfg->pidfile != NULL) fprintf_conf(f, CONFVARWIDTH, "pidfile", "%s\n", cfg->pidfile);
|
---|
1526 | if (cfg->usrfile != NULL) fprintf_conf(f, CONFVARWIDTH, "usrfile", "%s\n", cfg->usrfile);
|
---|
1527 | if (cfg->logfile != NULL) fprintf_conf(f, CONFVARWIDTH, "logfile", "%s\n", cfg->logfile);
|
---|
1528 | if (cfg->cwlogdir != NULL) fprintf_conf(f, CONFVARWIDTH, "cwlogdir", "%s\n", cfg->cwlogdir);
|
---|
1529 | fprintf_conf(f, CONFVARWIDTH, "disablelog", "%d\n", cfg->disablelog);
|
---|
1530 | fprintf_conf(f, CONFVARWIDTH, "usrfileflag", "%d\n", cfg->usrfileflag);
|
---|
1531 | fprintf_conf(f, CONFVARWIDTH, "clienttimeout", "%ld\n", cfg->ctimeout/1000);
|
---|
1532 | fprintf_conf(f, CONFVARWIDTH, "fallbacktimeout", "%ld\n", cfg->ftimeout/1000);
|
---|
1533 | fprintf_conf(f, CONFVARWIDTH, "clientmaxidle", "%d\n", cfg->cmaxidle);
|
---|
1534 | fprintf_conf(f, CONFVARWIDTH, "cachedelay", "%ld\n", cfg->delay);
|
---|
1535 | fprintf_conf(f, CONFVARWIDTH, "bindwait", "%d\n", cfg->bindwait);
|
---|
1536 | fprintf_conf(f, CONFVARWIDTH, "netprio", "%ld\n", cfg->netprio);
|
---|
1537 | fprintf_conf(f, CONFVARWIDTH, "resolvedelay", "%d\n", cfg->resolvedelay);
|
---|
1538 | if (cfg->tosleep) fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", cfg->tosleep);
|
---|
1539 | fprintf_conf(f, CONFVARWIDTH, "unlockparental", "%d\n", cfg->ulparent);
|
---|
1540 | fprintf_conf(f, CONFVARWIDTH, "nice", "%d\n", cfg->nice);
|
---|
1541 | fprintf_conf(f, CONFVARWIDTH, "serialreadertimeout", "%d\n", cfg->srtimeout);
|
---|
1542 | fprintf_conf(f, CONFVARWIDTH, "maxlogsize", "%d\n", cfg->max_log_size);
|
---|
1543 | fprintf_conf(f, CONFVARWIDTH, "waitforcards", "%d\n", cfg->waitforcards);
|
---|
1544 | fprintf_conf(f, CONFVARWIDTH, "preferlocalcards", "%d\n", cfg->preferlocalcards);
|
---|
1545 | fputc((int)'\n', f);
|
---|
1546 |
|
---|
1547 | /*monitor settings*/
|
---|
1548 | fprintf(f,"[monitor]\n");
|
---|
1549 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->mon_port);
|
---|
1550 | if (cfg->mon_srvip != 0)
|
---|
1551 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip));
|
---|
1552 |
|
---|
1553 | fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
|
---|
1554 | struct s_ip *cip;
|
---|
1555 | for (cip = cfg->mon_allowed; cip; cip = cip->next){
|
---|
1556 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
1557 | if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
1558 | dot=",";
|
---|
1559 | }
|
---|
1560 | fputc((int)'\n', f);
|
---|
1561 | fprintf_conf(f, CONFVARWIDTH, "aulow", "%d\n", cfg->mon_aulow);
|
---|
1562 | fprintf_conf(f, CONFVARWIDTH, "hideclient_to", "%d\n", cfg->mon_hideclient_to);
|
---|
1563 | fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", cfg->mon_level);
|
---|
1564 | fputc((int)'\n', f);
|
---|
1565 |
|
---|
1566 | /*newcamd*/
|
---|
1567 | if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)){
|
---|
1568 | fprintf(f,"[newcamd]\n");
|
---|
1569 | fprintf_conf(f, CONFVARWIDTH, "port", "");
|
---|
1570 | dot1 = "";
|
---|
1571 | for(i = 0; i < cfg->ncd_ptab.nports; ++i){
|
---|
1572 | fprintf(f,"%s%d@%04X", dot1, cfg->ncd_ptab.ports[i].s_port, cfg->ncd_ptab.ports[i].ftab.filts[0].caid);
|
---|
1573 | if (cfg->ncd_ptab.ports[i].ftab.filts[0].nprids > 0){
|
---|
1574 | fprintf(f,":");
|
---|
1575 | dot2 = "";
|
---|
1576 | for (j = 0; j < cfg->ncd_ptab.ports[i].ftab.filts[0].nprids; ++j){
|
---|
1577 | fprintf(f,"%s%06X", dot2, (int)cfg->ncd_ptab.ports[i].ftab.filts[0].prids[j]);
|
---|
1578 | dot2 = ",";
|
---|
1579 | }
|
---|
1580 | }
|
---|
1581 | dot1=";";
|
---|
1582 | }
|
---|
1583 |
|
---|
1584 | fputc((int)'\n', f);
|
---|
1585 | if (cfg->ncd_srvip != 0)
|
---|
1586 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->ncd_srvip));
|
---|
1587 | fprintf_conf(f, CONFVARWIDTH, "key", "");
|
---|
1588 | for (i=0;i<14;i++) fprintf(f,"%02X", cfg->ncd_key[i]);
|
---|
1589 | fprintf(f,"\n");
|
---|
1590 | fprintf_conf(f, CONFVARWIDTH, "allowed", "");
|
---|
1591 | struct s_ip *cip;
|
---|
1592 | dot="";
|
---|
1593 | for (cip = cfg->ncd_allowed; cip; cip = cip->next){
|
---|
1594 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
1595 | if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
1596 | dot=",";
|
---|
1597 | }
|
---|
1598 | fprintf(f,"\n");
|
---|
1599 | fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", cfg->ncd_keepalive);
|
---|
1600 | fprintf(f,"\n");
|
---|
1601 | }
|
---|
1602 |
|
---|
1603 | /*camd3.3*/
|
---|
1604 | if ( cfg->c33_port > 0) {
|
---|
1605 | fprintf(f,"[camd33]\n");
|
---|
1606 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c33_port);
|
---|
1607 | if (cfg->c33_srvip != 0)
|
---|
1608 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip));
|
---|
1609 | fprintf_conf(f, CONFVARWIDTH, "passive", "%d\n", cfg->c33_passive);
|
---|
1610 | fprintf_conf(f, CONFVARWIDTH, "key", ""); for (i = 0; i < (int) sizeof(cfg->c33_key); ++i) fprintf(f,"%02X", cfg->c33_key[i]); fputc((int)'\n', f);
|
---|
1611 | fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
|
---|
1612 | dot="";
|
---|
1613 | for (cip = cfg->c33_plain; cip; cip = cip->next){
|
---|
1614 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
1615 | if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
1616 | dot=",";
|
---|
1617 | }
|
---|
1618 | fprintf(f,"\n\n");
|
---|
1619 | }
|
---|
1620 |
|
---|
1621 | /*camd3.5*/
|
---|
1622 | if ( cfg->c35_port > 0) {
|
---|
1623 | fprintf(f,"[cs357x]\n");
|
---|
1624 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c35_port);
|
---|
1625 | if (cfg->c35_tcp_srvip != 0)
|
---|
1626 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
|
---|
1627 | if (cfg->c35_suppresscmd08)
|
---|
1628 | fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", cfg->c35_suppresscmd08);
|
---|
1629 | fprintf(f,"\n");
|
---|
1630 | }
|
---|
1631 |
|
---|
1632 | /*camd3.5 TCP*/
|
---|
1633 | if ((cfg->c35_tcp_ptab.nports > 0) && (cfg->c35_tcp_ptab.ports[0].s_port > 0)) {
|
---|
1634 | fprintf(f,"[cs378x]\n");
|
---|
1635 | fprintf_conf(f, CONFVARWIDTH, "port", "");
|
---|
1636 | dot1 = "";
|
---|
1637 | for(i = 0; i < cfg->c35_tcp_ptab.nports; ++i){
|
---|
1638 | fprintf(f,"%s%d@%04X", dot1, cfg->c35_tcp_ptab.ports[i].s_port, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].caid);
|
---|
1639 | if (cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 0){
|
---|
1640 | fprintf(f,":");
|
---|
1641 | dot2 = "";
|
---|
1642 | for (j = 0; j < cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j){
|
---|
1643 | fprintf(f,"%s%lX", dot2, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]);
|
---|
1644 | dot2 = ",";
|
---|
1645 | }
|
---|
1646 | }
|
---|
1647 | dot1=";";
|
---|
1648 | }
|
---|
1649 |
|
---|
1650 | fputc((int)'\n', f);
|
---|
1651 | if (cfg->c35_tcp_srvip != 0)
|
---|
1652 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
|
---|
1653 | fputc((int)'\n', f);
|
---|
1654 | }
|
---|
1655 |
|
---|
1656 | /*Radegast*/
|
---|
1657 | if ( cfg->rad_port > 0) {
|
---|
1658 | fprintf(f,"[radegast]\n");
|
---|
1659 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->rad_port);
|
---|
1660 | if (cfg->rad_srvip != 0)
|
---|
1661 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->rad_srvip));
|
---|
1662 | fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->rad_usr);
|
---|
1663 | fprintf_conf(f, CONFVARWIDTH, "allowed", "");
|
---|
1664 | struct s_ip *cip;
|
---|
1665 | for (cip = cfg->rad_allowed; cip; cip = cip->next){
|
---|
1666 | fprintf(f,"%s%s", dot, inet_ntoa(*(struct in_addr *)&cip->ip[0]));
|
---|
1667 | if (cip->ip[0] == cip->ip[1]) fprintf(f,"-%s", inet_ntoa(*(struct in_addr *)&cip->ip[1]));
|
---|
1668 | dot=",";
|
---|
1669 | }
|
---|
1670 | fprintf(f,"\n\n");
|
---|
1671 | }
|
---|
1672 |
|
---|
1673 | #ifdef CS_WITH_GBOX
|
---|
1674 | /*Gbox*/
|
---|
1675 | if ((cfg->gbox_pwd[0] > 0) || (cfg->gbox_pwd[1] > 0) || (cfg->gbox_pwd[2] > 0) || (cfg->gbox_pwd[3] > 0)){
|
---|
1676 | fprintf(f,"[gbox]\n");
|
---|
1677 | fprintf_conf(f, CONFVARWIDTH, "password", ""); for (i=0;i<4;i++) fprintf(f,"%02X", cfg->gbox_pwd[i]); fputc((int)'\n', f);;
|
---|
1678 | fprintf_conf(f, CONFVARWIDTH, "maxdist", "%d\n", cfg->maxdist);
|
---|
1679 | fprintf_conf(f, CONFVARWIDTH, "ignorelist", "%s\n", cfg->ignorefile);
|
---|
1680 | fprintf_conf(f, CONFVARWIDTH, "onlineinfos", "%s\n", cfg->gbxShareOnl);
|
---|
1681 | fprintf_conf(f, CONFVARWIDTH, "cardinfos", "%s\n", cfg->cardfile);
|
---|
1682 | fprintf_conf(f, CONFVARWIDTH, "locals", "");
|
---|
1683 | char *dot = "";
|
---|
1684 | for (i = 0; i < cfg->num_locals; i++){
|
---|
1685 | fprintf(f,"%s%06lX", dot, cfg->locals[i]);
|
---|
1686 | dot=";";
|
---|
1687 | }
|
---|
1688 | fprintf(f,"\n\n");
|
---|
1689 | }
|
---|
1690 | #endif
|
---|
1691 |
|
---|
1692 | /*serial*/
|
---|
1693 |
|
---|
1694 |
|
---|
1695 | /*cccam*/
|
---|
1696 | if ( cfg->cc_port > 0) {
|
---|
1697 | fprintf(f,"[cccam]\n");
|
---|
1698 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->cc_port);
|
---|
1699 | fprintf_conf(f, CONFVARWIDTH, "reshare", "%d\n", cfg->cc_reshare);
|
---|
1700 | fprintf_conf(f, CONFVARWIDTH, "version", "%s\n", cfg->cc_version);
|
---|
1701 | fprintf_conf(f, CONFVARWIDTH, "build", "%s\n", cfg->cc_build);
|
---|
1702 | fprintf(f,"\n");
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 | #ifdef HAVE_DVBAPI
|
---|
1706 | /*dvb-api*/
|
---|
1707 | if (cfg->dvbapi_enabled > 0) {
|
---|
1708 | fprintf(f,"[dvbapi]\n");
|
---|
1709 | fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->dvbapi_enabled);
|
---|
1710 | fprintf_conf(f, CONFVARWIDTH, "au", "%d\n", cfg->dvbapi_au);
|
---|
1711 | fprintf_conf(f, CONFVARWIDTH, "boxtype", "%s\n", cfg->dvbapi_boxtype);
|
---|
1712 | fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->dvbapi_usr);
|
---|
1713 | fputc((int)'\n', f);
|
---|
1714 | }
|
---|
1715 | #endif
|
---|
1716 |
|
---|
1717 | #ifdef WEBIF
|
---|
1718 | /*webinterface*/
|
---|
1719 | if (cfg->http_port > 0) {
|
---|
1720 | fprintf(f,"[webif]\n");
|
---|
1721 | fprintf_conf(f, CONFVARWIDTH, "httpport", "%d\n", cfg->http_port);
|
---|
1722 | fprintf_conf(f, CONFVARWIDTH, "httpuser", "%s\n", cfg->http_user);
|
---|
1723 | fprintf_conf(f, CONFVARWIDTH, "httppwd", "%s\n", cfg->http_pwd);
|
---|
1724 | fprintf_conf(f, CONFVARWIDTH, "httpcss", "%s\n", cfg->http_css);
|
---|
1725 | fprintf_conf(f, CONFVARWIDTH, "httpscript", "%s\n", cfg->http_script);
|
---|
1726 | fprintf_conf(f, CONFVARWIDTH, "httprefresh", "%d\n", cfg->http_refresh);
|
---|
1727 | fprintf_conf(f, CONFVARWIDTH, "httphideidleclients", "%d\n", cfg->http_hide_idle_clients);
|
---|
1728 | fputc((int)'\n', f);
|
---|
1729 | }
|
---|
1730 | #endif
|
---|
1731 |
|
---|
1732 | #ifdef CS_ANTICASC
|
---|
1733 | fprintf(f,"[anticasc]\n");
|
---|
1734 | fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->ac_enabled);
|
---|
1735 | fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", cfg->ac_users);
|
---|
1736 | fprintf_conf(f, CONFVARWIDTH, "sampletime", "%d\n", cfg->ac_stime);
|
---|
1737 | fprintf_conf(f, CONFVARWIDTH, "samples", "%d\n", cfg->ac_samples);
|
---|
1738 | fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", cfg->ac_penalty);
|
---|
1739 | fprintf_conf(f, CONFVARWIDTH, "aclogfile", "%s\n", cfg->ac_logfile);
|
---|
1740 | fprintf_conf(f, CONFVARWIDTH, "denysamples", "%d\n", cfg->ac_denysamples);
|
---|
1741 | fprintf_conf(f, CONFVARWIDTH, "fakedelay", "%d\n", cfg->ac_fakedelay);
|
---|
1742 | fputc((int)'\n', f);
|
---|
1743 | #endif
|
---|
1744 |
|
---|
1745 | fclose(f);
|
---|
1746 |
|
---|
1747 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
1748 | }
|
---|
1749 |
|
---|
1750 | int write_userdb()
|
---|
1751 | {
|
---|
1752 | int i;
|
---|
1753 | FILE *f;
|
---|
1754 | struct s_auth *account;
|
---|
1755 | char *dot = ""; //flag for comma
|
---|
1756 | char tmpfile[256];
|
---|
1757 | char destfile[256];
|
---|
1758 | char bakfile[256];
|
---|
1759 |
|
---|
1760 | snprintf(destfile, 255,"%s%s", cs_confdir, cs_user);
|
---|
1761 | snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_user);
|
---|
1762 | snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_user);
|
---|
1763 |
|
---|
1764 | if (!(f=fopen(tmpfile, "w"))){
|
---|
1765 | cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
|
---|
1766 | return(1);
|
---|
1767 | }
|
---|
1768 | fprintf(f,"#oscam.user generated automatically\n\n");
|
---|
1769 |
|
---|
1770 | //each account
|
---|
1771 | for (account=cfg->account; (account) ; account=account->next){
|
---|
1772 | fprintf(f,"[account]\n");
|
---|
1773 | fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", account->usr);
|
---|
1774 | fprintf_conf(f, CONFVARWIDTH, "pwd", "%s\n", account->pwd);
|
---|
1775 | fprintf_conf(f, CONFVARWIDTH, "disabled", "%d\n", account->disabled);
|
---|
1776 | struct tm * timeinfo = localtime (&account->expirationdate);
|
---|
1777 | char buf [80];
|
---|
1778 | strftime (buf,80,"%Y-%m-%d",timeinfo);
|
---|
1779 | if(strcmp(buf,"1970-01-01"))
|
---|
1780 | fprintf_conf(f, CONFVARWIDTH, "expdate", "%s\n", buf);
|
---|
1781 | else
|
---|
1782 | fprintf_conf(f, CONFVARWIDTH, "expdate", "\n");
|
---|
1783 |
|
---|
1784 | //group
|
---|
1785 | char *value = mk_t_group((ulong*)account->grp);
|
---|
1786 | fprintf_conf(f, CONFVARWIDTH, "group", "%s\n", value);
|
---|
1787 | free(value);
|
---|
1788 |
|
---|
1789 | fprintf_conf(f, CONFVARWIDTH, "hostname", "%s\n", account->dyndns);
|
---|
1790 | fprintf_conf(f, CONFVARWIDTH, "uniq", "%d\n", account->uniq);
|
---|
1791 | fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", account->tosleep);
|
---|
1792 | fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", account->monlvl);
|
---|
1793 |
|
---|
1794 | if (account->au > -1)
|
---|
1795 | if (account->au < CS_MAXREADER)
|
---|
1796 | fprintf_conf(f, CONFVARWIDTH, "au", "%s\n", reader[account->au].label);
|
---|
1797 | if (account->autoau == 1) fprintf_conf(f, CONFVARWIDTH, "au", "1\n");
|
---|
1798 |
|
---|
1799 | fprintf_conf(f, CONFVARWIDTH, "services", "");
|
---|
1800 | char sidok[33]; long2bitchar(account->sidtabok,sidok);
|
---|
1801 | char sidno[33]; long2bitchar(account->sidtabno,sidno);
|
---|
1802 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
1803 | i=0; dot = "";
|
---|
1804 | for (; sidtab; sidtab=sidtab->next){
|
---|
1805 | if(sidok[i]=='1') {fprintf(f,"%s%s", dot, sidtab->label); dot = ",";}
|
---|
1806 | if(sidno[i]=='1') {fprintf(f,"%s!%s", dot, sidtab->label); dot = ",";}
|
---|
1807 | i++;
|
---|
1808 | }
|
---|
1809 | fputc((int)'\n', f);
|
---|
1810 |
|
---|
1811 | //CAID
|
---|
1812 | value = mk_t_caidtab(&account->ctab);
|
---|
1813 | fprintf_conf(f, CONFVARWIDTH, "caid", "%s\n", value);
|
---|
1814 | free(value);
|
---|
1815 |
|
---|
1816 | //betatunnel
|
---|
1817 | value = mk_t_tuntab(&account->ttab);
|
---|
1818 | fprintf_conf(f, CONFVARWIDTH, "betatunnel", "%s\n", value);
|
---|
1819 | free(value);
|
---|
1820 |
|
---|
1821 | //ident
|
---|
1822 | value = mk_t_ftab(&account->ftab);
|
---|
1823 | fprintf_conf(f, CONFVARWIDTH, "ident", "%s\n", value);
|
---|
1824 | free(value);
|
---|
1825 |
|
---|
1826 | if (account->c35_suppresscmd08)
|
---|
1827 | fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", account->c35_suppresscmd08);
|
---|
1828 |
|
---|
1829 | fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", account->ncd_keepalive);
|
---|
1830 |
|
---|
1831 | #ifdef CS_ANTICASC
|
---|
1832 | fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", account->ac_users);
|
---|
1833 | fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", account->ac_penalty);
|
---|
1834 | #endif
|
---|
1835 | fputc((int)'\n', f);
|
---|
1836 | }
|
---|
1837 | fclose(f);
|
---|
1838 |
|
---|
1839 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
1840 | }
|
---|
1841 |
|
---|
1842 | int init_userdb()
|
---|
1843 | {
|
---|
1844 | int tag = 0, nr, nro, expired, disabled;
|
---|
1845 | //int first=1;
|
---|
1846 | FILE *fp;
|
---|
1847 | char *value;
|
---|
1848 | struct s_auth *ptr;
|
---|
1849 | /*static */struct s_auth *account=(struct s_auth *)0;
|
---|
1850 |
|
---|
1851 | sprintf(token, "%s%s", cs_confdir, cs_user);
|
---|
1852 | if (!(fp = fopen(token, "r"))) {
|
---|
1853 | cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
|
---|
1854 | return(1);
|
---|
1855 | }
|
---|
1856 |
|
---|
1857 | for (nro = 0, ptr = cfg->account; ptr; nro++) {
|
---|
1858 | struct s_auth *ptr_next;
|
---|
1859 | ptr_next = ptr->next;
|
---|
1860 | free(ptr);
|
---|
1861 | ptr = ptr_next;
|
---|
1862 | }
|
---|
1863 | nr = 0;
|
---|
1864 |
|
---|
1865 | while (fgets(token, sizeof(token), fp)) {
|
---|
1866 | int i, l;
|
---|
1867 | void *ptr;
|
---|
1868 |
|
---|
1869 | if ((l=strlen(trim(token))) < 3)
|
---|
1870 | continue;
|
---|
1871 |
|
---|
1872 | if ((token[0] == '[') && (token[l-1] == ']')) {
|
---|
1873 | token[l - 1] = 0;
|
---|
1874 | tag = (!strcmp("account", strtolower(token + 1)));
|
---|
1875 |
|
---|
1876 | if (!(ptr=malloc(sizeof(struct s_auth)))) {
|
---|
1877 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
1878 | return(1);
|
---|
1879 | }
|
---|
1880 |
|
---|
1881 | if (account)
|
---|
1882 | account->next = ptr;
|
---|
1883 | else
|
---|
1884 | cfg->account = ptr;
|
---|
1885 |
|
---|
1886 | account = ptr;
|
---|
1887 | memset(account, 0, sizeof(struct s_auth));
|
---|
1888 | account->au = (-1);
|
---|
1889 | account->monlvl = cfg->mon_level;
|
---|
1890 | account->tosleep = cfg->tosleep;
|
---|
1891 | account->c35_suppresscmd08 = cfg->c35_suppresscmd08;
|
---|
1892 | account->ncd_keepalive = cfg->ncd_keepalive;
|
---|
1893 | for (i = 1; i < CS_MAXCAIDTAB; account->ctab.mask[i++] = 0xffff);
|
---|
1894 | for (i = 1; i < CS_MAXTUNTAB; account->ttab.bt_srvid[i++] = 0x0000);
|
---|
1895 | nr++;
|
---|
1896 |
|
---|
1897 | #ifdef CS_ANTICASC
|
---|
1898 | account->ac_users = cfg->ac_users;
|
---|
1899 | account->ac_penalty = cfg->ac_penalty;
|
---|
1900 | account->ac_idx = nr;
|
---|
1901 | #endif
|
---|
1902 | continue;
|
---|
1903 | }
|
---|
1904 |
|
---|
1905 | if (!tag)
|
---|
1906 | continue;
|
---|
1907 |
|
---|
1908 | if (!(value=strchr(token, '=')))
|
---|
1909 | continue;
|
---|
1910 |
|
---|
1911 | *value++ = '\0';
|
---|
1912 | chk_account(trim(strtolower(token)), trim(value), account);
|
---|
1913 | }
|
---|
1914 |
|
---|
1915 | fclose(fp);
|
---|
1916 |
|
---|
1917 | for (expired = 0, disabled = 0, ptr = cfg->account; ptr;) {
|
---|
1918 |
|
---|
1919 | if(ptr->expirationdate && ptr->expirationdate < time(NULL))
|
---|
1920 | expired++;
|
---|
1921 |
|
---|
1922 | if(ptr->disabled != 0)
|
---|
1923 | disabled++;
|
---|
1924 |
|
---|
1925 | ptr = ptr->next;
|
---|
1926 | }
|
---|
1927 |
|
---|
1928 | cs_log("userdb reloaded: %d accounts freed, %d accounts loaded, %d expired, %d disabled", nro, nr, expired, disabled);
|
---|
1929 | return(0);
|
---|
1930 | }
|
---|
1931 |
|
---|
1932 | static void chk_entry4sidtab(char *value, struct s_sidtab *sidtab, int what)
|
---|
1933 | {
|
---|
1934 | int i, b;
|
---|
1935 | char *ptr;
|
---|
1936 | ushort *slist=(ushort *) 0;
|
---|
1937 | ulong *llist=(ulong *) 0;
|
---|
1938 | ulong caid;
|
---|
1939 | char buf[strlen(value) + 1];
|
---|
1940 | cs_strncpy(buf, value, sizeof(buf));
|
---|
1941 | b=(what==1) ? sizeof(ulong) : sizeof(ushort);
|
---|
1942 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
1943 | {
|
---|
1944 | caid=a2i(ptr, b);
|
---|
1945 | if (!errno) i++;
|
---|
1946 | }
|
---|
1947 | //if (!i) return(0);
|
---|
1948 | if (b==sizeof(ushort))
|
---|
1949 | slist=malloc(i*sizeof(ushort));
|
---|
1950 | else
|
---|
1951 | llist=malloc(i*sizeof(ulong));
|
---|
1952 | strcpy(value, buf);
|
---|
1953 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
1954 | {
|
---|
1955 | caid=a2i(ptr, b);
|
---|
1956 | if (errno) continue;
|
---|
1957 | if (b==sizeof(ushort))
|
---|
1958 | slist[i++]=(ushort) caid;
|
---|
1959 | else
|
---|
1960 | llist[i++]=caid;
|
---|
1961 | }
|
---|
1962 | switch (what)
|
---|
1963 | {
|
---|
1964 | case 0: sidtab->caid=slist;
|
---|
1965 | sidtab->num_caid=i;
|
---|
1966 | break;
|
---|
1967 | case 1: sidtab->provid=llist;
|
---|
1968 | sidtab->num_provid=i;
|
---|
1969 | break;
|
---|
1970 | case 2: sidtab->srvid=slist;
|
---|
1971 | sidtab->num_srvid=i;
|
---|
1972 | break;
|
---|
1973 | }
|
---|
1974 | }
|
---|
1975 |
|
---|
1976 | void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab)
|
---|
1977 | {
|
---|
1978 | if (!strcmp(token, "caid")) { chk_entry4sidtab(value, sidtab, 0); return; }
|
---|
1979 | if (!strcmp(token, "provid")) { chk_entry4sidtab(value, sidtab, 1); return; }
|
---|
1980 | if (!strcmp(token, "ident")) { chk_entry4sidtab(value, sidtab, 1); return; }
|
---|
1981 | if (!strcmp(token, "srvid")) { chk_entry4sidtab(value, sidtab, 2); return; }
|
---|
1982 | if (token[0] != '#')
|
---|
1983 | cs_log("Warning: keyword '%s' in sidtab section not recognized",token);
|
---|
1984 | }
|
---|
1985 |
|
---|
1986 | int init_sidtab()
|
---|
1987 | {
|
---|
1988 | int nr, nro;
|
---|
1989 | FILE *fp;
|
---|
1990 | char *value;
|
---|
1991 | struct s_sidtab *ptr;
|
---|
1992 | struct s_sidtab *sidtab=(struct s_sidtab *)0;
|
---|
1993 |
|
---|
1994 | sprintf(token, "%s%s", cs_confdir, cs_sidt);
|
---|
1995 | if (!(fp=fopen(token, "r")))
|
---|
1996 | {
|
---|
1997 | cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
|
---|
1998 | return(1);
|
---|
1999 | }
|
---|
2000 | for (nro=0, ptr=cfg->sidtab; ptr; nro++)
|
---|
2001 | {
|
---|
2002 | struct s_sidtab *ptr_next;
|
---|
2003 | ptr_next=ptr->next;
|
---|
2004 | if (ptr->caid) free(ptr->caid);
|
---|
2005 | if (ptr->provid) free(ptr->provid);
|
---|
2006 | if (ptr->srvid) free(ptr->srvid);
|
---|
2007 | free(ptr);
|
---|
2008 | ptr=ptr_next;
|
---|
2009 | }
|
---|
2010 | nr=0;
|
---|
2011 | while (fgets(token, sizeof(token), fp))
|
---|
2012 | {
|
---|
2013 | int l;
|
---|
2014 | void *ptr;
|
---|
2015 | if ((l=strlen(trim(token)))<3) continue;
|
---|
2016 | if ((token[0]=='[') && (token[l-1]==']'))
|
---|
2017 | {
|
---|
2018 | token[l-1]=0;
|
---|
2019 | if (!(ptr=malloc(sizeof(struct s_sidtab))))
|
---|
2020 | {
|
---|
2021 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
2022 | return(1);
|
---|
2023 | }
|
---|
2024 | if (sidtab)
|
---|
2025 | sidtab->next=ptr;
|
---|
2026 | else
|
---|
2027 | cfg->sidtab=ptr;
|
---|
2028 | sidtab=ptr;
|
---|
2029 | nr++;
|
---|
2030 | memset(sidtab, 0, sizeof(struct s_sidtab));
|
---|
2031 | cs_strncpy(sidtab->label, strtolower(token+1), sizeof(sidtab->label));
|
---|
2032 | continue;
|
---|
2033 | }
|
---|
2034 | if (!sidtab) continue;
|
---|
2035 | if (!(value=strchr(token, '='))) continue;
|
---|
2036 | *value++='\0';
|
---|
2037 | chk_sidtab(trim(strtolower(token)), trim(strtolower(value)), sidtab);
|
---|
2038 | }
|
---|
2039 | fclose(fp);
|
---|
2040 |
|
---|
2041 | #ifdef DEBUG_SIDTAB
|
---|
2042 | show_sidtab(cfg->sidtab);
|
---|
2043 | #endif
|
---|
2044 | cs_log("services reloaded: %d services freed, %d services loaded", nro, nr);
|
---|
2045 | return(0);
|
---|
2046 | }
|
---|
2047 |
|
---|
2048 | int init_srvid()
|
---|
2049 | {
|
---|
2050 | int nr;
|
---|
2051 | FILE *fp;
|
---|
2052 | char *payload;
|
---|
2053 | static struct s_srvid *srvid=(struct s_srvid *)0;
|
---|
2054 | sprintf(token, "%s%s", cs_confdir, cs_srid);
|
---|
2055 |
|
---|
2056 | if (!(fp=fopen(token, "r"))) {
|
---|
2057 | cs_log("can't open file \"%s\" (err=%d), no service-id's loaded", token, errno);
|
---|
2058 | return(0);
|
---|
2059 | }
|
---|
2060 |
|
---|
2061 | nr=0;
|
---|
2062 | while (fgets(token, sizeof(token), fp)) {
|
---|
2063 |
|
---|
2064 | int l;
|
---|
2065 | void *ptr;
|
---|
2066 | char *tmp;
|
---|
2067 | tmp = trim(token);
|
---|
2068 |
|
---|
2069 | if (tmp[0] == '#') continue;
|
---|
2070 | if ((l=strlen(tmp)) < 6) continue;
|
---|
2071 | if (!(payload=strchr(token, '|'))) continue;
|
---|
2072 | *payload++ = '\0';
|
---|
2073 |
|
---|
2074 | if (!(ptr = malloc(sizeof(struct s_srvid)))) {
|
---|
2075 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
2076 | return(1);
|
---|
2077 | }
|
---|
2078 |
|
---|
2079 | if (srvid)
|
---|
2080 | srvid->next = ptr;
|
---|
2081 | else
|
---|
2082 | cfg->srvid = ptr;
|
---|
2083 |
|
---|
2084 | srvid = ptr;
|
---|
2085 | memset(srvid, 0, sizeof(struct s_srvid));
|
---|
2086 |
|
---|
2087 | int i;
|
---|
2088 | char *ptr1;
|
---|
2089 | for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
|
---|
2090 | switch(i){
|
---|
2091 | case 0:
|
---|
2092 | cs_strncpy(srvid->prov, trim(ptr1), sizeof(srvid->prov));
|
---|
2093 | break;
|
---|
2094 | case 1:
|
---|
2095 | cs_strncpy(srvid->name, trim(ptr1), sizeof(srvid->name));
|
---|
2096 | break;
|
---|
2097 | case 2:
|
---|
2098 | cs_strncpy(srvid->type, trim(ptr1), sizeof(srvid->type));
|
---|
2099 | break;
|
---|
2100 | case 3:
|
---|
2101 | cs_strncpy(srvid->desc, trim(ptr1), sizeof(srvid->desc));
|
---|
2102 | break;
|
---|
2103 | }
|
---|
2104 | }
|
---|
2105 |
|
---|
2106 | char *srvidasc = strchr(token, ':');
|
---|
2107 | *srvidasc++ = '\0';
|
---|
2108 | srvid->srvid = word_atob(srvidasc);
|
---|
2109 |
|
---|
2110 | srvid->ncaid = 0;
|
---|
2111 | for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
|
---|
2112 | srvid->caid[i] = word_atob(ptr1);
|
---|
2113 | srvid->ncaid = i+1;
|
---|
2114 | //cs_debug("ld caid: %04X srvid: %04X Prov: %s Chan: %s",srvid->caid[i],srvid->srvid,srvid->prov,srvid->name);
|
---|
2115 | }
|
---|
2116 | nr++;
|
---|
2117 | }
|
---|
2118 |
|
---|
2119 | fclose(fp);
|
---|
2120 | if (nr>0)
|
---|
2121 | cs_log("%d service-id's loaded", nr);
|
---|
2122 | else{
|
---|
2123 | cs_log("oscam.srvid loading failed, old format");
|
---|
2124 | }
|
---|
2125 | return(0);
|
---|
2126 | }
|
---|
2127 |
|
---|
2128 | static void chk_reader(char *token, char *value, struct s_reader *rdr)
|
---|
2129 | {
|
---|
2130 | int i;
|
---|
2131 | char *ptr;
|
---|
2132 | /*
|
---|
2133 | * case sensitive first
|
---|
2134 | */
|
---|
2135 | if (!strcmp(token, "device")) {
|
---|
2136 | for (i = 0, ptr = strtok(value, ","); (i < 3) && (ptr); ptr = strtok(NULL, ","), i++) {
|
---|
2137 | trim(ptr);
|
---|
2138 | switch(i) {
|
---|
2139 | case 0:
|
---|
2140 | cs_strncpy(rdr->device, ptr, sizeof(rdr->device));
|
---|
2141 | break;
|
---|
2142 |
|
---|
2143 | case 1:
|
---|
2144 | rdr->r_port = atoi(ptr);
|
---|
2145 | break;
|
---|
2146 |
|
---|
2147 | case 2:
|
---|
2148 | rdr->l_port = atoi(ptr);
|
---|
2149 | break;
|
---|
2150 | }
|
---|
2151 | }
|
---|
2152 | return;
|
---|
2153 | }
|
---|
2154 |
|
---|
2155 | if (!strcmp(token, "key")) {
|
---|
2156 | if (key_atob14(value, rdr->ncd_key)) {
|
---|
2157 | fprintf(stderr, "Configuration newcamd: Error in Key\n");
|
---|
2158 | exit(1);
|
---|
2159 | }
|
---|
2160 | return;
|
---|
2161 | }
|
---|
2162 |
|
---|
2163 | #ifdef CS_WITH_GBOX
|
---|
2164 | if (!strcmp(token, "password")) {
|
---|
2165 | cs_strncpy((char *)rdr->gbox_pwd, (const char *)i2b(4, a2i(value, 4)), 4);
|
---|
2166 | return;
|
---|
2167 | }
|
---|
2168 |
|
---|
2169 | if (!strcmp(token, "premium")) {
|
---|
2170 | rdr->gbox_prem = 1;
|
---|
2171 | return;
|
---|
2172 | }
|
---|
2173 | #endif
|
---|
2174 | if (!strcmp(token, "account")) {
|
---|
2175 | for (i = 0, ptr = strtok(value, ","); (i < 2) && (ptr); ptr = strtok(NULL, ","), i++) {
|
---|
2176 | trim(ptr);
|
---|
2177 | switch(i) {
|
---|
2178 | case 0:
|
---|
2179 | cs_strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr));
|
---|
2180 | break;
|
---|
2181 |
|
---|
2182 | case 1:
|
---|
2183 | cs_strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd));
|
---|
2184 | break;
|
---|
2185 | }
|
---|
2186 | }
|
---|
2187 | return;
|
---|
2188 | }
|
---|
2189 |
|
---|
2190 | if (!strcmp(token, "pincode")) {
|
---|
2191 | strncpy(rdr->pincode, value, sizeof(rdr->pincode) - 1);
|
---|
2192 | return;
|
---|
2193 | }
|
---|
2194 |
|
---|
2195 | if (!strcmp(token, "readnano") && value[0]) {
|
---|
2196 | if (rdr->emmfile != NULL) {
|
---|
2197 | free(rdr->emmfile);
|
---|
2198 | rdr->emmfile = NULL;
|
---|
2199 | }
|
---|
2200 | if (strlen(value) > 0)
|
---|
2201 | asprintf(&(rdr->emmfile), "%s", value);
|
---|
2202 | return;
|
---|
2203 | }
|
---|
2204 |
|
---|
2205 | /*
|
---|
2206 | * case insensitive
|
---|
2207 | */
|
---|
2208 | strtolower(value);
|
---|
2209 |
|
---|
2210 | if (!strcmp(token, "enable")) {
|
---|
2211 | if(strlen(value) == 0) {
|
---|
2212 | rdr->enable = 0;
|
---|
2213 | return;
|
---|
2214 | } else {
|
---|
2215 | rdr->enable = atoi(value) ? 1 : 0;
|
---|
2216 | return;
|
---|
2217 | }
|
---|
2218 | }
|
---|
2219 |
|
---|
2220 | if (!strcmp(token, "services")) {
|
---|
2221 | if(strlen(value) == 0) {
|
---|
2222 | rdr->sidtabok = 0;
|
---|
2223 | rdr->sidtabno = 0;
|
---|
2224 | return;
|
---|
2225 | } else {
|
---|
2226 | chk_services(value, &rdr->sidtabok, &rdr->sidtabno);
|
---|
2227 | return;
|
---|
2228 | }
|
---|
2229 | }
|
---|
2230 |
|
---|
2231 | if (!strcmp(token, "inactivitytimeout")) {
|
---|
2232 | if(strlen(value) == 0) {
|
---|
2233 | rdr->tcp_ito = 0;
|
---|
2234 | return;
|
---|
2235 | } else {
|
---|
2236 | rdr->tcp_ito = atoi(value);
|
---|
2237 | return;
|
---|
2238 | }
|
---|
2239 | }
|
---|
2240 |
|
---|
2241 | if (!strcmp(token, "reconnecttimeout")) {
|
---|
2242 | if(strlen(value) == 0) {
|
---|
2243 | rdr->tcp_rto = 0;
|
---|
2244 | return;
|
---|
2245 | } else {
|
---|
2246 | rdr->tcp_rto = atoi(value);
|
---|
2247 | return;
|
---|
2248 | }
|
---|
2249 | }
|
---|
2250 |
|
---|
2251 | if (!strcmp(token, "disableserverfilter")) {
|
---|
2252 | if(strlen(value) == 0) {
|
---|
2253 | rdr->ncd_disable_server_filt = 0;
|
---|
2254 | return;
|
---|
2255 | } else {
|
---|
2256 | rdr->ncd_disable_server_filt = atoi(value);
|
---|
2257 | return;
|
---|
2258 | }
|
---|
2259 | }
|
---|
2260 |
|
---|
2261 | //FIXME workaround for Smargo until native mode works
|
---|
2262 | if (!strcmp(token, "smargopatch")) {
|
---|
2263 | if(strlen(value) == 0) {
|
---|
2264 | rdr->smargopatch = 0;
|
---|
2265 | return;
|
---|
2266 | } else {
|
---|
2267 | rdr->smargopatch = atoi(value);
|
---|
2268 | return;
|
---|
2269 | }
|
---|
2270 | }
|
---|
2271 |
|
---|
2272 | if (!strcmp(token, "label")) {
|
---|
2273 | cs_strncpy(rdr->label, value, sizeof(rdr->label));
|
---|
2274 | return;
|
---|
2275 | }
|
---|
2276 |
|
---|
2277 | if (!strcmp(token, "fallback")) {
|
---|
2278 | if(strlen(value) == 0) {
|
---|
2279 | rdr->fallback = 0;
|
---|
2280 | return;
|
---|
2281 | } else {
|
---|
2282 | rdr->fallback = atoi(value) ? 1 : 0;
|
---|
2283 | return;
|
---|
2284 | }
|
---|
2285 | }
|
---|
2286 |
|
---|
2287 | if (!strcmp(token, "logport")) {
|
---|
2288 | if(strlen(value) == 0) {
|
---|
2289 | rdr->log_port = 0;
|
---|
2290 | return;
|
---|
2291 | } else {
|
---|
2292 | rdr->log_port = atoi(value);
|
---|
2293 | return;
|
---|
2294 | }
|
---|
2295 | }
|
---|
2296 |
|
---|
2297 | if (!strcmp(token, "caid")) {
|
---|
2298 | if(strlen(value) == 0) {
|
---|
2299 | clear_caidtab(&rdr->ctab);
|
---|
2300 | return;
|
---|
2301 | } else {
|
---|
2302 | chk_caidtab(value, &rdr->ctab);
|
---|
2303 | return;
|
---|
2304 | }
|
---|
2305 | }
|
---|
2306 |
|
---|
2307 | if (!strcmp(token, "boxid")) {
|
---|
2308 | if(strlen(value) == 0) {
|
---|
2309 | rdr->boxid = 0;
|
---|
2310 | return;
|
---|
2311 | } else {
|
---|
2312 | rdr->boxid = a2i(value, 4);
|
---|
2313 | return;
|
---|
2314 | }
|
---|
2315 | }
|
---|
2316 |
|
---|
2317 | if (!strcmp(token, "aeskey")) {
|
---|
2318 | if (key_atob(value, rdr->aes_key)) {
|
---|
2319 | fprintf(stderr, "Configuration reader: Error in AES Key\n");
|
---|
2320 | exit(1);
|
---|
2321 | }
|
---|
2322 | return;
|
---|
2323 | }
|
---|
2324 |
|
---|
2325 | if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey"))) {
|
---|
2326 | rdr->has_rsa = 1;
|
---|
2327 | if (key_atob_l(value, rdr->rsa_mod, 128)) {
|
---|
2328 | fprintf(stderr, "Configuration reader: Error in rsakey\n");
|
---|
2329 | exit(1);
|
---|
2330 | }
|
---|
2331 | return;
|
---|
2332 | }
|
---|
2333 |
|
---|
2334 | if (!strcmp(token, "tiger_rsakey")) {
|
---|
2335 | if (key_atob_l(value, rdr->rsa_mod, 240)) {
|
---|
2336 | fprintf(stderr, "Configuration reader: Error in tiger_rsakey\n");
|
---|
2337 | exit(1);
|
---|
2338 | }
|
---|
2339 | return;
|
---|
2340 | }
|
---|
2341 |
|
---|
2342 | if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey"))) {
|
---|
2343 | if (key_atob_l(value, rdr->nagra_boxkey, 16)) {
|
---|
2344 | fprintf(stderr, "Configuration reader: Error in boxkey\n");
|
---|
2345 | exit(1);
|
---|
2346 | }
|
---|
2347 | return;
|
---|
2348 | }
|
---|
2349 |
|
---|
2350 | if (!strcmp(token, "detect")) {
|
---|
2351 | for (i = 0; RDR_CD_TXT[i]; i++) {
|
---|
2352 | if (!strcmp(value, RDR_CD_TXT[i])) {
|
---|
2353 | rdr->detect = i;
|
---|
2354 | }
|
---|
2355 | else {
|
---|
2356 | if ((value[0] == '!') && (!strcmp(value+1, RDR_CD_TXT[i])))
|
---|
2357 | rdr->detect = i|0x80;
|
---|
2358 | }
|
---|
2359 | }
|
---|
2360 | return;
|
---|
2361 | }
|
---|
2362 |
|
---|
2363 | if (!strcmp(token, "mhz")) {
|
---|
2364 | if(strlen(value) == 0) {
|
---|
2365 | rdr->mhz = 0;
|
---|
2366 | return;
|
---|
2367 | } else {
|
---|
2368 | rdr->mhz = atoi(value);
|
---|
2369 | return;
|
---|
2370 | }
|
---|
2371 | }
|
---|
2372 |
|
---|
2373 | if (!strcmp(token, "cardmhz")) {
|
---|
2374 | if(strlen(value) == 0) {
|
---|
2375 | rdr->cardmhz = 0;
|
---|
2376 | return;
|
---|
2377 | } else {
|
---|
2378 | rdr->cardmhz = atoi(value);
|
---|
2379 | return;
|
---|
2380 | }
|
---|
2381 | }
|
---|
2382 |
|
---|
2383 | if (!strcmp(token, "protocol")) {
|
---|
2384 |
|
---|
2385 | if (!strcmp(value, "mouse")) {
|
---|
2386 | rdr->typ = R_MOUSE;
|
---|
2387 | return;
|
---|
2388 | }
|
---|
2389 |
|
---|
2390 | if (!strcmp(value, "smartreader")) {
|
---|
2391 | rdr->typ = R_SMART;
|
---|
2392 | return;
|
---|
2393 | }
|
---|
2394 |
|
---|
2395 | if (!strcmp(value, "internal")) {
|
---|
2396 | rdr->typ = R_INTERNAL;
|
---|
2397 | return;
|
---|
2398 | }
|
---|
2399 |
|
---|
2400 | #ifdef HAVE_PCSC
|
---|
2401 | if (!strcmp(value, "pcsc")) {
|
---|
2402 | rdr->typ = R_PCSC;
|
---|
2403 | return;
|
---|
2404 | }
|
---|
2405 | #endif
|
---|
2406 |
|
---|
2407 | if (!strcmp(value, "serial")) {
|
---|
2408 | rdr->typ = R_SERIAL;
|
---|
2409 | return;
|
---|
2410 | }
|
---|
2411 |
|
---|
2412 | if (!strcmp(value, "camd35")) {
|
---|
2413 | rdr->typ = R_CAMD35;
|
---|
2414 | return;
|
---|
2415 | }
|
---|
2416 |
|
---|
2417 | if (!strcmp(value, "cs378x")) {
|
---|
2418 | rdr->typ = R_CS378X;
|
---|
2419 | return;
|
---|
2420 | }
|
---|
2421 |
|
---|
2422 | if (!strcmp(value, "cs357x")) {
|
---|
2423 | rdr->typ = R_CAMD35;
|
---|
2424 | return;
|
---|
2425 | }
|
---|
2426 |
|
---|
2427 | #ifdef CS_WITH_GBOX
|
---|
2428 | if (!strcmp(value, "gbox")) {
|
---|
2429 | rdr->typ = R_GBOX;
|
---|
2430 | return;
|
---|
2431 | }
|
---|
2432 | #endif
|
---|
2433 |
|
---|
2434 | if (!strcmp(value, "cccam")) {
|
---|
2435 | rdr->typ = R_CCCAM;
|
---|
2436 | //strcpy(value, "1");
|
---|
2437 | //chk_caidtab(value, &rdr->ctab);
|
---|
2438 | //this is a MAJOR hack for auto multiple caid support (not currently working due to ncd table issue)
|
---|
2439 | return;
|
---|
2440 | }
|
---|
2441 |
|
---|
2442 | if (!strcmp(value, "radegast")) {
|
---|
2443 | rdr->typ = R_RADEGAST;
|
---|
2444 | return;
|
---|
2445 | }
|
---|
2446 |
|
---|
2447 | if (!strcmp(value, "newcamd") || !strcmp(value, "newcamd525")) {
|
---|
2448 | rdr->typ = R_NEWCAMD;
|
---|
2449 | rdr->ncd_proto = NCD_525;
|
---|
2450 | return;
|
---|
2451 | }
|
---|
2452 |
|
---|
2453 | if (!strcmp(value, "newcamd524")) {
|
---|
2454 | rdr->typ = R_NEWCAMD;
|
---|
2455 | rdr->ncd_proto = NCD_524;
|
---|
2456 | return;
|
---|
2457 | }
|
---|
2458 |
|
---|
2459 | cs_log("WARNING: value '%s' in protocol-line not recognized, assuming MOUSE",value);
|
---|
2460 | rdr->typ = R_MOUSE;
|
---|
2461 | return;
|
---|
2462 | }
|
---|
2463 |
|
---|
2464 | if (!strcmp(token, "loadbalanced")) {
|
---|
2465 | if(strlen(value) == 0) {
|
---|
2466 | rdr->loadbalanced = 0;
|
---|
2467 | return;
|
---|
2468 | } else {
|
---|
2469 | rdr->loadbalanced = atoi(value);
|
---|
2470 | return;
|
---|
2471 | }
|
---|
2472 | }
|
---|
2473 |
|
---|
2474 | if (!strcmp(token, "ident")) {
|
---|
2475 | if(strlen(value) == 0) {
|
---|
2476 | clear_ftab(&rdr->ftab);
|
---|
2477 | return;
|
---|
2478 | } else {
|
---|
2479 | chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid");
|
---|
2480 | return;
|
---|
2481 | }
|
---|
2482 | }
|
---|
2483 |
|
---|
2484 | if (!strcmp(token, "class")) {
|
---|
2485 | chk_cltab(value, &rdr->cltab);
|
---|
2486 | return;
|
---|
2487 | }
|
---|
2488 |
|
---|
2489 | if (!strcmp(token, "chid")) {
|
---|
2490 | chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid");
|
---|
2491 | return;
|
---|
2492 | }
|
---|
2493 |
|
---|
2494 | if (!strcmp(token, "showcls")) {
|
---|
2495 | rdr->show_cls = atoi(value);
|
---|
2496 | return;
|
---|
2497 | }
|
---|
2498 |
|
---|
2499 | if (!strcmp(token, "maxqlen")) {
|
---|
2500 | rdr->maxqlen = atoi(value);
|
---|
2501 | if( rdr->maxqlen < 0 || rdr->maxqlen > CS_MAXQLEN) {
|
---|
2502 | rdr->maxqlen = CS_MAXQLEN;
|
---|
2503 | }
|
---|
2504 | return;
|
---|
2505 | }
|
---|
2506 |
|
---|
2507 | if (!strcmp(token, "group")) {
|
---|
2508 | if(strlen(value) == 0) {
|
---|
2509 | rdr->grp = 0;
|
---|
2510 | return;
|
---|
2511 | } else {
|
---|
2512 | for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
|
---|
2513 | int g;
|
---|
2514 | g = atoi(ptr);
|
---|
2515 | if ((g>0) && (g<33)) {
|
---|
2516 | rdr->grp |= (1<<(g-1));
|
---|
2517 | }
|
---|
2518 | }
|
---|
2519 | return;
|
---|
2520 | }
|
---|
2521 | }
|
---|
2522 |
|
---|
2523 | if (!strcmp(token, "emmcache")) {
|
---|
2524 | if(strlen(value) == 0) {
|
---|
2525 | rdr->cachemm = 0;
|
---|
2526 | rdr->rewritemm = 0;
|
---|
2527 | rdr->logemm = 0;
|
---|
2528 | return;
|
---|
2529 | } else {
|
---|
2530 | for (i = 0, ptr = strtok(value, ","); (i < 3) && (ptr); ptr = strtok(NULL, ","), i++) {
|
---|
2531 | switch(i)
|
---|
2532 | {
|
---|
2533 | case 0:
|
---|
2534 | rdr->cachemm = atoi(ptr);
|
---|
2535 | break;
|
---|
2536 |
|
---|
2537 | case 1:
|
---|
2538 | rdr->rewritemm = atoi(ptr);
|
---|
2539 | break;
|
---|
2540 |
|
---|
2541 | case 2: rdr->logemm = atoi(ptr);
|
---|
2542 | break;
|
---|
2543 | }
|
---|
2544 | }
|
---|
2545 |
|
---|
2546 | if (rdr->rewritemm <= 0) {
|
---|
2547 | fprintf(stderr, "Notice: Setting EMMCACHE to %i,1,%i instead of %i,%i,%i. ",
|
---|
2548 | rdr->cachemm, rdr->logemm,
|
---|
2549 | rdr->cachemm, rdr->rewritemm,
|
---|
2550 | rdr->logemm);
|
---|
2551 |
|
---|
2552 | fprintf(stderr, "Zero or negative number of rewrites is silly\n");
|
---|
2553 | rdr->rewritemm = 1;
|
---|
2554 | }
|
---|
2555 | return;
|
---|
2556 | }
|
---|
2557 | }
|
---|
2558 |
|
---|
2559 | if (!strcmp(token, "blocknano")) {
|
---|
2560 | //wildcard is used
|
---|
2561 | if (!strcmp(value,"all")) {
|
---|
2562 | for (i = 0 ; i < 256; i++) {
|
---|
2563 | rdr->b_nano[i] |= 0x01; //set all lsb's to block all nanos
|
---|
2564 | }
|
---|
2565 | }
|
---|
2566 | else {
|
---|
2567 | for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
|
---|
2568 | if ((i = byte_atob(ptr)) >= 0) {
|
---|
2569 | rdr->b_nano[i] |= 0x01; //lsb is set when to block nano
|
---|
2570 | }
|
---|
2571 | }
|
---|
2572 | }
|
---|
2573 | return;
|
---|
2574 | }
|
---|
2575 |
|
---|
2576 | if (!strcmp(token, "savenano")) {
|
---|
2577 | //wildcard is used
|
---|
2578 | if (!strcmp(value,"all")) {
|
---|
2579 | for (i = 0 ; i < 256; i++) {
|
---|
2580 | rdr->b_nano[i] |= 0x02; //set all lsb+1 to save all nanos to file
|
---|
2581 | }
|
---|
2582 | }
|
---|
2583 | else {
|
---|
2584 | for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
|
---|
2585 | if ((i = byte_atob(ptr)) >= 0) {
|
---|
2586 | rdr->b_nano[i] |= 0x02; //lsb+1 is set when to save nano to file
|
---|
2587 | }
|
---|
2588 | }
|
---|
2589 | }
|
---|
2590 | return;
|
---|
2591 | }
|
---|
2592 |
|
---|
2593 | if (!strcmp(token, "cccversion")) {
|
---|
2594 | // cccam version
|
---|
2595 | if (strlen(value) > sizeof(rdr->cc_version) - 1) {
|
---|
2596 | fprintf(stderr, "cccam config: version too long\n");
|
---|
2597 | exit(1);
|
---|
2598 | }
|
---|
2599 | memset(rdr->cc_version, 0, sizeof(rdr->cc_version));
|
---|
2600 | cs_strncpy(rdr->cc_version, value, sizeof(rdr->cc_version));
|
---|
2601 | return;
|
---|
2602 | }
|
---|
2603 |
|
---|
2604 | if (!strcmp(token, "cccbuild")) {
|
---|
2605 | // cccam build number
|
---|
2606 | if (strlen(value) > sizeof(rdr->cc_build) - 1) {
|
---|
2607 | fprintf(stderr, "cccam config build number too long\n");
|
---|
2608 | exit(1);
|
---|
2609 | }
|
---|
2610 |
|
---|
2611 | memset(rdr->cc_build, 0, sizeof(rdr->cc_build));
|
---|
2612 | cs_strncpy(rdr->cc_build, value, sizeof(rdr->cc_build));
|
---|
2613 | return;
|
---|
2614 | }
|
---|
2615 |
|
---|
2616 | if (!strcmp(token, "cccmaxhop")) {
|
---|
2617 | // cccam max card distance
|
---|
2618 | rdr->cc_maxhop = atoi(value);
|
---|
2619 | return;
|
---|
2620 | }
|
---|
2621 |
|
---|
2622 | if (!strcmp(token, "deprecated")) {
|
---|
2623 | rdr->deprecated = atoi(value);
|
---|
2624 | return;
|
---|
2625 | }
|
---|
2626 |
|
---|
2627 | if (token[0] != '#')
|
---|
2628 | cs_log("Warning: keyword '%s' in reader section not recognized",token);
|
---|
2629 | }
|
---|
2630 |
|
---|
2631 | int init_readerdb()
|
---|
2632 | {
|
---|
2633 | int tag = 0, nr;
|
---|
2634 | FILE *fp;
|
---|
2635 | char *value;
|
---|
2636 |
|
---|
2637 | sprintf(token, "%s%s", cs_confdir, cs_srvr);
|
---|
2638 | if (!(fp=fopen(token, "r"))) {
|
---|
2639 | cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
|
---|
2640 | return(1);
|
---|
2641 | }
|
---|
2642 | nr = 0;
|
---|
2643 | while (fgets(token, sizeof(token), fp)) {
|
---|
2644 | int i, l;
|
---|
2645 | if ((l = strlen(trim(token))) < 3)
|
---|
2646 | continue;
|
---|
2647 | if ((token[0] == '[') && (token[l-1] == ']')) {
|
---|
2648 | token[l-1] = 0;
|
---|
2649 | tag = (!strcmp("reader", strtolower(token+1)));
|
---|
2650 | if (reader[nr].label[0] && reader[nr].typ) nr++;
|
---|
2651 | memset(&reader[nr], 0, sizeof(struct s_reader));
|
---|
2652 | reader[nr].enable = 1;
|
---|
2653 | reader[nr].tcp_rto = 30;
|
---|
2654 | reader[nr].show_cls = 10;
|
---|
2655 | reader[nr].maxqlen = CS_MAXQLEN;
|
---|
2656 | reader[nr].mhz = 357;
|
---|
2657 | reader[nr].cardmhz = 357;
|
---|
2658 | reader[nr].deprecated = 0;
|
---|
2659 | strcpy(reader[nr].pincode, "none");
|
---|
2660 | for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff);
|
---|
2661 | continue;
|
---|
2662 | }
|
---|
2663 |
|
---|
2664 | if (!tag)
|
---|
2665 | continue;
|
---|
2666 | if (!(value=strchr(token, '=')))
|
---|
2667 | continue;
|
---|
2668 | *value++ ='\0';
|
---|
2669 | chk_reader(trim(strtolower(token)), trim(value), &reader[nr]);
|
---|
2670 | }
|
---|
2671 | fclose(fp);
|
---|
2672 | return(0);
|
---|
2673 | }
|
---|
2674 |
|
---|
2675 | #ifdef CS_ANTICASC
|
---|
2676 | void init_ac()
|
---|
2677 | {
|
---|
2678 | int nr;
|
---|
2679 | FILE *fp;
|
---|
2680 | //char *value;
|
---|
2681 |
|
---|
2682 | sprintf(token, "%s%s", cs_confdir, cs_ac);
|
---|
2683 | if (!(fp=fopen(token, "r")))
|
---|
2684 | {
|
---|
2685 | cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
|
---|
2686 | token, errno);
|
---|
2687 | return;
|
---|
2688 | }
|
---|
2689 |
|
---|
2690 | for(nr=0; fgets(token, sizeof(token), fp);)
|
---|
2691 | {
|
---|
2692 | int i, skip;
|
---|
2693 | ushort caid, sid, chid, dwtime;
|
---|
2694 | ulong provid;
|
---|
2695 | char *ptr, *ptr1;
|
---|
2696 | struct s_cpmap *ptr_cpmap;
|
---|
2697 | static struct s_cpmap *cpmap=(struct s_cpmap *)0;
|
---|
2698 |
|
---|
2699 | if( strlen(token)<4 ) continue;
|
---|
2700 |
|
---|
2701 | caid=sid=chid=dwtime=0;
|
---|
2702 | provid=0;
|
---|
2703 | skip=0;
|
---|
2704 | ptr1=0;
|
---|
2705 | for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
|
---|
2706 | {
|
---|
2707 | trim(ptr);
|
---|
2708 | if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
|
---|
2709 | skip=1;
|
---|
2710 | break;
|
---|
2711 | }
|
---|
2712 | switch( i )
|
---|
2713 | {
|
---|
2714 | case 0:
|
---|
2715 | ptr1=ptr;
|
---|
2716 | break;
|
---|
2717 | case 1:
|
---|
2718 | dwtime = atoi(ptr);
|
---|
2719 | break;
|
---|
2720 | }
|
---|
2721 | }
|
---|
2722 |
|
---|
2723 | if( !skip )
|
---|
2724 | {
|
---|
2725 | for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
|
---|
2726 | {
|
---|
2727 | trim(ptr);
|
---|
2728 | switch( i )
|
---|
2729 | {
|
---|
2730 | case 0:
|
---|
2731 | if( *ptr=='*' ) caid = 0;
|
---|
2732 | else caid = a2i(ptr, 4);
|
---|
2733 | break;
|
---|
2734 | case 1:
|
---|
2735 | if( *ptr=='*' ) provid = 0;
|
---|
2736 | else provid = a2i(ptr, 6);
|
---|
2737 | break;
|
---|
2738 | case 2:
|
---|
2739 | if( *ptr=='*' ) sid = 0;
|
---|
2740 | else sid = a2i(ptr, 4);
|
---|
2741 | break;
|
---|
2742 | case 3:
|
---|
2743 | if( *ptr=='*' ) chid = 0;
|
---|
2744 | else chid = a2i(ptr, 4);
|
---|
2745 | break;
|
---|
2746 | }
|
---|
2747 | }
|
---|
2748 | if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
|
---|
2749 | {
|
---|
2750 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
2751 | return;
|
---|
2752 | }
|
---|
2753 | if( cpmap )
|
---|
2754 | cpmap->next=ptr_cpmap;
|
---|
2755 | else
|
---|
2756 | cfg->cpmap=ptr_cpmap;
|
---|
2757 | cpmap=ptr_cpmap;
|
---|
2758 |
|
---|
2759 | cpmap->caid = caid;
|
---|
2760 | cpmap->provid = provid;
|
---|
2761 | cpmap->sid = sid;
|
---|
2762 | cpmap->chid = chid;
|
---|
2763 | cpmap->dwtime = dwtime;
|
---|
2764 | cpmap->next = 0;
|
---|
2765 |
|
---|
2766 | cs_debug("nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
|
---|
2767 | nr, caid, provid, sid, chid, dwtime);
|
---|
2768 | nr++;
|
---|
2769 | }
|
---|
2770 | }
|
---|
2771 | fclose(fp);
|
---|
2772 | //cs_log("%d lengths for caid guessing loaded", nr);
|
---|
2773 | return;
|
---|
2774 | }
|
---|
2775 | #endif
|
---|
2776 |
|
---|
2777 | /*
|
---|
2778 | * makes a char ready to write a token into config or webIf
|
---|
2779 | */
|
---|
2780 | char *mk_t_caidtab(CAIDTAB *ctab){
|
---|
2781 | int i = 0, needed = 1, pos = 0;
|
---|
2782 | while(ctab->caid[i]){
|
---|
2783 | if(ctab->mask[i]) needed += 10;
|
---|
2784 | else needed += 5;
|
---|
2785 | if(ctab->cmap[i]) needed += 5;
|
---|
2786 | ++i;
|
---|
2787 | }
|
---|
2788 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
2789 | i = 0;
|
---|
2790 | while(ctab->caid[i]) {
|
---|
2791 | if(i == 0) {
|
---|
2792 | sprintf(value + pos, "%04X", ctab->caid[i]);
|
---|
2793 | pos += 4;
|
---|
2794 | } else {
|
---|
2795 | sprintf(value + pos, ",%04X", ctab->caid[i]);
|
---|
2796 | pos += 5;
|
---|
2797 | }
|
---|
2798 | if(ctab->mask[i]){
|
---|
2799 | sprintf(value + pos, "&%04X", ctab->mask[i]);
|
---|
2800 | pos += 5;
|
---|
2801 | }
|
---|
2802 | if(ctab->cmap[i]){
|
---|
2803 | sprintf(value + pos, ":%04X", ctab->cmap[i]);
|
---|
2804 | pos += 5;
|
---|
2805 | }
|
---|
2806 | ++i;
|
---|
2807 | }
|
---|
2808 | value[pos] = '\0';
|
---|
2809 | return value;
|
---|
2810 | }
|
---|
2811 |
|
---|
2812 | /*
|
---|
2813 | * makes a char ready to write a token into config or webIf
|
---|
2814 | */
|
---|
2815 | char *mk_t_tuntab(TUNTAB *ttab){
|
---|
2816 | int i = 0, needed = 1, pos = 0;
|
---|
2817 | while(ttab->bt_caidfrom[i]){
|
---|
2818 | if(ttab->bt_srvid[i]) needed += 10;
|
---|
2819 | else needed += 5;
|
---|
2820 | if(ttab->bt_caidto[i]) needed += 5;
|
---|
2821 | ++i;
|
---|
2822 | }
|
---|
2823 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
2824 | i = 0;
|
---|
2825 | while(ttab->bt_caidfrom[i]) {
|
---|
2826 | if(i == 0) {
|
---|
2827 | sprintf(value + pos, "%04X", ttab->bt_caidfrom[i]);
|
---|
2828 | pos += 4;
|
---|
2829 | } else {
|
---|
2830 | sprintf(value + pos, ",%04X", ttab->bt_caidfrom[i]);
|
---|
2831 | pos += 5;
|
---|
2832 | }
|
---|
2833 | if(ttab->bt_srvid[i]){
|
---|
2834 | sprintf(value + pos, ".%04X", ttab->bt_srvid[i]);
|
---|
2835 | pos += 5;
|
---|
2836 | }
|
---|
2837 | if(ttab->bt_caidto[i]){
|
---|
2838 | sprintf(value + pos, ":%04X", ttab->bt_caidto[i]);
|
---|
2839 | pos += 5;
|
---|
2840 | }
|
---|
2841 | ++i;
|
---|
2842 | }
|
---|
2843 | value[pos] = '\0';
|
---|
2844 | return value;
|
---|
2845 | }
|
---|
2846 |
|
---|
2847 | /*
|
---|
2848 | * makes a char ready to write a token into config or webIf
|
---|
2849 | */
|
---|
2850 | char *mk_t_group(ulong *grp){
|
---|
2851 | int i = 0, needed = 1, pos = 0, dot = 0;
|
---|
2852 | char grpbit[33];
|
---|
2853 | long2bitchar((long) grp, grpbit);
|
---|
2854 |
|
---|
2855 | for(i = 0; i < 32; i++){
|
---|
2856 | if (grpbit[i] == '1'){
|
---|
2857 | needed += 2;
|
---|
2858 | if(i > 9) needed += 1;
|
---|
2859 | }
|
---|
2860 | }
|
---|
2861 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
2862 |
|
---|
2863 | for(i = 0; i < 32; i++){
|
---|
2864 | if (grpbit[i] == '1'){
|
---|
2865 | if (dot == 0){
|
---|
2866 | sprintf(value + pos, "%d", i+1);
|
---|
2867 | if (i > 9)pos += 2;
|
---|
2868 | else pos += 1;
|
---|
2869 | dot = 1;
|
---|
2870 | } else {
|
---|
2871 | sprintf(value + pos, ",%d", i+1);
|
---|
2872 | if (i > 9)pos += 3;
|
---|
2873 | else pos += 2;
|
---|
2874 | }
|
---|
2875 | }
|
---|
2876 | }
|
---|
2877 | value[pos] = '\0';
|
---|
2878 | return value;
|
---|
2879 | }
|
---|
2880 |
|
---|
2881 | /*
|
---|
2882 | * makes a char ready to write a token into config or webIf
|
---|
2883 | */
|
---|
2884 | char *mk_t_ftab(FTAB *ftab){
|
---|
2885 | int i = 0, j = 0, needed = 1, pos = 0;
|
---|
2886 |
|
---|
2887 | needed = ftab->nfilts * 5;
|
---|
2888 | for (i = 0; i < ftab->nfilts; ++i)
|
---|
2889 | needed += ftab->filts[i].nprids * 7;
|
---|
2890 |
|
---|
2891 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
2892 |
|
---|
2893 | char *dot="";
|
---|
2894 | for (i = 0; i < ftab->nfilts; ++i){
|
---|
2895 | sprintf(value + pos, "%s%04X", dot, ftab->filts[i].caid);
|
---|
2896 | pos += 4;
|
---|
2897 | if (i > 0) pos += 1;
|
---|
2898 | dot=":";
|
---|
2899 | for (j = 0; j < ftab->filts[i].nprids; ++j) {
|
---|
2900 | sprintf(value + pos, "%s%06lX", dot, ftab->filts[i].prids[j]);
|
---|
2901 | pos += 7;
|
---|
2902 | dot=",";
|
---|
2903 | }
|
---|
2904 | dot=";";
|
---|
2905 | }
|
---|
2906 |
|
---|
2907 | value[pos] = '\0';
|
---|
2908 | return value;
|
---|
2909 | }
|
---|