1 | //FIXME Not checked on threadsafety yet; after checking please remove this line
|
---|
2 |
|
---|
3 | #include "globals.h"
|
---|
4 | #ifdef CS_WITH_BOXKEYS
|
---|
5 | # include "oscam-boxkeys.np"
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | #define CONFVARWIDTH 30
|
---|
9 |
|
---|
10 | static const char *cs_conf="oscam.conf";
|
---|
11 | static const char *cs_user="oscam.user";
|
---|
12 | static const char *cs_srvr="oscam.server";
|
---|
13 | static const char *cs_srid="oscam.srvid";
|
---|
14 | static const char *cs_trid="oscam.tiers";
|
---|
15 | static const char *cs_l4ca="oscam.guess";
|
---|
16 | static const char *cs_cert="oscam.cert";
|
---|
17 | static const char *cs_sidt="oscam.services";
|
---|
18 | #ifdef CS_ANTICASC
|
---|
19 | static const char *cs_ac="oscam.ac";
|
---|
20 | #endif
|
---|
21 |
|
---|
22 | //Todo #ifdef CCCAM
|
---|
23 | static const char *cs_provid="oscam.provid";
|
---|
24 |
|
---|
25 | #ifdef IRDETO_GUESSING
|
---|
26 | static const char *cs_ird="oscam.ird";
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | static char token[4096];
|
---|
30 |
|
---|
31 | typedef enum cs_proto_type
|
---|
32 | {
|
---|
33 | TAG_GLOBAL, // must be first !
|
---|
34 | TAG_MONITOR, // monitor
|
---|
35 | TAG_CAMD33, // camd 3.3x
|
---|
36 | TAG_CAMD35, // camd 3.5x UDP
|
---|
37 | TAG_NEWCAMD, // newcamd
|
---|
38 | TAG_RADEGAST, // radegast
|
---|
39 | TAG_SERIAL, // serial (static)
|
---|
40 | TAG_CS357X, // camd 3.5x UDP
|
---|
41 | TAG_CS378X, // camd 3.5x TCP
|
---|
42 | TAG_GBOX, // gbox
|
---|
43 | TAG_CCCAM, // cccam
|
---|
44 | TAG_CONSTCW, // constcw
|
---|
45 | TAG_DVBAPI, // dvbapi
|
---|
46 | TAG_WEBIF, // webif
|
---|
47 | TAG_ANTICASC // anti-cascading
|
---|
48 | } cs_proto_type_t;
|
---|
49 |
|
---|
50 | static const char *cctag[]={"global", "monitor", "camd33", "camd35", "newcamd", "radegast", "serial",
|
---|
51 | "cs357x", "cs378x", "gbox", "cccam", "constcw", "dvbapi", "webif", "anticasc", NULL};
|
---|
52 |
|
---|
53 | #ifdef DEBUG_SIDTAB
|
---|
54 | static void show_sidtab(struct s_sidtab *sidtab)
|
---|
55 | {
|
---|
56 | for (; sidtab; sidtab=sidtab->next)
|
---|
57 | {
|
---|
58 | int i;
|
---|
59 | char buf[1024];
|
---|
60 | cs_log("label=%s", sidtab->label);
|
---|
61 | sprintf(buf, "caid(%d)=", sidtab->num_caid);
|
---|
62 | for (i=0; i<sidtab->num_caid; i++)
|
---|
63 | sprintf(buf+strlen(buf), "%04X ", sidtab->caid[i]);
|
---|
64 | cs_log("%s", buf);
|
---|
65 | sprintf(buf, "provider(%d)=", sidtab->num_provid);
|
---|
66 | for (i=0; i<sidtab->num_provid; i++)
|
---|
67 | sprintf(buf+strlen(buf), "%08X ", sidtab->provid[i]);
|
---|
68 | cs_log("%s", buf);
|
---|
69 | sprintf(buf, "services(%d)=", sidtab->num_srvid);
|
---|
70 | for (i=0; i<sidtab->num_srvid; i++)
|
---|
71 | sprintf(buf+strlen(buf), "%04X ", sidtab->srvid[i]);
|
---|
72 | cs_log("%s", buf);
|
---|
73 | }
|
---|
74 | }
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | void chk_iprange(char *value, struct s_ip **base)
|
---|
78 | {
|
---|
79 | int i = 0;
|
---|
80 | char *ptr1, *ptr2;
|
---|
81 | struct s_ip *lip, *cip;
|
---|
82 |
|
---|
83 | for (cip=lip=*base; cip; cip=cip->next)
|
---|
84 | lip = cip;
|
---|
85 | if (!(cip=malloc(sizeof(struct s_ip)))) {
|
---|
86 | fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
|
---|
87 | exit(1);
|
---|
88 | }
|
---|
89 | if (*base)
|
---|
90 | lip->next = cip;
|
---|
91 | else
|
---|
92 | *base = cip;
|
---|
93 |
|
---|
94 | memset(cip, 0, sizeof(struct s_ip));
|
---|
95 | for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) {
|
---|
96 | if (i == 0)
|
---|
97 | ++i;
|
---|
98 | else {
|
---|
99 | if (!(cip=malloc(sizeof(struct s_ip)))) {
|
---|
100 | fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
|
---|
101 | exit(1);
|
---|
102 | }
|
---|
103 | lip->next = cip;
|
---|
104 | memset(cip, 0, sizeof(struct s_ip));
|
---|
105 | }
|
---|
106 |
|
---|
107 | if( (ptr2=strchr(trim(ptr1), '-')) ) {
|
---|
108 | *ptr2++ ='\0';
|
---|
109 | cip->ip[0]=cs_inet_addr(trim(ptr1));
|
---|
110 | cip->ip[1]=cs_inet_addr(trim(ptr2));
|
---|
111 | } else {
|
---|
112 | cip->ip[0]=cip->ip[1]=cs_inet_addr(ptr1);
|
---|
113 | }
|
---|
114 | lip = cip;
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | void chk_caidtab(char *caidasc, CAIDTAB *ctab)
|
---|
119 | {
|
---|
120 | int i;
|
---|
121 | char *ptr1, *ptr2, *ptr3;
|
---|
122 |
|
---|
123 | for (i = 0, ptr1 = strtok(caidasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
|
---|
124 | ulong caid, mask, cmap;
|
---|
125 | if( (ptr3 = strchr(trim(ptr1), ':')) )
|
---|
126 | *ptr3++ = '\0';
|
---|
127 | else
|
---|
128 | ptr3 = "";
|
---|
129 |
|
---|
130 | if( (ptr2 = strchr(trim(ptr1), '&')) )
|
---|
131 | *ptr2++ = '\0';
|
---|
132 | else
|
---|
133 | ptr2 = "";
|
---|
134 |
|
---|
135 | if (((caid = a2i(ptr1, 2)) | (mask = a2i(ptr2,-2)) | (cmap = a2i(ptr3, 2))) < 0x10000) {
|
---|
136 | ctab->caid[i] = caid;
|
---|
137 | ctab->mask[i] = mask;
|
---|
138 | ctab->cmap[i++] = cmap;
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | void chk_tuntab(char *tunasc, TUNTAB *ttab)
|
---|
144 | {
|
---|
145 | int i;
|
---|
146 | char *ptr1, *ptr2, *ptr3;
|
---|
147 |
|
---|
148 | for (i = 0, ptr1 = strtok(tunasc, ","); (i < CS_MAXTUNTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
|
---|
149 | ulong bt_caidfrom, bt_caidto, bt_srvid;
|
---|
150 | if( (ptr3 = strchr(trim(ptr1), ':')) )
|
---|
151 | *ptr3++ = '\0';
|
---|
152 | else
|
---|
153 | ptr3 = "";
|
---|
154 |
|
---|
155 | if( (ptr2 = strchr(trim(ptr1), '.')) )
|
---|
156 | *ptr2++ = '\0';
|
---|
157 | else
|
---|
158 | ptr2 = "";
|
---|
159 |
|
---|
160 | if ((bt_caidfrom = a2i(ptr1, 2)) | (bt_srvid = a2i(ptr2,-2)) | (bt_caidto = a2i(ptr3, 2))) {
|
---|
161 | ttab->bt_caidfrom[i] = bt_caidfrom;
|
---|
162 | ttab->bt_caidto[i] = bt_caidto;
|
---|
163 | ttab->bt_srvid[i++] = bt_srvid;
|
---|
164 | }
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | void chk_services(char *labels, SIDTABBITS *sidok, SIDTABBITS *sidno)
|
---|
169 | {
|
---|
170 | int i;
|
---|
171 | char *ptr;
|
---|
172 | SIDTAB *sidtab;
|
---|
173 | *sidok = *sidno = 0;
|
---|
174 | for (ptr=strtok(labels, ","); ptr; ptr=strtok(NULL, ",")) {
|
---|
175 | for (trim(ptr), i = 0, sidtab = cfg->sidtab; sidtab; sidtab = sidtab->next, i++) {
|
---|
176 | if (!strcmp(sidtab->label, ptr)) *sidok|=((SIDTABBITS)1<<i);
|
---|
177 | if ((ptr[0]=='!') && (!strcmp(sidtab->label, ptr+1))) *sidno|=((SIDTABBITS)1<<i);
|
---|
178 | }
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *D_USE(zType), const char *D_USE(zName), const char *zFiltName)
|
---|
183 | {
|
---|
184 | int i, j;
|
---|
185 | char *ptr1, *ptr2, *ptr3;
|
---|
186 | char *ptr[CS_MAXFILTERS] = {0};
|
---|
187 |
|
---|
188 | memset(ftab, 0, sizeof(FTAB));
|
---|
189 | for( i = 0, ptr1 = strtok(zFilterAsc, ";"); (i < CS_MAXFILTERS) && (ptr1); ptr1 = strtok(NULL, ";"), i++ ) {
|
---|
190 | ptr[i] = ptr1;
|
---|
191 | if( (ptr2 = strchr(trim(ptr1), ':')) ) {
|
---|
192 | *ptr2++ ='\0';
|
---|
193 | ftab->filts[i].caid = (ushort)a2i(ptr1, 4);
|
---|
194 | ptr[i] = ptr2;
|
---|
195 | }
|
---|
196 | else if (zFiltName && zFiltName[0] == 'c') {
|
---|
197 | cs_log("PANIC: CAID field not found in CHID parameter!");
|
---|
198 | cs_exit(1);
|
---|
199 | }
|
---|
200 | ftab->nfilts++;
|
---|
201 | }
|
---|
202 |
|
---|
203 | if( ftab->nfilts ) {
|
---|
204 | cs_debug_mask(D_CLIENT, "%s '%s' %s filter(s):", zType, zName, zFiltName);
|
---|
205 | }
|
---|
206 | for( i = 0; i < ftab->nfilts; i++ ) {
|
---|
207 | cs_debug_mask(D_CLIENT, "CAID #%d: %04X", i, ftab->filts[i].caid);
|
---|
208 | for( j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++ ) {
|
---|
209 | ftab->filts[i].prids[j] = a2i(ptr3,6);
|
---|
210 | ftab->filts[i].nprids++;
|
---|
211 | cs_debug_mask(D_CLIENT, "%s #%d: %06X", zFiltName, j, ftab->filts[i].prids[j]);
|
---|
212 | }
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | void chk_cltab(char *classasc, CLASSTAB *clstab)
|
---|
217 | {
|
---|
218 | int i;
|
---|
219 | char *ptr1;
|
---|
220 | for( i = 0, ptr1 = strtok(classasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",") ) {
|
---|
221 | ptr1 = trim(ptr1);
|
---|
222 | if( ptr1[0] == '!' )
|
---|
223 | clstab->bclass[clstab->bn++] = (uchar)a2i(ptr1+1, 2);
|
---|
224 | else
|
---|
225 | clstab->aclass[clstab->an++] = (uchar)a2i(ptr1, 2);
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | void chk_port_tab(char *portasc, PTAB *ptab)
|
---|
230 | {
|
---|
231 | int i, j, nfilts, ifilt, iport;
|
---|
232 | char *ptr1, *ptr2, *ptr3;
|
---|
233 | char *ptr[CS_MAXPORTS] = {0};
|
---|
234 | int port[CS_MAXPORTS] = {0};
|
---|
235 | int previous_nports = ptab->nports;
|
---|
236 |
|
---|
237 | for (nfilts = i = previous_nports, ptr1 = strtok(portasc, ";"); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ";"), i++) {
|
---|
238 | ptr[i] = ptr1;
|
---|
239 | if( (ptr2=strchr(trim(ptr1), '@')) ) {
|
---|
240 | *ptr2++ ='\0';
|
---|
241 | ptab->ports[i].s_port = atoi(ptr1);
|
---|
242 |
|
---|
243 | //checking for des key for port
|
---|
244 | ptab->ports[i].ncd_key_is_set = 0; //default to 0
|
---|
245 | if( (ptr3=strchr(trim(ptr1), '{')) ) {
|
---|
246 | *ptr3++='\0';
|
---|
247 | if (key_atob14(ptr3, ptab->ports[i].ncd_key))
|
---|
248 | fprintf(stderr, "newcamd: error in DES Key for port %s -> ignored\n", ptr1);
|
---|
249 | else
|
---|
250 | ptab->ports[i].ncd_key_is_set = 1;
|
---|
251 | }
|
---|
252 |
|
---|
253 | ptr[i] = ptr2;
|
---|
254 | port[i] = ptab->ports[i].s_port;
|
---|
255 | ptab->nports++;
|
---|
256 | }
|
---|
257 | nfilts++;
|
---|
258 | }
|
---|
259 |
|
---|
260 | if( nfilts == 1 && strlen(portasc) < 6 && ptab->ports[0].s_port == 0 ) {
|
---|
261 | ptab->ports[0].s_port = atoi(portasc);
|
---|
262 | ptab->nports = 1;
|
---|
263 | }
|
---|
264 |
|
---|
265 | iport = ifilt = previous_nports;
|
---|
266 | for (i=previous_nports; i<nfilts; i++) {
|
---|
267 | if( port[i] != 0 )
|
---|
268 | iport = i;
|
---|
269 | for (j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++) {
|
---|
270 | if( (ptr2=strchr(trim(ptr3), ':')) ) {
|
---|
271 | *ptr2++='\0';
|
---|
272 | ptab->ports[iport].ftab.nfilts++;
|
---|
273 | ifilt = ptab->ports[iport].ftab.nfilts-1;
|
---|
274 | ptab->ports[iport].ftab.filts[ifilt].caid = (ushort)a2i(ptr3, 4);
|
---|
275 | ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6);
|
---|
276 | } else {
|
---|
277 | ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6);
|
---|
278 | }
|
---|
279 | ptab->ports[iport].ftab.filts[ifilt].nprids++;
|
---|
280 | }
|
---|
281 | }
|
---|
282 | }
|
---|
283 |
|
---|
284 | #ifdef NOTUSED
|
---|
285 | static void chk_srvip(char *value, in_addr_t *ip)
|
---|
286 | {
|
---|
287 | int i;
|
---|
288 | char *ptr;
|
---|
289 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
290 | if (i<8) ip[i++] = inet_addr(ptr);
|
---|
291 | }
|
---|
292 | #endif
|
---|
293 |
|
---|
294 | void chk_t_global(const char *token, char *value)
|
---|
295 | {
|
---|
296 |
|
---|
297 | #ifdef QBOXHD_LED
|
---|
298 | if (!strcmp(token, "disableqboxhdled")) {
|
---|
299 | if (strlen(value) == 0) {
|
---|
300 | cfg->disableqboxhdled = 0;
|
---|
301 | return;
|
---|
302 | } else {
|
---|
303 | cfg->disableqboxhdled = atoi(value);
|
---|
304 | return;
|
---|
305 | }
|
---|
306 | }
|
---|
307 | #endif
|
---|
308 |
|
---|
309 | if (!strcmp(token, "disablelog")) {
|
---|
310 | if (strlen(value) == 0) {
|
---|
311 | cfg->disablelog = 0;
|
---|
312 | return;
|
---|
313 | } else {
|
---|
314 | cfg->disablelog = atoi(value);
|
---|
315 | return;
|
---|
316 | }
|
---|
317 | }
|
---|
318 |
|
---|
319 | if (!strcmp(token, "disableuserfile")) {
|
---|
320 | if (strlen(value) == 0) {
|
---|
321 | cfg->disableuserfile = 0;
|
---|
322 | return;
|
---|
323 | } else {
|
---|
324 | cfg->disableuserfile = atoi(value);
|
---|
325 | return;
|
---|
326 | }
|
---|
327 | }
|
---|
328 |
|
---|
329 | if (!strcmp(token, "serverip")) {
|
---|
330 | if (strlen(value) == 0) {
|
---|
331 | cfg->srvip = 0;
|
---|
332 | return;
|
---|
333 | } else {
|
---|
334 | cfg->srvip=inet_addr(value);
|
---|
335 | return;
|
---|
336 | }
|
---|
337 | }
|
---|
338 |
|
---|
339 | if (!strcmp(token, "logfile")) {
|
---|
340 | NULLFREE(cfg->logfile);
|
---|
341 | if (strlen(value) > 0) {
|
---|
342 | if(asprintf(&(cfg->logfile), "%s", value) < 0)
|
---|
343 | fprintf(stderr, "Error allocating string for cfg->logfile\n");
|
---|
344 | }
|
---|
345 | return;
|
---|
346 | }
|
---|
347 |
|
---|
348 | if (!strcmp(token, "usrfile")) {
|
---|
349 | NULLFREE(cfg->usrfile);
|
---|
350 | if (strlen(value) > 0) {
|
---|
351 | if(asprintf(&(cfg->usrfile), "%s", value) < 0)
|
---|
352 | fprintf(stderr, "Error allocating string for cfg->usrfile\n");
|
---|
353 | }
|
---|
354 | return;
|
---|
355 | }
|
---|
356 |
|
---|
357 | if (!strcmp(token, "cwlogdir")) {
|
---|
358 | NULLFREE(cfg->cwlogdir);
|
---|
359 | if (strlen(value) > 0) {
|
---|
360 | if(asprintf(&(cfg->cwlogdir), "%s", value) < 0)
|
---|
361 | fprintf(stderr, "Error allocating string for cfg->cwlogdir\n");
|
---|
362 | }
|
---|
363 | return;
|
---|
364 | }
|
---|
365 |
|
---|
366 | if (!strcmp(token, "usrfileflag")) {
|
---|
367 | if (strlen(value) == 0) {
|
---|
368 | cfg->usrfileflag = 0;
|
---|
369 | return;
|
---|
370 | } else {
|
---|
371 | cfg->usrfileflag = atoi(value);
|
---|
372 | return;
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | if (!strcmp(token, "clienttimeout")) {
|
---|
377 | if (strlen(value) == 0) {
|
---|
378 | cfg->ctimeout = CS_CLIENT_TIMEOUT;
|
---|
379 | return;
|
---|
380 | } else {
|
---|
381 | cfg->ctimeout = atoi(value);
|
---|
382 | if (cfg->ctimeout < 100)
|
---|
383 | cfg->ctimeout *= 1000;
|
---|
384 | return;
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | if (!strcmp(token, "fallbacktimeout")) {
|
---|
389 | if (strlen(value) == 0) {
|
---|
390 | cfg->ftimeout = CS_CLIENT_TIMEOUT / 2;
|
---|
391 | return;
|
---|
392 | } else {
|
---|
393 | cfg->ftimeout = atoi(value);
|
---|
394 | if (cfg->ftimeout < 100)
|
---|
395 | cfg->ftimeout *= 1000;
|
---|
396 | return;
|
---|
397 | }
|
---|
398 | }
|
---|
399 |
|
---|
400 | if (!strcmp(token, "clientmaxidle")) {
|
---|
401 | if (strlen(value) == 0) {
|
---|
402 | cfg->cmaxidle = CS_CLIENT_MAXIDLE;
|
---|
403 | return;
|
---|
404 | } else {
|
---|
405 | cfg->cmaxidle = atoi(value);
|
---|
406 | return;
|
---|
407 | }
|
---|
408 | }
|
---|
409 |
|
---|
410 | if (!strcmp(token, "cachedelay")) {
|
---|
411 | if (strlen(value) == 0) {
|
---|
412 | cfg->delay = CS_DELAY;
|
---|
413 | return;
|
---|
414 | } else {
|
---|
415 | cfg->delay = atoi(value);
|
---|
416 | return;
|
---|
417 | }
|
---|
418 | /*cfg->delay = CS_DELAY;
|
---|
419 | fprintf(stderr, "Parameter %s is deprecated -> ignored\n", token);
|
---|
420 | return;*/
|
---|
421 | }
|
---|
422 |
|
---|
423 | if (!strcmp(token, "bindwait")) {
|
---|
424 | if (strlen(value) == 0) {
|
---|
425 | cfg->bindwait = CS_BIND_TIMEOUT;
|
---|
426 | return;
|
---|
427 | } else {
|
---|
428 | cfg->bindwait = atoi(value);
|
---|
429 | return;
|
---|
430 | }
|
---|
431 | }
|
---|
432 |
|
---|
433 | if (!strcmp(token, "netprio")) {
|
---|
434 | if (strlen(value) == 0) {
|
---|
435 | cfg->netprio = 0;
|
---|
436 | return;
|
---|
437 | } else {
|
---|
438 | cfg->netprio = atoi(value);
|
---|
439 | return;
|
---|
440 | }
|
---|
441 | }
|
---|
442 |
|
---|
443 | if (!strcmp(token, "resolvedelay")) {
|
---|
444 | if (strlen(value) == 0) {
|
---|
445 | cfg->resolvedelay = CS_RESOLVE_DELAY;
|
---|
446 | return;
|
---|
447 | } else {
|
---|
448 | cfg->resolvedelay = atoi(value);
|
---|
449 | return;
|
---|
450 | }
|
---|
451 | }
|
---|
452 |
|
---|
453 | if (!strcmp(token, "clientdyndns")) {
|
---|
454 | if (strlen(value) == 0) {
|
---|
455 | cfg->clientdyndns = 0;
|
---|
456 | return;
|
---|
457 | } else {
|
---|
458 | cfg->clientdyndns = atoi(value);
|
---|
459 | return;
|
---|
460 | }
|
---|
461 | }
|
---|
462 |
|
---|
463 | if (!strcmp(token, "sleep")) {
|
---|
464 | if (strlen(value) == 0) {
|
---|
465 | cfg->tosleep = 0;
|
---|
466 | return;
|
---|
467 | } else {
|
---|
468 | cfg->tosleep = atoi(value);
|
---|
469 | return;
|
---|
470 | }
|
---|
471 | }
|
---|
472 |
|
---|
473 | if (!strcmp(token, "unlockparental")) {
|
---|
474 | if (strlen(value) == 0) {
|
---|
475 | cfg->ulparent = 0;
|
---|
476 | return;
|
---|
477 | } else {
|
---|
478 | cfg->ulparent = atoi(value);
|
---|
479 | return;
|
---|
480 | }
|
---|
481 | }
|
---|
482 |
|
---|
483 | if (!strcmp(token, "nice")) {
|
---|
484 | if (strlen(value) == 0) {
|
---|
485 | cfg->nice = 99;
|
---|
486 | return;
|
---|
487 | } else {
|
---|
488 | cfg->nice = atoi(value);
|
---|
489 | if ((cfg->nice<-20) || (cfg->nice>20)) cfg->nice = 99;
|
---|
490 | if (cfg->nice != 99) cs_setpriority(cfg->nice); // ignore errors
|
---|
491 | return;
|
---|
492 | }
|
---|
493 | }
|
---|
494 |
|
---|
495 | if (!strcmp(token, "serialreadertimeout")) {
|
---|
496 | if (cfg->srtimeout < 100)
|
---|
497 | cfg->srtimeout = atoi(value) * 1000;
|
---|
498 | else
|
---|
499 | cfg->srtimeout = atoi(value);
|
---|
500 | if (cfg->srtimeout <= 0)
|
---|
501 | cfg->srtimeout = 1500;
|
---|
502 | return;
|
---|
503 | }
|
---|
504 |
|
---|
505 | if (!strcmp(token, "maxlogsize")) {
|
---|
506 | if (strlen(value) == 0) {
|
---|
507 | cfg->max_log_size = 10;
|
---|
508 | return;
|
---|
509 | } else {
|
---|
510 | cfg->max_log_size = atoi(value);
|
---|
511 | if( cfg->max_log_size <= 10 )
|
---|
512 | cfg->max_log_size = 10;
|
---|
513 | return;
|
---|
514 | }
|
---|
515 | }
|
---|
516 |
|
---|
517 | if( !strcmp(token, "waitforcards")) {
|
---|
518 | if (strlen(value) == 0) {
|
---|
519 | cfg->waitforcards = 1;
|
---|
520 | return;
|
---|
521 | } else {
|
---|
522 | cfg->waitforcards = atoi(value);
|
---|
523 | return;
|
---|
524 | }
|
---|
525 | }
|
---|
526 |
|
---|
527 | if( !strcmp(token, "preferlocalcards")) {
|
---|
528 | if (strlen(value) == 0) {
|
---|
529 | cfg->preferlocalcards = 0;
|
---|
530 | return;
|
---|
531 | } else {
|
---|
532 | cfg->preferlocalcards = atoi(value);
|
---|
533 | return;
|
---|
534 | }
|
---|
535 | }
|
---|
536 |
|
---|
537 | if( !strcmp(token, "saveinithistory")) {
|
---|
538 | if (strlen(value) == 0) {
|
---|
539 | cfg->saveinithistory = 0;
|
---|
540 | return;
|
---|
541 | } else {
|
---|
542 | cfg->saveinithistory = atoi(value);
|
---|
543 | return;
|
---|
544 | }
|
---|
545 | }
|
---|
546 |
|
---|
547 | if (!strcmp(token, "readerrestartseconds")) {
|
---|
548 | if (strlen(value) == 0) {
|
---|
549 | cfg->reader_restart_seconds = 5;
|
---|
550 | return;
|
---|
551 | } else {
|
---|
552 | cfg->reader_restart_seconds = atoi(value);
|
---|
553 | return;
|
---|
554 | }
|
---|
555 | }
|
---|
556 |
|
---|
557 | if (!strcmp(token, "readerautoloadbalance") || !strcmp(token, "lb_mode")) {
|
---|
558 | if (strlen(value) == 0) {
|
---|
559 | cfg->lb_mode = 0;
|
---|
560 | return;
|
---|
561 | } else {
|
---|
562 | cfg->lb_mode = atoi(value);
|
---|
563 | return;
|
---|
564 | }
|
---|
565 | }
|
---|
566 |
|
---|
567 | if (!strcmp(token, "readerautoloadbalance_save") || !strcmp(token, "lb_save")) {
|
---|
568 | if (strlen(value) == 0) {
|
---|
569 | cfg->lb_save = 0;
|
---|
570 | return;
|
---|
571 | } else {
|
---|
572 | int i = atoi(value);
|
---|
573 | if (i > 0 && i < 100) {
|
---|
574 | cfg->lb_save = 100;
|
---|
575 | fprintf(stderr, "Warning: '%s' corrected to the minimum -> 100\n", token);
|
---|
576 | }
|
---|
577 | else
|
---|
578 | cfg->lb_save = i;
|
---|
579 |
|
---|
580 | return;
|
---|
581 | }
|
---|
582 | }
|
---|
583 |
|
---|
584 | if (!strcmp(token, "lb_nbest_readers")) {
|
---|
585 | if (strlen(value))
|
---|
586 | cfg->lb_nbest_readers = atoi(value);
|
---|
587 | return;
|
---|
588 | }
|
---|
589 |
|
---|
590 | if (!strcmp(token, "lb_nfb_readers")) {
|
---|
591 | if (strlen(value))
|
---|
592 | cfg->lb_nfb_readers = atoi(value);
|
---|
593 | return;
|
---|
594 | }
|
---|
595 |
|
---|
596 | if (!strcmp(token, "lb_min_ecmcount")) {
|
---|
597 | if (strlen(value))
|
---|
598 | cfg->lb_min_ecmcount = atoi(value);
|
---|
599 | return;
|
---|
600 | }
|
---|
601 |
|
---|
602 | if (!strcmp(token, "lb_max_ecmcount")) {
|
---|
603 | if (strlen(value))
|
---|
604 | cfg->lb_max_ecmcount = atoi(value);
|
---|
605 | return;
|
---|
606 | }
|
---|
607 |
|
---|
608 | if (!strcmp(token, "lb_reopen_seconds")) {
|
---|
609 | if (strlen(value))
|
---|
610 | cfg->lb_reopen_seconds = atoi(value);
|
---|
611 | return;
|
---|
612 | }
|
---|
613 |
|
---|
614 | if (!strcmp(token, "resolvegethostbyname")) {
|
---|
615 | if (strlen(value) == 0) {
|
---|
616 | cfg->resolve_gethostbyname = 0;
|
---|
617 | return;
|
---|
618 | } else {
|
---|
619 | cfg->resolve_gethostbyname = atoi(value);
|
---|
620 | return;
|
---|
621 | }
|
---|
622 | }
|
---|
623 |
|
---|
624 | if (!strcmp(token, "failbantime")) {
|
---|
625 | if(strlen(value) == 0) {
|
---|
626 | cfg->failbantime = 0;
|
---|
627 | return;
|
---|
628 | } else {
|
---|
629 | cfg->failbantime = atoi(value);
|
---|
630 | return;
|
---|
631 | }
|
---|
632 | }
|
---|
633 |
|
---|
634 | #ifdef CS_WITH_DOUBLECHECK
|
---|
635 | if (!strcmp(token, "double_check")) {
|
---|
636 | if (strlen(value) == 0) {
|
---|
637 | cfg->double_check = 0;
|
---|
638 | return;
|
---|
639 | } else {
|
---|
640 | cfg->double_check = atoi(value);
|
---|
641 | return;
|
---|
642 | }
|
---|
643 | }
|
---|
644 | #endif
|
---|
645 |
|
---|
646 |
|
---|
647 | if (token[0] != '#')
|
---|
648 | fprintf(stderr, "Warning: keyword '%s' in global section not recognized\n", token);
|
---|
649 | }
|
---|
650 |
|
---|
651 | #ifdef CS_ANTICASC
|
---|
652 | void chk_t_ac(char *token, char *value)
|
---|
653 | {
|
---|
654 | if (!strcmp(token, "enabled")) {
|
---|
655 | cfg->ac_enabled = atoi(value);
|
---|
656 | if( cfg->ac_enabled <= 0 )
|
---|
657 | cfg->ac_enabled = 0;
|
---|
658 | else
|
---|
659 | cfg->ac_enabled = 1;
|
---|
660 | return;
|
---|
661 | }
|
---|
662 |
|
---|
663 | if (!strcmp(token, "numusers")) {
|
---|
664 | cfg->ac_users = atoi(value);
|
---|
665 | if( cfg->ac_users < 0 )
|
---|
666 | cfg->ac_users = 0;
|
---|
667 | return;
|
---|
668 | }
|
---|
669 |
|
---|
670 | if (!strcmp(token, "sampletime")) {
|
---|
671 | cfg->ac_stime = atoi(value);
|
---|
672 | if( cfg->ac_stime < 0 )
|
---|
673 | cfg->ac_stime = 2;
|
---|
674 | return;
|
---|
675 | }
|
---|
676 |
|
---|
677 | if (!strcmp(token, "samples")) {
|
---|
678 | cfg->ac_samples = atoi(value);
|
---|
679 | if( cfg->ac_samples < 2 || cfg->ac_samples > 10)
|
---|
680 | cfg->ac_samples = 10;
|
---|
681 | return;
|
---|
682 | }
|
---|
683 |
|
---|
684 | if (!strcmp(token, "penalty")) {
|
---|
685 | cfg->ac_penalty = atoi(value);
|
---|
686 | if( cfg->ac_penalty < 0 )
|
---|
687 | cfg->ac_penalty = 0;
|
---|
688 | return;
|
---|
689 | }
|
---|
690 |
|
---|
691 | if (!strcmp(token, "aclogfile")) {
|
---|
692 | cs_strncpy(cfg->ac_logfile, value, sizeof(cfg->ac_logfile));
|
---|
693 | return;
|
---|
694 | }
|
---|
695 |
|
---|
696 | if( !strcmp(token, "fakedelay") ) {
|
---|
697 | cfg->ac_fakedelay = atoi(value);
|
---|
698 | if( cfg->ac_fakedelay < 100 || cfg->ac_fakedelay > 1000 )
|
---|
699 | cfg->ac_fakedelay = 1000;
|
---|
700 | return;
|
---|
701 | }
|
---|
702 |
|
---|
703 | if( !strcmp(token, "denysamples") ) {
|
---|
704 | cfg->ac_denysamples = atoi(value);
|
---|
705 | if( cfg->ac_denysamples < 2 || cfg->ac_denysamples > cfg->ac_samples - 1 )
|
---|
706 | cfg->ac_denysamples=cfg->ac_samples-1;
|
---|
707 | return;
|
---|
708 | }
|
---|
709 |
|
---|
710 | if (token[0] != '#')
|
---|
711 | fprintf(stderr, "Warning: keyword '%s' in anticascading section not recognized\n",token);
|
---|
712 | }
|
---|
713 | #endif
|
---|
714 |
|
---|
715 | void chk_t_monitor(char *token, char *value)
|
---|
716 | {
|
---|
717 | if (!strcmp(token, "port")) {
|
---|
718 | if(strlen(value) == 0) {
|
---|
719 | cfg->mon_port = 0;
|
---|
720 | return;
|
---|
721 | } else {
|
---|
722 | cfg->mon_port=atoi(value);
|
---|
723 | return;
|
---|
724 | }
|
---|
725 | }
|
---|
726 |
|
---|
727 | if (!strcmp(token, "serverip")) {
|
---|
728 | if(strlen(value) == 0) {
|
---|
729 | cfg->mon_srvip = 0;
|
---|
730 | return;
|
---|
731 | } else {
|
---|
732 | cfg->mon_srvip=inet_addr(value);
|
---|
733 | return;
|
---|
734 | }
|
---|
735 | }
|
---|
736 |
|
---|
737 | if (!strcmp(token, "nocrypt")) {
|
---|
738 | if(strlen(value) == 0) {
|
---|
739 | clear_sip(&cfg->mon_allowed);
|
---|
740 | return;
|
---|
741 | } else {
|
---|
742 | chk_iprange(value, &cfg->mon_allowed);
|
---|
743 | return;
|
---|
744 | }
|
---|
745 | }
|
---|
746 |
|
---|
747 | if (!strcmp(token, "aulow")) {
|
---|
748 | if(strlen(value) == 0) {
|
---|
749 | cfg->mon_aulow = 0;
|
---|
750 | return;
|
---|
751 | } else {
|
---|
752 | cfg->mon_aulow = atoi(value);
|
---|
753 | return;
|
---|
754 | }
|
---|
755 | }
|
---|
756 |
|
---|
757 | if (!strcmp(token, "monlevel")) {
|
---|
758 | if(strlen(value) == 0) {
|
---|
759 | cfg->mon_level = 0;
|
---|
760 | return;
|
---|
761 | } else {
|
---|
762 | cfg->mon_level = atoi(value);
|
---|
763 | return;
|
---|
764 | }
|
---|
765 | }
|
---|
766 |
|
---|
767 | if (!strcmp(token, "hideclient_to")) {
|
---|
768 | if(strlen(value) == 0) {
|
---|
769 | cfg->mon_hideclient_to = 0;
|
---|
770 | return;
|
---|
771 | } else {
|
---|
772 | cfg->mon_hideclient_to = atoi(value);
|
---|
773 | return;
|
---|
774 | }
|
---|
775 | }
|
---|
776 |
|
---|
777 | if (!strcmp(token, "appendchaninfo")) {
|
---|
778 | if(strlen(value) == 0) {
|
---|
779 | cfg->mon_appendchaninfo = 0;
|
---|
780 | return;
|
---|
781 | } else {
|
---|
782 | cfg->mon_appendchaninfo = atoi(value);
|
---|
783 | return;
|
---|
784 | }
|
---|
785 | }
|
---|
786 |
|
---|
787 | if (token[0] != '#')
|
---|
788 | fprintf(stderr, "Warning: keyword '%s' in monitor section not recognized\n",token);
|
---|
789 | }
|
---|
790 |
|
---|
791 | #ifdef WEBIF
|
---|
792 | void chk_t_webif(char *token, char *value)
|
---|
793 | {
|
---|
794 | if (!strcmp(token, "httpport")) {
|
---|
795 | if(strlen(value) == 0) {
|
---|
796 | cfg->http_port = 0;
|
---|
797 | return;
|
---|
798 | } else {
|
---|
799 | if (value[0]=='+') {
|
---|
800 | #ifdef WITH_SSL
|
---|
801 | cfg->http_use_ssl=1;
|
---|
802 | #else
|
---|
803 | fprintf(stderr, "Warning: OSCam compiled without SSL support.\n");
|
---|
804 | #endif
|
---|
805 | cfg->http_port = atoi(value+1);
|
---|
806 | } else {
|
---|
807 | cfg->http_port = atoi(value);
|
---|
808 | }
|
---|
809 | return;
|
---|
810 | }
|
---|
811 | }
|
---|
812 |
|
---|
813 | if (!strcmp(token, "httpuser")) {
|
---|
814 | cs_strncpy(cfg->http_user, value, sizeof(cfg->http_user));
|
---|
815 | return;
|
---|
816 | }
|
---|
817 |
|
---|
818 | if (!strcmp(token, "httppwd")) {
|
---|
819 | cs_strncpy(cfg->http_pwd, value, sizeof(cfg->http_pwd));
|
---|
820 | return;
|
---|
821 | }
|
---|
822 |
|
---|
823 | if (!strcmp(token, "httpcss")) {
|
---|
824 | cs_strncpy(cfg->http_css, value, sizeof(cfg->http_css));
|
---|
825 | return;
|
---|
826 | }
|
---|
827 |
|
---|
828 | if (!strcmp(token, "httpjscript")) {
|
---|
829 | cs_strncpy(cfg->http_jscript, value, sizeof(cfg->http_jscript));
|
---|
830 | return;
|
---|
831 | }
|
---|
832 |
|
---|
833 | if (!strcmp(token, "httpscript")) {
|
---|
834 | cs_strncpy(cfg->http_script, value, sizeof(cfg->http_script));
|
---|
835 | return;
|
---|
836 | }
|
---|
837 |
|
---|
838 | if (!strcmp(token, "httpcert")) {
|
---|
839 | cs_strncpy(cfg->http_cert, value, sizeof(cfg->http_cert));
|
---|
840 | return;
|
---|
841 | }
|
---|
842 |
|
---|
843 | if (!strcmp(token, "httptpl")) {
|
---|
844 | cfg->http_tpl[0] = '\0';
|
---|
845 | cs_strncpy(cfg->http_tpl, value, sizeof(cfg->http_tpl));
|
---|
846 | if(strlen(value) != 0) {
|
---|
847 | if(strlen(cfg->http_tpl) < (sizeof(cfg->http_tpl)-2) && cfg->http_tpl[strlen(cfg->http_tpl)-1] != '/') {
|
---|
848 | cfg->http_tpl[strlen(cfg->http_tpl)] = '/';
|
---|
849 | cfg->http_tpl[strlen(cfg->http_tpl)] = '\0';
|
---|
850 | }
|
---|
851 | }
|
---|
852 | return;
|
---|
853 | }
|
---|
854 |
|
---|
855 | if (!strcmp(token, "httprefresh")) {
|
---|
856 | if(strlen(value) == 0) {
|
---|
857 | cfg->http_refresh = 0;
|
---|
858 | return;
|
---|
859 | } else {
|
---|
860 | cfg->http_refresh = atoi(value);
|
---|
861 | return;
|
---|
862 | }
|
---|
863 | }
|
---|
864 |
|
---|
865 | if (!strcmp(token, "httphideidleclients")) {
|
---|
866 | if(strlen(value) == 0) {
|
---|
867 | cfg->http_hide_idle_clients = 0;
|
---|
868 | return;
|
---|
869 | } else {
|
---|
870 | cfg->http_hide_idle_clients = atoi(value);
|
---|
871 | return;
|
---|
872 | }
|
---|
873 | }
|
---|
874 |
|
---|
875 | if (!strcmp(token, "httpallowed")) {
|
---|
876 | if(strlen(value) == 0) {
|
---|
877 | clear_sip(&cfg->http_allowed);
|
---|
878 | return;
|
---|
879 | } else {
|
---|
880 | chk_iprange(value, &cfg->http_allowed);
|
---|
881 | return;
|
---|
882 | }
|
---|
883 | }
|
---|
884 |
|
---|
885 | if (!strcmp(token, "httpreadonly")) {
|
---|
886 | if(strlen(value) == 0) {
|
---|
887 | cfg->http_readonly = 0;
|
---|
888 | return;
|
---|
889 | } else {
|
---|
890 | cfg->http_readonly = atoi(value);
|
---|
891 | return;
|
---|
892 | }
|
---|
893 | }
|
---|
894 |
|
---|
895 | if (!strcmp(token, "httpdyndns")) {
|
---|
896 | cs_strncpy((char *)cfg->http_dyndns, value, sizeof(cfg->http_dyndns));
|
---|
897 | return;
|
---|
898 | }
|
---|
899 |
|
---|
900 | if (!strcmp(token, "httpsavefullcfg")) {
|
---|
901 | if(strlen(value) == 0) {
|
---|
902 | cfg->http_full_cfg = 0;
|
---|
903 | return;
|
---|
904 | } else {
|
---|
905 | cfg->http_full_cfg = atoi(value);
|
---|
906 | return;
|
---|
907 | }
|
---|
908 | }
|
---|
909 |
|
---|
910 | if (token[0] != '#')
|
---|
911 | fprintf(stderr, "Warning: keyword '%s' in webif section not recognized\n",token);
|
---|
912 | }
|
---|
913 | #endif
|
---|
914 |
|
---|
915 |
|
---|
916 | void chk_t_camd33(char *token, char *value)
|
---|
917 | {
|
---|
918 | if (!strcmp(token, "port")) {
|
---|
919 | if(strlen(value) == 0) {
|
---|
920 | cfg->c33_port = 0;
|
---|
921 | return;
|
---|
922 | } else {
|
---|
923 | cfg->c33_port = atoi(value);
|
---|
924 | return;
|
---|
925 | }
|
---|
926 | }
|
---|
927 |
|
---|
928 | if (!strcmp(token, "serverip")) {
|
---|
929 | if(strlen(value) == 0) {
|
---|
930 | cfg->c33_srvip = 0;
|
---|
931 | return;
|
---|
932 | } else {
|
---|
933 | cfg->c33_srvip = inet_addr(value);
|
---|
934 | return;
|
---|
935 | }
|
---|
936 | }
|
---|
937 |
|
---|
938 | if (!strcmp(token, "nocrypt")) {
|
---|
939 | if(strlen(value) == 0) {
|
---|
940 | return;
|
---|
941 | } else {
|
---|
942 | chk_iprange(value, &cfg->c33_plain);
|
---|
943 | return;
|
---|
944 | }
|
---|
945 | }
|
---|
946 |
|
---|
947 | if (!strcmp(token, "passive")) {
|
---|
948 | cfg->c33_passive = (value[0]!='0');
|
---|
949 | return;
|
---|
950 | }
|
---|
951 |
|
---|
952 | if (!strcmp(token, "key")) {
|
---|
953 | if(strlen(value) == 0) {
|
---|
954 | cfg->c33_crypted = 0;
|
---|
955 | return;
|
---|
956 | }
|
---|
957 | if (key_atob(value, cfg->c33_key)) {
|
---|
958 | fprintf(stderr, "Configuration camd3.3x: Error in Key\n");
|
---|
959 | exit(1);
|
---|
960 | }
|
---|
961 | cfg->c33_crypted=1;
|
---|
962 | return;
|
---|
963 | }
|
---|
964 |
|
---|
965 | if (token[0] != '#')
|
---|
966 | fprintf(stderr, "Warning: keyword '%s' in camd33 section not recognized\n",token);
|
---|
967 | }
|
---|
968 |
|
---|
969 | void chk_t_camd35(char *token, char *value)
|
---|
970 | {
|
---|
971 | if (!strcmp(token, "port")) {
|
---|
972 | if(strlen(value) == 0) {
|
---|
973 | cfg->c35_port = 0;
|
---|
974 | return;
|
---|
975 | } else {
|
---|
976 | cfg->c35_port = atoi(value);
|
---|
977 | return;
|
---|
978 | }
|
---|
979 | }
|
---|
980 |
|
---|
981 | if (!strcmp(token, "serverip")) {
|
---|
982 | if(strlen(value) == 0) {
|
---|
983 | cfg->c35_srvip = 0;
|
---|
984 | return;
|
---|
985 | } else {
|
---|
986 | cfg->c35_srvip = inet_addr(value);
|
---|
987 | return;
|
---|
988 | }
|
---|
989 | }
|
---|
990 |
|
---|
991 | if (!strcmp(token, "suppresscmd08")) {
|
---|
992 | if(strlen(value) == 0) {
|
---|
993 | cfg->c35_suppresscmd08 = 0;
|
---|
994 | return;
|
---|
995 | } else {
|
---|
996 | cfg->c35_suppresscmd08=atoi(value);
|
---|
997 | return;
|
---|
998 | }
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | if (token[0] != '#')
|
---|
1002 | fprintf(stderr, "Warning: keyword '%s' in camd35 section not recognized\n", token);
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | void chk_t_camd35_tcp(char *token, char *value)
|
---|
1006 | {
|
---|
1007 | if (!strcmp(token, "port")) {
|
---|
1008 | if(strlen(value) == 0) {
|
---|
1009 | clear_ptab(&cfg->c35_tcp_ptab);
|
---|
1010 | return;
|
---|
1011 | } else {
|
---|
1012 | chk_port_tab(value, &cfg->c35_tcp_ptab);
|
---|
1013 | return;
|
---|
1014 | }
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | if (!strcmp(token, "serverip")) {
|
---|
1018 | if(strlen(value) == 0) {
|
---|
1019 | cfg->c35_tcp_srvip = 0;
|
---|
1020 | return;
|
---|
1021 | } else {
|
---|
1022 | cfg->c35_tcp_srvip = inet_addr(value);
|
---|
1023 | return;
|
---|
1024 | }
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | if (token[0] != '#')
|
---|
1028 | fprintf(stderr, "Warning: keyword '%s' in camd35 tcp section not recognized\n", token);
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | void chk_t_newcamd(char *token, char *value)
|
---|
1032 | {
|
---|
1033 | if (!strcmp(token, "port")) {
|
---|
1034 | if(strlen(value) == 0) {
|
---|
1035 | clear_ptab(&cfg->ncd_ptab);
|
---|
1036 | return;
|
---|
1037 | } else {
|
---|
1038 | chk_port_tab(value, &cfg->ncd_ptab);
|
---|
1039 | return;
|
---|
1040 | }
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | if (!strcmp(token, "serverip")) {
|
---|
1044 | if(strlen(value) == 0) {
|
---|
1045 | cfg->ncd_srvip = 0;
|
---|
1046 | return;
|
---|
1047 | } else {
|
---|
1048 | cfg->ncd_srvip = inet_addr(value);
|
---|
1049 | return;
|
---|
1050 | }
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | if (!strcmp(token, "allowed")) {
|
---|
1054 | if(strlen(value) == 0) {
|
---|
1055 | clear_sip(&cfg->ncd_allowed);
|
---|
1056 | return;
|
---|
1057 | } else {
|
---|
1058 | chk_iprange(value, &cfg->ncd_allowed);
|
---|
1059 | return;
|
---|
1060 | }
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | if (!strcmp(token, "key")) {
|
---|
1064 | if(strlen(value) == 0)
|
---|
1065 | return;
|
---|
1066 | if (key_atob14(value, cfg->ncd_key)) {
|
---|
1067 | fprintf(stderr, "Configuration newcamd: Error in Key\n");
|
---|
1068 | exit(1);
|
---|
1069 | }
|
---|
1070 | return;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | if (!strcmp(token, "keepalive")) {
|
---|
1074 | if(strlen(value) == 0) {
|
---|
1075 | cfg->ncd_keepalive = 1;
|
---|
1076 | return;
|
---|
1077 | } else {
|
---|
1078 | cfg->ncd_keepalive = atoi(value);
|
---|
1079 | return;
|
---|
1080 | }
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | if (!strcmp(token, "mgclient")) {
|
---|
1084 | if(strlen(value) == 0) {
|
---|
1085 | cfg->ncd_mgclient = 0;
|
---|
1086 | return;
|
---|
1087 | } else {
|
---|
1088 | cfg->ncd_mgclient = atoi(value);
|
---|
1089 | return;
|
---|
1090 | }
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | if (token[0] != '#')
|
---|
1094 | fprintf(stderr, "Warning: keyword '%s' in newcamd section not recognized\n", token);
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | void chk_t_cccam(char *token, char *value)
|
---|
1098 | {
|
---|
1099 | if (!strcmp(token, "port")) {
|
---|
1100 | if(strlen(value) == 0)
|
---|
1101 | cfg->cc_port = 0;
|
---|
1102 | else
|
---|
1103 | cfg->cc_port = atoi(value);
|
---|
1104 | return;
|
---|
1105 | }
|
---|
1106 | //if (!strcmp(token, "serverip")) { cfg->cc_srvip=inet_addr(value); return; }
|
---|
1107 |
|
---|
1108 | if (!strcmp(token, "reshare")) {
|
---|
1109 | if(strlen(value) == 0)
|
---|
1110 | cfg->cc_reshare = 0;
|
---|
1111 | else
|
---|
1112 | cfg->cc_reshare=atoi(value);
|
---|
1113 | return;
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | if (!strcmp(token, "stealth")) {
|
---|
1117 | if(strlen(value) == 0)
|
---|
1118 | cfg->cc_stealth = 1;
|
---|
1119 | else
|
---|
1120 | cfg->cc_stealth=atoi(value);
|
---|
1121 | return;
|
---|
1122 | }
|
---|
1123 |
|
---|
1124 | if (!strcmp(token, "reshare_mode")) {
|
---|
1125 | if(strlen(value) == 0)
|
---|
1126 | cfg->cc_reshare_services = 0;
|
---|
1127 | else
|
---|
1128 | cfg->cc_reshare_services=atoi(value);
|
---|
1129 | return;
|
---|
1130 | }
|
---|
1131 |
|
---|
1132 | if (!strcmp(token, "ignorereshare")) {
|
---|
1133 | if(strlen(value) == 0)
|
---|
1134 | cfg->cc_ignore_reshare = 0;
|
---|
1135 | else
|
---|
1136 | cfg->cc_ignore_reshare=atoi(value);
|
---|
1137 | return;
|
---|
1138 | }
|
---|
1139 | // cccam version
|
---|
1140 | if (!strcmp(token, "version")) {
|
---|
1141 | if (strlen(value) > sizeof(cfg->cc_version) - 1) {
|
---|
1142 | fprintf(stderr, "cccam config: version too long\n");
|
---|
1143 | exit(1);
|
---|
1144 | }
|
---|
1145 | memset(cfg->cc_version, 0, sizeof(cfg->cc_version));
|
---|
1146 | strncpy((char*)cfg->cc_version, value, sizeof(cfg->cc_version) - 1);
|
---|
1147 | return;
|
---|
1148 | }
|
---|
1149 | // cccam: Update cards interval
|
---|
1150 | if (!strcmp(token, "updateinterval")) {
|
---|
1151 | if (strlen(value) == 0)
|
---|
1152 | cfg->cc_update_interval = 4*60; //4x60s = 4min
|
---|
1153 | else
|
---|
1154 | cfg->cc_update_interval = atoi(value);
|
---|
1155 | return;
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | // cccam: Kind of card updates
|
---|
1159 | if (!strcmp(token, "minimizecards")) {
|
---|
1160 | if (strlen(value) == 0)
|
---|
1161 | cfg->cc_minimize_cards = 0;
|
---|
1162 | else
|
---|
1163 | cfg->cc_minimize_cards = atoi(value);
|
---|
1164 | return;
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | // cccam: keep clients connected
|
---|
1168 | if (!strcmp(token, "keepconnected")) {
|
---|
1169 | if (strlen(value) == 0)
|
---|
1170 | cfg->cc_keep_connected = 1;
|
---|
1171 | else
|
---|
1172 | cfg->cc_keep_connected = atoi(value);
|
---|
1173 | return;
|
---|
1174 | }
|
---|
1175 |
|
---|
1176 |
|
---|
1177 | if (token[0] != '#')
|
---|
1178 | fprintf(stderr, "Warning: keyword '%s' in cccam section not recognized\n",token);
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 | void chk_t_radegast(char *token, char *value)
|
---|
1182 | {
|
---|
1183 | if (!strcmp(token, "port")) {
|
---|
1184 | if(strlen(value) == 0) {
|
---|
1185 | cfg->rad_port = 0;
|
---|
1186 | return;
|
---|
1187 | } else {
|
---|
1188 | cfg->rad_port = atoi(value);
|
---|
1189 | return;
|
---|
1190 | }
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | if (!strcmp(token, "serverip")) {
|
---|
1194 | if(strlen(value) == 0) {
|
---|
1195 | cfg->rad_srvip = 0;
|
---|
1196 | return;
|
---|
1197 | } else {
|
---|
1198 | cfg->rad_srvip = inet_addr(value);
|
---|
1199 | return;
|
---|
1200 | }
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | if (!strcmp(token, "allowed")) {
|
---|
1204 | if(strlen(value) == 0) {
|
---|
1205 | clear_sip(&cfg->rad_allowed);
|
---|
1206 | return;
|
---|
1207 | } else {
|
---|
1208 | chk_iprange(value, &cfg->rad_allowed);
|
---|
1209 | return;
|
---|
1210 | }
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | if (!strcmp(token, "user")) {
|
---|
1214 | cs_strncpy(cfg->rad_usr, value, sizeof(cfg->rad_usr));
|
---|
1215 | return;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | if (token[0] != '#')
|
---|
1219 | fprintf(stderr, "Warning: keyword '%s' in radegast section not recognized\n", token);
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | void chk_t_serial(char *token, char *value)
|
---|
1223 | {
|
---|
1224 | if (!strcmp(token, "device")) {
|
---|
1225 | int l;
|
---|
1226 | l = strlen(cfg->ser_device);
|
---|
1227 | if (l)
|
---|
1228 | cfg->ser_device[l++]=1; // use ctrl-a as delimiter
|
---|
1229 | cs_strncpy(cfg->ser_device+l, value, sizeof(cfg->ser_device)-l);
|
---|
1230 | return;
|
---|
1231 | }
|
---|
1232 | if (token[0] != '#')
|
---|
1233 | fprintf(stderr, "Warning: keyword '%s' in serial section not recognized\n", token);
|
---|
1234 | }
|
---|
1235 |
|
---|
1236 | #ifdef CS_WITH_GBOX
|
---|
1237 | void chk_t_gbox(char *token, char *value)
|
---|
1238 | {
|
---|
1239 | //if (!strcmp(token, "password")) strncpy(cfg->gbox_pwd, i2b(4, a2i(value, 4)), 4);
|
---|
1240 | if (!strcmp(token, "password")) {
|
---|
1241 | cs_atob(cfg->gbox_pwd, value, 4);
|
---|
1242 | return;
|
---|
1243 | }
|
---|
1244 |
|
---|
1245 | if (!strcmp(token, "maxdist")) {
|
---|
1246 | cfg->maxdist=atoi(value);
|
---|
1247 | return;
|
---|
1248 | }
|
---|
1249 |
|
---|
1250 | if (!strcmp(token, "ignorelist")) {
|
---|
1251 | cs_strncpy((char *)cfg->ignorefile, value, sizeof(cfg->ignorefile));
|
---|
1252 | return;
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | if (!strcmp(token, "onlineinfos")) {
|
---|
1256 | cs_strncpy((char *)cfg->gbxShareOnl, value, sizeof(cfg->gbxShareOnl));
|
---|
1257 | return;
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | if (!strcmp(token, "cardinfos")) {
|
---|
1261 | cs_strncpy((char *)cfg->cardfile, value, sizeof(cfg->cardfile));
|
---|
1262 | return;
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | if (!strcmp(token, "locals"))
|
---|
1266 | {
|
---|
1267 | char *ptr1;
|
---|
1268 | int n = 0, i;
|
---|
1269 | for (i = 0, ptr1 = strtok(value, ","); (i < CS_MAXLOCALS) && (ptr1); ptr1 = strtok(NULL, ",")) {
|
---|
1270 | cfg->locals[n++] = a2i(ptr1, 8);
|
---|
1271 | //printf("%i %08X",n,cfg->locals[n-1]);
|
---|
1272 | }
|
---|
1273 | cfg->num_locals = n;
|
---|
1274 | return;
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | if (token[0] != '#')
|
---|
1278 | fprintf(stderr, "Warning: keyword '%s' in gbox section not recognized\n",token);
|
---|
1279 | }
|
---|
1280 | #endif
|
---|
1281 |
|
---|
1282 | #ifdef HAVE_DVBAPI
|
---|
1283 | void chk_t_dvbapi(char *token, char *value)
|
---|
1284 | {
|
---|
1285 | if (!strcmp(token, "enabled")) {
|
---|
1286 | if(strlen(value) == 0) {
|
---|
1287 | cfg->dvbapi_enabled = 0;
|
---|
1288 | } else {
|
---|
1289 | cfg->dvbapi_enabled = atoi(value);
|
---|
1290 | }
|
---|
1291 | return;
|
---|
1292 | }
|
---|
1293 |
|
---|
1294 | if (!strcmp(token, "au")) {
|
---|
1295 | if(strlen(value) == 0) {
|
---|
1296 | cfg->dvbapi_au = 0;
|
---|
1297 | } else {
|
---|
1298 | cfg->dvbapi_au = atoi(value);
|
---|
1299 | }
|
---|
1300 | return;
|
---|
1301 | }
|
---|
1302 |
|
---|
1303 | if (!strcmp(token, "pmt_mode")) {
|
---|
1304 | if(strlen(value) == 0) {
|
---|
1305 | cfg->dvbapi_pmtmode = 0;
|
---|
1306 | } else {
|
---|
1307 | cfg->dvbapi_pmtmode = atoi(value);
|
---|
1308 | }
|
---|
1309 | return;
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | if (!strcmp(token, "boxtype")) {
|
---|
1313 | int i;
|
---|
1314 | for (i=1;i<=BOXTYPES;i++) {
|
---|
1315 | if (strcmp(value, boxdesc[i])==0) {
|
---|
1316 | cfg->dvbapi_boxtype=i;
|
---|
1317 | return;
|
---|
1318 | }
|
---|
1319 | }
|
---|
1320 |
|
---|
1321 | cfg->dvbapi_boxtype=0;
|
---|
1322 | return;
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | if (!strcmp(token, "user")) {
|
---|
1326 | cs_strncpy(cfg->dvbapi_usr, value, sizeof(cfg->dvbapi_usr));
|
---|
1327 | return;
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | if(!strcmp(token, "services")) {
|
---|
1331 | chk_services(value, &cfg->dvbapi_sidtabok, &cfg->dvbapi_sidtabno);
|
---|
1332 | return;
|
---|
1333 | }
|
---|
1334 |
|
---|
1335 | //obsolete
|
---|
1336 | if (!strcmp(token, "priority")) {
|
---|
1337 | dvbapi_chk_caidtab(value, 'p');
|
---|
1338 | return;
|
---|
1339 | }
|
---|
1340 |
|
---|
1341 | if (!strcmp(token, "ignore")) {
|
---|
1342 | dvbapi_chk_caidtab(value, 'i');
|
---|
1343 | return;
|
---|
1344 | }
|
---|
1345 |
|
---|
1346 | if (!strcmp(token, "cw_delay")) {
|
---|
1347 | dvbapi_chk_caidtab(value, 'd');
|
---|
1348 | return;
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | if (token[0] != '#')
|
---|
1352 | fprintf(stderr, "Warning: keyword '%s' in dvbapi section not recognized\n",token);
|
---|
1353 | }
|
---|
1354 | #endif
|
---|
1355 |
|
---|
1356 | static void chk_token(char *token, char *value, int tag)
|
---|
1357 | {
|
---|
1358 | switch(tag) {
|
---|
1359 | case TAG_GLOBAL : chk_t_global(token, value); break;
|
---|
1360 | case TAG_MONITOR : chk_t_monitor(token, value); break;
|
---|
1361 | case TAG_CAMD33 : chk_t_camd33(token, value); break;
|
---|
1362 | case TAG_CAMD35 :
|
---|
1363 | case TAG_CS357X : chk_t_camd35(token, value); break;
|
---|
1364 | case TAG_NEWCAMD : chk_t_newcamd(token, value); break;
|
---|
1365 | case TAG_RADEGAST: chk_t_radegast(token, value); break;
|
---|
1366 | case TAG_SERIAL : chk_t_serial(token, value); break;
|
---|
1367 | case TAG_CS378X : chk_t_camd35_tcp(token, value); break;
|
---|
1368 | case TAG_CCCAM : chk_t_cccam(token, value); break;
|
---|
1369 |
|
---|
1370 | #ifdef CS_WITH_GBOX
|
---|
1371 | case TAG_GBOX : chk_t_gbox(token, value); break;
|
---|
1372 | #else
|
---|
1373 | case TAG_GBOX : fprintf(stderr, "OSCam compiled without gbox support. Parameter %s ignored\n", token); break;
|
---|
1374 | #endif
|
---|
1375 |
|
---|
1376 |
|
---|
1377 | #ifdef HAVE_DVBAPI
|
---|
1378 | case TAG_DVBAPI : chk_t_dvbapi(token, value); break;
|
---|
1379 | #else
|
---|
1380 | case TAG_DVBAPI : fprintf(stderr, "OSCam compiled without DVB API support. Parameter %s ignored\n", token); break;
|
---|
1381 | #endif
|
---|
1382 |
|
---|
1383 |
|
---|
1384 | #ifdef WEBIF
|
---|
1385 | case TAG_WEBIF : chk_t_webif(token, value); break;
|
---|
1386 | #else
|
---|
1387 | case TAG_WEBIF : fprintf(stderr, "OSCam compiled without Webinterface support. Parameter %s ignored\n", token); break;
|
---|
1388 | #endif
|
---|
1389 |
|
---|
1390 |
|
---|
1391 | #ifdef CS_ANTICASC
|
---|
1392 | case TAG_ANTICASC: chk_t_ac(token, value); break;
|
---|
1393 | #else
|
---|
1394 | case TAG_ANTICASC: fprintf(stderr, "OSCam compiled without Anticascading support. Parameter %s ignored\n", token); break;
|
---|
1395 | #endif
|
---|
1396 |
|
---|
1397 | }
|
---|
1398 | }
|
---|
1399 |
|
---|
1400 | void init_len4caid()
|
---|
1401 | {
|
---|
1402 | int nr;
|
---|
1403 | FILE *fp;
|
---|
1404 | char *value;
|
---|
1405 |
|
---|
1406 | memset(len4caid, 0, sizeof(ushort)<<8);
|
---|
1407 | sprintf(token, "%s%s", cs_confdir, cs_l4ca);
|
---|
1408 | if (!(fp = fopen(token, "r")))
|
---|
1409 | return;
|
---|
1410 | for(nr = 0; fgets(token, sizeof(token), fp);) {
|
---|
1411 | int i, c;
|
---|
1412 | char *ptr;
|
---|
1413 | if (!(value=strchr(token, ':')))
|
---|
1414 | continue;
|
---|
1415 | *value++ ='\0';
|
---|
1416 | if( (ptr = strchr(value, '#')) )
|
---|
1417 | *ptr = '\0';
|
---|
1418 | if (strlen(trim(token)) != 2)
|
---|
1419 | continue;
|
---|
1420 | if (strlen(trim(value)) != 4)
|
---|
1421 | continue;
|
---|
1422 | if ((i = byte_atob(token)) < 0)
|
---|
1423 | continue;
|
---|
1424 | if ((c = word_atob(value)) < 0)
|
---|
1425 | continue;
|
---|
1426 | len4caid[i] = c;
|
---|
1427 | nr++;
|
---|
1428 | }
|
---|
1429 | fclose(fp);
|
---|
1430 | cs_log("%d lengths for caid guessing loaded", nr);
|
---|
1431 | return;
|
---|
1432 | }
|
---|
1433 |
|
---|
1434 | int search_boxkey(ushort caid, char *key)
|
---|
1435 | {
|
---|
1436 | int i, rc = 0;
|
---|
1437 | FILE *fp;
|
---|
1438 | char c_caid[512];
|
---|
1439 |
|
---|
1440 | sprintf(c_caid, "%s%s", cs_confdir, cs_cert);
|
---|
1441 | fp = fopen(c_caid, "r");
|
---|
1442 | if (fp) {
|
---|
1443 | for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);) {
|
---|
1444 | char *c_provid, *c_key;
|
---|
1445 |
|
---|
1446 | c_provid = strchr(c_caid, '#');
|
---|
1447 | if (c_provid)
|
---|
1448 | *c_provid = '\0';
|
---|
1449 | if (!(c_provid = strchr(c_caid, ':')))
|
---|
1450 | continue;
|
---|
1451 | *c_provid++ ='\0';
|
---|
1452 | if (!(c_key = strchr(c_provid, ':')))
|
---|
1453 | continue;
|
---|
1454 | *c_key++ ='\0';
|
---|
1455 | if (word_atob(trim(c_caid))!=caid)
|
---|
1456 | continue;
|
---|
1457 | if ((i=(strlen(trim(c_key))>>1)) > 256)
|
---|
1458 | continue;
|
---|
1459 | if (cs_atob((uchar *)key, c_key, i) < 0) {
|
---|
1460 | cs_log("wrong key in \"%s\"", cs_cert);
|
---|
1461 | continue;
|
---|
1462 | }
|
---|
1463 | rc = 1;
|
---|
1464 | }
|
---|
1465 | fclose(fp);
|
---|
1466 | }
|
---|
1467 | #ifdef OSCAM_INBUILD_KEYS
|
---|
1468 | for(i=0; (!rc) && (npkey[i].keylen); i++)
|
---|
1469 | if (rc=((caid==npkey[i].caid) && (npkey[i].provid==0)))
|
---|
1470 | memcpy(key, npkey[i].key, npkey[i].keylen);
|
---|
1471 | #endif
|
---|
1472 | return(rc);
|
---|
1473 | }
|
---|
1474 |
|
---|
1475 | int init_config()
|
---|
1476 | {
|
---|
1477 | int tag=TAG_GLOBAL;
|
---|
1478 | FILE *fp;
|
---|
1479 | char *value;
|
---|
1480 |
|
---|
1481 | #ifndef CS_EMBEDDED
|
---|
1482 | #ifdef PRIO_PROCESS
|
---|
1483 | errno=0;
|
---|
1484 | if ((cfg->nice = getpriority(PRIO_PROCESS, 0)) == (-1))
|
---|
1485 | if (errno)
|
---|
1486 | #endif
|
---|
1487 | #endif
|
---|
1488 | cfg->nice = 99;
|
---|
1489 | cfg->ctimeout = CS_CLIENT_TIMEOUT;
|
---|
1490 | cfg->ftimeout = CS_CLIENT_TIMEOUT / 2;
|
---|
1491 | cfg->cmaxidle = CS_CLIENT_MAXIDLE;
|
---|
1492 | cfg->delay = CS_DELAY;
|
---|
1493 | cfg->bindwait = CS_BIND_TIMEOUT;
|
---|
1494 | cfg->resolvedelay = CS_RESOLVE_DELAY;
|
---|
1495 | cfg->mon_level = 2;
|
---|
1496 | cfg->mon_hideclient_to = 0;
|
---|
1497 | cfg->srtimeout = 1500;
|
---|
1498 | cfg->ulparent = 0;
|
---|
1499 | cfg->logfile = NULL;
|
---|
1500 | cfg->usrfile = NULL;
|
---|
1501 | cfg->cwlogdir = NULL;
|
---|
1502 | cfg->reader_restart_seconds = 5;
|
---|
1503 | cfg->waitforcards = 1;
|
---|
1504 | #ifdef QBOXHD_LED
|
---|
1505 | cfg->disableqboxhdled = 1;
|
---|
1506 | #endif
|
---|
1507 |
|
---|
1508 | #ifdef WEBIF
|
---|
1509 | strcpy(cfg->http_user, "");
|
---|
1510 | strcpy(cfg->http_pwd, "");
|
---|
1511 | strcpy(cfg->http_css, "");
|
---|
1512 | cfg->http_refresh = 0;
|
---|
1513 | cfg->http_hide_idle_clients = 0;
|
---|
1514 | strcpy(cfg->http_tpl, "");
|
---|
1515 | #endif
|
---|
1516 | cfg->ncd_keepalive = 1;
|
---|
1517 | #ifdef CS_ANTICASC
|
---|
1518 | cfg->ac_enabled = 0;
|
---|
1519 | cfg->ac_users = 0;
|
---|
1520 | cfg->ac_stime = 2;
|
---|
1521 | cfg->ac_samples = 10;
|
---|
1522 | cfg->ac_denysamples = 8;
|
---|
1523 | cfg->ac_fakedelay = 1000;
|
---|
1524 | strcpy(cfg->ac_logfile, "./oscam_ac.log");
|
---|
1525 | #endif
|
---|
1526 | #ifdef MODULE_CCCAM
|
---|
1527 | cfg->cc_update_interval = 240;
|
---|
1528 | cfg->cc_keep_connected = 1;
|
---|
1529 | #endif
|
---|
1530 | sprintf(token, "%s%s", cs_confdir, cs_conf);
|
---|
1531 | if (!(fp = fopen(token, "r"))) {
|
---|
1532 | fprintf(stderr, "Cannot open config file '%s' (errno=%d)\n", token, errno);
|
---|
1533 | exit(1);
|
---|
1534 | }
|
---|
1535 | while (fgets(token, sizeof(token), fp)) {
|
---|
1536 | int i, l;
|
---|
1537 | //void *ptr;
|
---|
1538 | if ((l = strlen(trim(token))) < 3)
|
---|
1539 | continue;
|
---|
1540 | if ((token[0] == '[') && (token[l-1] == ']')) {
|
---|
1541 | for (token[l-1] = 0, tag = -1, i = TAG_GLOBAL; cctag[i]; i++)
|
---|
1542 | if (!strcmp(cctag[i], strtolower(token+1)))
|
---|
1543 | tag = i;
|
---|
1544 | continue;
|
---|
1545 | }
|
---|
1546 | if (!(value=strchr(token, '=')))
|
---|
1547 | continue;
|
---|
1548 | *value++ ='\0';
|
---|
1549 | chk_token(trim(strtolower(token)), trim(value), tag);
|
---|
1550 | }
|
---|
1551 | fclose(fp);
|
---|
1552 | #ifdef CS_LOGFILE
|
---|
1553 | if (cfg->logfile == NULL) {
|
---|
1554 | if(asprintf(&(cfg->logfile), "%s", CS_LOGFILE) < 0)
|
---|
1555 | fprintf(stderr, "Error allocating string for cfg->logfile\n");
|
---|
1556 | }
|
---|
1557 | #endif
|
---|
1558 | cs_init_log();
|
---|
1559 | cs_init_statistics();
|
---|
1560 | if (cfg->ftimeout >= cfg->ctimeout) {
|
---|
1561 | cfg->ftimeout = cfg->ctimeout - 100;
|
---|
1562 | cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be smaller than clienttimeout (%lu ms))", cfg->ftimeout, cfg->ctimeout);
|
---|
1563 | }
|
---|
1564 | if(cfg->ftimeout < cfg->srtimeout) {
|
---|
1565 | cfg->ftimeout = cfg->srtimeout + 100;
|
---|
1566 | cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ftimeout, cfg->srtimeout);
|
---|
1567 | }
|
---|
1568 | if(cfg->ctimeout < cfg->srtimeout) {
|
---|
1569 | cfg->ctimeout = cfg->srtimeout + 100;
|
---|
1570 | cs_log("WARNING: clienttimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ctimeout, cfg->srtimeout);
|
---|
1571 | }
|
---|
1572 | #ifdef CS_ANTICASC
|
---|
1573 | if( cfg->ac_denysamples+1 > cfg->ac_samples ) {
|
---|
1574 | cfg->ac_denysamples = cfg->ac_samples - 1;
|
---|
1575 | cs_log("WARNING: DenySamples adjusted to %d", cfg->ac_denysamples);
|
---|
1576 | }
|
---|
1577 | #endif
|
---|
1578 | return 0;
|
---|
1579 | }
|
---|
1580 |
|
---|
1581 | void chk_account(const char *token, char *value, struct s_auth *account)
|
---|
1582 | {
|
---|
1583 | int i;
|
---|
1584 | char *ptr1;
|
---|
1585 |
|
---|
1586 | if (!strcmp(token, "user")) {
|
---|
1587 | cs_strncpy(account->usr, value, sizeof(account->usr));
|
---|
1588 | return;
|
---|
1589 | }
|
---|
1590 |
|
---|
1591 | if (!strcmp(token, "pwd")) {
|
---|
1592 | cs_strncpy(account->pwd, value, sizeof(account->pwd));
|
---|
1593 | return;
|
---|
1594 | }
|
---|
1595 |
|
---|
1596 | if (!strcmp(token, "hostname")) {
|
---|
1597 | cs_strncpy((char *)account->dyndns, value, sizeof(account->dyndns));
|
---|
1598 | return;
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 | if (!strcmp(token, "betatunnel")) {
|
---|
1602 | if(strlen(value) == 0) {
|
---|
1603 | clear_tuntab(&account->ttab);
|
---|
1604 | return;
|
---|
1605 | } else {
|
---|
1606 | chk_tuntab(value, &account->ttab);
|
---|
1607 | return;
|
---|
1608 | }
|
---|
1609 | }
|
---|
1610 |
|
---|
1611 | if (!strcmp(token, "uniq")) {
|
---|
1612 | if(strlen(value) == 0) {
|
---|
1613 | account->uniq = 0;
|
---|
1614 | return;
|
---|
1615 | } else {
|
---|
1616 | account->uniq = atoi(value);
|
---|
1617 | return;
|
---|
1618 | }
|
---|
1619 | }
|
---|
1620 |
|
---|
1621 | if (!strcmp(token, "sleep")) {
|
---|
1622 | if(strlen(value) == 0) {
|
---|
1623 | account->tosleep = 0;
|
---|
1624 | return;
|
---|
1625 | } else {
|
---|
1626 | account->tosleep = atoi(value);
|
---|
1627 | return;
|
---|
1628 | }
|
---|
1629 | }
|
---|
1630 |
|
---|
1631 | if (!strcmp(token, "sleepsend")) {
|
---|
1632 | if(strlen(value) == 0) {
|
---|
1633 | account->c35_sleepsend = 0;
|
---|
1634 | return;
|
---|
1635 | } else {
|
---|
1636 | account->c35_sleepsend = atoi(value);
|
---|
1637 | if (account->c35_sleepsend > 0xFF)
|
---|
1638 | account->c35_sleepsend = 0xFF;
|
---|
1639 | return;
|
---|
1640 | }
|
---|
1641 | }
|
---|
1642 |
|
---|
1643 | if (!strcmp(token, "monlevel")) {
|
---|
1644 | if(strlen(value) == 0) {
|
---|
1645 | account->monlvl = 0;
|
---|
1646 | return;
|
---|
1647 | } else {
|
---|
1648 | account->monlvl = atoi(value);
|
---|
1649 | return;
|
---|
1650 | }
|
---|
1651 | }
|
---|
1652 |
|
---|
1653 | if (!strcmp(token, "caid")) {
|
---|
1654 | if(strlen(value) == 0) {
|
---|
1655 | clear_caidtab(&account->ctab);
|
---|
1656 | return;
|
---|
1657 | } else {
|
---|
1658 | chk_caidtab(value, &account->ctab);
|
---|
1659 | return;
|
---|
1660 | }
|
---|
1661 | }
|
---|
1662 |
|
---|
1663 | if (!strcmp(token, "disabled")) {
|
---|
1664 | if(strlen(value) == 0) {
|
---|
1665 | account->disabled = 0;
|
---|
1666 | return;
|
---|
1667 | } else {
|
---|
1668 | account->disabled = atoi(value);
|
---|
1669 | return;
|
---|
1670 | }
|
---|
1671 | }
|
---|
1672 |
|
---|
1673 | if (!strcmp(token, "suppresscmd08")) {
|
---|
1674 | if(strlen(value) == 0) {
|
---|
1675 | account->c35_suppresscmd08 = 0;
|
---|
1676 | return;
|
---|
1677 | } else {
|
---|
1678 | account->c35_suppresscmd08=atoi(value);
|
---|
1679 | return;
|
---|
1680 | }
|
---|
1681 | }
|
---|
1682 |
|
---|
1683 | if (!strcmp(token, "cccmaxhops")) {
|
---|
1684 | if (strlen(value) == 0) {
|
---|
1685 | account->cccmaxhops = 10;
|
---|
1686 | return;
|
---|
1687 | } else {
|
---|
1688 | account->cccmaxhops = atoi(value);
|
---|
1689 | return;
|
---|
1690 | }
|
---|
1691 | }
|
---|
1692 |
|
---|
1693 | if (!strcmp(token, "cccreshare")) {
|
---|
1694 | if (strlen(value) == 0) {
|
---|
1695 | account->cccreshare = 0;
|
---|
1696 | return;
|
---|
1697 | } else {
|
---|
1698 | account->cccreshare = atoi(value);
|
---|
1699 | return;
|
---|
1700 | }
|
---|
1701 | }
|
---|
1702 |
|
---|
1703 | if (!strcmp(token, "keepalive")) {
|
---|
1704 | if(strlen(value) == 0) {
|
---|
1705 | account->ncd_keepalive = 1;
|
---|
1706 | return;
|
---|
1707 | } else {
|
---|
1708 | account->ncd_keepalive = atoi(value);
|
---|
1709 | return;
|
---|
1710 | }
|
---|
1711 | }
|
---|
1712 | /*
|
---|
1713 | * case insensitive
|
---|
1714 | */
|
---|
1715 | strtolower(value);
|
---|
1716 |
|
---|
1717 | if (!strcmp(token, "au")) {
|
---|
1718 | //set default values for usage during runtime from Webif
|
---|
1719 | account->aureader = NULL;
|
---|
1720 | account->autoau=0;
|
---|
1721 |
|
---|
1722 | if(value && value[0] == '1')
|
---|
1723 | account->autoau = 1;
|
---|
1724 | struct s_reader *rdr;
|
---|
1725 | for (rdr=first_reader; rdr ; rdr=rdr->next)
|
---|
1726 | if ((rdr->label[0]) && (!strncmp(rdr->label, value, strlen(rdr->label))))
|
---|
1727 | account->aureader = rdr;
|
---|
1728 | return;
|
---|
1729 | }
|
---|
1730 |
|
---|
1731 | if (!strcmp(token, "group")) {
|
---|
1732 | account->grp = 0;
|
---|
1733 | for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) {
|
---|
1734 | int g;
|
---|
1735 | g = atoi(ptr1);
|
---|
1736 | if ((g>0) && (g < 65)) account->grp|=(((uint64)1)<<(g-1));
|
---|
1737 | }
|
---|
1738 | return;
|
---|
1739 | }
|
---|
1740 |
|
---|
1741 | if(!strcmp(token, "services")) {
|
---|
1742 | chk_services(value, &account->sidtabok, &account->sidtabno);
|
---|
1743 | return;
|
---|
1744 | }
|
---|
1745 |
|
---|
1746 | if(!strcmp(token, "ident")) { /*ToDo ftab clear*/
|
---|
1747 | chk_ftab(value, &account->ftab, "user", account->usr, "provid");
|
---|
1748 | return;
|
---|
1749 | }
|
---|
1750 |
|
---|
1751 | if(!strcmp(token, "class")) {
|
---|
1752 | chk_cltab(value, &account->cltab);
|
---|
1753 | return;
|
---|
1754 | }
|
---|
1755 |
|
---|
1756 | if(!strcmp(token, "chid")) {
|
---|
1757 | chk_ftab(value, &account->fchid, "user", account->usr, "chid");
|
---|
1758 | return;
|
---|
1759 | }
|
---|
1760 |
|
---|
1761 | if (!strcmp(token, "expdate")) {
|
---|
1762 | if (!value[0]) {
|
---|
1763 | account->expirationdate=(time_t)NULL;
|
---|
1764 | return;
|
---|
1765 | }
|
---|
1766 | struct tm cstime;
|
---|
1767 | memset(&cstime,0,sizeof(cstime));
|
---|
1768 | for (i=0, ptr1=strtok(value, "-/"); (i<3)&&(ptr1); ptr1=strtok(NULL, "-/"), i++) {
|
---|
1769 | switch(i) {
|
---|
1770 | case 0: cstime.tm_year=atoi(ptr1)-1900; break;
|
---|
1771 | case 1: cstime.tm_mon =atoi(ptr1)-1; break;
|
---|
1772 | case 2: cstime.tm_mday=atoi(ptr1); break;
|
---|
1773 | }
|
---|
1774 | }
|
---|
1775 | account->expirationdate=mktime(&cstime);
|
---|
1776 | return;
|
---|
1777 | }
|
---|
1778 |
|
---|
1779 | if (!strcmp(token, "allowedtimeframe")) {
|
---|
1780 | if(strlen(value) == 0) {
|
---|
1781 | account->allowedtimeframe[0] = 0;
|
---|
1782 | account->allowedtimeframe[1] = 0;
|
---|
1783 | } else {
|
---|
1784 | int allowed[4];
|
---|
1785 | if (sscanf(value, "%d:%d-%d:%d", &allowed[0], &allowed[1], &allowed[2], &allowed[3]) != 4) {
|
---|
1786 | account->allowedtimeframe[0] = 0;
|
---|
1787 | account->allowedtimeframe[1] = 0;
|
---|
1788 | fprintf(stderr, "Warning: value '%s' is not valid for allowedtimeframe (hh:mm-hh:mm)\n", value);
|
---|
1789 | } else {
|
---|
1790 | account->allowedtimeframe[0] = (allowed[0]*60) + allowed[1];
|
---|
1791 | account->allowedtimeframe[1] = (allowed[2]*60) + allowed[3];
|
---|
1792 | }
|
---|
1793 | }
|
---|
1794 | return;
|
---|
1795 | }
|
---|
1796 |
|
---|
1797 | if (!strcmp(token, "failban")) {
|
---|
1798 | if(strlen(value) == 0) {
|
---|
1799 | account->failban = 0;
|
---|
1800 | return;
|
---|
1801 | } else {
|
---|
1802 | account->failban = atoi(value);
|
---|
1803 | return;
|
---|
1804 | }
|
---|
1805 | }
|
---|
1806 |
|
---|
1807 | #ifdef CS_ANTICASC
|
---|
1808 | if( !strcmp(token, "numusers") ) {
|
---|
1809 | account->ac_users = atoi(value);
|
---|
1810 | return;
|
---|
1811 | }
|
---|
1812 |
|
---|
1813 | if( !strcmp(token, "penalty") ) {
|
---|
1814 | account->ac_penalty = atoi(value);
|
---|
1815 | return;
|
---|
1816 | }
|
---|
1817 | #endif
|
---|
1818 |
|
---|
1819 | if (token[0] != '#')
|
---|
1820 | fprintf(stderr, "Warning: keyword '%s' in account section not recognized\n",token);
|
---|
1821 | }
|
---|
1822 |
|
---|
1823 | int write_services()
|
---|
1824 | {
|
---|
1825 | int i;
|
---|
1826 | FILE *f;
|
---|
1827 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
1828 | char tmpfile[256];
|
---|
1829 | char destfile[256];
|
---|
1830 | char bakfile[256];
|
---|
1831 |
|
---|
1832 | snprintf(destfile, 255,"%s%s", cs_confdir, cs_sidt);
|
---|
1833 | snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_sidt);
|
---|
1834 | snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_sidt);
|
---|
1835 |
|
---|
1836 | if (!(f=fopen(tmpfile, "w"))){
|
---|
1837 | cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
|
---|
1838 | return(1);
|
---|
1839 | }
|
---|
1840 | fprintf(f,"# oscam.services generated automatically by Streamboard OSCAM %s build #%s\n", CS_VERSION, CS_SVN_VERSION);
|
---|
1841 | fprintf(f,"# Read more: http://streamboard.gmc.to/oscam/browser/trunk/Distribution/doc/txt/oscam.services.txt\n\n");
|
---|
1842 |
|
---|
1843 | while(sidtab != NULL){
|
---|
1844 | fprintf(f,"[%s]\n", sidtab->label);
|
---|
1845 | fprintf_conf(f, CONFVARWIDTH, "caid", "");
|
---|
1846 | for (i=0; i<sidtab->num_caid; i++){
|
---|
1847 | if (i==0) fprintf(f,"%04X", sidtab->caid[i]);
|
---|
1848 | else fprintf(f,",%04X", sidtab->caid[i]);
|
---|
1849 | }
|
---|
1850 | fputc((int)'\n', f);
|
---|
1851 | fprintf_conf(f, CONFVARWIDTH, "provid", "");
|
---|
1852 | for (i=0; i<sidtab->num_provid; i++){
|
---|
1853 | if (i==0) fprintf(f,"%06lX", sidtab->provid[i]);
|
---|
1854 | else fprintf(f,",%06lX", sidtab->provid[i]);
|
---|
1855 | }
|
---|
1856 | fputc((int)'\n', f);
|
---|
1857 | fprintf_conf(f, CONFVARWIDTH, "srvid", "");
|
---|
1858 | for (i=0; i<sidtab->num_srvid; i++){
|
---|
1859 | if (i==0) fprintf(f,"%04X", sidtab->srvid[i]);
|
---|
1860 | else fprintf(f,",%04X", sidtab->srvid[i]);
|
---|
1861 | }
|
---|
1862 | fprintf(f,"\n\n");
|
---|
1863 | sidtab=sidtab->next;
|
---|
1864 | }
|
---|
1865 |
|
---|
1866 | fclose(f);
|
---|
1867 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
1868 | }
|
---|
1869 |
|
---|
1870 | int write_config()
|
---|
1871 | {
|
---|
1872 | int i,j;
|
---|
1873 | FILE *f;
|
---|
1874 | char *dot = "", *dot1 = "", *dot2 = ""; //flags for delimiters
|
---|
1875 | char tmpfile[256];
|
---|
1876 | char destfile[256];
|
---|
1877 | char bakfile[256];
|
---|
1878 |
|
---|
1879 | snprintf(destfile, 255,"%s%s", cs_confdir, cs_conf);
|
---|
1880 | snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_conf);
|
---|
1881 | snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_conf);
|
---|
1882 |
|
---|
1883 | if (!(f=fopen(tmpfile, "w"))){
|
---|
1884 | cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
|
---|
1885 | return(1);
|
---|
1886 | }
|
---|
1887 | fprintf(f,"# oscam.conf generated automatically by Streamboard OSCAM %s build #%s\n", CS_VERSION, CS_SVN_VERSION);
|
---|
1888 | fprintf(f,"# Read more: http://streamboard.gmc.to/oscam/browser/trunk/Distribution/doc/txt/oscam.conf.txt\n\n");
|
---|
1889 |
|
---|
1890 | /*global settings*/
|
---|
1891 | fprintf(f,"[global]\n");
|
---|
1892 | if (cfg->srvip != 0 || (cfg->srvip == 0 && cfg->http_full_cfg))
|
---|
1893 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->srvip));
|
---|
1894 | if (cfg->usrfile != NULL || (cfg->usrfile == NULL && cfg->http_full_cfg))
|
---|
1895 | fprintf_conf(f, CONFVARWIDTH, "usrfile", "%s\n", cfg->usrfile);
|
---|
1896 | if (cfg->logfile != NULL || (cfg->logfile == NULL && cfg->http_full_cfg))
|
---|
1897 | fprintf_conf(f, CONFVARWIDTH, "logfile", "%s\n", cfg->logfile);
|
---|
1898 | if (cfg->cwlogdir != NULL || (cfg->cwlogdir == NULL && cfg->http_full_cfg))
|
---|
1899 | fprintf_conf(f, CONFVARWIDTH, "cwlogdir", "%s\n", cfg->cwlogdir);
|
---|
1900 | #ifdef QBOXHD_LED
|
---|
1901 | if (cfg->disableqboxhdled || (!cfg->disableqboxhdled && cfg->http_full_cfg))
|
---|
1902 | fprintf_conf(f, CONFVARWIDTH, "disableqboxhdled", "%d\n", cfg->disableqboxhdled);
|
---|
1903 | #endif
|
---|
1904 | if (cfg->disablelog || (!cfg->disablelog && cfg->http_full_cfg))
|
---|
1905 | fprintf_conf(f, CONFVARWIDTH, "disablelog", "%d\n", cfg->disablelog);
|
---|
1906 | if (cfg->disableuserfile || (!cfg->disableuserfile && cfg->http_full_cfg))
|
---|
1907 | fprintf_conf(f, CONFVARWIDTH, "disableuserfile", "%d\n", cfg->disableuserfile);
|
---|
1908 | if (cfg->usrfileflag || (!cfg->usrfileflag && cfg->http_full_cfg))
|
---|
1909 | fprintf_conf(f, CONFVARWIDTH, "usrfileflag", "%d\n", cfg->usrfileflag);
|
---|
1910 | if (cfg->ctimeout != CS_CLIENT_TIMEOUT || (cfg->ctimeout != CS_CLIENT_TIMEOUT && cfg->http_full_cfg))
|
---|
1911 | fprintf_conf(f, CONFVARWIDTH, "clienttimeout", "%ld\n", cfg->ctimeout);
|
---|
1912 | if ((cfg->ftimeout && cfg->ftimeout != (CS_CLIENT_TIMEOUT /2)) || ((!cfg->ftimeout || cfg->ftimeout == (CS_CLIENT_TIMEOUT /2)) && cfg->http_full_cfg))
|
---|
1913 | fprintf_conf(f, CONFVARWIDTH, "fallbacktimeout", "%ld\n", cfg->ftimeout);
|
---|
1914 | if (cfg->cmaxidle != CS_CLIENT_MAXIDLE || (cfg->cmaxidle == CS_CLIENT_MAXIDLE && cfg->http_full_cfg))
|
---|
1915 | fprintf_conf(f, CONFVARWIDTH, "clientmaxidle", "%d\n", cfg->cmaxidle);
|
---|
1916 | if (cfg->failbantime || (!cfg->failbantime && cfg->http_full_cfg))
|
---|
1917 | fprintf_conf(f, CONFVARWIDTH, "failbantime", "%d\n", cfg->failbantime);
|
---|
1918 | if (cfg->delay != CS_DELAY || (cfg->delay == CS_DELAY && cfg->http_full_cfg))
|
---|
1919 | fprintf_conf(f, CONFVARWIDTH, "cachedelay", "%ld\n", cfg->delay); //deprecated
|
---|
1920 | if (cfg->bindwait != CS_BIND_TIMEOUT || (cfg->bindwait != CS_BIND_TIMEOUT && cfg->http_full_cfg))
|
---|
1921 | fprintf_conf(f, CONFVARWIDTH, "bindwait", "%d\n", cfg->bindwait);
|
---|
1922 | if (cfg->netprio || (!cfg->netprio && cfg->http_full_cfg))
|
---|
1923 | fprintf_conf(f, CONFVARWIDTH, "netprio", "%ld\n", cfg->netprio);
|
---|
1924 | if (cfg->clientdyndns || (!cfg->clientdyndns && cfg->http_full_cfg))
|
---|
1925 | fprintf_conf(f, CONFVARWIDTH, "clientdyndns", "%d\n", cfg->clientdyndns);
|
---|
1926 | if (cfg->resolvedelay != CS_RESOLVE_DELAY || (cfg->resolvedelay == CS_RESOLVE_DELAY && cfg->http_full_cfg))
|
---|
1927 | fprintf_conf(f, CONFVARWIDTH, "resolvedelay", "%d\n", cfg->resolvedelay);
|
---|
1928 | if (cfg->tosleep ||(!cfg->tosleep && cfg->http_full_cfg))
|
---|
1929 | fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", cfg->tosleep);
|
---|
1930 | if (cfg->ulparent ||(!cfg->ulparent && cfg->http_full_cfg))
|
---|
1931 | fprintf_conf(f, CONFVARWIDTH, "unlockparental", "%d\n", cfg->ulparent);
|
---|
1932 | if (cfg->nice != 99 || (cfg->nice == 99 && cfg->http_full_cfg))
|
---|
1933 | fprintf_conf(f, CONFVARWIDTH, "nice", "%d\n", cfg->nice);
|
---|
1934 | if (cfg->srtimeout != 1500 || (cfg->srtimeout == 1500 && cfg->http_full_cfg))
|
---|
1935 | fprintf_conf(f, CONFVARWIDTH, "serialreadertimeout", "%d\n", cfg->srtimeout);
|
---|
1936 | if (cfg->max_log_size != 10 || (cfg->max_log_size == 10 && cfg->http_full_cfg))
|
---|
1937 | fprintf_conf(f, CONFVARWIDTH, "maxlogsize", "%d\n", cfg->max_log_size);
|
---|
1938 | if (!cfg->waitforcards ||(cfg->waitforcards && cfg->http_full_cfg))
|
---|
1939 | fprintf_conf(f, CONFVARWIDTH, "waitforcards", "%d\n", cfg->waitforcards);
|
---|
1940 | if (cfg->preferlocalcards ||(!cfg->preferlocalcards && cfg->http_full_cfg))
|
---|
1941 | fprintf_conf(f, CONFVARWIDTH, "preferlocalcards", "%d\n", cfg->preferlocalcards);
|
---|
1942 | if (cfg->saveinithistory ||(!cfg->saveinithistory && cfg->http_full_cfg))
|
---|
1943 | fprintf_conf(f, CONFVARWIDTH, "saveinithistory", "%d\n", cfg->saveinithistory);
|
---|
1944 | if (cfg->reader_restart_seconds != 5 ||(cfg->reader_restart_seconds == 5 && cfg->http_full_cfg))
|
---|
1945 | fprintf_conf(f, CONFVARWIDTH, "readerrestartseconds", "%d\n", cfg->reader_restart_seconds);
|
---|
1946 |
|
---|
1947 | if (cfg->lb_mode ||(!cfg->lb_mode && cfg->http_full_cfg))
|
---|
1948 | fprintf_conf(f, CONFVARWIDTH, "lb_mode", "%d\n", cfg->lb_mode);
|
---|
1949 | if (cfg->lb_save ||(!cfg->lb_save && cfg->http_full_cfg))
|
---|
1950 | fprintf_conf(f, CONFVARWIDTH, "lb_save", "%d\n", cfg->lb_save);
|
---|
1951 | if (cfg->lb_nbest_readers != DEFAULT_NBEST ||(cfg->lb_nbest_readers == DEFAULT_NBEST && cfg->http_full_cfg))
|
---|
1952 | fprintf_conf(f, CONFVARWIDTH, "lb_nbest_readers", "%d\n", cfg->lb_nbest_readers);
|
---|
1953 | if (cfg->lb_nfb_readers != DEFAULT_NFB ||(cfg->lb_nfb_readers == DEFAULT_NFB && cfg->http_full_cfg))
|
---|
1954 | fprintf_conf(f, CONFVARWIDTH, "lb_nfb_readers", "%d\n", cfg->lb_nfb_readers);
|
---|
1955 | if (cfg->lb_min_ecmcount != DEFAULT_MIN_ECM_COUNT ||(cfg->lb_min_ecmcount == DEFAULT_MIN_ECM_COUNT && cfg->http_full_cfg))
|
---|
1956 | fprintf_conf(f, CONFVARWIDTH, "lb_min_ecmcount", "%d\n", cfg->lb_min_ecmcount);
|
---|
1957 | if (cfg->lb_max_ecmcount != DEFAULT_MAX_ECM_COUNT ||(cfg->lb_max_ecmcount == DEFAULT_MAX_ECM_COUNT && cfg->http_full_cfg))
|
---|
1958 | fprintf_conf(f, CONFVARWIDTH, "lb_max_ecmcount", "%d\n", cfg->lb_max_ecmcount);
|
---|
1959 | if (cfg->lb_reopen_seconds != DEFAULT_REOPEN_SECONDS ||(cfg->lb_reopen_seconds == DEFAULT_REOPEN_SECONDS && cfg->http_full_cfg))
|
---|
1960 | fprintf_conf(f, CONFVARWIDTH, "lb_reopen_seconds", "%d\n", cfg->lb_reopen_seconds);
|
---|
1961 |
|
---|
1962 | if (cfg->resolve_gethostbyname ||(!cfg->resolve_gethostbyname && cfg->http_full_cfg))
|
---|
1963 | fprintf_conf(f, CONFVARWIDTH, "resolvegethostbyname", "%d\n", cfg->resolve_gethostbyname);
|
---|
1964 |
|
---|
1965 | #ifdef CS_WITH_DOUBLECHECK
|
---|
1966 | if (cfg->double_check ||(!cfg->double_check && cfg->http_full_cfg))
|
---|
1967 | fprintf_conf(f, CONFVARWIDTH, "double_check", "%d\n", cfg->double_check);
|
---|
1968 | #endif
|
---|
1969 |
|
---|
1970 | fputc((int)'\n', f);
|
---|
1971 |
|
---|
1972 | /*monitor settings*/
|
---|
1973 | if(cfg->mon_port || cfg->mon_appendchaninfo || cfg->mon_hideclient_to) {
|
---|
1974 | fprintf(f,"[monitor]\n");
|
---|
1975 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->mon_port);
|
---|
1976 | if (cfg->mon_srvip != 0)
|
---|
1977 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip));
|
---|
1978 |
|
---|
1979 | fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
|
---|
1980 | struct s_ip *cip;
|
---|
1981 | for (cip = cfg->mon_allowed; cip; cip = cip->next){
|
---|
1982 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
1983 | if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
1984 | dot=",";
|
---|
1985 | }
|
---|
1986 | fputc((int)'\n', f);
|
---|
1987 | fprintf_conf(f, CONFVARWIDTH, "aulow", "%d\n", cfg->mon_aulow);
|
---|
1988 | fprintf_conf(f, CONFVARWIDTH, "hideclient_to", "%d\n", cfg->mon_hideclient_to);
|
---|
1989 | fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", cfg->mon_level);
|
---|
1990 | fprintf_conf(f, CONFVARWIDTH, "appendchaninfo", "%d\n", cfg->mon_appendchaninfo);
|
---|
1991 | fputc((int)'\n', f);
|
---|
1992 | }
|
---|
1993 |
|
---|
1994 | /*newcamd*/
|
---|
1995 | if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)){
|
---|
1996 | fprintf(f,"[newcamd]\n");
|
---|
1997 | fprintf_conf(f, CONFVARWIDTH, "port", "");
|
---|
1998 | dot1 = "";
|
---|
1999 | for(i = 0; i < cfg->ncd_ptab.nports; ++i){
|
---|
2000 | fprintf(f,"%s%d", dot1, cfg->ncd_ptab.ports[i].s_port);
|
---|
2001 |
|
---|
2002 | // separate DES Key
|
---|
2003 | if(cfg->ncd_ptab.ports[i].ncd_key_is_set){
|
---|
2004 | int k;
|
---|
2005 | fprintf(f,"{");
|
---|
2006 | for (k = 0; k < 14; k++)
|
---|
2007 | fprintf(f,"%02X", cfg->ncd_ptab.ports[i].ncd_key[k]);
|
---|
2008 | fprintf(f,"}");
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | fprintf(f,"@%04X", cfg->ncd_ptab.ports[i].ftab.filts[0].caid);
|
---|
2012 |
|
---|
2013 | if (cfg->ncd_ptab.ports[i].ftab.filts[0].nprids > 0){
|
---|
2014 | fprintf(f,":");
|
---|
2015 | dot2 = "";
|
---|
2016 | for (j = 0; j < cfg->ncd_ptab.ports[i].ftab.filts[0].nprids; ++j){
|
---|
2017 | fprintf(f,"%s%06X", dot2, (int)cfg->ncd_ptab.ports[i].ftab.filts[0].prids[j]);
|
---|
2018 | dot2 = ",";
|
---|
2019 | }
|
---|
2020 | }
|
---|
2021 | dot1=";";
|
---|
2022 | }
|
---|
2023 |
|
---|
2024 | fputc((int)'\n', f);
|
---|
2025 | if (cfg->ncd_srvip != 0)
|
---|
2026 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->ncd_srvip));
|
---|
2027 | fprintf_conf(f, CONFVARWIDTH, "key", "");
|
---|
2028 | for (i = 0; i < 14; i++) fprintf(f,"%02X", cfg->ncd_key[i]);
|
---|
2029 | fprintf(f,"\n");
|
---|
2030 | fprintf_conf(f, CONFVARWIDTH, "allowed", "");
|
---|
2031 | struct s_ip *cip;
|
---|
2032 | dot="";
|
---|
2033 | for (cip = cfg->ncd_allowed; cip; cip = cip->next){
|
---|
2034 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
2035 | if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
2036 | dot=",";
|
---|
2037 | }
|
---|
2038 | fprintf(f,"\n");
|
---|
2039 | fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", cfg->ncd_keepalive);
|
---|
2040 | fprintf_conf(f, CONFVARWIDTH, "mgclient", "%d\n", cfg->ncd_mgclient);
|
---|
2041 | fprintf(f,"\n");
|
---|
2042 | }
|
---|
2043 |
|
---|
2044 | /*camd3.3*/
|
---|
2045 | if ( cfg->c33_port > 0) {
|
---|
2046 | fprintf(f,"[camd33]\n");
|
---|
2047 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c33_port);
|
---|
2048 | if (cfg->c33_srvip != 0)
|
---|
2049 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip));
|
---|
2050 | fprintf_conf(f, CONFVARWIDTH, "passive", "%d\n", cfg->c33_passive);
|
---|
2051 | 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);
|
---|
2052 | fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
|
---|
2053 | struct s_ip *cip;
|
---|
2054 | dot="";
|
---|
2055 | for (cip = cfg->c33_plain; cip; cip = cip->next){
|
---|
2056 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
2057 | if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
2058 | dot=",";
|
---|
2059 | }
|
---|
2060 | fprintf(f,"\n\n");
|
---|
2061 | }
|
---|
2062 |
|
---|
2063 | /*camd3.5*/
|
---|
2064 | if ( cfg->c35_port > 0) {
|
---|
2065 | fprintf(f,"[cs357x]\n");
|
---|
2066 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c35_port);
|
---|
2067 | if (cfg->c35_srvip != 0)
|
---|
2068 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_srvip));
|
---|
2069 | if (cfg->c35_suppresscmd08)
|
---|
2070 | fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", cfg->c35_suppresscmd08);
|
---|
2071 | fprintf(f,"\n");
|
---|
2072 | }
|
---|
2073 |
|
---|
2074 | /*camd3.5 TCP*/
|
---|
2075 | if ((cfg->c35_tcp_ptab.nports > 0) && (cfg->c35_tcp_ptab.ports[0].s_port > 0)) {
|
---|
2076 | fprintf(f,"[cs378x]\n");
|
---|
2077 | fprintf_conf(f, CONFVARWIDTH, "port", "");
|
---|
2078 | dot1 = "";
|
---|
2079 | for(i = 0; i < cfg->c35_tcp_ptab.nports; ++i){
|
---|
2080 | fprintf(f,"%s%d@%04X", dot1, cfg->c35_tcp_ptab.ports[i].s_port, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].caid);
|
---|
2081 | if (cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 1){
|
---|
2082 | fprintf(f,":");
|
---|
2083 | dot2 = "";
|
---|
2084 | for (j = 0; j < cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j){
|
---|
2085 | fprintf(f,"%s%lX", dot2, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]);
|
---|
2086 | dot2 = ",";
|
---|
2087 | }
|
---|
2088 | }
|
---|
2089 | dot1=";";
|
---|
2090 | }
|
---|
2091 |
|
---|
2092 | fputc((int)'\n', f);
|
---|
2093 | if (cfg->c35_tcp_srvip != 0)
|
---|
2094 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
|
---|
2095 | fputc((int)'\n', f);
|
---|
2096 | }
|
---|
2097 |
|
---|
2098 | /*Radegast*/
|
---|
2099 | if ( cfg->rad_port > 0) {
|
---|
2100 | fprintf(f,"[radegast]\n");
|
---|
2101 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->rad_port);
|
---|
2102 | if (cfg->rad_srvip != 0)
|
---|
2103 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->rad_srvip));
|
---|
2104 | fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->rad_usr);
|
---|
2105 | fprintf_conf(f, CONFVARWIDTH, "allowed", "");
|
---|
2106 | struct s_ip *cip;
|
---|
2107 | dot="";
|
---|
2108 | for (cip = cfg->rad_allowed; cip; cip = cip->next){
|
---|
2109 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
2110 | if (cip->ip[0] != cip->ip[1])
|
---|
2111 | fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
2112 | dot=",";
|
---|
2113 | }
|
---|
2114 | fprintf(f,"\n\n");
|
---|
2115 | }
|
---|
2116 |
|
---|
2117 | #ifdef CS_WITH_GBOX
|
---|
2118 | /*Gbox*/
|
---|
2119 | if ((cfg->gbox_pwd[0] > 0) || (cfg->gbox_pwd[1] > 0) || (cfg->gbox_pwd[2] > 0) || (cfg->gbox_pwd[3] > 0)){
|
---|
2120 | fprintf(f,"[gbox]\n");
|
---|
2121 | fprintf_conf(f, CONFVARWIDTH, "password", ""); for (i=0;i<4;i++) fprintf(f,"%02X", cfg->gbox_pwd[i]); fputc((int)'\n', f);;
|
---|
2122 | fprintf_conf(f, CONFVARWIDTH, "maxdist", "%d\n", cfg->maxdist);
|
---|
2123 | fprintf_conf(f, CONFVARWIDTH, "ignorelist", "%s\n", cfg->ignorefile);
|
---|
2124 | fprintf_conf(f, CONFVARWIDTH, "onlineinfos", "%s\n", cfg->gbxShareOnl);
|
---|
2125 | fprintf_conf(f, CONFVARWIDTH, "cardinfos", "%s\n", cfg->cardfile);
|
---|
2126 | fprintf_conf(f, CONFVARWIDTH, "locals", "");
|
---|
2127 | char *dot = "";
|
---|
2128 | for (i = 0; i < cfg->num_locals; i++){
|
---|
2129 | fprintf(f,"%s%06lX", dot, cfg->locals[i]);
|
---|
2130 | dot=";";
|
---|
2131 | }
|
---|
2132 | fprintf(f,"\n\n");
|
---|
2133 | }
|
---|
2134 | #endif
|
---|
2135 |
|
---|
2136 | /*serial*/
|
---|
2137 | if (cfg->ser_device[0]){
|
---|
2138 | fprintf(f,"[serial]\n");
|
---|
2139 | char sdevice[512];
|
---|
2140 | cs_strncpy(sdevice, cfg->ser_device, sizeof(sdevice));
|
---|
2141 | char *ptr;
|
---|
2142 | char delimiter[2]; delimiter[0] = 1; delimiter[1] = '\0';
|
---|
2143 |
|
---|
2144 | ptr = strtok(sdevice, delimiter);
|
---|
2145 | while(ptr != NULL) {
|
---|
2146 | fprintf_conf(f, CONFVARWIDTH, "device", "%s\n", ptr);
|
---|
2147 | ptr = strtok(NULL, delimiter);
|
---|
2148 | }
|
---|
2149 | fprintf(f,"\n");
|
---|
2150 | }
|
---|
2151 |
|
---|
2152 | /*cccam*/
|
---|
2153 | if ( cfg->cc_port > 0) {
|
---|
2154 | fprintf(f,"[cccam]\n");
|
---|
2155 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->cc_port);
|
---|
2156 | fprintf_conf(f, CONFVARWIDTH, "reshare", "%d\n", cfg->cc_reshare);
|
---|
2157 | fprintf_conf(f, CONFVARWIDTH, "ignorereshare", "%d\n", cfg->cc_ignore_reshare);
|
---|
2158 | fprintf_conf(f, CONFVARWIDTH, "version", "%s\n", cfg->cc_version);
|
---|
2159 | fprintf_conf(f, CONFVARWIDTH, "updateinterval", "%d\n", cfg->cc_update_interval);
|
---|
2160 | fprintf_conf(f, CONFVARWIDTH, "minimizecards", "%d\n", cfg->cc_minimize_cards);
|
---|
2161 | fprintf_conf(f, CONFVARWIDTH, "keepconnected", "%d\n", cfg->cc_keep_connected);
|
---|
2162 | fprintf(f,"\n");
|
---|
2163 | }
|
---|
2164 |
|
---|
2165 | #ifdef HAVE_DVBAPI
|
---|
2166 | /*dvb-api*/
|
---|
2167 | if (cfg->dvbapi_enabled > 0) {
|
---|
2168 | fprintf(f,"[dvbapi]\n");
|
---|
2169 | fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->dvbapi_enabled);
|
---|
2170 | fprintf_conf(f, CONFVARWIDTH, "au", "%d\n", cfg->dvbapi_au);
|
---|
2171 | fprintf_conf(f, CONFVARWIDTH, "boxtype", "%s\n", boxdesc[cfg->dvbapi_boxtype]);
|
---|
2172 | fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->dvbapi_usr);
|
---|
2173 | fprintf_conf(f, CONFVARWIDTH, "pmt_mode", "%d\n", cfg->dvbapi_pmtmode);
|
---|
2174 |
|
---|
2175 | fputc((int)'\n', f);
|
---|
2176 | }
|
---|
2177 | #endif
|
---|
2178 |
|
---|
2179 | #ifdef WEBIF
|
---|
2180 | /*webinterface*/
|
---|
2181 | if (cfg->http_port > 0) {
|
---|
2182 | fprintf(f,"[webif]\n");
|
---|
2183 | if (cfg->http_use_ssl) {
|
---|
2184 | fprintf_conf(f, CONFVARWIDTH, "httpport", "+%d\n", cfg->http_port);
|
---|
2185 | } else {
|
---|
2186 | fprintf_conf(f, CONFVARWIDTH, "httpport", "%d\n", cfg->http_port);
|
---|
2187 | }
|
---|
2188 | if(strlen(cfg->http_user) > 0)
|
---|
2189 | fprintf_conf(f, CONFVARWIDTH, "httpuser", "%s\n", cfg->http_user);
|
---|
2190 | if(strlen(cfg->http_pwd) > 0)
|
---|
2191 | fprintf_conf(f, CONFVARWIDTH, "httppwd", "%s\n", cfg->http_pwd);
|
---|
2192 | if(strlen(cfg->http_cert) > 0)
|
---|
2193 | fprintf_conf(f, CONFVARWIDTH, "httpcert", "%s\n", cfg->http_cert);
|
---|
2194 | if(strlen(cfg->http_css) > 0)
|
---|
2195 | fprintf_conf(f, CONFVARWIDTH, "httpcss", "%s\n", cfg->http_css);
|
---|
2196 | if(strlen(cfg->http_jscript) > 0)
|
---|
2197 | fprintf_conf(f, CONFVARWIDTH, "httpjscript", "%s\n", cfg->http_jscript);
|
---|
2198 | if(strlen(cfg->http_tpl) > 0)
|
---|
2199 | fprintf_conf(f, CONFVARWIDTH, "httptpl", "%s\n", cfg->http_tpl);
|
---|
2200 | if(strlen(cfg->http_script) > 0)
|
---|
2201 | fprintf_conf(f, CONFVARWIDTH, "httpscript", "%s\n", cfg->http_script);
|
---|
2202 | fprintf_conf(f, CONFVARWIDTH, "httprefresh", "%d\n", cfg->http_refresh);
|
---|
2203 | fprintf_conf(f, CONFVARWIDTH, "httpallowed", "");
|
---|
2204 | struct s_ip *cip;
|
---|
2205 | dot = "";
|
---|
2206 | for (cip = cfg->http_allowed; cip; cip = cip->next){
|
---|
2207 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
2208 | if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
2209 | dot = ",";
|
---|
2210 | }
|
---|
2211 | fputc((int)'\n', f);
|
---|
2212 | if(strlen((const char *) (cfg->http_dyndns)) > 0)
|
---|
2213 | fprintf_conf(f, CONFVARWIDTH, "httpdyndns", "%s\n", cfg->http_dyndns);
|
---|
2214 | fprintf_conf(f, CONFVARWIDTH, "httphideidleclients", "%d\n", cfg->http_hide_idle_clients);
|
---|
2215 | fprintf_conf(f, CONFVARWIDTH, "httpreadonly", "%d\n", cfg->http_readonly);
|
---|
2216 | fprintf_conf(f, CONFVARWIDTH, "httpsavefullcfg", "%d\n", cfg->http_full_cfg);
|
---|
2217 |
|
---|
2218 | fputc((int)'\n', f);
|
---|
2219 | }
|
---|
2220 | #endif
|
---|
2221 |
|
---|
2222 | #ifdef CS_ANTICASC
|
---|
2223 | if(cfg->ac_enabled) {
|
---|
2224 | fprintf(f,"[anticasc]\n");
|
---|
2225 | fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->ac_enabled);
|
---|
2226 | fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", cfg->ac_users);
|
---|
2227 | fprintf_conf(f, CONFVARWIDTH, "sampletime", "%d\n", cfg->ac_stime);
|
---|
2228 | fprintf_conf(f, CONFVARWIDTH, "samples", "%d\n", cfg->ac_samples);
|
---|
2229 | fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", cfg->ac_penalty);
|
---|
2230 | fprintf_conf(f, CONFVARWIDTH, "aclogfile", "%s\n", cfg->ac_logfile);
|
---|
2231 | fprintf_conf(f, CONFVARWIDTH, "denysamples", "%d\n", cfg->ac_denysamples);
|
---|
2232 | fprintf_conf(f, CONFVARWIDTH, "fakedelay", "%d\n", cfg->ac_fakedelay);
|
---|
2233 | fputc((int)'\n', f);
|
---|
2234 | }
|
---|
2235 | #endif
|
---|
2236 |
|
---|
2237 | fclose(f);
|
---|
2238 |
|
---|
2239 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
2240 | }
|
---|
2241 |
|
---|
2242 | int write_userdb(struct s_auth *authptr)
|
---|
2243 | {
|
---|
2244 | int i;
|
---|
2245 | FILE *f;
|
---|
2246 | struct s_auth *account;
|
---|
2247 | char *value;
|
---|
2248 | char *dot = ""; //flag for comma
|
---|
2249 | char tmpfile[256];
|
---|
2250 | char destfile[256];
|
---|
2251 | char bakfile[256];
|
---|
2252 |
|
---|
2253 | snprintf(destfile, 255,"%s%s", cs_confdir, cs_user);
|
---|
2254 | snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_user);
|
---|
2255 | snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_user);
|
---|
2256 |
|
---|
2257 | if (!(f=fopen(tmpfile, "w"))){
|
---|
2258 | cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
|
---|
2259 | return(1);
|
---|
2260 | }
|
---|
2261 | fprintf(f,"# oscam.user generated automatically by Streamboard OSCAM %s build #%s\n", CS_VERSION, CS_SVN_VERSION);
|
---|
2262 | fprintf(f,"# Read more: http://streamboard.gmc.to/oscam/browser/trunk/Distribution/doc/txt/oscam.user.txt\n\n");
|
---|
2263 |
|
---|
2264 | //each account
|
---|
2265 | for (account=authptr; (account) ; account=account->next){
|
---|
2266 | fprintf(f,"[account]\n");
|
---|
2267 | fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", account->usr);
|
---|
2268 | fprintf_conf(f, CONFVARWIDTH, "pwd", "%s\n", account->pwd);
|
---|
2269 |
|
---|
2270 | if (account->disabled || (!account->disabled && cfg->http_full_cfg))
|
---|
2271 | fprintf_conf(f, CONFVARWIDTH, "disabled", "%d\n", account->disabled);
|
---|
2272 |
|
---|
2273 | if (account->expirationdate || (!account->expirationdate && cfg->http_full_cfg)) {
|
---|
2274 | struct tm * timeinfo = localtime (&account->expirationdate);
|
---|
2275 | char buf [80];
|
---|
2276 | strftime (buf,80,"%Y-%m-%d",timeinfo);
|
---|
2277 | if(strcmp(buf,"1970-01-01"))
|
---|
2278 | fprintf_conf(f, CONFVARWIDTH, "expdate", "%s\n", buf);
|
---|
2279 | else
|
---|
2280 | fprintf_conf(f, CONFVARWIDTH, "expdate", "\n");
|
---|
2281 | }
|
---|
2282 |
|
---|
2283 |
|
---|
2284 | if(account->allowedtimeframe[0] && account->allowedtimeframe[1]) {
|
---|
2285 | fprintf_conf(f, CONFVARWIDTH, "allowedtimeframe", "%02d:%02d-%02d:%02d\n",
|
---|
2286 | account->allowedtimeframe[0]/60,
|
---|
2287 | account->allowedtimeframe[0]%60,
|
---|
2288 | account->allowedtimeframe[1]/60,
|
---|
2289 | account->allowedtimeframe[1]%60 );
|
---|
2290 | } else {
|
---|
2291 | if (cfg->http_full_cfg)
|
---|
2292 | fprintf_conf(f, CONFVARWIDTH, "allowedtimeframe", "\n");
|
---|
2293 | }
|
---|
2294 |
|
---|
2295 | //group
|
---|
2296 | if (account->grp || (!account->grp && cfg->http_full_cfg)) {
|
---|
2297 | value = mk_t_group(account->grp);
|
---|
2298 | fprintf_conf(f, CONFVARWIDTH, "group", "%s\n", value);
|
---|
2299 | free(value);
|
---|
2300 | }
|
---|
2301 |
|
---|
2302 | if (account->dyndns[0] || (!account->dyndns[0] && cfg->http_full_cfg))
|
---|
2303 | fprintf_conf(f, CONFVARWIDTH, "hostname", "%s\n", account->dyndns);
|
---|
2304 |
|
---|
2305 | if (account->uniq || (!account->uniq && cfg->http_full_cfg))
|
---|
2306 | fprintf_conf(f, CONFVARWIDTH, "uniq", "%d\n", account->uniq);
|
---|
2307 |
|
---|
2308 | if (account->tosleep || (!account->tosleep && cfg->http_full_cfg))
|
---|
2309 | fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", account->tosleep);
|
---|
2310 |
|
---|
2311 | if (account->monlvl || (!account->monlvl && cfg->http_full_cfg))
|
---|
2312 | fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", account->monlvl);
|
---|
2313 |
|
---|
2314 | if (account->aureader)
|
---|
2315 | fprintf_conf(f, CONFVARWIDTH, "au", "%s\n", account->aureader->label);
|
---|
2316 | if (account->autoau == 1)
|
---|
2317 | fprintf_conf(f, CONFVARWIDTH, "au", "1\n");
|
---|
2318 |
|
---|
2319 | if ((account->sidtabok + account->sidtabno > 0) || ((account->sidtabok + account->sidtabno == 0) && cfg->http_full_cfg)) {
|
---|
2320 | fprintf_conf(f, CONFVARWIDTH, "services", "");
|
---|
2321 | char sidok[MAX_SIDBITS+1]; sidtabbits2bitchar(account->sidtabok,sidok);
|
---|
2322 | char sidno[MAX_SIDBITS+1]; sidtabbits2bitchar(account->sidtabno,sidno);
|
---|
2323 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
2324 | i=0; dot = "";
|
---|
2325 | for (; sidtab; sidtab=sidtab->next){
|
---|
2326 | if(sidok[i]=='1') {fprintf(f,"%s%s", dot, sidtab->label); dot = ",";}
|
---|
2327 | if(sidno[i]=='1') {fprintf(f,"%s!%s", dot, sidtab->label); dot = ",";}
|
---|
2328 | i++;
|
---|
2329 | }
|
---|
2330 | fputc((int)'\n', f);
|
---|
2331 | }
|
---|
2332 |
|
---|
2333 | //CAID
|
---|
2334 | if (account->ctab.caid[0] || (!account->ctab.caid[0] && cfg->http_full_cfg)) {
|
---|
2335 | value = mk_t_caidtab(&account->ctab);
|
---|
2336 | fprintf_conf(f, CONFVARWIDTH, "caid", "%s\n", value);
|
---|
2337 | free(value);
|
---|
2338 | }
|
---|
2339 |
|
---|
2340 | //betatunnel
|
---|
2341 | if (account->ttab.bt_caidfrom[0] || (!account->ttab.bt_caidfrom[0] && cfg->http_full_cfg)) {
|
---|
2342 | value = mk_t_tuntab(&account->ttab);
|
---|
2343 | fprintf_conf(f, CONFVARWIDTH, "betatunnel", "%s\n", value);
|
---|
2344 | free(value);
|
---|
2345 | }
|
---|
2346 |
|
---|
2347 | //ident
|
---|
2348 | if (account->ftab.nfilts || (!account->ftab.nfilts && cfg->http_full_cfg)) {
|
---|
2349 | value = mk_t_ftab(&account->ftab);
|
---|
2350 | fprintf_conf(f, CONFVARWIDTH, "ident", "%s\n", value);
|
---|
2351 | free(value);
|
---|
2352 | }
|
---|
2353 |
|
---|
2354 | //CHID
|
---|
2355 | if (account->fchid.nfilts || (!account->fchid.nfilts && cfg->http_full_cfg)) {
|
---|
2356 | value = mk_t_ftab(&account->fchid);
|
---|
2357 | fprintf_conf(f, CONFVARWIDTH, "chid", "%s\n", value);
|
---|
2358 | free(value);
|
---|
2359 | }
|
---|
2360 |
|
---|
2361 | if ((account->c35_suppresscmd08 != cfg->c35_suppresscmd08) || ((account->c35_suppresscmd08 == cfg->c35_suppresscmd08) && cfg->http_full_cfg))
|
---|
2362 | fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", account->c35_suppresscmd08);
|
---|
2363 |
|
---|
2364 | if (account->cccmaxhops != 10 || ((account->cccmaxhops == 10) && cfg->http_full_cfg))
|
---|
2365 | fprintf_conf(f, CONFVARWIDTH, "cccmaxhops", "%d\n", account->cccmaxhops);
|
---|
2366 |
|
---|
2367 | if ((account->cccreshare != cfg->cc_reshare) || ((account->cccreshare == cfg->cc_reshare) && cfg->http_full_cfg))
|
---|
2368 | fprintf_conf(f, CONFVARWIDTH, "cccreshare", "%d\n", account->cccreshare);
|
---|
2369 |
|
---|
2370 | if (account->c35_sleepsend || (!account->c35_sleepsend && cfg->http_full_cfg))
|
---|
2371 | fprintf_conf(f, CONFVARWIDTH, "sleepsend", "%d\n", account->c35_sleepsend);
|
---|
2372 |
|
---|
2373 | if (account->failban || (!account->failban && cfg->http_full_cfg))
|
---|
2374 | fprintf_conf(f, CONFVARWIDTH, "failban", "%d\n", account->failban);
|
---|
2375 |
|
---|
2376 | if ((account->ncd_keepalive != cfg->ncd_keepalive) || ((account->ncd_keepalive == cfg->ncd_keepalive) && cfg->http_full_cfg))
|
---|
2377 | fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", account->ncd_keepalive);
|
---|
2378 |
|
---|
2379 | #ifdef CS_ANTICASC
|
---|
2380 | if (account->ac_users || (!account->ac_users && cfg->http_full_cfg))
|
---|
2381 | fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", account->ac_users);
|
---|
2382 | if (account->ac_penalty || (!account->ac_penalty && cfg->http_full_cfg))
|
---|
2383 | fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", account->ac_penalty);
|
---|
2384 | #endif
|
---|
2385 | fputc((int)'\n', f);
|
---|
2386 | }
|
---|
2387 | fclose(f);
|
---|
2388 |
|
---|
2389 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
2390 | }
|
---|
2391 |
|
---|
2392 | int write_server()
|
---|
2393 | {
|
---|
2394 | int j;
|
---|
2395 | char *value;
|
---|
2396 | FILE *f;
|
---|
2397 |
|
---|
2398 | char *dot = ""; //flag for comma
|
---|
2399 | char tmpfile[256];
|
---|
2400 | char destfile[256];
|
---|
2401 | char bakfile[256];
|
---|
2402 |
|
---|
2403 | snprintf(destfile, 255,"%s%s", cs_confdir, cs_srvr);
|
---|
2404 | snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_srvr);
|
---|
2405 | snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_srvr);
|
---|
2406 |
|
---|
2407 | if (!(f=fopen(tmpfile, "w"))){
|
---|
2408 | cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
|
---|
2409 | return(1);
|
---|
2410 | }
|
---|
2411 | fprintf(f,"# oscam.server generated automatically by Streamboard OSCAM %s build #%s\n", CS_VERSION, CS_SVN_VERSION);
|
---|
2412 | fprintf(f,"# Read more: http://streamboard.gmc.to/oscam/browser/trunk/Distribution/doc/txt/oscam.server.txt\n\n");
|
---|
2413 |
|
---|
2414 | struct s_reader *rdr;
|
---|
2415 | for (rdr=first_reader; rdr ; rdr=rdr->next) {
|
---|
2416 | if ( rdr->label[0] && !rdr->deleted) {
|
---|
2417 | fprintf(f,"[reader]\n");
|
---|
2418 |
|
---|
2419 | fprintf_conf(f, CONFVARWIDTH, "label", "%s\n", rdr->label);
|
---|
2420 | fprintf_conf(f, CONFVARWIDTH, "enable", "%d\n", rdr->enable);
|
---|
2421 | char *ctyp = reader_get_type_desc(rdr, 0);
|
---|
2422 |
|
---|
2423 | fprintf_conf(f, CONFVARWIDTH, "protocol", "%s\n", ctyp);
|
---|
2424 |
|
---|
2425 | fprintf_conf(f, CONFVARWIDTH, "device", "%s", rdr->device);
|
---|
2426 | if (rdr->r_port)
|
---|
2427 | fprintf(f, ",%d", rdr->r_port);
|
---|
2428 | if (rdr->l_port)
|
---|
2429 | fprintf(f, ",%d", rdr->l_port);
|
---|
2430 | fprintf(f, "\n");
|
---|
2431 |
|
---|
2432 | #ifdef LIBUSB
|
---|
2433 | if (!(rdr->typ & R_IS_NETWORK))
|
---|
2434 | if (rdr->device_endpoint)
|
---|
2435 | fprintf_conf(f, CONFVARWIDTH, "device_out_endpoint", "0x%2X\n", rdr->device_endpoint);
|
---|
2436 | #endif
|
---|
2437 |
|
---|
2438 | if (rdr->ncd_key[0] || rdr->ncd_key[13]) {
|
---|
2439 | fprintf_conf(f, CONFVARWIDTH, "key", "");
|
---|
2440 | for (j = 0; j < 14; j++) {
|
---|
2441 | fprintf(f, "%02X", rdr->ncd_key[j]);
|
---|
2442 | }
|
---|
2443 | fprintf(f, "\n");
|
---|
2444 | }
|
---|
2445 |
|
---|
2446 | int isphysical = (rdr->typ & R_IS_NETWORK)?0:1;
|
---|
2447 | if (rdr->r_usr[0] && !isphysical)
|
---|
2448 | fprintf_conf(f, CONFVARWIDTH, "account", "%s\n", rdr->r_usr);
|
---|
2449 |
|
---|
2450 | #ifdef CS_WITH_GBOX
|
---|
2451 | if (rdr->typ == R_GBOX) {
|
---|
2452 | if (strlen(rdr->gbox_pwd) > 0)
|
---|
2453 | fprintf_conf(f, CONFVARWIDTH, "password", "%s\n", rdr->gbox_pwd);
|
---|
2454 | fprintf_conf(f, CONFVARWIDTH, "premium", "%d\n", rdr->gbox_prem);
|
---|
2455 | }
|
---|
2456 | #endif
|
---|
2457 |
|
---|
2458 | if (strlen(rdr->r_pwd) > 0)
|
---|
2459 | fprintf_conf(f, CONFVARWIDTH, "password", "%s\n", rdr->r_pwd);
|
---|
2460 |
|
---|
2461 | if(strcmp(rdr->pincode, "none"))
|
---|
2462 | fprintf_conf(f, CONFVARWIDTH, "pincode", "%s\n", rdr->pincode);
|
---|
2463 |
|
---|
2464 | if (rdr->emmfile && isphysical)
|
---|
2465 | fprintf_conf(f, CONFVARWIDTH, "readnano", "%s\n", rdr->emmfile);
|
---|
2466 |
|
---|
2467 | fprintf_conf(f, CONFVARWIDTH, "services", "");
|
---|
2468 | char sidok[MAX_SIDBITS+1]; sidtabbits2bitchar(rdr->sidtabok, sidok);
|
---|
2469 | char sidno[MAX_SIDBITS+1]; sidtabbits2bitchar(rdr->sidtabno, sidno);
|
---|
2470 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
2471 | j=0; dot = "";
|
---|
2472 | for (; sidtab; sidtab=sidtab->next){
|
---|
2473 | if(sidok[j]=='1') {fprintf(f,"%s%s", dot, sidtab->label); dot = ",";}
|
---|
2474 | if(sidno[j]=='1') {fprintf(f,"%s!%s", dot, sidtab->label); dot = ",";}
|
---|
2475 | j++;
|
---|
2476 | }
|
---|
2477 | fputc((int)'\n', f);
|
---|
2478 |
|
---|
2479 | if (rdr->tcp_ito && !isphysical)
|
---|
2480 | fprintf_conf(f, CONFVARWIDTH, "inactivitytimeout", "%d\n", rdr->tcp_ito);
|
---|
2481 |
|
---|
2482 | if (rdr->tcp_rto && !isphysical )
|
---|
2483 | fprintf_conf(f, CONFVARWIDTH, "reconnecttimeout", "%d\n", rdr->tcp_rto);
|
---|
2484 |
|
---|
2485 | if (rdr->ncd_disable_server_filt && !isphysical)
|
---|
2486 | fprintf_conf(f, CONFVARWIDTH, "disableserverfilter", "%d\n", rdr->ncd_disable_server_filt);
|
---|
2487 |
|
---|
2488 | if (rdr->smargopatch && isphysical)
|
---|
2489 | fprintf_conf(f, CONFVARWIDTH, "smargopatch", "%d\n", rdr->smargopatch);
|
---|
2490 |
|
---|
2491 | if (rdr->fallback)
|
---|
2492 | fprintf_conf(f, CONFVARWIDTH, "fallback", "%d\n", rdr->fallback);
|
---|
2493 |
|
---|
2494 | if (rdr->log_port)
|
---|
2495 | fprintf_conf(f, CONFVARWIDTH, "logport", "%d\n", rdr->log_port);
|
---|
2496 |
|
---|
2497 | value = mk_t_caidtab(&rdr->ctab);
|
---|
2498 | fprintf_conf(f, CONFVARWIDTH, "caid", "%s\n", value);
|
---|
2499 | free(value);
|
---|
2500 |
|
---|
2501 | if (rdr->boxid && isphysical)
|
---|
2502 | fprintf_conf(f, CONFVARWIDTH, "boxid", "%08X\n", rdr->boxid);
|
---|
2503 |
|
---|
2504 | if (rdr->aes_key[0] && isphysical)
|
---|
2505 | fprintf_conf(f, CONFVARWIDTH, "aeskey", "%s\n", cs_hexdump(0, rdr->aes_key, 16));
|
---|
2506 |
|
---|
2507 |
|
---|
2508 | //check for rsa
|
---|
2509 | for (j=0;j<64;j++) {
|
---|
2510 | if(rdr->rsa_mod[j] > 0) {
|
---|
2511 | rdr->has_rsa = 1;
|
---|
2512 | break;
|
---|
2513 | }
|
---|
2514 | }
|
---|
2515 |
|
---|
2516 | //check for tiger
|
---|
2517 | int tigerkey = 0;
|
---|
2518 | for (j=64;j<120;j++) {
|
---|
2519 | if(rdr->rsa_mod[j] > 0) {
|
---|
2520 | tigerkey = 1;
|
---|
2521 | break;
|
---|
2522 | }
|
---|
2523 | }
|
---|
2524 |
|
---|
2525 | //n3_rsakey
|
---|
2526 | if (rdr->has_rsa) {
|
---|
2527 | if (!tigerkey) {
|
---|
2528 | fprintf_conf(f, CONFVARWIDTH, "rsakey", "");
|
---|
2529 | for (j=0;j<64;j++) {
|
---|
2530 | fprintf(f, "%02X", rdr->rsa_mod[j]);
|
---|
2531 | }
|
---|
2532 | fprintf(f, "\n");
|
---|
2533 | }
|
---|
2534 | else {
|
---|
2535 | //tiger_rsakey
|
---|
2536 | if (tigerkey) {
|
---|
2537 | fprintf_conf(f, CONFVARWIDTH, "tiger_rsakey", "");
|
---|
2538 | for (j=0;j<120;j++) {
|
---|
2539 | fprintf(f, "%02X", rdr->rsa_mod[j]);
|
---|
2540 | }
|
---|
2541 | fprintf(f, "\n");
|
---|
2542 | }
|
---|
2543 | }
|
---|
2544 | }
|
---|
2545 |
|
---|
2546 | if (rdr->force_irdeto && isphysical) {
|
---|
2547 | fprintf_conf(f, CONFVARWIDTH, "force_irdeto", "%d\n", rdr->force_irdeto);
|
---|
2548 | }
|
---|
2549 |
|
---|
2550 | if (rdr->nagra_boxkey[0] && isphysical) {
|
---|
2551 | fprintf_conf(f, CONFVARWIDTH, "boxkey", "");
|
---|
2552 | for (j=0;j<8;j++) {
|
---|
2553 | fprintf(f, "%02X", rdr->nagra_boxkey[j]);
|
---|
2554 | }
|
---|
2555 | fprintf(f, "\n");
|
---|
2556 | }
|
---|
2557 |
|
---|
2558 | if ( rdr->atr[0] && isphysical) {
|
---|
2559 | fprintf_conf(f, CONFVARWIDTH, "atr", "");
|
---|
2560 | for (j=0; j < rdr->atrlen/2; j++) {
|
---|
2561 | fprintf(f, "%02X", rdr->atr[j]);
|
---|
2562 | }
|
---|
2563 | fprintf(f, "\n");
|
---|
2564 | }
|
---|
2565 |
|
---|
2566 | if (isphysical) {
|
---|
2567 | if (rdr->detect&0x80)
|
---|
2568 | fprintf_conf(f, CONFVARWIDTH, "detect", "!%s\n", RDR_CD_TXT[rdr->detect&0x7f]);
|
---|
2569 | else
|
---|
2570 | fprintf_conf(f, CONFVARWIDTH, "detect", "%s\n", RDR_CD_TXT[rdr->detect&0x7f]);
|
---|
2571 | }
|
---|
2572 |
|
---|
2573 | if (rdr->nagra_read && isphysical)
|
---|
2574 | fprintf_conf(f, CONFVARWIDTH, "nagra_read", "%d\n", rdr->nagra_read);
|
---|
2575 |
|
---|
2576 | if (rdr->mhz && isphysical)
|
---|
2577 | fprintf_conf(f, CONFVARWIDTH, "mhz", "%d\n", rdr->mhz);
|
---|
2578 |
|
---|
2579 | if (rdr->cardmhz && isphysical)
|
---|
2580 | fprintf_conf(f, CONFVARWIDTH, "cardmhz", "%d\n", rdr->cardmhz);
|
---|
2581 |
|
---|
2582 | value = mk_t_ftab(&rdr->ftab);
|
---|
2583 | fprintf_conf(f, CONFVARWIDTH, "ident", "%s\n", value);
|
---|
2584 | free(value);
|
---|
2585 |
|
---|
2586 | //Todo: write reader class
|
---|
2587 |
|
---|
2588 | value = mk_t_ftab(&rdr->fchid);
|
---|
2589 | if(value[0])
|
---|
2590 | fprintf_conf(f, CONFVARWIDTH, "chid", "%s\n", value);
|
---|
2591 | free(value);
|
---|
2592 |
|
---|
2593 | if (rdr->show_cls && !rdr->show_cls == 10)
|
---|
2594 | fprintf_conf(f, CONFVARWIDTH, "showcls", "%d\n", rdr->show_cls);
|
---|
2595 |
|
---|
2596 | if (rdr->maxqlen && !rdr->maxqlen == CS_MAXQLEN)
|
---|
2597 | fprintf_conf(f, CONFVARWIDTH, "maxqlen", "%d\n", rdr->maxqlen);
|
---|
2598 |
|
---|
2599 | value = mk_t_group(rdr->grp);
|
---|
2600 | fprintf_conf(f, CONFVARWIDTH, "group", "%s\n", value);
|
---|
2601 | free(value);
|
---|
2602 |
|
---|
2603 | if (rdr->cachemm)
|
---|
2604 | fprintf_conf(f, CONFVARWIDTH, "emmcache", "%d,%d,%d\n", rdr->cachemm, rdr->rewritemm, rdr->logemm);
|
---|
2605 |
|
---|
2606 | //Todo: write blocknano
|
---|
2607 |
|
---|
2608 | if (rdr->blockemm_unknown)
|
---|
2609 | fprintf_conf(f, CONFVARWIDTH, "blockemm-unknown", "%d\n", rdr->blockemm_unknown);
|
---|
2610 |
|
---|
2611 | if (rdr->blockemm_u)
|
---|
2612 | fprintf_conf(f, CONFVARWIDTH, "blockemm-u", "%d\n", rdr->blockemm_u);
|
---|
2613 |
|
---|
2614 | if (rdr->blockemm_s)
|
---|
2615 | fprintf_conf(f, CONFVARWIDTH, "blockemm-s", "%d\n", rdr->blockemm_s);
|
---|
2616 |
|
---|
2617 | if (rdr->blockemm_g)
|
---|
2618 | fprintf_conf(f, CONFVARWIDTH, "blockemm-g", "%d\n", rdr->blockemm_g);
|
---|
2619 |
|
---|
2620 | if (rdr->lb_weight)
|
---|
2621 | fprintf_conf(f, CONFVARWIDTH, "lb_weight", "%d\n", rdr->lb_weight);
|
---|
2622 |
|
---|
2623 | //Todo: write savenano
|
---|
2624 |
|
---|
2625 | if (rdr->typ == R_CCCAM) {
|
---|
2626 | if (rdr->cc_version[0])
|
---|
2627 | fprintf_conf(f, CONFVARWIDTH, "cccversion", "%s\n", rdr->cc_version);
|
---|
2628 |
|
---|
2629 | if (rdr->cc_maxhop)
|
---|
2630 | fprintf_conf(f, CONFVARWIDTH, "cccmaxhops", "%d\n", rdr->cc_maxhop);
|
---|
2631 |
|
---|
2632 | if (rdr->cc_want_emu)
|
---|
2633 | fprintf_conf(f, CONFVARWIDTH, "cccwantemu", "%d\n", rdr->cc_want_emu);
|
---|
2634 |
|
---|
2635 | if (rdr->cc_keepalive)
|
---|
2636 | fprintf_conf(f, CONFVARWIDTH, "ccckeepalive", "%d\n", rdr->cc_keepalive);
|
---|
2637 | }
|
---|
2638 |
|
---|
2639 | if (rdr->deprecated && isphysical)
|
---|
2640 | fprintf_conf(f, CONFVARWIDTH, "deprecated", "%d\n", rdr->deprecated);
|
---|
2641 |
|
---|
2642 | if (rdr->audisabled)
|
---|
2643 | fprintf_conf(f, CONFVARWIDTH, "audisabled", "%d\n", rdr->audisabled);
|
---|
2644 |
|
---|
2645 | if (rdr->auprovid)
|
---|
2646 | fprintf_conf(f, CONFVARWIDTH, "auprovid", "%06lX", rdr->auprovid);
|
---|
2647 |
|
---|
2648 | if (rdr->ndsversion && isphysical)
|
---|
2649 | fprintf_conf(f, CONFVARWIDTH, "ndsversion", "%d\n", rdr->ndsversion);
|
---|
2650 |
|
---|
2651 | if (rdr->ratelimitecm && isphysical) {
|
---|
2652 | fprintf_conf(f, CONFVARWIDTH, "ratelimitecm", "%d\n", rdr->ratelimitecm);
|
---|
2653 | fprintf_conf(f, CONFVARWIDTH, "ratelimitseconds", "%d\n", rdr->ratelimitseconds);
|
---|
2654 | }
|
---|
2655 | fprintf(f, "\n\n");
|
---|
2656 | }
|
---|
2657 | }
|
---|
2658 | fclose(f);
|
---|
2659 |
|
---|
2660 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
2661 | }
|
---|
2662 |
|
---|
2663 | void write_versionfile() {
|
---|
2664 |
|
---|
2665 | #ifndef OS_CYGWIN32
|
---|
2666 | // /tmp/oscam.version file (Uptime + Version)
|
---|
2667 | char targetfile[256];
|
---|
2668 | snprintf(targetfile, 255,"%s%s", get_tmp_dir(), "/oscam.version");
|
---|
2669 | FILE *fp;
|
---|
2670 |
|
---|
2671 | if (!(fp=fopen(targetfile, "w"))) {
|
---|
2672 | cs_log("Cannot open %s (errno=%d)", targetfile, errno);
|
---|
2673 | } else {
|
---|
2674 | time_t now = time((time_t)0);
|
---|
2675 | struct tm *st;
|
---|
2676 | st = localtime(&now);
|
---|
2677 | fprintf(fp, "Uxstarttime: %d\n", (int)now);
|
---|
2678 | fprintf(fp, "Starttime: %02d.%02d.%02d", st->tm_mday, st->tm_mon+1, st->tm_year%100);
|
---|
2679 | fprintf(fp, " %02d:%02d:%02d\n", st->tm_hour, st->tm_min, st->tm_sec);
|
---|
2680 | fprintf(fp, "Version: %s Rev. %s\n", CS_VERSION, CS_SVN_VERSION);
|
---|
2681 | fprintf(fp, "Maxpid: UNLIMITED\n\n\n");
|
---|
2682 | fprintf(fp, "Active modules:\n");
|
---|
2683 |
|
---|
2684 | #ifdef WEBIF
|
---|
2685 | fprintf(fp, "Webif support: yes\n");
|
---|
2686 | #ifdef WITH_SSL
|
---|
2687 | fprintf(fp, "Webif with SSL support: yes\n");
|
---|
2688 | #else
|
---|
2689 | fprintf(fp, "Webif with SSL support: no\n");
|
---|
2690 | #endif
|
---|
2691 | #else
|
---|
2692 | fprintf(fp, "Webif support: no\n");
|
---|
2693 | #endif
|
---|
2694 | #ifdef HAVE_DVBAPI
|
---|
2695 | fprintf(fp, "Dvbapi support: yes\n");
|
---|
2696 | #ifdef WITH_STAPI
|
---|
2697 | fprintf(fp, "Dvbapi with stapi support: yes\n");
|
---|
2698 | #else
|
---|
2699 | fprintf(fp, "Dvbapi with stapi support: no\n");
|
---|
2700 | #endif
|
---|
2701 | #else
|
---|
2702 | fprintf(fp, "Dvbapi support: no\n");
|
---|
2703 | #endif
|
---|
2704 | #ifdef CS_WITH_GBOX
|
---|
2705 | fprintf(fp, "Gbox support: yes\n");
|
---|
2706 | #else
|
---|
2707 | fprintf(fp, "Gbox support: no\n");
|
---|
2708 | #endif
|
---|
2709 | #ifdef CS_ANTICASC
|
---|
2710 | fprintf(fp, "Anticasc support: yes\n");
|
---|
2711 | #else
|
---|
2712 | fprintf(fp, "Anticasc support: no\n");
|
---|
2713 | #endif
|
---|
2714 | #ifdef CS_WITH_DOUBLECHECK
|
---|
2715 | fprintf(fp, "ECM doublecheck: yes\n");
|
---|
2716 | #else
|
---|
2717 | fprintf(fp, "ECM doublecheck: no\n");
|
---|
2718 | #endif
|
---|
2719 | #ifdef IRDETO_GUESSING
|
---|
2720 | fprintf(fp, "Irdeto guessing: yes\n");
|
---|
2721 | #else
|
---|
2722 | fprintf(fp, "Irdeto guessing: no\n");
|
---|
2723 | #endif
|
---|
2724 | #ifdef WITH_DEBUG
|
---|
2725 | fprintf(fp, "Debug: yes\n");
|
---|
2726 | #else
|
---|
2727 | fprintf(fp, "Debug: no\n");
|
---|
2728 | #endif
|
---|
2729 | #ifdef CS_LED
|
---|
2730 | fprintf(fp, "LED support: yes\n");
|
---|
2731 | #else
|
---|
2732 | fprintf(fp, "LED support: no\n");
|
---|
2733 | #endif
|
---|
2734 | #ifdef QBOXHD_LED
|
---|
2735 | fprintf(fp, "Qboxhd-LED support: yes\n");
|
---|
2736 | #else
|
---|
2737 | fprintf(fp, "Qboxhd-LED support: no\n");
|
---|
2738 | #endif
|
---|
2739 | #ifdef CS_LOGHISTORY
|
---|
2740 | fprintf(fp, "Log history: yes\n");
|
---|
2741 | #else
|
---|
2742 | fprintf(fp, "Log history: no\n");
|
---|
2743 | #endif
|
---|
2744 | #ifdef MODULE_MONITOR
|
---|
2745 | fprintf(fp, "Monitor: yes\n");
|
---|
2746 | #else
|
---|
2747 | fprintf(fp, "Monitor: no\n");
|
---|
2748 | #endif
|
---|
2749 | #ifdef MODULE_CAMD33
|
---|
2750 | fprintf(fp, "Camd33: yes\n");
|
---|
2751 | #else
|
---|
2752 | fprintf(fp, "Camd33: no\n");
|
---|
2753 | #endif
|
---|
2754 | #ifdef MODULE_CAMD35
|
---|
2755 | fprintf(fp, "Camd35 UDP: yes\n");
|
---|
2756 | #else
|
---|
2757 | fprintf(fp, "Camd35 UDP: no\n");
|
---|
2758 | #endif
|
---|
2759 | #ifdef MODULE_CAMD35_TCP
|
---|
2760 | fprintf(fp, "Camd35 TCP: yes\n");
|
---|
2761 | #else
|
---|
2762 | fprintf(fp, "Camd35 TCP: no\n");
|
---|
2763 | #endif
|
---|
2764 | #ifdef MODULE_NEWCAMD
|
---|
2765 | fprintf(fp, "Newcamd: yes\n");
|
---|
2766 | #else
|
---|
2767 | fprintf(fp, "Newcamd: no\n");
|
---|
2768 | #endif
|
---|
2769 | #ifdef MODULE_CCCAM
|
---|
2770 | fprintf(fp, "Cccam: yes\n");
|
---|
2771 | #else
|
---|
2772 | fprintf(fp, "Cccam: no\n");
|
---|
2773 | #endif
|
---|
2774 | #ifdef MODULE_RADEGAST
|
---|
2775 | fprintf(fp, "Radegast: yes\n");
|
---|
2776 | #else
|
---|
2777 | fprintf(fp, "Radegast: no\n");
|
---|
2778 | #endif
|
---|
2779 | #ifdef MODULE_SERIAL
|
---|
2780 | fprintf(fp, "Serial: yes\n");
|
---|
2781 | #else
|
---|
2782 | fprintf(fp, "Serial: no\n");
|
---|
2783 | #endif
|
---|
2784 | #ifdef MODULE_CONSTCW
|
---|
2785 | fprintf(fp, "ConstCW: yes\n");
|
---|
2786 | #else
|
---|
2787 | fprintf(fp, "ConstCW: no\n");
|
---|
2788 | #endif
|
---|
2789 | #ifdef WITH_CARDREADER
|
---|
2790 | fprintf(fp, "Cardreader: yes\n");
|
---|
2791 |
|
---|
2792 | #ifdef READER_NAGRA
|
---|
2793 | fprintf(fp, "Nagra: yes\n");
|
---|
2794 | #else
|
---|
2795 | fprintf(fp, "Nagra: no\n");
|
---|
2796 | #endif
|
---|
2797 | #ifdef READER_IRDETO
|
---|
2798 | fprintf(fp, "Irdeto: yes\n");
|
---|
2799 | #else
|
---|
2800 | fprintf(fp, "Irdeto: no\n");
|
---|
2801 | #endif
|
---|
2802 | #ifdef READER_CONAX
|
---|
2803 | fprintf(fp, "Conax: yes\n");
|
---|
2804 | #else
|
---|
2805 | fprintf(fp, "Conax: no\n");
|
---|
2806 | #endif
|
---|
2807 | #ifdef READER_CRYPTOWORKS
|
---|
2808 | fprintf(fp, "Cryptoworks: yes\n");
|
---|
2809 | #else
|
---|
2810 | fprintf(fp, "Cryptoworks: no\n");
|
---|
2811 | #endif
|
---|
2812 | #ifdef READER_SECA
|
---|
2813 | fprintf(fp, "Seca: yes\n");
|
---|
2814 | #else
|
---|
2815 | fprintf(fp, "Seca: no\n");
|
---|
2816 | #endif
|
---|
2817 | #ifdef READER_VIACCESS
|
---|
2818 | fprintf(fp, "Viaccess: yes\n");
|
---|
2819 | #else
|
---|
2820 | fprintf(fp, "Viaccess: no\n");
|
---|
2821 | #endif
|
---|
2822 | #ifdef READER_VIDEOGUARD
|
---|
2823 | fprintf(fp, "Videoguard: yes\n");
|
---|
2824 | #else
|
---|
2825 | fprintf(fp, "Videoguard: no\n");
|
---|
2826 | #endif
|
---|
2827 | #ifdef READER_DRE
|
---|
2828 | fprintf(fp, "Dre: yes\n");
|
---|
2829 | #else
|
---|
2830 | fprintf(fp, "Dre: no\n");
|
---|
2831 | #endif
|
---|
2832 |
|
---|
2833 | #ifdef READER_TONGFANG
|
---|
2834 | fprintf(fp, "Tongfang: yes\n");
|
---|
2835 | #else
|
---|
2836 | fprintf(fp, "Tongfang: no\n");
|
---|
2837 | #endif
|
---|
2838 | #else
|
---|
2839 | fprintf(fp, "Cardreader: no\n");
|
---|
2840 | #endif
|
---|
2841 |
|
---|
2842 | fclose(fp);
|
---|
2843 | }
|
---|
2844 | #endif
|
---|
2845 |
|
---|
2846 | }
|
---|
2847 |
|
---|
2848 | int init_userdb(struct s_auth **authptr_org)
|
---|
2849 | {
|
---|
2850 | struct s_auth *authptr = *authptr_org;
|
---|
2851 | int tag = 0, nr, nro, expired, disabled;
|
---|
2852 | //int first=1;
|
---|
2853 | FILE *fp;
|
---|
2854 | char *value;
|
---|
2855 | struct s_auth *ptr;
|
---|
2856 | /*static */struct s_auth *account=(struct s_auth *)0;
|
---|
2857 |
|
---|
2858 | sprintf(token, "%s%s", cs_confdir, cs_user);
|
---|
2859 | if (!(fp = fopen(token, "r"))) {
|
---|
2860 | cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
|
---|
2861 | return(1);
|
---|
2862 | }
|
---|
2863 |
|
---|
2864 | for (nro = 0, ptr = authptr; ptr; nro++) {
|
---|
2865 | struct s_auth *ptr_next;
|
---|
2866 | ptr_next = ptr->next;
|
---|
2867 | free(ptr);
|
---|
2868 | ptr = ptr_next;
|
---|
2869 | }
|
---|
2870 | nr = 0;
|
---|
2871 |
|
---|
2872 | while (fgets(token, sizeof(token), fp)) {
|
---|
2873 | int i, l;
|
---|
2874 | void *ptr;
|
---|
2875 |
|
---|
2876 | if ((l=strlen(trim(token))) < 3)
|
---|
2877 | continue;
|
---|
2878 |
|
---|
2879 | if ((token[0] == '[') && (token[l-1] == ']')) {
|
---|
2880 | token[l - 1] = 0;
|
---|
2881 | tag = (!strcmp("account", strtolower(token + 1)));
|
---|
2882 |
|
---|
2883 | if (!(ptr=malloc(sizeof(struct s_auth)))) {
|
---|
2884 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
2885 | return(1);
|
---|
2886 | }
|
---|
2887 |
|
---|
2888 | if (account)
|
---|
2889 | account->next = ptr;
|
---|
2890 | else
|
---|
2891 | authptr = ptr;
|
---|
2892 |
|
---|
2893 | account = ptr;
|
---|
2894 | memset(account, 0, sizeof(struct s_auth));
|
---|
2895 | account->allowedtimeframe[0] = 0;
|
---|
2896 | account->allowedtimeframe[1] = 0;
|
---|
2897 | account->aureader = NULL;
|
---|
2898 | account->monlvl = cfg->mon_level;
|
---|
2899 | account->tosleep = cfg->tosleep;
|
---|
2900 | account->c35_suppresscmd08 = cfg->c35_suppresscmd08;
|
---|
2901 | account->cccmaxhops = 10;
|
---|
2902 | account->cccreshare = cfg->cc_reshare;
|
---|
2903 | account->ncd_keepalive = cfg->ncd_keepalive;
|
---|
2904 | for (i = 1; i < CS_MAXCAIDTAB; account->ctab.mask[i++] = 0xffff);
|
---|
2905 | for (i = 1; i < CS_MAXTUNTAB; account->ttab.bt_srvid[i++] = 0x0000);
|
---|
2906 | nr++;
|
---|
2907 |
|
---|
2908 | #ifdef CS_ANTICASC
|
---|
2909 | account->ac_users = cfg->ac_users;
|
---|
2910 | account->ac_penalty = cfg->ac_penalty;
|
---|
2911 | account->ac_idx = nr;
|
---|
2912 | #endif
|
---|
2913 | continue;
|
---|
2914 | }
|
---|
2915 |
|
---|
2916 | if (!tag)
|
---|
2917 | continue;
|
---|
2918 |
|
---|
2919 | if (!(value=strchr(token, '=')))
|
---|
2920 | continue;
|
---|
2921 |
|
---|
2922 | *value++ = '\0';
|
---|
2923 | chk_account(trim(strtolower(token)), trim(value), account);
|
---|
2924 | }
|
---|
2925 |
|
---|
2926 | fclose(fp);
|
---|
2927 |
|
---|
2928 | for (expired = 0, disabled = 0, ptr = authptr; ptr;) {
|
---|
2929 |
|
---|
2930 | if(ptr->expirationdate && ptr->expirationdate < time(NULL))
|
---|
2931 | expired++;
|
---|
2932 |
|
---|
2933 | if(ptr->disabled != 0)
|
---|
2934 | disabled++;
|
---|
2935 |
|
---|
2936 | ptr = ptr->next;
|
---|
2937 | }
|
---|
2938 |
|
---|
2939 | *authptr_org = authptr;
|
---|
2940 |
|
---|
2941 | cs_log("userdb reloaded: %d accounts freed, %d accounts loaded, %d expired, %d disabled", nro, nr, expired, disabled);
|
---|
2942 | return(0);
|
---|
2943 | }
|
---|
2944 |
|
---|
2945 | static void chk_entry4sidtab(char *value, struct s_sidtab *sidtab, int what)
|
---|
2946 | {
|
---|
2947 | int i, b;
|
---|
2948 | char *ptr;
|
---|
2949 | ushort *slist=(ushort *) 0;
|
---|
2950 | ulong *llist=(ulong *) 0;
|
---|
2951 | ulong caid;
|
---|
2952 | char buf[strlen(value) + 1];
|
---|
2953 | cs_strncpy(buf, value, sizeof(buf));
|
---|
2954 | b=(what==1) ? sizeof(ulong) : sizeof(ushort);
|
---|
2955 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
2956 | {
|
---|
2957 | caid=a2i(ptr, b);
|
---|
2958 | if (!errno) i++;
|
---|
2959 | }
|
---|
2960 | //if (!i) return(0);
|
---|
2961 | if (b==sizeof(ushort))
|
---|
2962 | slist=malloc(i*sizeof(ushort));
|
---|
2963 | else
|
---|
2964 | llist=malloc(i*sizeof(ulong));
|
---|
2965 | strcpy(value, buf);
|
---|
2966 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
2967 | {
|
---|
2968 | caid=a2i(ptr, b);
|
---|
2969 | if (errno) continue;
|
---|
2970 | if (b==sizeof(ushort))
|
---|
2971 | slist[i++]=(ushort) caid;
|
---|
2972 | else
|
---|
2973 | llist[i++]=caid;
|
---|
2974 | }
|
---|
2975 | switch (what)
|
---|
2976 | {
|
---|
2977 | case 0: sidtab->caid=slist;
|
---|
2978 | sidtab->num_caid=i;
|
---|
2979 | break;
|
---|
2980 | case 1: sidtab->provid=llist;
|
---|
2981 | sidtab->num_provid=i;
|
---|
2982 | break;
|
---|
2983 | case 2: sidtab->srvid=slist;
|
---|
2984 | sidtab->num_srvid=i;
|
---|
2985 | break;
|
---|
2986 | }
|
---|
2987 | }
|
---|
2988 |
|
---|
2989 | void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab)
|
---|
2990 | {
|
---|
2991 | if (!strcmp(token, "caid")) { chk_entry4sidtab(value, sidtab, 0); return; }
|
---|
2992 | if (!strcmp(token, "provid")) { chk_entry4sidtab(value, sidtab, 1); return; }
|
---|
2993 | if (!strcmp(token, "ident")) { chk_entry4sidtab(value, sidtab, 1); return; }
|
---|
2994 | if (!strcmp(token, "srvid")) { chk_entry4sidtab(value, sidtab, 2); return; }
|
---|
2995 | if (token[0] != '#')
|
---|
2996 | fprintf(stderr, "Warning: keyword '%s' in sidtab section not recognized\n",token);
|
---|
2997 | }
|
---|
2998 |
|
---|
2999 | int init_sidtab()
|
---|
3000 | {
|
---|
3001 | int nr, nro;
|
---|
3002 | FILE *fp;
|
---|
3003 | char *value;
|
---|
3004 | struct s_sidtab *ptr;
|
---|
3005 | struct s_sidtab *sidtab=(struct s_sidtab *)0;
|
---|
3006 |
|
---|
3007 | sprintf(token, "%s%s", cs_confdir, cs_sidt);
|
---|
3008 | if (!(fp=fopen(token, "r")))
|
---|
3009 | {
|
---|
3010 | cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
|
---|
3011 | return(1);
|
---|
3012 | }
|
---|
3013 | for (nro=0, ptr=cfg->sidtab; ptr; nro++)
|
---|
3014 | {
|
---|
3015 | struct s_sidtab *ptr_next;
|
---|
3016 | ptr_next=ptr->next;
|
---|
3017 | free(ptr->caid); //no need to check on NULL first, freeing NULL doesnt do anything
|
---|
3018 | free(ptr->provid);
|
---|
3019 | free(ptr->srvid);
|
---|
3020 | free(ptr);
|
---|
3021 | ptr=ptr_next;
|
---|
3022 | }
|
---|
3023 | nr=0;
|
---|
3024 | while (fgets(token, sizeof(token), fp))
|
---|
3025 | {
|
---|
3026 | int l;
|
---|
3027 | void *ptr;
|
---|
3028 | if ((l=strlen(trim(token)))<3) continue;
|
---|
3029 | if ((token[0]=='[') && (token[l-1]==']'))
|
---|
3030 | {
|
---|
3031 | token[l-1]=0;
|
---|
3032 | if (!(ptr=malloc(sizeof(struct s_sidtab))))
|
---|
3033 | {
|
---|
3034 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
3035 | return(1);
|
---|
3036 | }
|
---|
3037 | if (sidtab)
|
---|
3038 | sidtab->next=ptr;
|
---|
3039 | else
|
---|
3040 | cfg->sidtab=ptr;
|
---|
3041 | sidtab=ptr;
|
---|
3042 | nr++;
|
---|
3043 | memset(sidtab, 0, sizeof(struct s_sidtab));
|
---|
3044 | cs_strncpy(sidtab->label, strtolower(token+1), sizeof(sidtab->label));
|
---|
3045 | continue;
|
---|
3046 | }
|
---|
3047 | if (!sidtab) continue;
|
---|
3048 | if (!(value=strchr(token, '='))) continue;
|
---|
3049 | *value++='\0';
|
---|
3050 | chk_sidtab(trim(strtolower(token)), trim(strtolower(value)), sidtab);
|
---|
3051 | }
|
---|
3052 | fclose(fp);
|
---|
3053 |
|
---|
3054 | #ifdef DEBUG_SIDTAB
|
---|
3055 | show_sidtab(cfg->sidtab);
|
---|
3056 | #endif
|
---|
3057 | cs_log("services reloaded: %d services freed, %d services loaded", nro, nr);
|
---|
3058 | return(0);
|
---|
3059 | }
|
---|
3060 |
|
---|
3061 | //Todo #ifdef CCCAM
|
---|
3062 | int init_provid() {
|
---|
3063 | int nr;
|
---|
3064 | FILE *fp;
|
---|
3065 | char *payload;
|
---|
3066 | static struct s_provid *provid=(struct s_provid *)0;
|
---|
3067 | sprintf(token, "%s%s", cs_confdir, cs_provid);
|
---|
3068 |
|
---|
3069 | if (!(fp=fopen(token, "r"))) {
|
---|
3070 | cs_log("can't open file \"%s\" (err=%d), no provids's loaded", token, errno);
|
---|
3071 | return(0);
|
---|
3072 | }
|
---|
3073 | nr=0;
|
---|
3074 | while (fgets(token, sizeof(token), fp)) {
|
---|
3075 |
|
---|
3076 | int l;
|
---|
3077 | void *ptr;
|
---|
3078 | char *tmp;
|
---|
3079 | tmp = trim(token);
|
---|
3080 |
|
---|
3081 | if (tmp[0] == '#') continue;
|
---|
3082 | if ((l = strlen(tmp)) < 11) continue;
|
---|
3083 | if (!(payload = strchr(token, '|'))) continue;
|
---|
3084 | *payload++ = '\0';
|
---|
3085 |
|
---|
3086 | if (!(ptr = malloc(sizeof(struct s_provid)))) {
|
---|
3087 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
3088 | return(1);
|
---|
3089 | }
|
---|
3090 |
|
---|
3091 | if (provid)
|
---|
3092 | provid->next = ptr;
|
---|
3093 | else
|
---|
3094 | cfg->provid = ptr;
|
---|
3095 |
|
---|
3096 | provid = ptr;
|
---|
3097 | memset(provid, 0, sizeof(struct s_provid));
|
---|
3098 |
|
---|
3099 | int i;
|
---|
3100 | char *ptr1;
|
---|
3101 | for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
|
---|
3102 | switch(i){
|
---|
3103 | case 0:
|
---|
3104 | cs_strncpy(provid->prov, trim(ptr1), sizeof(provid->prov));
|
---|
3105 | break;
|
---|
3106 | case 1:
|
---|
3107 | cs_strncpy(provid->sat, trim(ptr1), sizeof(provid->sat));
|
---|
3108 | break;
|
---|
3109 | case 2:
|
---|
3110 | cs_strncpy(provid->lang, trim(ptr1), sizeof(provid->lang));
|
---|
3111 | break;
|
---|
3112 | }
|
---|
3113 | }
|
---|
3114 |
|
---|
3115 | char *providasc = strchr(token, ':');
|
---|
3116 | *providasc++ = '\0';
|
---|
3117 | provid->provid = a2i(providasc, 3);
|
---|
3118 | provid->caid = a2i(token, 3);
|
---|
3119 | nr++;
|
---|
3120 | }
|
---|
3121 |
|
---|
3122 | fclose(fp);
|
---|
3123 | if (nr>0)
|
---|
3124 | cs_log("%d provid's loaded", nr);
|
---|
3125 | else{
|
---|
3126 | cs_log("oscam.provid loading failed, wrong format?");
|
---|
3127 | }
|
---|
3128 | return(0);
|
---|
3129 | }
|
---|
3130 |
|
---|
3131 | int init_srvid()
|
---|
3132 | {
|
---|
3133 | int nr;
|
---|
3134 | FILE *fp;
|
---|
3135 | char *payload;
|
---|
3136 | static struct s_srvid *srvid=(struct s_srvid *)0;
|
---|
3137 | sprintf(token, "%s%s", cs_confdir, cs_srid);
|
---|
3138 |
|
---|
3139 | if (!(fp=fopen(token, "r"))) {
|
---|
3140 | cs_log("can't open file \"%s\" (err=%d), no service-id's loaded", token, errno);
|
---|
3141 | return(0);
|
---|
3142 | }
|
---|
3143 |
|
---|
3144 | nr=0;
|
---|
3145 | while (fgets(token, sizeof(token), fp)) {
|
---|
3146 |
|
---|
3147 | int l;
|
---|
3148 | void *ptr;
|
---|
3149 | char *tmp;
|
---|
3150 | tmp = trim(token);
|
---|
3151 |
|
---|
3152 | if (tmp[0] == '#') continue;
|
---|
3153 | if ((l=strlen(tmp)) < 6) continue;
|
---|
3154 | if (!(payload=strchr(token, '|'))) continue;
|
---|
3155 | *payload++ = '\0';
|
---|
3156 |
|
---|
3157 | if (!(ptr = malloc(sizeof(struct s_srvid)))) {
|
---|
3158 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
3159 | return(1);
|
---|
3160 | }
|
---|
3161 |
|
---|
3162 | if (srvid)
|
---|
3163 | srvid->next = ptr;
|
---|
3164 | else
|
---|
3165 | cfg->srvid = ptr;
|
---|
3166 |
|
---|
3167 | srvid = ptr;
|
---|
3168 | memset(srvid, 0, sizeof(struct s_srvid));
|
---|
3169 |
|
---|
3170 | int i;
|
---|
3171 | char *ptr1;
|
---|
3172 | for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
|
---|
3173 | switch(i){
|
---|
3174 | case 0:
|
---|
3175 | cs_strncpy(srvid->prov, trim(ptr1), sizeof(srvid->prov));
|
---|
3176 | break;
|
---|
3177 | case 1:
|
---|
3178 | cs_strncpy(srvid->name, trim(ptr1), sizeof(srvid->name));
|
---|
3179 | break;
|
---|
3180 | case 2:
|
---|
3181 | cs_strncpy(srvid->type, trim(ptr1), sizeof(srvid->type));
|
---|
3182 | break;
|
---|
3183 | case 3:
|
---|
3184 | cs_strncpy(srvid->desc, trim(ptr1), sizeof(srvid->desc));
|
---|
3185 | break;
|
---|
3186 | }
|
---|
3187 | }
|
---|
3188 |
|
---|
3189 | char *srvidasc = strchr(token, ':');
|
---|
3190 | *srvidasc++ = '\0';
|
---|
3191 | srvid->srvid = dyn_word_atob(srvidasc);
|
---|
3192 | //printf("srvid %s - %d\n",srvidasc,srvid->srvid );
|
---|
3193 |
|
---|
3194 | srvid->ncaid = 0;
|
---|
3195 | for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
|
---|
3196 | srvid->caid[i] = dyn_word_atob(ptr1);
|
---|
3197 | srvid->ncaid = i+1;
|
---|
3198 | //cs_debug_mask(D_CLIENT, "ld caid: %04X srvid: %04X Prov: %s Chan: %s",srvid->caid[i],srvid->srvid,srvid->prov,srvid->name);
|
---|
3199 | }
|
---|
3200 | nr++;
|
---|
3201 | }
|
---|
3202 |
|
---|
3203 | fclose(fp);
|
---|
3204 | if (nr>0)
|
---|
3205 | cs_log("%d service-id's loaded", nr);
|
---|
3206 | else{
|
---|
3207 | cs_log("oscam.srvid loading failed, old format");
|
---|
3208 | }
|
---|
3209 | return(0);
|
---|
3210 | }
|
---|
3211 |
|
---|
3212 | int init_tierid()
|
---|
3213 | {
|
---|
3214 | int nr;
|
---|
3215 | FILE *fp;
|
---|
3216 | char *payload;
|
---|
3217 | static struct s_tierid *tierid=(struct s_tierid *)0;
|
---|
3218 | sprintf(token, "%s%s", cs_confdir, cs_trid);
|
---|
3219 |
|
---|
3220 | if (!(fp=fopen(token, "r"))) {
|
---|
3221 | cs_log("can't open file \"%s\" (err=%d), no tier-id's loaded", token, errno);
|
---|
3222 | return(0);
|
---|
3223 | }
|
---|
3224 |
|
---|
3225 | nr=0;
|
---|
3226 | while (fgets(token, sizeof(token), fp)) {
|
---|
3227 |
|
---|
3228 | int l;
|
---|
3229 | void *ptr;
|
---|
3230 | char *tmp;
|
---|
3231 | tmp = trim(token);
|
---|
3232 |
|
---|
3233 | if (tmp[0] == '#') continue;
|
---|
3234 | if ((l=strlen(tmp)) < 6) continue;
|
---|
3235 | if (!(payload=strchr(token, '|'))) continue;
|
---|
3236 | *payload++ = '\0';
|
---|
3237 |
|
---|
3238 | if (!(ptr = malloc(sizeof(struct s_tierid)))) {
|
---|
3239 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
3240 | return(1);
|
---|
3241 | }
|
---|
3242 |
|
---|
3243 | if (tierid)
|
---|
3244 | tierid->next = ptr;
|
---|
3245 | else
|
---|
3246 | cfg->tierid = ptr;
|
---|
3247 |
|
---|
3248 | tierid = ptr;
|
---|
3249 | memset(tierid, 0, sizeof(struct s_tierid));
|
---|
3250 |
|
---|
3251 | int i;
|
---|
3252 | char *ptr1 = strtok(payload, "|");
|
---|
3253 | if (ptr1)
|
---|
3254 | cs_strncpy(tierid->name, trim(ptr1), sizeof(tierid->name));
|
---|
3255 |
|
---|
3256 | char *tieridasc = strchr(token, ':');
|
---|
3257 | *tieridasc++ = '\0';
|
---|
3258 | tierid->tierid = dyn_word_atob(tieridasc);
|
---|
3259 | //printf("tierid %s - %d\n",tieridasc,tierid->tierid );
|
---|
3260 |
|
---|
3261 | tierid->ncaid = 0;
|
---|
3262 | for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
|
---|
3263 | tierid->caid[i] = dyn_word_atob(ptr1);
|
---|
3264 | tierid->ncaid = i+1;
|
---|
3265 | // cs_log("ld caid: %04X tierid: %04X name: %s",tierid->caid[i],tierid->tierid,tierid->name);
|
---|
3266 | }
|
---|
3267 | nr++;
|
---|
3268 | }
|
---|
3269 |
|
---|
3270 | fclose(fp);
|
---|
3271 | if (nr>0)
|
---|
3272 | cs_log("%d tier-id's loaded", nr);
|
---|
3273 | else{
|
---|
3274 | cs_log("%s loading failed", cs_trid);
|
---|
3275 | }
|
---|
3276 | return(0);
|
---|
3277 | }
|
---|
3278 |
|
---|
3279 | void chk_reader(char *token, char *value, struct s_reader *rdr)
|
---|
3280 | {
|
---|
3281 | int i;
|
---|
3282 | char *ptr;
|
---|
3283 | /*
|
---|
3284 | * case sensitive first
|
---|
3285 | */
|
---|
3286 | if (!strcmp(token, "device")) {
|
---|
3287 | for (i = 0, ptr = strtok(value, ","); (i < 3) && (ptr); ptr = strtok(NULL, ","), i++) {
|
---|
3288 | trim(ptr);
|
---|
3289 | switch(i) {
|
---|
3290 | case 0:
|
---|
3291 | cs_strncpy(rdr->device, ptr, sizeof(rdr->device));
|
---|
3292 | break;
|
---|
3293 |
|
---|
3294 | case 1:
|
---|
3295 | rdr->r_port = atoi(ptr);
|
---|
3296 | break;
|
---|
3297 |
|
---|
3298 | case 2:
|
---|
3299 | rdr->l_port = atoi(ptr);
|
---|
3300 | break;
|
---|
3301 | }
|
---|
3302 | }
|
---|
3303 | return;
|
---|
3304 | }
|
---|
3305 |
|
---|
3306 | #ifdef LIBUSB
|
---|
3307 | if (!strcmp(token, "device_out_endpoint")) {
|
---|
3308 | if (strlen(value) > 0) {
|
---|
3309 | sscanf(value, "0x%2X", &i);
|
---|
3310 | rdr->device_endpoint = i;
|
---|
3311 | } else {
|
---|
3312 | rdr->device_endpoint = 0;
|
---|
3313 | }
|
---|
3314 | return;
|
---|
3315 | }
|
---|
3316 | #endif
|
---|
3317 |
|
---|
3318 | if (!strcmp(token, "key")) {
|
---|
3319 | if (key_atob14(value, rdr->ncd_key)) {
|
---|
3320 | fprintf(stderr, "Configuration newcamd: Error in Key\n");
|
---|
3321 | exit(1);
|
---|
3322 | }
|
---|
3323 | return;
|
---|
3324 | }
|
---|
3325 |
|
---|
3326 | if (!strcmp(token, "password")) {
|
---|
3327 | #ifdef CS_WITH_GBOX
|
---|
3328 | cs_strncpy((char *)rdr->gbox_pwd, (const char *)i2b(4, a2i(value, 4)), 4);
|
---|
3329 | #endif
|
---|
3330 | cs_strncpy(rdr->r_pwd, value, sizeof(rdr->r_pwd));
|
---|
3331 | return;
|
---|
3332 | }
|
---|
3333 |
|
---|
3334 | #ifdef CS_WITH_GBOX
|
---|
3335 | if (!strcmp(token, "premium")) {
|
---|
3336 | rdr->gbox_prem = 1;
|
---|
3337 | return;
|
---|
3338 | }
|
---|
3339 | #endif
|
---|
3340 |
|
---|
3341 | if (!strcmp(token, "account")) {
|
---|
3342 | if (strstr(value, ",")) {
|
---|
3343 | for (i = 0, ptr = strtok(value, ","); (i < 2) && (ptr); ptr = strtok(NULL, ","), i++) {
|
---|
3344 | trim(ptr);
|
---|
3345 | switch(i) {
|
---|
3346 | case 0:
|
---|
3347 | cs_strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr));
|
---|
3348 | break;
|
---|
3349 |
|
---|
3350 | case 1:
|
---|
3351 | cs_strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd));
|
---|
3352 | break;
|
---|
3353 | }
|
---|
3354 | }
|
---|
3355 | } else {
|
---|
3356 | cs_strncpy(rdr->r_usr, value, sizeof(rdr->r_usr));
|
---|
3357 | }
|
---|
3358 | return;
|
---|
3359 | }
|
---|
3360 |
|
---|
3361 | if (!strcmp(token, "pincode")) {
|
---|
3362 | strncpy(rdr->pincode, value, sizeof(rdr->pincode) - 1);
|
---|
3363 | return;
|
---|
3364 | }
|
---|
3365 |
|
---|
3366 | if (!strcmp(token, "readnano")) {
|
---|
3367 | NULLFREE(rdr->emmfile);
|
---|
3368 | if (strlen(value) > 0) {
|
---|
3369 | if(asprintf(&(rdr->emmfile), "%s", value) < 0)
|
---|
3370 | fprintf(stderr, "Error allocating string for rdr->emmfile\n");
|
---|
3371 | }
|
---|
3372 | return;
|
---|
3373 | }
|
---|
3374 |
|
---|
3375 | /*
|
---|
3376 | * case insensitive
|
---|
3377 | */
|
---|
3378 | strtolower(value);
|
---|
3379 |
|
---|
3380 | if (!strcmp(token, "enable")) {
|
---|
3381 | if(strlen(value) == 0) {
|
---|
3382 | rdr->enable = 0;
|
---|
3383 | return;
|
---|
3384 | } else {
|
---|
3385 | rdr->enable = atoi(value) ? 1 : 0;
|
---|
3386 | return;
|
---|
3387 | }
|
---|
3388 | }
|
---|
3389 |
|
---|
3390 | if (!strcmp(token, "services")) {
|
---|
3391 | if(strlen(value) == 0) {
|
---|
3392 | rdr->sidtabok = 0;
|
---|
3393 | rdr->sidtabno = 0;
|
---|
3394 | return;
|
---|
3395 | } else {
|
---|
3396 | chk_services(value, &rdr->sidtabok, &rdr->sidtabno);
|
---|
3397 | return;
|
---|
3398 | }
|
---|
3399 | }
|
---|
3400 |
|
---|
3401 | if (!strcmp(token, "inactivitytimeout")) {
|
---|
3402 | if(strlen(value) == 0) {
|
---|
3403 | rdr->tcp_ito = 0;
|
---|
3404 | return;
|
---|
3405 | } else {
|
---|
3406 | rdr->tcp_ito = atoi(value);
|
---|
3407 | return;
|
---|
3408 | }
|
---|
3409 | }
|
---|
3410 |
|
---|
3411 | if (!strcmp(token, "reconnecttimeout")) {
|
---|
3412 | if(strlen(value) == 0) {
|
---|
3413 | rdr->tcp_rto = 0;
|
---|
3414 | return;
|
---|
3415 | } else {
|
---|
3416 | rdr->tcp_rto = atoi(value);
|
---|
3417 | return;
|
---|
3418 | }
|
---|
3419 | }
|
---|
3420 |
|
---|
3421 | if (!strcmp(token, "disableserverfilter")) {
|
---|
3422 | if(strlen(value) == 0) {
|
---|
3423 | rdr->ncd_disable_server_filt = 0;
|
---|
3424 | return;
|
---|
3425 | } else {
|
---|
3426 | rdr->ncd_disable_server_filt = atoi(value);
|
---|
3427 | return;
|
---|
3428 | }
|
---|
3429 | }
|
---|
3430 |
|
---|
3431 | //FIXME workaround for Smargo until native mode works
|
---|
3432 | if (!strcmp(token, "smargopatch")) {
|
---|
3433 | if(strlen(value) == 0) {
|
---|
3434 | rdr->smargopatch = 0;
|
---|
3435 | return;
|
---|
3436 | } else {
|
---|
3437 | rdr->smargopatch = atoi(value);
|
---|
3438 | return;
|
---|
3439 | }
|
---|
3440 | }
|
---|
3441 |
|
---|
3442 | if (!strcmp(token, "label")) {
|
---|
3443 | int found = 0;
|
---|
3444 | for(i = 0; i < (int)strlen(value); i++) {
|
---|
3445 | if (value[i] == ' ') {
|
---|
3446 | value[i] = '_';
|
---|
3447 | found++;
|
---|
3448 | }
|
---|
3449 | }
|
---|
3450 |
|
---|
3451 | if (found) fprintf(stderr, "Configuration reader: corrected label to %s\n",value);
|
---|
3452 | cs_strncpy(rdr->label, value, sizeof(rdr->label));
|
---|
3453 | return;
|
---|
3454 | }
|
---|
3455 |
|
---|
3456 | if (!strcmp(token, "fallback")) {
|
---|
3457 | if(strlen(value) == 0) {
|
---|
3458 | rdr->fallback = 0;
|
---|
3459 | return;
|
---|
3460 | } else {
|
---|
3461 | rdr->fallback = atoi(value) ? 1 : 0;
|
---|
3462 | return;
|
---|
3463 | }
|
---|
3464 | }
|
---|
3465 |
|
---|
3466 | if (!strcmp(token, "logport")) {
|
---|
3467 | if(strlen(value) == 0) {
|
---|
3468 | rdr->log_port = 0;
|
---|
3469 | return;
|
---|
3470 | } else {
|
---|
3471 | rdr->log_port = atoi(value);
|
---|
3472 | return;
|
---|
3473 | }
|
---|
3474 | }
|
---|
3475 |
|
---|
3476 | if (!strcmp(token, "caid")) {
|
---|
3477 | if(strlen(value) == 0) {
|
---|
3478 | clear_caidtab(&rdr->ctab);
|
---|
3479 | return;
|
---|
3480 | } else {
|
---|
3481 | chk_caidtab(value, &rdr->ctab);
|
---|
3482 | return;
|
---|
3483 | }
|
---|
3484 | }
|
---|
3485 |
|
---|
3486 | if (!strcmp(token, "boxid")) {
|
---|
3487 | if(strlen(value) == 0) {
|
---|
3488 | rdr->boxid = 0;
|
---|
3489 | return;
|
---|
3490 | } else {
|
---|
3491 | rdr->boxid = a2i(value, 4);
|
---|
3492 | return;
|
---|
3493 | }
|
---|
3494 | }
|
---|
3495 |
|
---|
3496 | if (!strcmp(token, "aeskey")) {
|
---|
3497 | if (key_atob(value, rdr->aes_key)) {
|
---|
3498 | fprintf(stderr, "Configuration reader: Error in AES Key\n");
|
---|
3499 | exit(1);
|
---|
3500 | }
|
---|
3501 | return;
|
---|
3502 | }
|
---|
3503 |
|
---|
3504 | if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey"))) {
|
---|
3505 | if(strlen(value) == 0) {
|
---|
3506 | memset(rdr->rsa_mod, 0, 120);
|
---|
3507 | rdr->has_rsa = 0;
|
---|
3508 | return;
|
---|
3509 | } else {
|
---|
3510 | rdr->has_rsa = 1;
|
---|
3511 | if (key_atob_l(value, rdr->rsa_mod, 128)) {
|
---|
3512 | fprintf(stderr, "Configuration reader: Error in rsakey\n");
|
---|
3513 | exit(1);
|
---|
3514 | }
|
---|
3515 | return;
|
---|
3516 | }
|
---|
3517 | }
|
---|
3518 |
|
---|
3519 | if (!strcmp(token, "tiger_rsakey")) {
|
---|
3520 | if(strlen(value) == 0) {
|
---|
3521 | memset(rdr->rsa_mod, 0, 120);
|
---|
3522 | return;
|
---|
3523 | } else {
|
---|
3524 | if (key_atob_l(value, rdr->rsa_mod, 240)) {
|
---|
3525 | fprintf(stderr, "Configuration reader: Error in tiger_rsakey\n");
|
---|
3526 | exit(1);
|
---|
3527 | }
|
---|
3528 | return;
|
---|
3529 | }
|
---|
3530 | }
|
---|
3531 |
|
---|
3532 | if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey"))) {
|
---|
3533 | if(strlen(value) == 0) {
|
---|
3534 | memset(rdr->nagra_boxkey, 0, 16);
|
---|
3535 | return;
|
---|
3536 | } else {
|
---|
3537 | if (key_atob_l(value, rdr->nagra_boxkey, 16)) {
|
---|
3538 | fprintf(stderr, "Configuration reader: Error in boxkey\n");
|
---|
3539 | exit(1);
|
---|
3540 | }
|
---|
3541 | return;
|
---|
3542 | }
|
---|
3543 | }
|
---|
3544 |
|
---|
3545 | if (!strcmp(token, "force_irdeto")) {
|
---|
3546 | if(strlen(value) == 0) {
|
---|
3547 | rdr->force_irdeto = 0;
|
---|
3548 | return;
|
---|
3549 | } else {
|
---|
3550 | rdr->force_irdeto = atoi(value);
|
---|
3551 | return;
|
---|
3552 | }
|
---|
3553 | }
|
---|
3554 |
|
---|
3555 |
|
---|
3556 | if ((!strcmp(token, "atr"))) {
|
---|
3557 | memset(rdr->atr, 0, 128);
|
---|
3558 | rdr->atrlen = strlen(value);
|
---|
3559 | if(rdr->atrlen == 0) {
|
---|
3560 | return;
|
---|
3561 | } else {
|
---|
3562 | key_atob_l(value, rdr->atr, rdr->atrlen);
|
---|
3563 | return;
|
---|
3564 | }
|
---|
3565 | }
|
---|
3566 |
|
---|
3567 | if (!strcmp(token, "detect")) {
|
---|
3568 | for (i = 0; RDR_CD_TXT[i]; i++) {
|
---|
3569 | if (!strcmp(value, RDR_CD_TXT[i])) {
|
---|
3570 | rdr->detect = i;
|
---|
3571 | }
|
---|
3572 | else {
|
---|
3573 | if ((value[0] == '!') && (!strcmp(value+1, RDR_CD_TXT[i])))
|
---|
3574 | rdr->detect = i|0x80;
|
---|
3575 | }
|
---|
3576 | }
|
---|
3577 | return;
|
---|
3578 | }
|
---|
3579 |
|
---|
3580 | if (!strcmp(token, "nagra_read")) {
|
---|
3581 | if(strlen(value) == 0) {
|
---|
3582 | rdr->nagra_read = 0;
|
---|
3583 | return;
|
---|
3584 | } else {
|
---|
3585 | rdr->nagra_read = atoi(value);
|
---|
3586 | return;
|
---|
3587 | }
|
---|
3588 | }
|
---|
3589 |
|
---|
3590 | if (!strcmp(token, "mhz")) {
|
---|
3591 | if(strlen(value) == 0) {
|
---|
3592 | rdr->mhz = 0;
|
---|
3593 | return;
|
---|
3594 | } else {
|
---|
3595 | rdr->mhz = atoi(value);
|
---|
3596 | return;
|
---|
3597 | }
|
---|
3598 | }
|
---|
3599 |
|
---|
3600 | if (!strcmp(token, "cardmhz")) {
|
---|
3601 | if(strlen(value) == 0) {
|
---|
3602 | rdr->cardmhz = 0;
|
---|
3603 | return;
|
---|
3604 | } else {
|
---|
3605 | rdr->cardmhz = atoi(value);
|
---|
3606 | return;
|
---|
3607 | }
|
---|
3608 | }
|
---|
3609 |
|
---|
3610 | if (!strcmp(token, "protocol")) {
|
---|
3611 |
|
---|
3612 | if (!strcmp(value, "mp35")) {
|
---|
3613 | rdr->typ = R_MP35;
|
---|
3614 | return;
|
---|
3615 | }
|
---|
3616 |
|
---|
3617 | if (!strcmp(value, "mouse")) {
|
---|
3618 | rdr->typ = R_MOUSE;
|
---|
3619 | return;
|
---|
3620 | }
|
---|
3621 |
|
---|
3622 | if (!strcmp(value, "sc8in1")) {
|
---|
3623 | rdr->typ = R_SC8in1;
|
---|
3624 | return;
|
---|
3625 | }
|
---|
3626 |
|
---|
3627 | if (!strcmp(value, "smartreader")) {
|
---|
3628 | rdr->typ = R_SMART;
|
---|
3629 | return;
|
---|
3630 | }
|
---|
3631 |
|
---|
3632 | if (!strcmp(value, "internal")) {
|
---|
3633 | rdr->typ = R_INTERNAL;
|
---|
3634 | return;
|
---|
3635 | }
|
---|
3636 |
|
---|
3637 | #ifdef HAVE_PCSC
|
---|
3638 | if (!strcmp(value, "pcsc")) {
|
---|
3639 | rdr->typ = R_PCSC;
|
---|
3640 | return;
|
---|
3641 | }
|
---|
3642 | #endif
|
---|
3643 |
|
---|
3644 | if (!strcmp(value, "serial")) {
|
---|
3645 | rdr->typ = R_SERIAL;
|
---|
3646 | return;
|
---|
3647 | }
|
---|
3648 |
|
---|
3649 | if (!strcmp(value, "camd35")) {
|
---|
3650 | rdr->typ = R_CAMD35;
|
---|
3651 | return;
|
---|
3652 | }
|
---|
3653 |
|
---|
3654 | if (!strcmp(value, "cs378x")) {
|
---|
3655 | rdr->typ = R_CS378X;
|
---|
3656 | return;
|
---|
3657 | }
|
---|
3658 |
|
---|
3659 | if (!strcmp(value, "cs357x")) {
|
---|
3660 | rdr->typ = R_CAMD35;
|
---|
3661 | return;
|
---|
3662 | }
|
---|
3663 |
|
---|
3664 | #ifdef CS_WITH_GBOX
|
---|
3665 | if (!strcmp(value, "gbox")) {
|
---|
3666 | rdr->typ = R_GBOX;
|
---|
3667 | return;
|
---|
3668 | }
|
---|
3669 | #endif
|
---|
3670 |
|
---|
3671 | if (!strcmp(value, "cccam") || !strcmp(value, "cccam ext")) {
|
---|
3672 | rdr->typ = R_CCCAM;
|
---|
3673 | //strcpy(value, "1");
|
---|
3674 | //chk_caidtab(value, &rdr->ctab);
|
---|
3675 | //this is a MAJOR hack for auto multiple caid support (not currently working due to ncd table issue)
|
---|
3676 | return;
|
---|
3677 | }
|
---|
3678 |
|
---|
3679 | if (!strcmp(value, "constcw")) {
|
---|
3680 | rdr->typ = R_CONSTCW;
|
---|
3681 | return;
|
---|
3682 | }
|
---|
3683 |
|
---|
3684 | if (!strcmp(value, "radegast")) {
|
---|
3685 | rdr->typ = R_RADEGAST;
|
---|
3686 | return;
|
---|
3687 | }
|
---|
3688 |
|
---|
3689 | if (!strcmp(value, "newcamd") || !strcmp(value, "newcamd525")) {
|
---|
3690 | rdr->typ = R_NEWCAMD;
|
---|
3691 | rdr->ncd_proto = NCD_525;
|
---|
3692 | return;
|
---|
3693 | }
|
---|
3694 |
|
---|
3695 | if (!strcmp(value, "newcamd524")) {
|
---|
3696 | rdr->typ = R_NEWCAMD;
|
---|
3697 | rdr->ncd_proto = NCD_524;
|
---|
3698 | return;
|
---|
3699 | }
|
---|
3700 |
|
---|
3701 | fprintf(stderr, "WARNING: value '%s' in protocol-line not recognized, assuming MOUSE\n",value);
|
---|
3702 | rdr->typ = R_MOUSE;
|
---|
3703 | return;
|
---|
3704 | }
|
---|
3705 |
|
---|
3706 | if (!strcmp(token, "ident")) {
|
---|
3707 | if(strlen(value) == 0) {
|
---|
3708 | clear_ftab(&rdr->ftab);
|
---|
3709 | return;
|
---|
3710 | } else {
|
---|
3711 | chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid");
|
---|
3712 | return;
|
---|
3713 | }
|
---|
3714 | }
|
---|
3715 |
|
---|
3716 | if (!strcmp(token, "class")) {
|
---|
3717 | chk_cltab(value, &rdr->cltab);
|
---|
3718 | return;
|
---|
3719 | }
|
---|
3720 |
|
---|
3721 | if (!strcmp(token, "chid")) {
|
---|
3722 | chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid");
|
---|
3723 | return;
|
---|
3724 | }
|
---|
3725 |
|
---|
3726 | if (!strcmp(token, "showcls")) {
|
---|
3727 | rdr->show_cls = atoi(value);
|
---|
3728 | return;
|
---|
3729 | }
|
---|
3730 |
|
---|
3731 | if (!strcmp(token, "maxqlen")) {
|
---|
3732 | rdr->maxqlen = atoi(value);
|
---|
3733 | if( rdr->maxqlen < 0 || rdr->maxqlen > CS_MAXQLEN) {
|
---|
3734 | rdr->maxqlen = CS_MAXQLEN;
|
---|
3735 | }
|
---|
3736 | return;
|
---|
3737 | }
|
---|
3738 |
|
---|
3739 | if (!strcmp(token, "group")) {
|
---|
3740 | if(strlen(value) == 0) {
|
---|
3741 | rdr->grp = 0;
|
---|
3742 | return;
|
---|
3743 | } else {
|
---|
3744 | for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
|
---|
3745 | int g;
|
---|
3746 | g = atoi(ptr);
|
---|
3747 | if ((g>0) && (g<65)) {
|
---|
3748 | rdr->grp |= (((uint64)1)<<(g-1));
|
---|
3749 | }
|
---|
3750 | }
|
---|
3751 | return;
|
---|
3752 | }
|
---|
3753 | }
|
---|
3754 |
|
---|
3755 | if (!strcmp(token, "emmcache")) {
|
---|
3756 | if(strlen(value) == 0) {
|
---|
3757 | rdr->cachemm = 0;
|
---|
3758 | rdr->rewritemm = 0;
|
---|
3759 | rdr->logemm = 0;
|
---|
3760 | return;
|
---|
3761 | } else {
|
---|
3762 | for (i = 0, ptr = strtok(value, ","); (i < 3) && (ptr); ptr = strtok(NULL, ","), i++) {
|
---|
3763 | switch(i)
|
---|
3764 | {
|
---|
3765 | case 0:
|
---|
3766 | rdr->cachemm = atoi(ptr);
|
---|
3767 | break;
|
---|
3768 |
|
---|
3769 | case 1:
|
---|
3770 | rdr->rewritemm = atoi(ptr);
|
---|
3771 | break;
|
---|
3772 |
|
---|
3773 | case 2: rdr->logemm = atoi(ptr);
|
---|
3774 | break;
|
---|
3775 | }
|
---|
3776 | }
|
---|
3777 |
|
---|
3778 | if (rdr->rewritemm <= 0) {
|
---|
3779 | fprintf(stderr, "Notice: Setting EMMCACHE to %i,1,%i instead of %i,%i,%i. ",
|
---|
3780 | rdr->cachemm, rdr->logemm,
|
---|
3781 | rdr->cachemm, rdr->rewritemm,
|
---|
3782 | rdr->logemm);
|
---|
3783 |
|
---|
3784 | fprintf(stderr, "Zero or negative number of rewrites is silly\n");
|
---|
3785 | rdr->rewritemm = 1;
|
---|
3786 | }
|
---|
3787 | return;
|
---|
3788 | }
|
---|
3789 | }
|
---|
3790 |
|
---|
3791 | if (!strcmp(token, "blocknano")) {
|
---|
3792 | //wildcard is used
|
---|
3793 | if (!strcmp(value,"all")) {
|
---|
3794 | for (i = 0 ; i < 256; i++) {
|
---|
3795 | rdr->b_nano[i] |= 0x01; //set all lsb's to block all nanos
|
---|
3796 | }
|
---|
3797 | }
|
---|
3798 | else {
|
---|
3799 | for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
|
---|
3800 | if ((i = byte_atob(ptr)) >= 0) {
|
---|
3801 | rdr->b_nano[i] |= 0x01; //lsb is set when to block nano
|
---|
3802 | }
|
---|
3803 | }
|
---|
3804 | }
|
---|
3805 | return;
|
---|
3806 | }
|
---|
3807 |
|
---|
3808 | if (!strcmp(token, "blockemm-unknown")) {
|
---|
3809 | if (strlen(value) == 0) {
|
---|
3810 | rdr->blockemm_unknown = 0;
|
---|
3811 | return;
|
---|
3812 | }
|
---|
3813 | else {
|
---|
3814 | rdr->blockemm_unknown = atoi(value);
|
---|
3815 | return;
|
---|
3816 | }
|
---|
3817 | }
|
---|
3818 |
|
---|
3819 | if (!strcmp(token, "blockemm-u")) {
|
---|
3820 | if (strlen(value) == 0) {
|
---|
3821 | rdr->blockemm_u = 0;
|
---|
3822 | return;
|
---|
3823 | }
|
---|
3824 | else {
|
---|
3825 | rdr->blockemm_u = atoi(value);
|
---|
3826 | return;
|
---|
3827 | }
|
---|
3828 | }
|
---|
3829 |
|
---|
3830 | if (!strcmp(token, "blockemm-s")) {
|
---|
3831 | if (strlen(value) == 0) {
|
---|
3832 | rdr->blockemm_s = 0;
|
---|
3833 | return;
|
---|
3834 | }
|
---|
3835 | else {
|
---|
3836 | rdr->blockemm_s = atoi(value);
|
---|
3837 | return;
|
---|
3838 | }
|
---|
3839 | }
|
---|
3840 |
|
---|
3841 | if (!strcmp(token, "blockemm-g")) {
|
---|
3842 | if (strlen(value) == 0) {
|
---|
3843 | rdr->blockemm_g = 0;
|
---|
3844 | return;
|
---|
3845 | }
|
---|
3846 | else {
|
---|
3847 | rdr->blockemm_g = atoi(value);
|
---|
3848 | return;
|
---|
3849 | }
|
---|
3850 | }
|
---|
3851 |
|
---|
3852 | if (!strcmp(token, "lb_weight")) {
|
---|
3853 | if(strlen(value) == 0) {
|
---|
3854 | rdr->lb_weight = 100;
|
---|
3855 | return;
|
---|
3856 | } else {
|
---|
3857 | rdr->lb_weight = atoi(value);
|
---|
3858 | if (rdr->lb_weight > 1000) rdr->lb_weight = 1000;
|
---|
3859 | else if (rdr->lb_weight <= 0) rdr->lb_weight = 100;
|
---|
3860 | return;
|
---|
3861 | }
|
---|
3862 | }
|
---|
3863 |
|
---|
3864 | if (!strcmp(token, "savenano")) {
|
---|
3865 | //wildcard is used
|
---|
3866 | if (!strcmp(value,"all")) {
|
---|
3867 | for (i = 0 ; i < 256; i++) {
|
---|
3868 | rdr->b_nano[i] |= 0x02; //set all lsb+1 to save all nanos to file
|
---|
3869 | }
|
---|
3870 | }
|
---|
3871 | else {
|
---|
3872 | for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
|
---|
3873 | if ((i = byte_atob(ptr)) >= 0) {
|
---|
3874 | rdr->b_nano[i] |= 0x02; //lsb+1 is set when to save nano to file
|
---|
3875 | }
|
---|
3876 | }
|
---|
3877 | }
|
---|
3878 | return;
|
---|
3879 | }
|
---|
3880 |
|
---|
3881 | if (!strcmp(token, "cccversion")) {
|
---|
3882 | // cccam version
|
---|
3883 | if (strlen(value) > sizeof(rdr->cc_version) - 1) {
|
---|
3884 | fprintf(stderr, "cccam config: version too long\n");
|
---|
3885 | exit(1);
|
---|
3886 | }
|
---|
3887 | memset(rdr->cc_version, 0, sizeof(rdr->cc_version));
|
---|
3888 | cs_strncpy(rdr->cc_version, value, sizeof(rdr->cc_version));
|
---|
3889 | return;
|
---|
3890 | }
|
---|
3891 |
|
---|
3892 | if (!strcmp(token, "cccmaxhop") || !strcmp(token, "cccmaxhops")) { //Schlocke: cccmaxhops is better!
|
---|
3893 | // cccam max card distance
|
---|
3894 | if (!strlen(value))
|
---|
3895 | rdr->cc_maxhop = 10;
|
---|
3896 | else
|
---|
3897 | rdr->cc_maxhop = atoi(value);
|
---|
3898 | return;
|
---|
3899 | }
|
---|
3900 |
|
---|
3901 | if (!strcmp(token, "cccwantemu")) {
|
---|
3902 | if (strlen(value) == 0) {
|
---|
3903 | rdr->cc_want_emu = 0;
|
---|
3904 | return;
|
---|
3905 | } else {
|
---|
3906 | rdr->cc_want_emu = atoi(value);
|
---|
3907 | return;
|
---|
3908 | }
|
---|
3909 | }
|
---|
3910 |
|
---|
3911 | if (!strcmp(token, "ccckeepalive")) {
|
---|
3912 | if (strlen(value) == 0) {
|
---|
3913 | rdr->cc_keepalive = 0;
|
---|
3914 | return;
|
---|
3915 | } else {
|
---|
3916 | rdr->cc_keepalive = atoi(value);
|
---|
3917 | return;
|
---|
3918 | }
|
---|
3919 | }
|
---|
3920 |
|
---|
3921 | if (!strcmp(token, "deprecated")) {
|
---|
3922 | if (strlen(value) == 0) {
|
---|
3923 | rdr->deprecated = 0;
|
---|
3924 | return;
|
---|
3925 | } else {
|
---|
3926 | rdr->deprecated = atoi(value);
|
---|
3927 | return;
|
---|
3928 | }
|
---|
3929 | }
|
---|
3930 |
|
---|
3931 | if (!strcmp(token, "ccchopsaway") || !strcmp(token, "cccreshar") || !strcmp(token, "cccreshare")) {
|
---|
3932 | rdr->cc_reshare = atoi(value);
|
---|
3933 | return;
|
---|
3934 | }
|
---|
3935 |
|
---|
3936 | if (!strcmp(token, "audisabled")) {
|
---|
3937 | if (strlen(value) == 0) {
|
---|
3938 | rdr->audisabled = 0;
|
---|
3939 | return;
|
---|
3940 | } else {
|
---|
3941 | rdr->audisabled = atoi(value);
|
---|
3942 | return;
|
---|
3943 | }
|
---|
3944 | }
|
---|
3945 |
|
---|
3946 | if (!strcmp(token, "auprovid")) {
|
---|
3947 | if (strlen(value) == 0) {
|
---|
3948 | rdr->auprovid = 0;
|
---|
3949 | return;
|
---|
3950 | } else {
|
---|
3951 | rdr->auprovid = a2i(value, 3);
|
---|
3952 | return;
|
---|
3953 | }
|
---|
3954 | }
|
---|
3955 | // new code for multiple aes key per reader
|
---|
3956 | if (!strcmp(token, "aeskeys")) {
|
---|
3957 | parse_aes_keys(rdr,value);
|
---|
3958 | return;
|
---|
3959 | }
|
---|
3960 |
|
---|
3961 | if (!strcmp(token, "ndsversion")) {
|
---|
3962 | if (strlen(value) == 0) {
|
---|
3963 | rdr->ndsversion = 0;
|
---|
3964 | return;
|
---|
3965 | } else {
|
---|
3966 | rdr->ndsversion = atoi(value);
|
---|
3967 | return;
|
---|
3968 | }
|
---|
3969 | }
|
---|
3970 |
|
---|
3971 |
|
---|
3972 | #ifdef AZBOX
|
---|
3973 | if (!strcmp(token, "mode")) {
|
---|
3974 | if(strlen(value) == 0) {
|
---|
3975 | rdr->mode = -1;
|
---|
3976 | return;
|
---|
3977 | } else {
|
---|
3978 | rdr->mode = atoi(value);
|
---|
3979 | return;
|
---|
3980 | }
|
---|
3981 | }
|
---|
3982 | #endif
|
---|
3983 |
|
---|
3984 | //ratelimit
|
---|
3985 | if (!strcmp(token, "ratelimitecm")) {
|
---|
3986 | if (strlen(value) == 0) {
|
---|
3987 | rdr->ratelimitecm = 0;
|
---|
3988 | return;
|
---|
3989 | } else {
|
---|
3990 | rdr->ratelimitecm = atoi(value);
|
---|
3991 | int h;
|
---|
3992 | for (h=0;h<rdr->ratelimitecm;h++) rdr->rlecmh[h].last=-1;
|
---|
3993 | return;
|
---|
3994 | }
|
---|
3995 | }
|
---|
3996 | if (!strcmp(token, "ratelimitseconds")) {
|
---|
3997 | if (strlen(value) == 0) {
|
---|
3998 | if (rdr->ratelimitecm>0) {
|
---|
3999 | rdr->ratelimitseconds = 10;
|
---|
4000 | } else {
|
---|
4001 | rdr->ratelimitseconds = 0;
|
---|
4002 | }
|
---|
4003 | return;
|
---|
4004 | } else {
|
---|
4005 | rdr->ratelimitseconds = atoi(value);
|
---|
4006 | return;
|
---|
4007 | }
|
---|
4008 | }
|
---|
4009 | if (token[0] != '#')
|
---|
4010 | fprintf(stderr, "Warning: keyword '%s' in reader section not recognized\n",token);
|
---|
4011 | }
|
---|
4012 |
|
---|
4013 | #ifdef IRDETO_GUESSING
|
---|
4014 | int init_irdeto_guess_tab()
|
---|
4015 | {
|
---|
4016 | int i, j, skip;
|
---|
4017 | int b47;
|
---|
4018 | FILE *fp;
|
---|
4019 | char token[128], *ptr;
|
---|
4020 | char zSid[5];
|
---|
4021 | uchar b3;
|
---|
4022 | ushort caid, sid;
|
---|
4023 | struct s_irdeto_quess *ird_row, *head;
|
---|
4024 |
|
---|
4025 | memset(cfg->itab, 0, sizeof(cfg->itab));
|
---|
4026 | sprintf(token, "%s%s", cs_confdir, cs_ird);
|
---|
4027 | if (!(fp=fopen(token, "r")))
|
---|
4028 | {
|
---|
4029 | cs_log("can't open file \"%s\" (errno=%d) irdeto guessing not loaded",
|
---|
4030 | token, errno);
|
---|
4031 | return(1);
|
---|
4032 | }
|
---|
4033 | while (fgets(token, sizeof(token), fp))
|
---|
4034 | {
|
---|
4035 | if( strlen(token)<20 ) continue;
|
---|
4036 | for( i=b3=b47=caid=sid=skip=0, ptr=strtok(token, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
|
---|
4037 | {
|
---|
4038 | trim(ptr);
|
---|
4039 | if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
|
---|
4040 | skip=1;
|
---|
4041 | break;
|
---|
4042 | }
|
---|
4043 | switch(i)
|
---|
4044 | {
|
---|
4045 | case 0: b3 = a2i(ptr, 2); break;
|
---|
4046 | case 1: b47 = a2i(ptr, 8); break;
|
---|
4047 | case 2: caid = a2i(ptr, 4); break;
|
---|
4048 | case 3:
|
---|
4049 | for( j=0; j<4; j++ )
|
---|
4050 | zSid[j]=ptr[j];
|
---|
4051 | zSid[4]=0;
|
---|
4052 | sid = a2i(zSid, 4);
|
---|
4053 | break;
|
---|
4054 | }
|
---|
4055 | }
|
---|
4056 | if( !skip )
|
---|
4057 | {
|
---|
4058 | if (!(ird_row=(struct s_irdeto_quess*)malloc(sizeof(struct s_irdeto_quess))))
|
---|
4059 | {
|
---|
4060 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
4061 | return(1);
|
---|
4062 | }
|
---|
4063 | ird_row->b47 = b47;
|
---|
4064 | ird_row->caid = caid;
|
---|
4065 | ird_row->sid = sid;
|
---|
4066 | ird_row->next = 0;
|
---|
4067 |
|
---|
4068 | head = cfg->itab[b3];
|
---|
4069 | if( head ) {
|
---|
4070 | while( head->next )
|
---|
4071 | head=head->next;
|
---|
4072 | head->next=ird_row;
|
---|
4073 | }
|
---|
4074 | else
|
---|
4075 | cfg->itab[b3]=ird_row;
|
---|
4076 | //cs_debug_mask(D_CLIENT, "%02X:%08X:%04X:%04X", b3, b47, caid, sid);
|
---|
4077 | }
|
---|
4078 | }
|
---|
4079 | fclose(fp);
|
---|
4080 |
|
---|
4081 | for( i=0; i<0xff; i++ )
|
---|
4082 | {
|
---|
4083 | head=cfg->itab[i];
|
---|
4084 | while(head)
|
---|
4085 | {
|
---|
4086 | cs_debug_mask(D_CLIENT, "itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
|
---|
4087 | i, head->b47, head->caid, head->sid);
|
---|
4088 | head=head->next;
|
---|
4089 | }
|
---|
4090 | }
|
---|
4091 | return(0);
|
---|
4092 | }
|
---|
4093 | #endif
|
---|
4094 |
|
---|
4095 | int init_readerdb()
|
---|
4096 | {
|
---|
4097 | int tag = 0;
|
---|
4098 | FILE *fp;
|
---|
4099 | char *value;
|
---|
4100 | int rcount=1;
|
---|
4101 |
|
---|
4102 | sprintf(token, "%s%s", cs_confdir, cs_srvr);
|
---|
4103 | if (!(fp=fopen(token, "r"))) {
|
---|
4104 | cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
|
---|
4105 | return(1);
|
---|
4106 | }
|
---|
4107 | struct s_reader *rdr = first_reader = (struct s_reader*) malloc (sizeof(struct s_reader));
|
---|
4108 | memset(rdr, 0, sizeof(struct s_reader));
|
---|
4109 | while (fgets(token, sizeof(token), fp)) {
|
---|
4110 | int i, l;
|
---|
4111 | if ((l = strlen(trim(token))) < 3)
|
---|
4112 | continue;
|
---|
4113 | if ((token[0] == '[') && (token[l-1] == ']')) {
|
---|
4114 | token[l-1] = 0;
|
---|
4115 | tag = (!strcmp("reader", strtolower(token+1)));
|
---|
4116 | if (rdr->label[0] && rdr->typ) {
|
---|
4117 | rcount++;
|
---|
4118 | if (rcount>=CS_MAXREADER) break;
|
---|
4119 | struct s_reader *newreader = (struct s_reader*) malloc (sizeof(struct s_reader));
|
---|
4120 | rdr->next = newreader; //add reader to list
|
---|
4121 | rdr = newreader; //and advance to end of list
|
---|
4122 | }
|
---|
4123 | memset(rdr, 0, sizeof(struct s_reader));
|
---|
4124 | rdr->enable = 1;
|
---|
4125 | rdr->tcp_rto = 30;
|
---|
4126 | rdr->show_cls = 10;
|
---|
4127 | rdr->maxqlen = CS_MAXQLEN;
|
---|
4128 | rdr->nagra_read = 0;
|
---|
4129 | rdr->mhz = 357;
|
---|
4130 | rdr->cardmhz = 357;
|
---|
4131 | rdr->deprecated = 0;
|
---|
4132 | rdr->force_irdeto = 0;
|
---|
4133 | rdr->cc_reshare = cfg->cc_reshare; //set global value as init value
|
---|
4134 | rdr->cc_maxhop = 10;
|
---|
4135 | rdr->lb_weight = 100;
|
---|
4136 | strcpy(rdr->pincode, "none");
|
---|
4137 | rdr->ndsversion = 0;
|
---|
4138 | for (i=1; i<CS_MAXCAIDTAB; rdr->ctab.mask[i++]=0xffff);
|
---|
4139 | continue;
|
---|
4140 | }
|
---|
4141 |
|
---|
4142 | if (!tag)
|
---|
4143 | continue;
|
---|
4144 | if (!(value=strchr(token, '=')))
|
---|
4145 | continue;
|
---|
4146 | *value++ ='\0';
|
---|
4147 | chk_reader(trim(strtolower(token)), trim(value), rdr);
|
---|
4148 | }
|
---|
4149 | fclose(fp);
|
---|
4150 | return(0);
|
---|
4151 | }
|
---|
4152 |
|
---|
4153 | #ifdef CS_ANTICASC
|
---|
4154 | void init_ac()
|
---|
4155 | {
|
---|
4156 | int nr;
|
---|
4157 | FILE *fp;
|
---|
4158 | //char *value;
|
---|
4159 |
|
---|
4160 | sprintf(token, "%s%s", cs_confdir, cs_ac);
|
---|
4161 | if (!(fp=fopen(token, "r")))
|
---|
4162 | {
|
---|
4163 | cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
|
---|
4164 | token, errno);
|
---|
4165 | return;
|
---|
4166 | }
|
---|
4167 |
|
---|
4168 | for(nr=0; fgets(token, sizeof(token), fp);)
|
---|
4169 | {
|
---|
4170 | int i, skip;
|
---|
4171 | ushort caid, sid, chid, dwtime;
|
---|
4172 | ulong provid;
|
---|
4173 | char *ptr, *ptr1;
|
---|
4174 | struct s_cpmap *ptr_cpmap;
|
---|
4175 | static struct s_cpmap *cpmap=(struct s_cpmap *)0;
|
---|
4176 |
|
---|
4177 | if( strlen(token)<4 ) continue;
|
---|
4178 |
|
---|
4179 | caid=sid=chid=dwtime=0;
|
---|
4180 | provid=0;
|
---|
4181 | skip=0;
|
---|
4182 | ptr1=0;
|
---|
4183 | for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
|
---|
4184 | {
|
---|
4185 | trim(ptr);
|
---|
4186 | if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
|
---|
4187 | skip=1;
|
---|
4188 | break;
|
---|
4189 | }
|
---|
4190 | switch( i )
|
---|
4191 | {
|
---|
4192 | case 0:
|
---|
4193 | ptr1=ptr;
|
---|
4194 | break;
|
---|
4195 | case 1:
|
---|
4196 | dwtime = atoi(ptr);
|
---|
4197 | break;
|
---|
4198 | }
|
---|
4199 | }
|
---|
4200 |
|
---|
4201 | if( !skip )
|
---|
4202 | {
|
---|
4203 | for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
|
---|
4204 | {
|
---|
4205 | trim(ptr);
|
---|
4206 | switch( i )
|
---|
4207 | {
|
---|
4208 | case 0:
|
---|
4209 | if( *ptr=='*' ) caid = 0;
|
---|
4210 | else caid = a2i(ptr, 4);
|
---|
4211 | break;
|
---|
4212 | case 1:
|
---|
4213 | if( *ptr=='*' ) provid = 0;
|
---|
4214 | else provid = a2i(ptr, 6);
|
---|
4215 | break;
|
---|
4216 | case 2:
|
---|
4217 | if( *ptr=='*' ) sid = 0;
|
---|
4218 | else sid = a2i(ptr, 4);
|
---|
4219 | break;
|
---|
4220 | case 3:
|
---|
4221 | if( *ptr=='*' ) chid = 0;
|
---|
4222 | else chid = a2i(ptr, 4);
|
---|
4223 | break;
|
---|
4224 | }
|
---|
4225 | }
|
---|
4226 | if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
|
---|
4227 | {
|
---|
4228 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
4229 | return;
|
---|
4230 | }
|
---|
4231 | if( cpmap )
|
---|
4232 | cpmap->next=ptr_cpmap;
|
---|
4233 | else
|
---|
4234 | cfg->cpmap=ptr_cpmap;
|
---|
4235 | cpmap=ptr_cpmap;
|
---|
4236 |
|
---|
4237 | cpmap->caid = caid;
|
---|
4238 | cpmap->provid = provid;
|
---|
4239 | cpmap->sid = sid;
|
---|
4240 | cpmap->chid = chid;
|
---|
4241 | cpmap->dwtime = dwtime;
|
---|
4242 | cpmap->next = 0;
|
---|
4243 |
|
---|
4244 | cs_debug_mask(D_CLIENT, "nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
|
---|
4245 | nr, caid, provid, sid, chid, dwtime);
|
---|
4246 | nr++;
|
---|
4247 | }
|
---|
4248 | }
|
---|
4249 | fclose(fp);
|
---|
4250 | //cs_log("%d lengths for caid guessing loaded", nr);
|
---|
4251 | return;
|
---|
4252 | }
|
---|
4253 | #endif
|
---|
4254 |
|
---|
4255 | /*
|
---|
4256 | * makes a char ready to write a token into config or webIf
|
---|
4257 | */
|
---|
4258 | char *mk_t_caidtab(CAIDTAB *ctab){
|
---|
4259 | int i = 0, needed = 1, pos = 0;
|
---|
4260 | while(ctab->caid[i]){
|
---|
4261 | if(ctab->mask[i]) needed += 10;
|
---|
4262 | else needed += 5;
|
---|
4263 | if(ctab->cmap[i]) needed += 5;
|
---|
4264 | ++i;
|
---|
4265 | }
|
---|
4266 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
4267 | i = 0;
|
---|
4268 | while(ctab->caid[i]) {
|
---|
4269 | if(i == 0) {
|
---|
4270 | sprintf(value + pos, "%04X", ctab->caid[i]);
|
---|
4271 | pos += 4;
|
---|
4272 | } else {
|
---|
4273 | sprintf(value + pos, ",%04X", ctab->caid[i]);
|
---|
4274 | pos += 5;
|
---|
4275 | }
|
---|
4276 | if((ctab->mask[i]) && (ctab->mask[i] != 0xFFFF)){
|
---|
4277 | sprintf(value + pos, "&%04X", ctab->mask[i]);
|
---|
4278 | pos += 5;
|
---|
4279 | }
|
---|
4280 | if(ctab->cmap[i]){
|
---|
4281 | sprintf(value + pos, ":%04X", ctab->cmap[i]);
|
---|
4282 | pos += 5;
|
---|
4283 | }
|
---|
4284 | ++i;
|
---|
4285 | }
|
---|
4286 | value[pos] = '\0';
|
---|
4287 | return value;
|
---|
4288 | }
|
---|
4289 |
|
---|
4290 | /*
|
---|
4291 | * makes a char ready to write a token into config or webIf
|
---|
4292 | */
|
---|
4293 | char *mk_t_tuntab(TUNTAB *ttab){
|
---|
4294 | int i = 0, needed = 1, pos = 0;
|
---|
4295 | while(ttab->bt_caidfrom[i]){
|
---|
4296 | if(ttab->bt_srvid[i]) needed += 10;
|
---|
4297 | else needed += 5;
|
---|
4298 | if(ttab->bt_caidto[i]) needed += 5;
|
---|
4299 | ++i;
|
---|
4300 | }
|
---|
4301 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
4302 | i = 0;
|
---|
4303 | while(ttab->bt_caidfrom[i]) {
|
---|
4304 | if(i == 0) {
|
---|
4305 | sprintf(value + pos, "%04X", ttab->bt_caidfrom[i]);
|
---|
4306 | pos += 4;
|
---|
4307 | } else {
|
---|
4308 | sprintf(value + pos, ",%04X", ttab->bt_caidfrom[i]);
|
---|
4309 | pos += 5;
|
---|
4310 | }
|
---|
4311 | if(ttab->bt_srvid[i]){
|
---|
4312 | sprintf(value + pos, ".%04X", ttab->bt_srvid[i]);
|
---|
4313 | pos += 5;
|
---|
4314 | }
|
---|
4315 | if(ttab->bt_caidto[i]){
|
---|
4316 | sprintf(value + pos, ":%04X", ttab->bt_caidto[i]);
|
---|
4317 | pos += 5;
|
---|
4318 | }
|
---|
4319 | ++i;
|
---|
4320 | }
|
---|
4321 | value[pos] = '\0';
|
---|
4322 | return value;
|
---|
4323 | }
|
---|
4324 |
|
---|
4325 | /*
|
---|
4326 | * makes a char ready to write a token into config or webIf
|
---|
4327 | */
|
---|
4328 | char *mk_t_group(uint64 grp){
|
---|
4329 | int i = 0, needed = 1, pos = 0, dot = 0;
|
---|
4330 | char grpbit[65];
|
---|
4331 | uint642bitchar(grp, grpbit);
|
---|
4332 |
|
---|
4333 | for(i = 0; i < 64; i++){
|
---|
4334 | if (grpbit[i] == '1'){
|
---|
4335 | needed += 2;
|
---|
4336 | if(i > 9) needed += 1;
|
---|
4337 | }
|
---|
4338 | }
|
---|
4339 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
4340 |
|
---|
4341 | for(i = 0; i < 64; i++){
|
---|
4342 | if (grpbit[i] == '1'){
|
---|
4343 | if (dot == 0){
|
---|
4344 | sprintf(value + pos, "%d", i+1);
|
---|
4345 | if (i > 8)pos += 2;
|
---|
4346 | else pos += 1;
|
---|
4347 | dot = 1;
|
---|
4348 | } else {
|
---|
4349 | sprintf(value + pos, ",%d", i+1);
|
---|
4350 | if (i > 8)pos += 3;
|
---|
4351 | else pos += 2;
|
---|
4352 | }
|
---|
4353 | }
|
---|
4354 | }
|
---|
4355 | value[pos] = '\0';
|
---|
4356 | return value;
|
---|
4357 | }
|
---|
4358 |
|
---|
4359 | /*
|
---|
4360 | * makes a char ready to write a token into config or webIf
|
---|
4361 | */
|
---|
4362 | char *mk_t_ftab(FTAB *ftab){
|
---|
4363 | int i = 0, j = 0, needed = 1, pos = 0;
|
---|
4364 |
|
---|
4365 | if (ftab->nfilts != 0) {
|
---|
4366 | needed = ftab->nfilts * 5;
|
---|
4367 | for (i = 0; i < ftab->nfilts; ++i)
|
---|
4368 | needed += ftab->filts[i].nprids * 7;
|
---|
4369 | }
|
---|
4370 |
|
---|
4371 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
4372 |
|
---|
4373 | char *dot="";
|
---|
4374 | for (i = 0; i < ftab->nfilts; ++i){
|
---|
4375 | sprintf(value + pos, "%s%04X", dot, ftab->filts[i].caid);
|
---|
4376 | pos += 4;
|
---|
4377 | if (i > 0) pos += 1;
|
---|
4378 | dot=":";
|
---|
4379 | for (j = 0; j < ftab->filts[i].nprids; ++j) {
|
---|
4380 | sprintf(value + pos, "%s%06lX", dot, ftab->filts[i].prids[j]);
|
---|
4381 | pos += 7;
|
---|
4382 | dot=",";
|
---|
4383 | }
|
---|
4384 | dot=";";
|
---|
4385 | }
|
---|
4386 |
|
---|
4387 | value[pos] = '\0';
|
---|
4388 | return value;
|
---|
4389 | }
|
---|
4390 |
|
---|