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