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