1 | #include "globals.h"
|
---|
2 | #ifdef CS_WITH_BOXKEYS
|
---|
3 | # include "oscam-boxkeys.np"
|
---|
4 | #endif
|
---|
5 |
|
---|
6 | #define CONFVARWIDTH 20
|
---|
7 |
|
---|
8 | static char *cs_conf="oscam.conf";
|
---|
9 | static char *cs_user="oscam.user";
|
---|
10 | static char *cs_srvr="oscam.server";
|
---|
11 | static char *cs_srid="oscam.srvid";
|
---|
12 | static char *cs_l4ca="oscam.guess";
|
---|
13 | static char *cs_cert="oscam.cert";
|
---|
14 | static char *cs_sidt="oscam.services";
|
---|
15 | //static char *cs_ird="oscam.ird";
|
---|
16 | #ifdef CS_ANTICASC
|
---|
17 | static char *cs_ac="oscam.ac";
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | static char token[4096];
|
---|
21 |
|
---|
22 | typedef enum cs_proto_type
|
---|
23 | {
|
---|
24 | TAG_GLOBAL, // must be first !
|
---|
25 | TAG_MONITOR, // monitor
|
---|
26 | TAG_CAMD33, // camd 3.3x
|
---|
27 | TAG_CAMD35, // camd 3.5x UDP
|
---|
28 | TAG_NEWCAMD, // newcamd
|
---|
29 | TAG_RADEGAST, // radegast
|
---|
30 | TAG_SERIAL, // serial (static)
|
---|
31 | TAG_CS357X, // camd 3.5x UDP
|
---|
32 | TAG_CS378X, // camd 3.5x TCP
|
---|
33 | #ifdef CS_WITH_GBOX
|
---|
34 | TAG_GBOX, // gbox
|
---|
35 | #endif
|
---|
36 | TAG_CCCAM, // cccam
|
---|
37 | TAG_DVBAPI
|
---|
38 | #ifdef CS_ANTICASC
|
---|
39 | ,TAG_ANTICASC // anti-cascading
|
---|
40 | #endif
|
---|
41 | } cs_proto_type_t;
|
---|
42 |
|
---|
43 | static char *cctag[]={"global", "monitor", "camd33", "camd35",
|
---|
44 | "newcamd", "radegast", "serial", "cs357x", "cs378x",
|
---|
45 | #ifdef CS_WITH_GBOX
|
---|
46 | "gbox",
|
---|
47 | #endif
|
---|
48 | "cccam", "dvbapi",
|
---|
49 | #ifdef CS_ANTICASC
|
---|
50 | "anticasc",
|
---|
51 | #endif
|
---|
52 | NULL};
|
---|
53 |
|
---|
54 | #ifdef DEBUG_SIDTAB
|
---|
55 | static void show_sidtab(struct s_sidtab *sidtab)
|
---|
56 | {
|
---|
57 | for (; sidtab; sidtab=sidtab->next)
|
---|
58 | {
|
---|
59 | int i;
|
---|
60 | char buf[1024];
|
---|
61 | cs_log("label=%s", sidtab->label);
|
---|
62 | sprintf(buf, "caid(%d)=", sidtab->num_caid);
|
---|
63 | for (i=0; i<sidtab->num_caid; i++)
|
---|
64 | sprintf(buf+strlen(buf), "%04X ", sidtab->caid[i]);
|
---|
65 | cs_log("%s", buf);
|
---|
66 | sprintf(buf, "provider(%d)=", sidtab->num_provid);
|
---|
67 | for (i=0; i<sidtab->num_provid; i++)
|
---|
68 | sprintf(buf+strlen(buf), "%08X ", sidtab->provid[i]);
|
---|
69 | cs_log("%s", buf);
|
---|
70 | sprintf(buf, "services(%d)=", sidtab->num_srvid);
|
---|
71 | for (i=0; i<sidtab->num_srvid; i++)
|
---|
72 | sprintf(buf+strlen(buf), "%04X ", sidtab->srvid[i]);
|
---|
73 | cs_log("%s", buf);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | #endif
|
---|
77 |
|
---|
78 | void chk_iprange(char *value, struct s_ip **base)
|
---|
79 | {
|
---|
80 | int i = 0;
|
---|
81 | char *ptr1, *ptr2;
|
---|
82 | struct s_ip *lip, *cip;
|
---|
83 |
|
---|
84 | for (cip=lip=*base; cip; cip=cip->next)
|
---|
85 | lip=cip;
|
---|
86 | if (!(cip=malloc(sizeof(struct s_ip))))
|
---|
87 | {
|
---|
88 | fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
|
---|
89 | exit(1);
|
---|
90 | }
|
---|
91 | if (*base)
|
---|
92 | lip->next=cip;
|
---|
93 | else
|
---|
94 | *base=cip;
|
---|
95 |
|
---|
96 | memset(cip, 0, sizeof(struct s_ip));
|
---|
97 | for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ","))
|
---|
98 | {
|
---|
99 | if (i == 0) ++i;
|
---|
100 | else {
|
---|
101 | if (!(cip=malloc(sizeof(struct s_ip)))){
|
---|
102 | fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
|
---|
103 | exit(1);
|
---|
104 | }
|
---|
105 | lip->next = cip;
|
---|
106 | memset(cip, 0, sizeof(struct s_ip));
|
---|
107 | }
|
---|
108 | if( (ptr2=strchr(trim(ptr1), '-')) )
|
---|
109 | {
|
---|
110 | *ptr2++='\0';
|
---|
111 | cip->ip[0]=cs_inet_addr(trim(ptr1));
|
---|
112 | cip->ip[1]=cs_inet_addr(trim(ptr2));
|
---|
113 | }
|
---|
114 | else
|
---|
115 | cip->ip[0]=cip->ip[1]=cs_inet_addr(ptr1);
|
---|
116 | lip = cip;
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | void chk_caidtab(char *caidasc, CAIDTAB *ctab)
|
---|
121 | {
|
---|
122 | int i;
|
---|
123 | char *ptr1, *ptr2, *ptr3;
|
---|
124 |
|
---|
125 | for (i = 0, ptr1 = strtok(caidasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
|
---|
126 | ulong caid, mask, cmap;
|
---|
127 | if( (ptr3 = strchr(trim(ptr1), ':')) )
|
---|
128 | *ptr3++ = '\0';
|
---|
129 | else
|
---|
130 | ptr3 = "";
|
---|
131 |
|
---|
132 | if( (ptr2 = strchr(trim(ptr1), '&')) )
|
---|
133 | *ptr2++ = '\0';
|
---|
134 | else
|
---|
135 | ptr2 = "";
|
---|
136 |
|
---|
137 | if (((caid = a2i(ptr1, 2)) | (mask = a2i(ptr2,-2)) | (cmap = a2i(ptr3, 2))) < 0x10000) {
|
---|
138 | ctab->caid[i] = caid;
|
---|
139 | ctab->mask[i] = mask;
|
---|
140 | ctab->cmap[i++] = cmap;
|
---|
141 | }
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | void chk_tuntab(char *tunasc, TUNTAB *ttab)
|
---|
146 | {
|
---|
147 | int i;
|
---|
148 | char *ptr1, *ptr2, *ptr3;
|
---|
149 |
|
---|
150 | // ToDo: remove after using clear_tuntab() in Webif
|
---|
151 | for (i = 0; i < CS_MAXTUNTAB; i++) {
|
---|
152 | ttab->bt_caidfrom[i] = 0;
|
---|
153 | ttab->bt_caidto[i] = 0;
|
---|
154 | ttab->bt_srvid[i] = 0;
|
---|
155 | }
|
---|
156 |
|
---|
157 | for (i = 0, ptr1 = strtok(tunasc, ","); (i < CS_MAXTUNTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
|
---|
158 | ulong bt_caidfrom, bt_caidto, bt_srvid;
|
---|
159 | if( (ptr3 = strchr(trim(ptr1), ':')) )
|
---|
160 | *ptr3++ = '\0';
|
---|
161 | else
|
---|
162 | ptr3 = "";
|
---|
163 |
|
---|
164 | if( (ptr2 = strchr(trim(ptr1), '.')) )
|
---|
165 | *ptr2++ = '\0';
|
---|
166 | else
|
---|
167 | ptr2 = "";
|
---|
168 |
|
---|
169 | if ((bt_caidfrom = a2i(ptr1, 2)) | (bt_srvid = a2i(ptr2,-2)) | (bt_caidto = a2i(ptr3, 2))) {
|
---|
170 | ttab->bt_caidfrom[i] = bt_caidfrom;
|
---|
171 | ttab->bt_caidto[i] = bt_caidto;
|
---|
172 | ttab->bt_srvid[i++] = bt_srvid;
|
---|
173 | }
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | void chk_services(char *labels, ulong *sidok, ulong *sidno)
|
---|
178 | {
|
---|
179 | int i;
|
---|
180 | char *ptr;
|
---|
181 | SIDTAB *sidtab;
|
---|
182 | *sidok = *sidno = 0;
|
---|
183 | for (ptr=strtok(labels, ","); ptr; ptr=strtok(NULL, ",")) {
|
---|
184 | for (trim(ptr), i = 0, sidtab = cfg->sidtab; sidtab; sidtab = sidtab->next, i++) {
|
---|
185 | if (!strcmp(sidtab->label, ptr)) *sidok|=(1<<i);
|
---|
186 | if ((ptr[0]=='!') && (!strcmp(sidtab->label, ptr+1))) *sidno|=(1<<i);
|
---|
187 | }
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName)
|
---|
192 | {
|
---|
193 | int i,j;
|
---|
194 | char *ptr1,*ptr2,*ptr3;
|
---|
195 | char *ptr[CS_MAXFILTERS] = {0};
|
---|
196 |
|
---|
197 | memset(ftab, 0, sizeof(FTAB));
|
---|
198 | for( i=0, ptr1=strtok(zFilterAsc, ";"); (i<CS_MAXFILTERS) && (ptr1); ptr1=strtok(NULL, ";"), i++ )
|
---|
199 | {
|
---|
200 | //cs_log("ptr1=%s", ptr1);
|
---|
201 | ptr[i] = ptr1;
|
---|
202 | if( (ptr2=strchr(trim(ptr1), ':')) )
|
---|
203 | {
|
---|
204 | //cs_log("ptr2=%s", ptr2);
|
---|
205 | *ptr2++='\0';
|
---|
206 | //cs_log("ptr2=%s", ptr2);
|
---|
207 | ftab->filts[i].caid = (ushort)a2i(ptr1, 4);
|
---|
208 | //cs_log("caid=%04X", ftab->filts[i].caid);
|
---|
209 | ptr[i] = ptr2;
|
---|
210 | }
|
---|
211 | else if (zFiltName && zFiltName[0]=='c')
|
---|
212 | {
|
---|
213 | cs_log("PANIC: CAID field not found in CHID parameter!");
|
---|
214 | cs_exit(1);
|
---|
215 | }
|
---|
216 | ftab->nfilts++;
|
---|
217 | }
|
---|
218 |
|
---|
219 | if( ftab->nfilts ) cs_debug("%s '%s' %s filter(s):", zType, zName, zFiltName);
|
---|
220 | for( i=0; i<ftab->nfilts; i++ )
|
---|
221 | {
|
---|
222 | cs_debug("CAID #%d: %04X", i, ftab->filts[i].caid);
|
---|
223 | for( j=0, ptr3=strtok(ptr[i], ","); (j<CS_MAXPROV) && (ptr3); ptr3=strtok(NULL, ","), j++ )
|
---|
224 | {
|
---|
225 | ftab->filts[i].prids[j] = a2i(ptr3,6);
|
---|
226 | ftab->filts[i].nprids++;
|
---|
227 | cs_debug("%s #%d: %06X", zFiltName, j, ftab->filts[i].prids[j]);
|
---|
228 | }
|
---|
229 | }
|
---|
230 | //cs_log("exit chk_ftab");
|
---|
231 | }
|
---|
232 |
|
---|
233 | void chk_cltab(char *classasc, CLASSTAB *clstab)
|
---|
234 | {
|
---|
235 | int i;
|
---|
236 | char *ptr1;
|
---|
237 | for( i=0, ptr1=strtok(classasc, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ",") )
|
---|
238 | {
|
---|
239 | ptr1=trim(ptr1);
|
---|
240 | if( ptr1[0] == '!' )
|
---|
241 | clstab->bclass[clstab->bn++] = (uchar)a2i(ptr1+1, 2);
|
---|
242 | else
|
---|
243 | clstab->aclass[clstab->an++] = (uchar)a2i(ptr1, 2);
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | void chk_port_tab(char *portasc, PTAB *ptab)
|
---|
248 | {
|
---|
249 | int i,j,nfilts,ifilt,iport;
|
---|
250 | char *ptr1,*ptr2,*ptr3;
|
---|
251 | char *ptr[CS_MAXPORTS] = {0};
|
---|
252 | int port[CS_MAXPORTS] = {0};
|
---|
253 | int previous_nports = ptab->nports;
|
---|
254 |
|
---|
255 | for (nfilts=i=previous_nports, ptr1=strtok(portasc, ";"); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ";"), i++)
|
---|
256 | {
|
---|
257 | ptr[i] = ptr1;
|
---|
258 | if( (ptr2=strchr(trim(ptr1), '@')) )
|
---|
259 | {
|
---|
260 | *ptr2++='\0';
|
---|
261 | ptab->ports[i].s_port = atoi(ptr1);
|
---|
262 | ptr[i] = ptr2;
|
---|
263 | port[i] = ptab->ports[i].s_port;
|
---|
264 | ptab->nports++;
|
---|
265 | }
|
---|
266 | nfilts++;
|
---|
267 | }
|
---|
268 |
|
---|
269 | if( nfilts==1 && strlen(portasc)<6 && ptab->ports[0].s_port == 0 ) {
|
---|
270 | ptab->ports[0].s_port = atoi(portasc);
|
---|
271 | ptab->nports = 1;
|
---|
272 | }
|
---|
273 |
|
---|
274 | iport=ifilt = previous_nports;
|
---|
275 | for (i=previous_nports; i<nfilts; i++)
|
---|
276 | {
|
---|
277 | if( port[i]!=0 ) iport = i;
|
---|
278 | for (j=0, ptr3=strtok(ptr[i], ","); (j<CS_MAXPROV) && (ptr3); ptr3=strtok(NULL, ","), j++)
|
---|
279 | {
|
---|
280 | if( (ptr2=strchr(trim(ptr3), ':')) )
|
---|
281 | {
|
---|
282 | *ptr2++='\0';
|
---|
283 | ptab->ports[iport].ftab.nfilts++;
|
---|
284 | ifilt = ptab->ports[iport].ftab.nfilts-1;
|
---|
285 | ptab->ports[iport].ftab.filts[ifilt].caid = (ushort)a2i(ptr3, 4);
|
---|
286 | ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6);
|
---|
287 | } else {
|
---|
288 | ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6);
|
---|
289 | }
|
---|
290 | ptab->ports[iport].ftab.filts[ifilt].nprids++;
|
---|
291 | }
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 | #ifdef NOTUSED
|
---|
296 | static void chk_srvip(char *value, in_addr_t *ip)
|
---|
297 | {
|
---|
298 | int i;
|
---|
299 | char *ptr;
|
---|
300 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
301 | if (i<8) ip[i++]=inet_addr(ptr);
|
---|
302 | }
|
---|
303 | #endif
|
---|
304 |
|
---|
305 | void chk_t_global(char *token, char *value)
|
---|
306 | {
|
---|
307 | // no value -> no parsing
|
---|
308 | if (strlen(value) == 0)
|
---|
309 | return;
|
---|
310 |
|
---|
311 | if (!strcmp(token, "disablelog")) { cfg->disablelog = atoi(value); return; }
|
---|
312 | if (!strcmp(token, "serverip")) { cfg->srvip=inet_addr(value); return; }
|
---|
313 | if (!strcmp(token, "logfile")) {
|
---|
314 | if (cfg->logfile != NULL) {
|
---|
315 | free(cfg->logfile);
|
---|
316 | cfg->logfile = NULL;
|
---|
317 | }
|
---|
318 | if (value[0])
|
---|
319 | asprintf(&(cfg->logfile), "%s", value);
|
---|
320 | return;
|
---|
321 | }
|
---|
322 | if (!strcmp(token, "pidfile")) {
|
---|
323 | if (cfg->pidfile != NULL) {
|
---|
324 | free(cfg->pidfile);
|
---|
325 | cfg->pidfile = NULL;
|
---|
326 | }
|
---|
327 | if (value[0])
|
---|
328 | asprintf(&(cfg->pidfile), "%s", value);
|
---|
329 | return;
|
---|
330 | }
|
---|
331 | if (!strcmp(token, "usrfile")) {
|
---|
332 | if (cfg->usrfile != NULL) {
|
---|
333 | free(cfg->usrfile);
|
---|
334 | cfg->usrfile = NULL;
|
---|
335 | }
|
---|
336 | if (value[0])
|
---|
337 | asprintf(&(cfg->usrfile), "%s", value);
|
---|
338 | return;
|
---|
339 | }
|
---|
340 | if (!strcmp(token, "cwlogdir")) {
|
---|
341 | if (cfg->cwlogdir != NULL) {
|
---|
342 | free(cfg->cwlogdir);
|
---|
343 | cfg->cwlogdir = NULL;
|
---|
344 | }
|
---|
345 | if (value[0])
|
---|
346 | asprintf(&(cfg->cwlogdir), "%s", value);
|
---|
347 | return;
|
---|
348 | }
|
---|
349 |
|
---|
350 | if (!strcmp(token, "usrfileflag")) { cfg->usrfileflag=atoi(value); return; }
|
---|
351 |
|
---|
352 | if (!strcmp(token, "clienttimeout"))
|
---|
353 | {
|
---|
354 | cfg->ctimeout = atoi(value);
|
---|
355 | if (cfg->ctimeout < 100)
|
---|
356 | cfg->ctimeout *= 1000;
|
---|
357 | return;
|
---|
358 | }
|
---|
359 | if (!strcmp(token, "fallbacktimeout"))
|
---|
360 | {
|
---|
361 | cfg->ftimeout = atoi(value);
|
---|
362 | if (cfg->ftimeout < 100)
|
---|
363 | cfg->ftimeout *= 1000;
|
---|
364 | return;
|
---|
365 | }
|
---|
366 |
|
---|
367 | if (!strcmp(token, "clientmaxidle")) { cfg->cmaxidle=atoi(value); return; }
|
---|
368 | if (!strcmp(token, "cachedelay")) { cfg->delay=atoi(value); return; }
|
---|
369 | if (!strcmp(token, "bindwait")) { cfg->bindwait=atoi(value); return; }
|
---|
370 | if (!strcmp(token, "netprio")) { cfg->netprio=atoi(value); return; }
|
---|
371 | if (!strcmp(token, "resolvedelay")) { cfg->resolvedelay=atoi(value); return; }
|
---|
372 | if (!strcmp(token, "sleep")) { cfg->tosleep=atoi(value); return; }
|
---|
373 | if (!strcmp(token, "unlockparental")) { cfg->ulparent=atoi(value); return; }
|
---|
374 | if (!strcmp(token, "nice"))
|
---|
375 | {
|
---|
376 | cfg->nice=atoi(value);
|
---|
377 | if ((cfg->nice<-20) || (cfg->nice>20)) cfg->nice=99;
|
---|
378 | if (cfg->nice!=99) cs_setpriority(cfg->nice); // ignore errors
|
---|
379 | return;
|
---|
380 | }
|
---|
381 | if (!strcmp(token, "serialreadertimeout"))
|
---|
382 | {
|
---|
383 | if (cfg->srtimeout < 100)
|
---|
384 | cfg->srtimeout = atoi(value) * 1000;
|
---|
385 | else
|
---|
386 | cfg->srtimeout = atoi(value);
|
---|
387 | if( cfg->srtimeout <=0 )
|
---|
388 | cfg->srtimeout=1500;
|
---|
389 | return;
|
---|
390 | }
|
---|
391 | if (!strcmp(token, "maxlogsize"))
|
---|
392 | {
|
---|
393 | cfg->max_log_size=atoi(value);
|
---|
394 | if( cfg->max_log_size <=10 )
|
---|
395 | cfg->max_log_size=10;
|
---|
396 | return;
|
---|
397 | }
|
---|
398 | if( !strcmp(token, "waitforcards")) { cfg->waitforcards = atoi(value); return; }
|
---|
399 | if( !strcmp(token, "preferlocalcards")) { cfg->preferlocalcards = atoi(value); return; }
|
---|
400 | if (token[0] != '#')
|
---|
401 | fprintf(stderr, "Warning: keyword '%s' in global section not recognized\n",token);
|
---|
402 | }
|
---|
403 |
|
---|
404 | #ifdef CS_ANTICASC
|
---|
405 | void chk_t_ac(char *token, char *value)
|
---|
406 | {
|
---|
407 | if (!strcmp(token, "enabled"))
|
---|
408 | {
|
---|
409 | cfg->ac_enabled=atoi(value);
|
---|
410 | if( cfg->ac_enabled<=0 ) cfg->ac_enabled=0;
|
---|
411 | else cfg->ac_enabled=1;
|
---|
412 | return;
|
---|
413 | }
|
---|
414 |
|
---|
415 | if (!strcmp(token, "numusers"))
|
---|
416 | {
|
---|
417 | cfg->ac_users=atoi(value);
|
---|
418 | if( cfg->ac_users<0 ) cfg->ac_users=0;
|
---|
419 | return;
|
---|
420 | }
|
---|
421 | if (!strcmp(token, "sampletime"))
|
---|
422 | {
|
---|
423 | cfg->ac_stime=atoi(value);
|
---|
424 | if( cfg->ac_stime<0 ) cfg->ac_stime=2;
|
---|
425 | return;
|
---|
426 | }
|
---|
427 | if (!strcmp(token, "samples"))
|
---|
428 | {
|
---|
429 | cfg->ac_samples=atoi(value);
|
---|
430 | if( cfg->ac_samples<2 || cfg->ac_samples>10) cfg->ac_samples=10;
|
---|
431 | return;
|
---|
432 | }
|
---|
433 | if (!strcmp(token, "penalty"))
|
---|
434 | {
|
---|
435 | cfg->ac_penalty=atoi(value);
|
---|
436 | if( cfg->ac_penalty<0 ) cfg->ac_penalty=0;
|
---|
437 | return;
|
---|
438 | }
|
---|
439 | if (!strcmp(token, "aclogfile"))
|
---|
440 | {
|
---|
441 | cs_strncpy(cfg->ac_logfile, value, sizeof(cfg->ac_logfile));
|
---|
442 | return;
|
---|
443 | }
|
---|
444 | if( !strcmp(token, "fakedelay") )
|
---|
445 | {
|
---|
446 | cfg->ac_fakedelay=atoi(value);
|
---|
447 | if( cfg->ac_fakedelay<100 || cfg->ac_fakedelay>1000 )
|
---|
448 | cfg->ac_fakedelay=1000;
|
---|
449 | return;
|
---|
450 | }
|
---|
451 | if( !strcmp(token, "denysamples") )
|
---|
452 | {
|
---|
453 | cfg->ac_denysamples=atoi(value);
|
---|
454 | if( cfg->ac_denysamples<2 || cfg->ac_denysamples>cfg->ac_samples-1 )
|
---|
455 | cfg->ac_denysamples=cfg->ac_samples-1;
|
---|
456 | return;
|
---|
457 | }
|
---|
458 | if (token[0] != '#')
|
---|
459 | fprintf(stderr, "Warning: keyword '%s' in anticascading section not recognized\n",token);
|
---|
460 | //#endif moved this endif up two lines, I think this was erroneous - dingo35
|
---|
461 | }
|
---|
462 | #endif
|
---|
463 |
|
---|
464 | void chk_t_monitor(char *token, char *value)
|
---|
465 | {
|
---|
466 | if (!strcmp(token, "port")) { cfg->mon_port=atoi(value); return; }
|
---|
467 | if (!strcmp(token, "serverip")) { cfg->mon_srvip=inet_addr(value); return; }
|
---|
468 | if (!strcmp(token, "nocrypt")) { chk_iprange(value, &cfg->mon_allowed); return; }
|
---|
469 | if (!strcmp(token, "aulow")) { cfg->mon_aulow=atoi(value); return; }
|
---|
470 | if (!strcmp(token, "monlevel")) { cfg->mon_level=atoi(value); return; }
|
---|
471 | if (!strcmp(token, "httpport")) { cfg->http_port=atoi(value); return; }
|
---|
472 | if (!strcmp(token, "httpuser")) { cs_strncpy(cfg->http_user, value, sizeof(cfg->http_user)); return; }
|
---|
473 | if (!strcmp(token, "httppwd")) { cs_strncpy(cfg->http_pwd, value, sizeof(cfg->http_pwd)); return; }
|
---|
474 | if (!strcmp(token, "httpcss")) { cs_strncpy(cfg->http_css, value, sizeof(cfg->http_css)); return; }
|
---|
475 | if (!strcmp(token, "httpscript")) { cs_strncpy(cfg->http_script, value, sizeof(cfg->http_script)); return; }
|
---|
476 | if (!strcmp(token, "httptpl")) {
|
---|
477 | cs_strncpy(cfg->http_tpl, value, sizeof(cfg->http_tpl));
|
---|
478 | if(strlen(cfg->http_tpl) < (sizeof(cfg->http_tpl)-2) && cfg->http_tpl[strlen(cfg->http_tpl)-1] != '/'){
|
---|
479 | cfg->http_tpl[strlen(cfg->http_tpl)] = '/';
|
---|
480 | cfg->http_tpl[strlen(cfg->http_tpl)] = '\0';
|
---|
481 | }
|
---|
482 | return;
|
---|
483 | }
|
---|
484 | if (!strcmp(token, "httprefresh")) { cfg->http_refresh=atoi(value); return; }
|
---|
485 | if (!strcmp(token, "httphideidleclients")) { cfg->http_hide_idle_clients=atoi(value); return; }
|
---|
486 | if (!strcmp(token, "hideclient_to")) { cfg->mon_hideclient_to=atoi(value); return; }
|
---|
487 | if (token[0] != '#')
|
---|
488 | fprintf(stderr, "Warning: keyword '%s' in monitor section not recognized\n",token);
|
---|
489 | }
|
---|
490 |
|
---|
491 | void chk_t_camd33(char *token, char *value)
|
---|
492 | {
|
---|
493 | if (!strcmp(token, "port")) { cfg->c33_port=atoi(value); return; }
|
---|
494 | if (!strcmp(token, "serverip")) { cfg->c33_srvip=inet_addr(value); return; }
|
---|
495 | if (!strcmp(token, "nocrypt")) { chk_iprange(value, &cfg->c33_plain); return; }
|
---|
496 | if (!strcmp(token, "passive")) { cfg->c33_passive=(value[0]!='0'); return; }
|
---|
497 | if (!strcmp(token, "key"))
|
---|
498 | {
|
---|
499 | if (key_atob(value, cfg->c33_key))
|
---|
500 | {
|
---|
501 | fprintf(stderr, "Configuration camd3.3x: Error in Key\n");
|
---|
502 | exit(1);
|
---|
503 | }
|
---|
504 | cfg->c33_crypted=1;
|
---|
505 | return;
|
---|
506 | }
|
---|
507 | if (token[0] != '#')
|
---|
508 | fprintf(stderr, "Warning: keyword '%s' in camd33 section not recognized\n",token);
|
---|
509 | }
|
---|
510 |
|
---|
511 | void chk_t_camd35(char *token, char *value)
|
---|
512 | {
|
---|
513 | if (!strcmp(token, "port")) { cfg->c35_port=atoi(value); return; }
|
---|
514 | if (!strcmp(token, "serverip")) { cfg->c35_tcp_srvip=inet_addr(value); return; }
|
---|
515 | if (!strcmp(token, "suppresscmd08")) { cfg->c35_suppresscmd08=atoi(value); return; }
|
---|
516 | if (token[0] != '#')
|
---|
517 | fprintf(stderr, "Warning: keyword '%s' in camd35 section not recognized\n",token);
|
---|
518 | }
|
---|
519 |
|
---|
520 | void chk_t_camd35_tcp(char *token, char *value)
|
---|
521 | {
|
---|
522 | if (!strcmp(token, "port")) { chk_port_tab(value, &cfg->c35_tcp_ptab); return; }
|
---|
523 | if (!strcmp(token, "serverip")) { cfg->c35_tcp_srvip=inet_addr(value); return; }
|
---|
524 | if (!strcmp(token, "suppresscmd08")) { cfg->c35_suppresscmd08=atoi(value); return; }
|
---|
525 | if (token[0] != '#')
|
---|
526 | fprintf(stderr, "Warning: keyword '%s' in camd35 tcp section not recognized\n",token);
|
---|
527 | }
|
---|
528 |
|
---|
529 | void chk_t_newcamd(char *token, char *value)
|
---|
530 | {
|
---|
531 | if (!strcmp(token, "port")) { chk_port_tab(value, &cfg->ncd_ptab); return; }
|
---|
532 | if (!strcmp(token, "serverip")) { cfg->ncd_srvip=inet_addr(value); return; }
|
---|
533 | if (!strcmp(token, "allowed")) { chk_iprange(value, &cfg->ncd_allowed); return; }
|
---|
534 | if (!strcmp(token, "key"))
|
---|
535 | {
|
---|
536 | if (key_atob14(value, cfg->ncd_key))
|
---|
537 | {
|
---|
538 | fprintf(stderr, "Configuration newcamd: Error in Key\n");
|
---|
539 | exit(1);
|
---|
540 | }
|
---|
541 | return;
|
---|
542 | }
|
---|
543 | if (!strcmp(token, "keepalive"))
|
---|
544 | {
|
---|
545 | cfg->ncd_keepalive = atoi(value);
|
---|
546 | return;
|
---|
547 | }
|
---|
548 | if (token[0] != '#')
|
---|
549 | fprintf(stderr, "Warning: keyword '%s' in newcamd section not recognized\n",token);
|
---|
550 | }
|
---|
551 |
|
---|
552 | void chk_t_cccam(char *token, char *value)
|
---|
553 | {
|
---|
554 | if (!strcmp(token, "port")) { cfg->cc_port=atoi(value); return; }
|
---|
555 | //if (!strcmp(token, "serverip")) { cfg->cc_srvip=inet_addr(value); return; }
|
---|
556 | if (!strcmp(token, "reshare")) { cfg->cc_reshare=atoi(value); return; }
|
---|
557 | if (!strcmp(token, "version")) { // cccam version
|
---|
558 | if (strlen(value)>sizeof(cfg->cc_version)-1) {
|
---|
559 | fprintf(stderr, "cccam config: version too long\n");
|
---|
560 | exit(1);
|
---|
561 | }
|
---|
562 | bzero(cfg->cc_version, sizeof(cfg->cc_version));
|
---|
563 | strncpy((char*)cfg->cc_version, value, sizeof(cfg->cc_version)-1);
|
---|
564 | return;
|
---|
565 | }
|
---|
566 | if (!strcmp(token, "build")) { // cccam build number
|
---|
567 | if (strlen(value)>sizeof(cfg->cc_build)-1) {
|
---|
568 | fprintf(stderr, "cccam config build number too long\n");
|
---|
569 | exit(1);
|
---|
570 | }
|
---|
571 | bzero(cfg->cc_build, sizeof(cfg->cc_build));
|
---|
572 | strncpy((char*)cfg->cc_build, value, sizeof(cfg->cc_build)-1);
|
---|
573 | return;
|
---|
574 | }
|
---|
575 | if (token[0] != '#')
|
---|
576 | fprintf(stderr, "Warning: keyword '%s' in cccam section not recognized\n",token);
|
---|
577 | }
|
---|
578 |
|
---|
579 | void chk_t_radegast(char *token, char *value)
|
---|
580 | {
|
---|
581 | if (!strcmp(token, "port")) { cfg->rad_port=atoi(value); return; }
|
---|
582 | if (!strcmp(token, "serverip")) { cfg->rad_srvip=inet_addr(value); return; }
|
---|
583 | if (!strcmp(token, "allowed")) { chk_iprange(value, &cfg->rad_allowed); return; }
|
---|
584 | if (!strcmp(token, "user")) { cs_strncpy(cfg->rad_usr, value, sizeof(cfg->rad_usr)); return; }
|
---|
585 | if (token[0] != '#')
|
---|
586 | fprintf(stderr, "Warning: keyword '%s' in radegast section not recognized\n",token);
|
---|
587 | }
|
---|
588 |
|
---|
589 | void chk_t_serial(char *token, char *value)
|
---|
590 | {
|
---|
591 | if (!strcmp(token, "device"))
|
---|
592 | {
|
---|
593 | int l;
|
---|
594 | l=strlen(cfg->ser_device);
|
---|
595 | if (l) cfg->ser_device[l++]=1; // use ctrl-a as delimiter
|
---|
596 | cs_strncpy(cfg->ser_device+l, value, sizeof(cfg->ser_device)-l);
|
---|
597 | return;
|
---|
598 | }
|
---|
599 | if (token[0] != '#')
|
---|
600 | fprintf(stderr, "Warning: keyword '%s' in serial section not recognized\n",token);
|
---|
601 | }
|
---|
602 |
|
---|
603 | #ifdef CS_WITH_GBOX
|
---|
604 | static void chk_t_gbox(char *token, char *value)
|
---|
605 | {
|
---|
606 | // if (!strcmp(token, "password")) strncpy(cfg->gbox_pwd, i2b(4, a2i(value, 4)), 4);
|
---|
607 | if (!strcmp(token, "password")) { cs_atob(cfg->gbox_pwd, value, 4); return; }
|
---|
608 | if (!strcmp(token, "maxdist")) { cfg->maxdist=atoi(value); return; }
|
---|
609 | if (!strcmp(token, "ignorelist")) { cs_strncpy((char *)cfg->ignorefile, value, sizeof(cfg->ignorefile)); return; }
|
---|
610 | if (!strcmp(token, "onlineinfos")) { cs_strncpy((char *)cfg->gbxShareOnl, value, sizeof(cfg->gbxShareOnl)); return; }
|
---|
611 | if (!strcmp(token, "cardinfos")) { cs_strncpy((char *)cfg->cardfile, value, sizeof(cfg->cardfile)); return; }
|
---|
612 | if (!strcmp(token, "locals"))
|
---|
613 | {
|
---|
614 | char *ptr1;
|
---|
615 | int n=0, i;
|
---|
616 | for (i=0, ptr1=strtok(value, ","); (i<CS_MAXLOCALS) && (ptr1); ptr1=strtok(NULL, ","))
|
---|
617 | {
|
---|
618 | cfg->locals[n++]=a2i(ptr1, 8);
|
---|
619 | //printf("%i %08X",n,cfg->locals[n-1]);
|
---|
620 | }
|
---|
621 | cfg->num_locals=n;
|
---|
622 | return;
|
---|
623 | }
|
---|
624 | if (token[0] != '#')
|
---|
625 | fprintf(stderr, "Warning: keyword '%s' in gbox section not recognized\n",token);
|
---|
626 | }
|
---|
627 | #endif
|
---|
628 |
|
---|
629 | #ifdef HAVE_DVBAPI
|
---|
630 | void chk_t_dvbapi(char *token, char *value)
|
---|
631 | {
|
---|
632 | if (!strcmp(token, "enabled")) { cfg->dvbapi_enabled=atoi(value); return; }
|
---|
633 | if (!strcmp(token, "au")) { cfg->dvbapi_au=atoi(value); return; }
|
---|
634 | if (!strcmp(token, "boxtype")) { cs_strncpy(cfg->dvbapi_boxtype, value, sizeof(cfg->dvbapi_boxtype)); return; }
|
---|
635 | if (!strcmp(token, "user")) { cs_strncpy(cfg->dvbapi_usr, value, sizeof(cfg->dvbapi_usr)); return; }
|
---|
636 | if (!strcmp(token, "priority")) { cs_strncpy(cfg->dvbapi_priority, value, sizeof(cfg->dvbapi_priority)); return; }
|
---|
637 | if (!strcmp(token, "ignore")) { cs_strncpy(cfg->dvbapi_ignore, value, sizeof(cfg->dvbapi_ignore)); return; }
|
---|
638 |
|
---|
639 | if (token[0] != '#')
|
---|
640 | fprintf(stderr, "Warning: keyword '%s' in dvbapi section not recognized\n",token);
|
---|
641 | }
|
---|
642 | #endif
|
---|
643 |
|
---|
644 | static void chk_token(char *token, char *value, int tag)
|
---|
645 | {
|
---|
646 | switch(tag)
|
---|
647 | {
|
---|
648 | case TAG_GLOBAL : chk_t_global(token, value); break;
|
---|
649 | case TAG_MONITOR : chk_t_monitor(token, value); break;
|
---|
650 | case TAG_CAMD33 : chk_t_camd33(token, value); break;
|
---|
651 | case TAG_CAMD35 :
|
---|
652 | case TAG_CS357X : chk_t_camd35(token, value); break;
|
---|
653 | case TAG_NEWCAMD : chk_t_newcamd(token, value); break;
|
---|
654 | case TAG_RADEGAST: chk_t_radegast(token, value); break;
|
---|
655 | case TAG_SERIAL : chk_t_serial(token, value); break;
|
---|
656 | case TAG_CS378X : chk_t_camd35_tcp(token, value); break;
|
---|
657 | #ifdef CS_WITH_GBOX
|
---|
658 | case TAG_GBOX : chk_t_gbox(token, value); break;
|
---|
659 | #endif
|
---|
660 | case TAG_CCCAM : chk_t_cccam(token, value); break;
|
---|
661 | #ifdef HAVE_DVBAPI
|
---|
662 | case TAG_DVBAPI : chk_t_dvbapi(token, value); break;
|
---|
663 | #else
|
---|
664 | case TAG_DVBAPI : fprintf(stderr, "Warning: OSCam compiled without DVB API support.\n"); break;
|
---|
665 | #endif
|
---|
666 | #ifdef CS_ANTICASC
|
---|
667 | case TAG_ANTICASC: chk_t_ac(token, value); break;
|
---|
668 | #endif
|
---|
669 | }
|
---|
670 | }
|
---|
671 |
|
---|
672 | void init_len4caid()
|
---|
673 | {
|
---|
674 | int nr;
|
---|
675 | FILE *fp;
|
---|
676 | char *value;
|
---|
677 |
|
---|
678 | memset(len4caid, 0, sizeof(ushort)<<8);
|
---|
679 | sprintf(token, "%s%s", cs_confdir, cs_l4ca);
|
---|
680 | if (!(fp=fopen(token, "r")))
|
---|
681 | return;
|
---|
682 | for(nr=0; fgets(token, sizeof(token), fp);)
|
---|
683 | {
|
---|
684 | int i, c;
|
---|
685 | char *ptr;
|
---|
686 | if (!(value=strchr(token, ':'))) continue;
|
---|
687 | *value++='\0';
|
---|
688 | if( (ptr=strchr(value, '#')) )
|
---|
689 | *ptr='\0';
|
---|
690 | if (strlen(trim(token))!=2) continue;
|
---|
691 | if (strlen(trim(value))!=4) continue;
|
---|
692 | if ((i=byte_atob(token))<0) continue;
|
---|
693 | if ((c=word_atob(value))<0) continue;
|
---|
694 | //printf("idx %02X = %04X\n", i, c); fflush(stdout);
|
---|
695 | len4caid[i]=c;
|
---|
696 | nr++;
|
---|
697 | }
|
---|
698 | fclose(fp);
|
---|
699 | cs_log("%d lengths for caid guessing loaded", nr);
|
---|
700 | return;
|
---|
701 | }
|
---|
702 |
|
---|
703 | int search_boxkey(ushort caid, char *key)
|
---|
704 | {
|
---|
705 | int i, rc=0;
|
---|
706 | FILE *fp;
|
---|
707 | char c_caid[512];
|
---|
708 |
|
---|
709 | sprintf(c_caid, "%s%s", cs_confdir, cs_cert);
|
---|
710 | fp=fopen(c_caid, "r");
|
---|
711 | if (fp)
|
---|
712 | {
|
---|
713 | for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);)
|
---|
714 | {
|
---|
715 | char *c_provid, *c_key;
|
---|
716 |
|
---|
717 | c_provid=strchr(c_caid, '#');
|
---|
718 | if (c_provid) *c_provid='\0';
|
---|
719 | if (!(c_provid=strchr(c_caid, ':'))) continue;
|
---|
720 | *c_provid++='\0';
|
---|
721 | if (!(c_key=strchr(c_provid, ':'))) continue;
|
---|
722 | *c_key++='\0';
|
---|
723 | if (word_atob(trim(c_caid))!=caid) continue;
|
---|
724 | if ((i=(strlen(trim(c_key))>>1))>256) continue;
|
---|
725 | if (cs_atob((uchar *)key, c_key, i)<0)
|
---|
726 | {
|
---|
727 | cs_log("wrong key in \"%s\"", cs_cert);
|
---|
728 | continue;
|
---|
729 | }
|
---|
730 | rc=1;
|
---|
731 | }
|
---|
732 | fclose(fp);
|
---|
733 | }
|
---|
734 | #ifdef OSCAM_INBUILD_KEYS
|
---|
735 | for(i=0; (!rc) && (npkey[i].keylen); i++)
|
---|
736 | if (rc=((caid==npkey[i].caid) && (npkey[i].provid==0)))
|
---|
737 | memcpy(key, npkey[i].key, npkey[i].keylen);
|
---|
738 | #endif
|
---|
739 | return(rc);
|
---|
740 | }
|
---|
741 |
|
---|
742 | int init_config()
|
---|
743 | {
|
---|
744 | int tag=TAG_GLOBAL;
|
---|
745 | FILE *fp;
|
---|
746 | char *value;
|
---|
747 |
|
---|
748 | #ifndef CS_EMBEDDED
|
---|
749 | #ifdef PRIO_PROCESS
|
---|
750 | errno=0;
|
---|
751 | if ((cfg->nice=getpriority(PRIO_PROCESS, 0))==(-1))
|
---|
752 | if (errno)
|
---|
753 | #endif
|
---|
754 | #endif
|
---|
755 | cfg->nice=99;
|
---|
756 | cfg->ctimeout=CS_CLIENT_TIMEOUT;
|
---|
757 | cfg->ftimeout=CS_CLIENT_TIMEOUT / 2;
|
---|
758 | cfg->cmaxidle=CS_CLIENT_MAXIDLE;
|
---|
759 | cfg->delay=CS_DELAY;
|
---|
760 | cfg->bindwait=CS_BIND_TIMEOUT;
|
---|
761 | cfg->resolvedelay=CS_RESOLVE_DELAY;
|
---|
762 | cfg->mon_level=2;
|
---|
763 | cfg->mon_hideclient_to=0;
|
---|
764 | cfg->srtimeout=1500;
|
---|
765 | cfg->ulparent=0;
|
---|
766 | cfg->logfile=NULL;
|
---|
767 | cfg->pidfile=NULL;
|
---|
768 | cfg->usrfile=NULL;
|
---|
769 | cfg->cwlogdir=NULL;
|
---|
770 | strcpy(cfg->http_user, "");
|
---|
771 | strcpy(cfg->http_pwd, "");
|
---|
772 | strcpy(cfg->http_css, "");
|
---|
773 | cfg->http_refresh=0;
|
---|
774 | cfg->http_hide_idle_clients=0;
|
---|
775 | strcpy(cfg->http_tpl, "");
|
---|
776 | #ifdef CS_ANTICASC
|
---|
777 | cfg->ac_enabled=0;
|
---|
778 | cfg->ac_users=0;
|
---|
779 | cfg->ac_stime=2;
|
---|
780 | cfg->ac_samples=10;
|
---|
781 | cfg->ac_denysamples=8;
|
---|
782 | cfg->ac_fakedelay=1000;
|
---|
783 | strcpy(cfg->ac_logfile, "./oscam_ac.log");
|
---|
784 | #endif
|
---|
785 | cfg->ncd_keepalive=1;
|
---|
786 | sprintf(token, "%s%s", cs_confdir, cs_conf);
|
---|
787 | if (!(fp=fopen(token, "r")))
|
---|
788 | {
|
---|
789 | fprintf(stderr, "Cannot open config file '%s' (errno=%d)\n", token, errno);
|
---|
790 | exit(1);
|
---|
791 | }
|
---|
792 | while (fgets(token, sizeof(token), fp))
|
---|
793 | {
|
---|
794 | int i, l;
|
---|
795 | //void *ptr;
|
---|
796 | if ((l=strlen(trim(token)))<3) continue;
|
---|
797 | if ((token[0]=='[') && (token[l-1]==']'))
|
---|
798 | {
|
---|
799 | for (token[l-1]=0, tag=-1, i=TAG_GLOBAL; cctag[i]; i++)
|
---|
800 | if (!strcmp(cctag[i], strtolower(token+1)))
|
---|
801 | tag=i;
|
---|
802 | continue;
|
---|
803 | }
|
---|
804 | if (!(value=strchr(token, '='))) continue;
|
---|
805 | *value++='\0';
|
---|
806 | chk_token(trim(strtolower(token)), trim(value), tag);
|
---|
807 | }
|
---|
808 | fclose(fp);
|
---|
809 | #ifdef CS_LOGFILE
|
---|
810 | if (cfg->logfile == NULL)
|
---|
811 | asprintf(&(cfg->logfile), "%s", CS_LOGFILE);
|
---|
812 | #endif
|
---|
813 | cs_init_log(cfg->logfile);
|
---|
814 | if (cfg->ftimeout>=cfg->ctimeout)
|
---|
815 | {
|
---|
816 | cfg->ftimeout = cfg->ctimeout - 100;
|
---|
817 | cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be smaller than clienttimeout (%lu ms))", cfg->ftimeout, cfg->ctimeout);
|
---|
818 | }
|
---|
819 | if(cfg->ftimeout < cfg->srtimeout)
|
---|
820 | {
|
---|
821 | cfg->ftimeout = cfg->srtimeout + 100;
|
---|
822 | cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ftimeout, cfg->srtimeout);
|
---|
823 | }
|
---|
824 | if(cfg->ctimeout < cfg->srtimeout)
|
---|
825 | {
|
---|
826 | cfg->ctimeout = cfg->srtimeout + 100;
|
---|
827 | cs_log("WARNING: clienttimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ctimeout, cfg->srtimeout);
|
---|
828 | }
|
---|
829 | #ifdef CS_ANTICASC
|
---|
830 | if( cfg->ac_denysamples+1>cfg->ac_samples )
|
---|
831 | {
|
---|
832 | cfg->ac_denysamples=cfg->ac_samples-1;
|
---|
833 | cs_log("WARNING: DenySamples adjusted to %d", cfg->ac_denysamples);
|
---|
834 | }
|
---|
835 | #endif
|
---|
836 | return 0;
|
---|
837 | }
|
---|
838 |
|
---|
839 | void chk_account(char *token, char *value, struct s_auth *account)
|
---|
840 | {
|
---|
841 | int i;
|
---|
842 | char *ptr1;//, *ptr2;
|
---|
843 |
|
---|
844 | if (!strcmp(token, "user")) { cs_strncpy(account->usr, value, sizeof(account->usr)); return; }
|
---|
845 | if (!strcmp(token, "pwd")) { cs_strncpy(account->pwd, value, sizeof(account->pwd)); return; }
|
---|
846 | if (!strcmp(token, "hostname")) { cs_strncpy((char *)account->dyndns, value, sizeof(account->dyndns));return; }
|
---|
847 | if (!strcmp(token, "betatunnel")) { chk_tuntab(value, &account->ttab); return; }
|
---|
848 | if (!strcmp(token, "uniq")) { account->uniq=atoi(value); return; }
|
---|
849 | if (!strcmp(token, "sleep")) { account->tosleep=atoi(value); return; }
|
---|
850 | if (!strcmp(token, "monlevel")) { account->monlvl=atoi(value); return; }
|
---|
851 | if (!strcmp(token, "caid")) { chk_caidtab(value, &account->ctab); return; }
|
---|
852 | if (!strcmp(token, "disabled")) { account->disabled=atoi(value); return; }
|
---|
853 | if (!strcmp(token, "suppresscmd08")) { account->c35_suppresscmd08=atoi(value); return; }
|
---|
854 | if (!strcmp(token, "keepalive"))
|
---|
855 | {
|
---|
856 | account->ncd_keepalive = atoi(value);
|
---|
857 | return;
|
---|
858 | }
|
---|
859 | /*
|
---|
860 | * case insensitive
|
---|
861 | */
|
---|
862 | strtolower(value);
|
---|
863 | if (!strcmp(token, "au"))
|
---|
864 | {
|
---|
865 | //set default values for usage during runtime from Webif
|
---|
866 | account->au=-1;
|
---|
867 | account->autoau=0;
|
---|
868 |
|
---|
869 | if(value && value[0]=='1') account->autoau=1;
|
---|
870 | for (i=0; i<CS_MAXREADER; i++)
|
---|
871 | if ((reader[i].label[0]) &&
|
---|
872 | (!strncmp(reader[i].label, value, strlen(reader[i].label))))
|
---|
873 | account->au=i;
|
---|
874 | return;
|
---|
875 | }
|
---|
876 | if (!strcmp(token, "group")) {
|
---|
877 | account->grp = 0;
|
---|
878 | for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ","))
|
---|
879 | {
|
---|
880 | int g;
|
---|
881 | g=atoi(ptr1);
|
---|
882 | if ((g>0) && (g<33)) account->grp|=(1<<(g-1));
|
---|
883 | }
|
---|
884 | return;
|
---|
885 | }
|
---|
886 | if(!strcmp(token, "services")) { chk_services(value, &account->sidtabok, &account->sidtabno); return; }
|
---|
887 | if(!strcmp(token, "ident")) { chk_ftab(value, &account->ftab, "user", account->usr, "provid"); return; }
|
---|
888 | if(!strcmp(token, "class")) { chk_cltab(value, &account->cltab); return; }
|
---|
889 | if(!strcmp(token, "chid")) { chk_ftab(value, &account->fchid, "user", account->usr, "chid"); return; }
|
---|
890 |
|
---|
891 | if (!strcmp(token, "expdate"))
|
---|
892 | {
|
---|
893 | if (!value[0]) {
|
---|
894 | account->expirationdate=(time_t)NULL;
|
---|
895 | return;
|
---|
896 | }
|
---|
897 | struct tm cstime;
|
---|
898 | memset(&cstime,0,sizeof(cstime));
|
---|
899 | for (i=0, ptr1=strtok(value, "-/"); (i<3)&&(ptr1); ptr1=strtok(NULL, "-/"), i++)
|
---|
900 | {
|
---|
901 | switch(i)
|
---|
902 | {
|
---|
903 | case 0: cstime.tm_year=atoi(ptr1)-1900; break;
|
---|
904 | case 1: cstime.tm_mon =atoi(ptr1)-1; break;
|
---|
905 | case 2: cstime.tm_mday=atoi(ptr1); break;
|
---|
906 | }
|
---|
907 | }
|
---|
908 | account->expirationdate=mktime(&cstime);
|
---|
909 | return;
|
---|
910 | }
|
---|
911 |
|
---|
912 | #ifdef CS_ANTICASC
|
---|
913 | if( !strcmp(token, "numusers") )
|
---|
914 | {
|
---|
915 | account->ac_users = atoi(value);
|
---|
916 | return;
|
---|
917 | }
|
---|
918 | if( !strcmp(token, "penalty") )
|
---|
919 | {
|
---|
920 | account->ac_penalty = atoi(value);
|
---|
921 | return;
|
---|
922 | }
|
---|
923 | #endif
|
---|
924 | if (token[0] != '#')
|
---|
925 | fprintf(stderr, "Warning: keyword '%s' in account section not recognized\n",token);
|
---|
926 |
|
---|
927 | // if (!strcmp(token, "caid"))
|
---|
928 | // {
|
---|
929 | // for (i=0, ptr1=strtok(value, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ","))
|
---|
930 | // {
|
---|
931 | // ulong caid, mask;
|
---|
932 | // if (ptr2=strchr(trim(ptr1), '&'))
|
---|
933 | // *ptr2++='\0';
|
---|
934 | // else
|
---|
935 | // ptr2="";
|
---|
936 | // if (((caid=a2i(ptr1, 2))|(mask=a2i(ptr2,-2))) < 0x10000)
|
---|
937 | // {
|
---|
938 | // account->caidtab[i][0]=caid;
|
---|
939 | // account->caidtab[i++][1]=mask;
|
---|
940 | // }
|
---|
941 | // else
|
---|
942 | // cs_log("WARNING: wrong CAID in %s -> ignored", cs_user);
|
---|
943 | // }
|
---|
944 | // }
|
---|
945 | }
|
---|
946 |
|
---|
947 | int write_services()
|
---|
948 | {
|
---|
949 | int i;
|
---|
950 | FILE *f;
|
---|
951 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
952 | char tmpfile[256];
|
---|
953 | char destfile[256];
|
---|
954 | char bakfile[256];
|
---|
955 |
|
---|
956 | snprintf(destfile, 255,"%s%s", cs_confdir, cs_sidt);
|
---|
957 | snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_sidt);
|
---|
958 | snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_sidt);
|
---|
959 |
|
---|
960 | if (!(f=fopen(tmpfile, "w"))){
|
---|
961 | cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
|
---|
962 | return(1);
|
---|
963 | }
|
---|
964 | fprintf(f,"#oscam.services generated automatically\n\n");
|
---|
965 |
|
---|
966 | while(sidtab != NULL){
|
---|
967 | fprintf(f,"[%s]\n", sidtab->label);
|
---|
968 | fprintf_conf(f, CONFVARWIDTH, "caid", "");
|
---|
969 | for (i=0; i<sidtab->num_caid; i++){
|
---|
970 | if (i==0) fprintf(f,"%04X", sidtab->caid[i]);
|
---|
971 | else fprintf(f,",%04X", sidtab->caid[i]);
|
---|
972 | }
|
---|
973 | fputc((int)'\n', f);
|
---|
974 | fprintf_conf(f, CONFVARWIDTH, "provid", "");
|
---|
975 | for (i=0; i<sidtab->num_provid; i++){
|
---|
976 | if (i==0) fprintf(f,"%08lX", sidtab->provid[i]);
|
---|
977 | else fprintf(f,",%08lX", sidtab->provid[i]);
|
---|
978 | }
|
---|
979 | fputc((int)'\n', f);
|
---|
980 | fprintf_conf(f, CONFVARWIDTH, "srvid", "");
|
---|
981 | for (i=0; i<sidtab->num_srvid; i++){
|
---|
982 | if (i==0) fprintf(f,"%04X", sidtab->srvid[i]);
|
---|
983 | else fprintf(f,",%04X", sidtab->srvid[i]);
|
---|
984 | }
|
---|
985 | fprintf(f,"\n\n");
|
---|
986 | sidtab=sidtab->next;
|
---|
987 | }
|
---|
988 |
|
---|
989 | fclose(f);
|
---|
990 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
991 | }
|
---|
992 |
|
---|
993 | int write_config()
|
---|
994 | {
|
---|
995 | int i,j;
|
---|
996 | FILE *f;
|
---|
997 | char *dot = "", *dot1 = "", *dot2 = ""; //flags for delimiters
|
---|
998 | char tmpfile[256];
|
---|
999 | char destfile[256];
|
---|
1000 | char bakfile[256];
|
---|
1001 |
|
---|
1002 | snprintf(destfile, 255,"%s%s", cs_confdir, cs_conf);
|
---|
1003 | snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_conf);
|
---|
1004 | snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_conf);
|
---|
1005 |
|
---|
1006 | if (!(f=fopen(tmpfile, "w"))){
|
---|
1007 | cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
|
---|
1008 | return(1);
|
---|
1009 | }
|
---|
1010 | fprintf(f,"#oscam.config generated automatically\n\n");
|
---|
1011 |
|
---|
1012 | /*global settings*/
|
---|
1013 | fprintf(f,"[global]\n");
|
---|
1014 | if (cfg->srvip != 0)
|
---|
1015 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->srvip));
|
---|
1016 | if (cfg->pidfile != NULL) fprintf_conf(f, CONFVARWIDTH, "pidfile", "%s\n", cfg->pidfile);
|
---|
1017 | if (cfg->usrfile != NULL) fprintf_conf(f, CONFVARWIDTH, "usrfile", "%s\n", cfg->usrfile);
|
---|
1018 | if (cfg->logfile != NULL) fprintf_conf(f, CONFVARWIDTH, "logfile", "%s\n", cfg->logfile);
|
---|
1019 | if (cfg->cwlogdir != NULL) fprintf_conf(f, CONFVARWIDTH, "cwlogdir", "%s\n", cfg->cwlogdir);
|
---|
1020 | fprintf_conf(f, CONFVARWIDTH, "usrfileflag", "%d\n", cfg->usrfileflag);
|
---|
1021 | fprintf_conf(f, CONFVARWIDTH, "clienttimeout", "%ld\n", cfg->ctimeout/1000);
|
---|
1022 | fprintf_conf(f, CONFVARWIDTH, "fallbacktimeout", "%ld\n", cfg->ftimeout/1000);
|
---|
1023 | fprintf_conf(f, CONFVARWIDTH, "clientmaxidle", "%d\n", cfg->cmaxidle);
|
---|
1024 | fprintf_conf(f, CONFVARWIDTH, "cachedelay", "%ld\n", cfg->delay);
|
---|
1025 | fprintf_conf(f, CONFVARWIDTH, "bindwait", "%d\n", cfg->bindwait);
|
---|
1026 | fprintf_conf(f, CONFVARWIDTH, "netprio", "%ld\n", cfg->netprio);
|
---|
1027 | fprintf_conf(f, CONFVARWIDTH, "resolvedelay", "%d\n", cfg->resolvedelay);
|
---|
1028 | if (cfg->tosleep) fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", cfg->tosleep);
|
---|
1029 | fprintf_conf(f, CONFVARWIDTH, "unlockparental", "%d\n", cfg->ulparent);
|
---|
1030 | fprintf_conf(f, CONFVARWIDTH, "nice", "%d\n", cfg->nice);
|
---|
1031 | fprintf_conf(f, CONFVARWIDTH, "serialreadertimeout", "%d\n", cfg->srtimeout);
|
---|
1032 | fprintf_conf(f, CONFVARWIDTH, "maxlogsize", "%d\n", cfg->max_log_size);
|
---|
1033 | fprintf_conf(f, CONFVARWIDTH, "waitforcards", "%d\n", cfg->waitforcards);
|
---|
1034 | fprintf_conf(f, CONFVARWIDTH, "preferlocalcards", "%d\n", cfg->preferlocalcards);
|
---|
1035 | fputc((int)'\n', f);
|
---|
1036 |
|
---|
1037 | /*monitor settings*/
|
---|
1038 | fprintf(f,"[monitor]\n");
|
---|
1039 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->mon_port);
|
---|
1040 | if (cfg->mon_srvip != 0)
|
---|
1041 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip));
|
---|
1042 |
|
---|
1043 | fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
|
---|
1044 | struct s_ip *cip;
|
---|
1045 | for (cip = cfg->mon_allowed; cip; cip = cip->next){
|
---|
1046 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
1047 | if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
1048 | dot=",";
|
---|
1049 | }
|
---|
1050 | fputc((int)'\n', f);
|
---|
1051 | fprintf_conf(f, CONFVARWIDTH, "aulow", "%d\n", cfg->mon_aulow);
|
---|
1052 | fprintf_conf(f, CONFVARWIDTH, "hideclient_to", "%d\n", cfg->mon_hideclient_to);
|
---|
1053 | fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", cfg->mon_level);
|
---|
1054 | fprintf_conf(f, CONFVARWIDTH, "httpport", "%d\n", cfg->http_port);
|
---|
1055 | fprintf_conf(f, CONFVARWIDTH, "httpuser", "%s\n", cfg->http_user);
|
---|
1056 | fprintf_conf(f, CONFVARWIDTH, "httppwd", "%s\n", cfg->http_pwd);
|
---|
1057 | fprintf_conf(f, CONFVARWIDTH, "httpcss", "%s\n", cfg->http_css);
|
---|
1058 | fprintf_conf(f, CONFVARWIDTH, "httpscript", "%s\n", cfg->http_script);
|
---|
1059 | fprintf_conf(f, CONFVARWIDTH, "httprefresh", "%d\n", cfg->http_refresh);
|
---|
1060 | fprintf_conf(f, CONFVARWIDTH, "httphideidleclients", "%d\n", cfg->http_hide_idle_clients);
|
---|
1061 | fputc((int)'\n', f);
|
---|
1062 |
|
---|
1063 | /*newcamd*/
|
---|
1064 | if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)){
|
---|
1065 | fprintf(f,"[newcamd]\n");
|
---|
1066 | fprintf_conf(f, CONFVARWIDTH, "port", "");
|
---|
1067 | dot1 = "";
|
---|
1068 | for(i = 0; i < cfg->ncd_ptab.nports; ++i){
|
---|
1069 | fprintf(f,"%s%d@%04X", dot1, cfg->ncd_ptab.ports[i].s_port, cfg->ncd_ptab.ports[i].ftab.filts[0].caid);
|
---|
1070 | if (cfg->ncd_ptab.ports[i].ftab.filts[0].nprids > 0){
|
---|
1071 | fprintf(f,":");
|
---|
1072 | dot2 = "";
|
---|
1073 | for (j = 0; j < cfg->ncd_ptab.ports[i].ftab.filts[0].nprids; ++j){
|
---|
1074 | fprintf(f,"%s%06X", dot2, (int)cfg->ncd_ptab.ports[i].ftab.filts[0].prids[j]);
|
---|
1075 | dot2 = ",";
|
---|
1076 | }
|
---|
1077 | }
|
---|
1078 | dot1=";";
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 | fputc((int)'\n', f);
|
---|
1082 | if (cfg->ncd_srvip != 0)
|
---|
1083 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->ncd_srvip));
|
---|
1084 | fprintf_conf(f, CONFVARWIDTH, "key", "");
|
---|
1085 | for (i=0;i<14;i++) fprintf(f,"%02X", cfg->ncd_key[i]);
|
---|
1086 | fprintf(f,"\n");
|
---|
1087 | fprintf_conf(f, CONFVARWIDTH, "allowed", "");
|
---|
1088 | struct s_ip *cip;
|
---|
1089 | dot="";
|
---|
1090 | for (cip = cfg->ncd_allowed; cip; cip = cip->next){
|
---|
1091 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
1092 | if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
1093 | dot=",";
|
---|
1094 | }
|
---|
1095 | fprintf(f,"\n");
|
---|
1096 | fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", cfg->ncd_keepalive);
|
---|
1097 | fprintf(f,"\n");
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | /*camd3.3*/
|
---|
1101 | if ( cfg->c33_port > 0) {
|
---|
1102 | fprintf(f,"[camd33]\n");
|
---|
1103 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c33_port);
|
---|
1104 | if (cfg->c33_srvip != 0)
|
---|
1105 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip));
|
---|
1106 | fprintf_conf(f, CONFVARWIDTH, "passive", "%d\n", cfg->c33_passive);
|
---|
1107 | 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);
|
---|
1108 | fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
|
---|
1109 | dot="";
|
---|
1110 | for (cip = cfg->c33_plain; cip; cip = cip->next){
|
---|
1111 | fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
|
---|
1112 | if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
|
---|
1113 | dot=",";
|
---|
1114 | }
|
---|
1115 | fprintf(f,"\n\n");
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | /*camd3.5*/
|
---|
1119 | if ( cfg->c35_port > 0) {
|
---|
1120 | fprintf(f,"[cs357x]\n");
|
---|
1121 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c35_port);
|
---|
1122 | if (cfg->c35_tcp_srvip != 0)
|
---|
1123 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
|
---|
1124 | if (cfg->c35_suppresscmd08)
|
---|
1125 | fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", cfg->c35_suppresscmd08);
|
---|
1126 | fprintf(f,"\n");
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | /*camd3.5 TCP*/
|
---|
1130 | if ((cfg->c35_tcp_ptab.nports > 0) && (cfg->c35_tcp_ptab.ports[0].s_port > 0)) {
|
---|
1131 | fprintf(f,"[cs378x]\n");
|
---|
1132 | fprintf_conf(f, CONFVARWIDTH, "port", "");
|
---|
1133 | dot1 = "";
|
---|
1134 | for(i = 0; i < cfg->c35_tcp_ptab.nports; ++i){
|
---|
1135 | fprintf(f,"%s%d@%04X", dot1, cfg->c35_tcp_ptab.ports[i].s_port, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].caid);
|
---|
1136 | if (cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 0){
|
---|
1137 | fprintf(f,":");
|
---|
1138 | dot2 = "";
|
---|
1139 | for (j = 0; j < cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j){
|
---|
1140 | fprintf(f,"%s%lX", dot2, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]);
|
---|
1141 | dot2 = ",";
|
---|
1142 | }
|
---|
1143 | }
|
---|
1144 | dot1=";";
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | fputc((int)'\n', f);
|
---|
1148 | if (cfg->c35_tcp_srvip != 0)
|
---|
1149 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
|
---|
1150 | fputc((int)'\n', f);
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | /*Radegast*/
|
---|
1154 | if ( cfg->rad_port > 0) {
|
---|
1155 | fprintf(f,"[radegast]\n");
|
---|
1156 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->rad_port);
|
---|
1157 | if (cfg->rad_srvip != 0)
|
---|
1158 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->rad_srvip));
|
---|
1159 | fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->rad_usr);
|
---|
1160 | fprintf_conf(f, CONFVARWIDTH, "allowed", "");
|
---|
1161 | struct s_ip *cip;
|
---|
1162 | for (cip = cfg->rad_allowed; cip; cip = cip->next){
|
---|
1163 | fprintf(f,"%s%s", dot, inet_ntoa(*(struct in_addr *)&cip->ip[0]));
|
---|
1164 | if (cip->ip[0] == cip->ip[1]) fprintf(f,"-%s", inet_ntoa(*(struct in_addr *)&cip->ip[1]));
|
---|
1165 | dot=",";
|
---|
1166 | }
|
---|
1167 | fprintf(f,"\n\n");
|
---|
1168 | }
|
---|
1169 |
|
---|
1170 | #ifdef CS_WITH_GBOX
|
---|
1171 | /*Gbox*/
|
---|
1172 | if ((cfg->gbox_pwd[0] > 0) || (cfg->gbox_pwd[1] > 0) || (cfg->gbox_pwd[2] > 0) || (cfg->gbox_pwd[3] > 0)){
|
---|
1173 | fprintf(f,"[gbox]\n");
|
---|
1174 | fprintf_conf(f, CONFVARWIDTH, "password", ""); for (i=0;i<4;i++) fprintf(f,"%02X", cfg->gbox_pwd[i]); fputc((int)'\n', f);;
|
---|
1175 | fprintf_conf(f, CONFVARWIDTH, "maxdist", "%d\n", cfg->maxdist);
|
---|
1176 | fprintf_conf(f, CONFVARWIDTH, "ignorelist", "%s\n", cfg->ignorefile);
|
---|
1177 | fprintf_conf(f, CONFVARWIDTH, "onlineinfos", "%s\n", cfg->gbxShareOnl);
|
---|
1178 | fprintf_conf(f, CONFVARWIDTH, "cardinfos", "%s\n", cfg->cardfile);
|
---|
1179 | fprintf_conf(f, CONFVARWIDTH, "locals", "");
|
---|
1180 | char *dot = "";
|
---|
1181 | for (i = 0; i < cfg->num_locals; i++){
|
---|
1182 | fprintf(f,"%s%06lX", dot, cfg->locals[i]);
|
---|
1183 | dot=";";
|
---|
1184 | }
|
---|
1185 | fprintf(f,"\n\n");
|
---|
1186 | }
|
---|
1187 | #endif
|
---|
1188 |
|
---|
1189 | /*serial*/
|
---|
1190 |
|
---|
1191 |
|
---|
1192 | /*cccam*/
|
---|
1193 | if ( cfg->cc_port > 0) {
|
---|
1194 | fprintf(f,"[cccam]\n");
|
---|
1195 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->cc_port);
|
---|
1196 | fprintf_conf(f, CONFVARWIDTH, "reshare", "%d\n", cfg->cc_reshare);
|
---|
1197 | fprintf_conf(f, CONFVARWIDTH, "version", "%s\n", cfg->cc_version);
|
---|
1198 | fprintf_conf(f, CONFVARWIDTH, "build", "%s\n", cfg->cc_build);
|
---|
1199 | fprintf(f,"\n");
|
---|
1200 | }
|
---|
1201 |
|
---|
1202 | #ifdef HAVE_DVBAPI
|
---|
1203 | /*dvb-api*/
|
---|
1204 | if (cfg->dvbapi_enabled > 0) {
|
---|
1205 | fprintf(f,"[dvbapi]\n");
|
---|
1206 | fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->dvbapi_enabled);
|
---|
1207 | fprintf_conf(f, CONFVARWIDTH, "au", "%d\n", cfg->dvbapi_au);
|
---|
1208 | fprintf_conf(f, CONFVARWIDTH, "boxtype", "%s\n", cfg->dvbapi_boxtype);
|
---|
1209 | fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->dvbapi_usr);
|
---|
1210 | fputc((int)'\n', f);
|
---|
1211 | }
|
---|
1212 | #endif
|
---|
1213 |
|
---|
1214 | #ifdef CS_ANTICASC
|
---|
1215 | fprintf(f,"[anticasc]\n");
|
---|
1216 | fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->ac_enabled);
|
---|
1217 | fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", cfg->ac_users);
|
---|
1218 | fprintf_conf(f, CONFVARWIDTH, "sampletime", "%d\n", cfg->ac_stime);
|
---|
1219 | fprintf_conf(f, CONFVARWIDTH, "samples", "%d\n", cfg->ac_samples);
|
---|
1220 | fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", cfg->ac_penalty);
|
---|
1221 | fprintf_conf(f, CONFVARWIDTH, "aclogfile", "%s\n", cfg->ac_logfile);
|
---|
1222 | fprintf_conf(f, CONFVARWIDTH, "denysamples", "%d\n", cfg->ac_denysamples);
|
---|
1223 | fprintf_conf(f, CONFVARWIDTH, "fakedelay", "%d\n", cfg->ac_fakedelay);
|
---|
1224 | fputc((int)'\n', f);
|
---|
1225 | #endif
|
---|
1226 |
|
---|
1227 | fclose(f);
|
---|
1228 |
|
---|
1229 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | int write_userdb()
|
---|
1233 | {
|
---|
1234 | int i;
|
---|
1235 | FILE *f;
|
---|
1236 | struct s_auth *account;
|
---|
1237 | char *dot = ""; //flag for comma
|
---|
1238 | char tmpfile[256];
|
---|
1239 | char destfile[256];
|
---|
1240 | char bakfile[256];
|
---|
1241 |
|
---|
1242 | snprintf(destfile, 255,"%s%s", cs_confdir, cs_user);
|
---|
1243 | snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_user);
|
---|
1244 | snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_user);
|
---|
1245 |
|
---|
1246 | if (!(f=fopen(tmpfile, "w"))){
|
---|
1247 | cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
|
---|
1248 | return(1);
|
---|
1249 | }
|
---|
1250 | fprintf(f,"#oscam.user generated automatically\n\n");
|
---|
1251 |
|
---|
1252 | //each account
|
---|
1253 | for (account=cfg->account; (account) ; account=account->next){
|
---|
1254 | fprintf(f,"[account]\n");
|
---|
1255 | fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", account->usr);
|
---|
1256 | fprintf_conf(f, CONFVARWIDTH, "pwd", "%s\n", account->pwd);
|
---|
1257 | fprintf_conf(f, CONFVARWIDTH, "disabled", "%d\n", account->disabled);
|
---|
1258 | struct tm * timeinfo = localtime (&account->expirationdate);
|
---|
1259 | char buf [80];
|
---|
1260 | strftime (buf,80,"%Y-%m-%d",timeinfo);
|
---|
1261 | if(strcmp(buf,"1970-01-01"))
|
---|
1262 | fprintf_conf(f, CONFVARWIDTH, "expdate", "%s\n", buf);
|
---|
1263 | else
|
---|
1264 | fprintf_conf(f, CONFVARWIDTH, "expdate", "\n");
|
---|
1265 |
|
---|
1266 | //group
|
---|
1267 | char *value = mk_t_group((ulong*)account->grp);
|
---|
1268 | fprintf_conf(f, CONFVARWIDTH, "group", "%s\n", value);
|
---|
1269 | free(value);
|
---|
1270 |
|
---|
1271 | fprintf_conf(f, CONFVARWIDTH, "hostname", "%s\n", account->dyndns);
|
---|
1272 | fprintf_conf(f, CONFVARWIDTH, "uniq", "%d\n", account->uniq);
|
---|
1273 | fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", account->tosleep);
|
---|
1274 | fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", account->monlvl);
|
---|
1275 |
|
---|
1276 | if (account->au > -1)
|
---|
1277 | if (account->au < CS_MAXREADER)
|
---|
1278 | fprintf_conf(f, CONFVARWIDTH, "au", "%s\n", reader[account->au].label);
|
---|
1279 | if (account->autoau == 1) fprintf_conf(f, CONFVARWIDTH, "au", "1\n");
|
---|
1280 |
|
---|
1281 | fprintf_conf(f, CONFVARWIDTH, "services", "");
|
---|
1282 | char sidok[33]; long2bitchar(account->sidtabok,sidok);
|
---|
1283 | char sidno[33]; long2bitchar(account->sidtabno,sidno);
|
---|
1284 | struct s_sidtab *sidtab = cfg->sidtab;
|
---|
1285 | i=0; dot = "";
|
---|
1286 | for (; sidtab; sidtab=sidtab->next){
|
---|
1287 | if(sidok[i]=='1') {fprintf(f,"%s%s", dot, sidtab->label); dot = ",";}
|
---|
1288 | if(sidno[i]=='1') {fprintf(f,"%s!%s", dot, sidtab->label); dot = ",";}
|
---|
1289 | i++;
|
---|
1290 | }
|
---|
1291 | fputc((int)'\n', f);
|
---|
1292 |
|
---|
1293 | //CAID
|
---|
1294 | value = mk_t_caidtab(&account->ctab);
|
---|
1295 | fprintf_conf(f, CONFVARWIDTH, "caid", "%s\n", value);
|
---|
1296 | free(value);
|
---|
1297 |
|
---|
1298 | //betatunnel
|
---|
1299 | value = mk_t_tuntab(&account->ttab);
|
---|
1300 | fprintf_conf(f, CONFVARWIDTH, "betatunnel", "%s\n", value);
|
---|
1301 | free(value);
|
---|
1302 |
|
---|
1303 | //ident
|
---|
1304 | value = mk_t_ftab(&account->ftab);
|
---|
1305 | fprintf_conf(f, CONFVARWIDTH, "ident", "%s\n", value);
|
---|
1306 | free(value);
|
---|
1307 |
|
---|
1308 | if (account->c35_suppresscmd08)
|
---|
1309 | fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", account->c35_suppresscmd08);
|
---|
1310 |
|
---|
1311 | fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", account->ncd_keepalive);
|
---|
1312 |
|
---|
1313 | #ifdef CS_ANTICASC
|
---|
1314 | fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", account->ac_users);
|
---|
1315 | fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", account->ac_penalty);
|
---|
1316 | #endif
|
---|
1317 | fputc((int)'\n', f);
|
---|
1318 | }
|
---|
1319 | fclose(f);
|
---|
1320 |
|
---|
1321 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | int init_userdb()
|
---|
1325 | {
|
---|
1326 | int tag = 0, nr, nro, expired, disabled;
|
---|
1327 | //int first=1;
|
---|
1328 | FILE *fp;
|
---|
1329 | char *value;
|
---|
1330 | struct s_auth *ptr;
|
---|
1331 | /*static */struct s_auth *account=(struct s_auth *)0;
|
---|
1332 |
|
---|
1333 | sprintf(token, "%s%s", cs_confdir, cs_user);
|
---|
1334 | if (!(fp = fopen(token, "r"))) {
|
---|
1335 | cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
|
---|
1336 | return(1);
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | for (nro = 0, ptr = cfg->account; ptr; nro++) {
|
---|
1340 | struct s_auth *ptr_next;
|
---|
1341 | ptr_next = ptr->next;
|
---|
1342 | free(ptr);
|
---|
1343 | ptr = ptr_next;
|
---|
1344 | }
|
---|
1345 | nr = 0;
|
---|
1346 |
|
---|
1347 | while (fgets(token, sizeof(token), fp)) {
|
---|
1348 | int i, l;
|
---|
1349 | void *ptr;
|
---|
1350 |
|
---|
1351 | if ((l=strlen(trim(token))) < 3)
|
---|
1352 | continue;
|
---|
1353 |
|
---|
1354 | if ((token[0] == '[') && (token[l-1] == ']')) {
|
---|
1355 | token[l - 1] = 0;
|
---|
1356 | tag = (!strcmp("account", strtolower(token + 1)));
|
---|
1357 |
|
---|
1358 | if (!(ptr=malloc(sizeof(struct s_auth)))) {
|
---|
1359 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
1360 | return(1);
|
---|
1361 | }
|
---|
1362 |
|
---|
1363 | if (account)
|
---|
1364 | account->next = ptr;
|
---|
1365 | else
|
---|
1366 | cfg->account = ptr;
|
---|
1367 |
|
---|
1368 | account = ptr;
|
---|
1369 | memset(account, 0, sizeof(struct s_auth));
|
---|
1370 | account->au = (-1);
|
---|
1371 | account->monlvl = cfg->mon_level;
|
---|
1372 | account->tosleep = cfg->tosleep;
|
---|
1373 | account->c35_suppresscmd08 = cfg->c35_suppresscmd08;
|
---|
1374 | account->ncd_keepalive = cfg->ncd_keepalive;
|
---|
1375 | for (i = 1; i < CS_MAXCAIDTAB; account->ctab.mask[i++] = 0xffff);
|
---|
1376 | for (i = 1; i < CS_MAXTUNTAB; account->ttab.bt_srvid[i++] = 0x0000);
|
---|
1377 | nr++;
|
---|
1378 |
|
---|
1379 | #ifdef CS_ANTICASC
|
---|
1380 | account->ac_users = cfg->ac_users;
|
---|
1381 | account->ac_penalty = cfg->ac_penalty;
|
---|
1382 | account->ac_idx = nr;
|
---|
1383 | #endif
|
---|
1384 | continue;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | if (!tag)
|
---|
1388 | continue;
|
---|
1389 |
|
---|
1390 | if (!(value=strchr(token, '=')))
|
---|
1391 | continue;
|
---|
1392 |
|
---|
1393 | *value++ = '\0';
|
---|
1394 | chk_account(trim(strtolower(token)), trim(value), account);
|
---|
1395 | }
|
---|
1396 |
|
---|
1397 | fclose(fp);
|
---|
1398 |
|
---|
1399 | for (expired = 0, disabled = 0, ptr = cfg->account; ptr;) {
|
---|
1400 |
|
---|
1401 | if(ptr->expirationdate && ptr->expirationdate < time(NULL))
|
---|
1402 | expired++;
|
---|
1403 |
|
---|
1404 | if(ptr->disabled != 0)
|
---|
1405 | disabled++;
|
---|
1406 |
|
---|
1407 | ptr = ptr->next;
|
---|
1408 | }
|
---|
1409 |
|
---|
1410 | cs_log("userdb reloaded: %d accounts freed, %d accounts loaded, %d expired, %d disabled", nro, nr, expired, disabled);
|
---|
1411 | return(0);
|
---|
1412 | }
|
---|
1413 |
|
---|
1414 | static void chk_entry4sidtab(char *value, struct s_sidtab *sidtab, int what)
|
---|
1415 | {
|
---|
1416 | int i, b;
|
---|
1417 | char *ptr;
|
---|
1418 | ushort *slist=(ushort *) 0;
|
---|
1419 | ulong *llist=(ulong *) 0;
|
---|
1420 | ulong caid;
|
---|
1421 | char buf[strlen(value) + 1];
|
---|
1422 | cs_strncpy(buf, value, sizeof(buf));
|
---|
1423 | b=(what==1) ? sizeof(ulong) : sizeof(ushort);
|
---|
1424 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
1425 | {
|
---|
1426 | caid=a2i(ptr, b);
|
---|
1427 | if (!errno) i++;
|
---|
1428 | }
|
---|
1429 | //if (!i) return(0);
|
---|
1430 | if (b==sizeof(ushort))
|
---|
1431 | slist=malloc(i*sizeof(ushort));
|
---|
1432 | else
|
---|
1433 | llist=malloc(i*sizeof(ulong));
|
---|
1434 | strcpy(value, buf);
|
---|
1435 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
1436 | {
|
---|
1437 | caid=a2i(ptr, b);
|
---|
1438 | if (errno) continue;
|
---|
1439 | if (b==sizeof(ushort))
|
---|
1440 | slist[i++]=(ushort) caid;
|
---|
1441 | else
|
---|
1442 | llist[i++]=caid;
|
---|
1443 | }
|
---|
1444 | switch (what)
|
---|
1445 | {
|
---|
1446 | case 0: sidtab->caid=slist;
|
---|
1447 | sidtab->num_caid=i;
|
---|
1448 | break;
|
---|
1449 | case 1: sidtab->provid=llist;
|
---|
1450 | sidtab->num_provid=i;
|
---|
1451 | break;
|
---|
1452 | case 2: sidtab->srvid=slist;
|
---|
1453 | sidtab->num_srvid=i;
|
---|
1454 | break;
|
---|
1455 | }
|
---|
1456 | }
|
---|
1457 |
|
---|
1458 | void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab)
|
---|
1459 | {
|
---|
1460 | if (!strcmp(token, "caid")) { chk_entry4sidtab(value, sidtab, 0); return; }
|
---|
1461 | if (!strcmp(token, "provid")) { chk_entry4sidtab(value, sidtab, 1); return; }
|
---|
1462 | if (!strcmp(token, "ident")) { chk_entry4sidtab(value, sidtab, 1); return; }
|
---|
1463 | if (!strcmp(token, "srvid")) { chk_entry4sidtab(value, sidtab, 2); return; }
|
---|
1464 | if (token[0] != '#')
|
---|
1465 | fprintf(stderr, "Warning: keyword '%s' in sidtab section not recognized\n",token);
|
---|
1466 | }
|
---|
1467 |
|
---|
1468 | int init_sidtab()
|
---|
1469 | {
|
---|
1470 | int nr, nro;
|
---|
1471 | FILE *fp;
|
---|
1472 | char *value;
|
---|
1473 | struct s_sidtab *ptr;
|
---|
1474 | struct s_sidtab *sidtab=(struct s_sidtab *)0;
|
---|
1475 |
|
---|
1476 | sprintf(token, "%s%s", cs_confdir, cs_sidt);
|
---|
1477 | if (!(fp=fopen(token, "r")))
|
---|
1478 | {
|
---|
1479 | cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
|
---|
1480 | return(1);
|
---|
1481 | }
|
---|
1482 | for (nro=0, ptr=cfg->sidtab; ptr; nro++)
|
---|
1483 | {
|
---|
1484 | struct s_sidtab *ptr_next;
|
---|
1485 | ptr_next=ptr->next;
|
---|
1486 | if (ptr->caid) free(ptr->caid);
|
---|
1487 | if (ptr->provid) free(ptr->provid);
|
---|
1488 | if (ptr->srvid) free(ptr->srvid);
|
---|
1489 | free(ptr);
|
---|
1490 | ptr=ptr_next;
|
---|
1491 | }
|
---|
1492 | nr=0;
|
---|
1493 | while (fgets(token, sizeof(token), fp))
|
---|
1494 | {
|
---|
1495 | int l;
|
---|
1496 | void *ptr;
|
---|
1497 | if ((l=strlen(trim(token)))<3) continue;
|
---|
1498 | if ((token[0]=='[') && (token[l-1]==']'))
|
---|
1499 | {
|
---|
1500 | token[l-1]=0;
|
---|
1501 | if (!(ptr=malloc(sizeof(struct s_sidtab))))
|
---|
1502 | {
|
---|
1503 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
1504 | return(1);
|
---|
1505 | }
|
---|
1506 | if (sidtab)
|
---|
1507 | sidtab->next=ptr;
|
---|
1508 | else
|
---|
1509 | cfg->sidtab=ptr;
|
---|
1510 | sidtab=ptr;
|
---|
1511 | nr++;
|
---|
1512 | memset(sidtab, 0, sizeof(struct s_sidtab));
|
---|
1513 | cs_strncpy(sidtab->label, strtolower(token+1), sizeof(sidtab->label));
|
---|
1514 | continue;
|
---|
1515 | }
|
---|
1516 | if (!sidtab) continue;
|
---|
1517 | if (!(value=strchr(token, '='))) continue;
|
---|
1518 | *value++='\0';
|
---|
1519 | chk_sidtab(trim(strtolower(token)), trim(strtolower(value)), sidtab);
|
---|
1520 | }
|
---|
1521 | fclose(fp);
|
---|
1522 |
|
---|
1523 | #ifdef DEBUG_SIDTAB
|
---|
1524 | show_sidtab(cfg->sidtab);
|
---|
1525 | #endif
|
---|
1526 | cs_log("services reloaded: %d services freed, %d services loaded", nro, nr);
|
---|
1527 | return(0);
|
---|
1528 | }
|
---|
1529 |
|
---|
1530 | int init_srvid()
|
---|
1531 | {
|
---|
1532 | int nr;
|
---|
1533 | FILE *fp;
|
---|
1534 | char *payload;
|
---|
1535 | static struct s_srvid *srvid=(struct s_srvid *)0;
|
---|
1536 | sprintf(token, "%s%s", cs_confdir, cs_srid);
|
---|
1537 |
|
---|
1538 | if (!(fp=fopen(token, "r"))) {
|
---|
1539 | cs_log("can't open file \"%s\" (err=%d), no service-id's loaded", token, errno);
|
---|
1540 | return(0);
|
---|
1541 | }
|
---|
1542 |
|
---|
1543 | nr=0;
|
---|
1544 | while (fgets(token, sizeof(token), fp)) {
|
---|
1545 |
|
---|
1546 | int l;
|
---|
1547 | void *ptr;
|
---|
1548 | char *tmp;
|
---|
1549 | tmp = trim(token);
|
---|
1550 |
|
---|
1551 | if (tmp[0] == '#') continue;
|
---|
1552 | if ((l=strlen(tmp)) < 6) continue;
|
---|
1553 | if (!(payload=strchr(token, '|'))) continue;
|
---|
1554 | *payload++ = '\0';
|
---|
1555 |
|
---|
1556 | if (!(ptr = malloc(sizeof(struct s_srvid)))) {
|
---|
1557 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
1558 | return(1);
|
---|
1559 | }
|
---|
1560 |
|
---|
1561 | if (srvid)
|
---|
1562 | srvid->next = ptr;
|
---|
1563 | else
|
---|
1564 | cfg->srvid = ptr;
|
---|
1565 |
|
---|
1566 | srvid = ptr;
|
---|
1567 | memset(srvid, 0, sizeof(struct s_srvid));
|
---|
1568 |
|
---|
1569 | int i;
|
---|
1570 | char *ptr1;
|
---|
1571 | for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
|
---|
1572 | switch(i){
|
---|
1573 | case 0:
|
---|
1574 | cs_strncpy(srvid->prov, trim(ptr1), sizeof(srvid->prov));
|
---|
1575 | break;
|
---|
1576 | case 1:
|
---|
1577 | cs_strncpy(srvid->name, trim(ptr1), sizeof(srvid->name));
|
---|
1578 | break;
|
---|
1579 | case 2:
|
---|
1580 | cs_strncpy(srvid->type, trim(ptr1), sizeof(srvid->type));
|
---|
1581 | break;
|
---|
1582 | case 3:
|
---|
1583 | cs_strncpy(srvid->desc, trim(ptr1), sizeof(srvid->desc));
|
---|
1584 | break;
|
---|
1585 | }
|
---|
1586 | }
|
---|
1587 |
|
---|
1588 | char *srvidasc = strchr(token, ':');
|
---|
1589 | *srvidasc++ = '\0';
|
---|
1590 | srvid->srvid = word_atob(srvidasc);
|
---|
1591 |
|
---|
1592 | srvid->ncaid = 0;
|
---|
1593 | for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
|
---|
1594 | srvid->caid[i] = word_atob(ptr1);
|
---|
1595 | srvid->ncaid = i+1;
|
---|
1596 | //cs_debug("ld caid: %04X srvid: %04X Prov: %s Chan: %s",srvid->caid[i],srvid->srvid,srvid->prov,srvid->name);
|
---|
1597 | }
|
---|
1598 | nr++;
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 | fclose(fp);
|
---|
1602 | if (nr>0)
|
---|
1603 | cs_log("%d service-id's loaded", nr);
|
---|
1604 | else{
|
---|
1605 | cs_log("oscam.srvid loading failed, old format");
|
---|
1606 | }
|
---|
1607 | return(0);
|
---|
1608 | }
|
---|
1609 |
|
---|
1610 | static void chk_reader(char *token, char *value, struct s_reader *rdr)
|
---|
1611 | {
|
---|
1612 | int i;
|
---|
1613 | char *ptr;
|
---|
1614 | /*
|
---|
1615 | * case sensitive first
|
---|
1616 | */
|
---|
1617 | if (!strcmp(token, "device"))
|
---|
1618 | {
|
---|
1619 | for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
|
---|
1620 | {
|
---|
1621 | trim(ptr);
|
---|
1622 | switch(i)
|
---|
1623 | {
|
---|
1624 | case 0: cs_strncpy(rdr->device, ptr, sizeof(rdr->device)); break;
|
---|
1625 | case 1: rdr->r_port=atoi(ptr); break;
|
---|
1626 | case 2: rdr->l_port=atoi(ptr); break;
|
---|
1627 | }
|
---|
1628 | }
|
---|
1629 | return;
|
---|
1630 | }
|
---|
1631 | if (!strcmp(token, "key"))
|
---|
1632 | {
|
---|
1633 | if (key_atob14(value, rdr->ncd_key))
|
---|
1634 | {
|
---|
1635 | fprintf(stderr, "Configuration newcamd: Error in Key\n");
|
---|
1636 | exit(1);
|
---|
1637 | }
|
---|
1638 | return;
|
---|
1639 | }
|
---|
1640 | #ifdef CS_WITH_GBOX
|
---|
1641 | if (!strcmp(token, "password")) { cs_strncpy((char *)rdr->gbox_pwd, (const char *)i2b(4, a2i(value, 4)), 4); return; }
|
---|
1642 | if (!strcmp(token, "premium")) { rdr->gbox_prem=1; return; }
|
---|
1643 | #endif
|
---|
1644 | if (!strcmp(token, "account"))
|
---|
1645 | {
|
---|
1646 | for (i=0, ptr=strtok(value, ","); (i<2)&&(ptr); ptr=strtok(NULL, ","), i++)
|
---|
1647 | {
|
---|
1648 | trim(ptr);
|
---|
1649 | switch(i)
|
---|
1650 | {
|
---|
1651 | case 0: cs_strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr)); break;
|
---|
1652 | case 1: cs_strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd)); break;
|
---|
1653 | }
|
---|
1654 | }
|
---|
1655 | return;
|
---|
1656 | }
|
---|
1657 | if( !strcmp(token, "pincode")) { strncpy(rdr->pincode, value, sizeof(rdr->pincode)-1); return; }
|
---|
1658 | if (!strcmp(token, "readnano") && value[0]) { asprintf(&(rdr->emmfile), "%s", value); return; }
|
---|
1659 | /*
|
---|
1660 | * case insensitive
|
---|
1661 | */
|
---|
1662 | strtolower(value);
|
---|
1663 |
|
---|
1664 | if (!strcmp(token, "enable")) { rdr->enable=atoi(value) ? 1 : 0; return; }
|
---|
1665 | if (!strcmp(token, "services")) { chk_services(value, &rdr->sidtabok, &rdr->sidtabno); return; }
|
---|
1666 | if (!strcmp(token, "inactivitytimeout")) { rdr->tcp_ito = atoi(value); return; }
|
---|
1667 | if (!strcmp(token, "reconnecttimeout")) { rdr->tcp_rto = atoi(value); return; }
|
---|
1668 | if (!strcmp(token, "disableserverfilter")) { rdr->ncd_disable_server_filt = atoi(value); return; }
|
---|
1669 | //FIXME workaround for Smargo until native mode works
|
---|
1670 | if (!strcmp(token, "smargopatch")) { rdr->smargopatch = atoi(value); return; }
|
---|
1671 | if (!strcmp(token, "label")) { cs_strncpy(rdr->label, value, sizeof(rdr->label)); return; }
|
---|
1672 | if (!strcmp(token, "fallback")) { rdr->fallback=atoi(value) ? 1 : 0; return; }
|
---|
1673 | if (!strcmp(token, "logport")) { rdr->log_port=atoi(value); return; }
|
---|
1674 | if (!strcmp(token, "caid")) { chk_caidtab(value, &rdr->ctab); return; }
|
---|
1675 | if (!strcmp(token, "boxid")) { rdr->boxid=a2i(value,4); return; }
|
---|
1676 | if (!strcmp(token, "aeskey"))
|
---|
1677 | {
|
---|
1678 | if (key_atob(value, rdr->aes_key))
|
---|
1679 | {
|
---|
1680 | fprintf(stderr, "Configuration reader: Error in AES Key\n");
|
---|
1681 | exit(1);
|
---|
1682 | }
|
---|
1683 | return;
|
---|
1684 | }
|
---|
1685 | if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey")) )
|
---|
1686 | {
|
---|
1687 | rdr->has_rsa=1;
|
---|
1688 | if (key_atob_l(value, rdr->rsa_mod, 128))
|
---|
1689 | {
|
---|
1690 | fprintf(stderr, "Configuration reader: Error in rsakey\n");
|
---|
1691 | exit(1);
|
---|
1692 | }
|
---|
1693 | return;
|
---|
1694 | }
|
---|
1695 | if (!strcmp(token, "tiger_rsakey"))
|
---|
1696 | {
|
---|
1697 | if (key_atob_l(value, rdr->rsa_mod, 240))
|
---|
1698 | {
|
---|
1699 | fprintf(stderr, "Configuration reader: Error in tiger_rsakey\n");
|
---|
1700 | exit(1);
|
---|
1701 | }
|
---|
1702 | return;
|
---|
1703 | }
|
---|
1704 | if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey")))
|
---|
1705 | {
|
---|
1706 | if (key_atob_l(value, rdr->nagra_boxkey, 16))
|
---|
1707 | {
|
---|
1708 | fprintf(stderr, "Configuration reader: Error in boxkey\n");
|
---|
1709 | exit(1);
|
---|
1710 | }
|
---|
1711 | return;
|
---|
1712 | }
|
---|
1713 | if (!strcmp(token, "detect"))
|
---|
1714 | {
|
---|
1715 | for (i=0; RDR_CD_TXT[i]; i++)
|
---|
1716 | {
|
---|
1717 | if (!strcmp(value, RDR_CD_TXT[i]))
|
---|
1718 | rdr->detect=i;
|
---|
1719 | else
|
---|
1720 | if ((value[0]=='!') && (!strcmp(value+1, RDR_CD_TXT[i])))
|
---|
1721 | rdr->detect=i|0x80;
|
---|
1722 | }
|
---|
1723 | return;
|
---|
1724 | }
|
---|
1725 | if (!strcmp(token, "mhz")) { rdr->mhz=atoi(value); return; }
|
---|
1726 | if (!strcmp(token, "cardmhz")) { rdr->cardmhz=atoi(value); return; }
|
---|
1727 | if (!strcmp(token, "protocol"))
|
---|
1728 | {
|
---|
1729 | if (!strcmp(value, "mouse")) { rdr->typ=R_MOUSE; return; }
|
---|
1730 | if (!strcmp(value, "smartreader")) { rdr->typ=R_SMART; return; }
|
---|
1731 | if (!strcmp(value, "internal")) { rdr->typ=R_INTERNAL; return; }
|
---|
1732 | #ifdef HAVE_PCSC
|
---|
1733 | if (!strcmp(value, "pcsc")) { rdr->typ=R_PCSC; return; }
|
---|
1734 | #endif
|
---|
1735 | if (!strcmp(value, "serial")) { rdr->typ=R_SERIAL; return; }
|
---|
1736 | if (!strcmp(value, "camd35")) { rdr->typ=R_CAMD35; return; }
|
---|
1737 | if (!strcmp(value, "cs378x")) { rdr->typ=R_CS378X; return; }
|
---|
1738 | if (!strcmp(value, "cs357x")) { rdr->typ=R_CAMD35; return; }
|
---|
1739 | if (!strcmp(value, "gbox")) { rdr->typ=R_GBOX; return; }
|
---|
1740 | if (!strcmp(value, "cccam")) {
|
---|
1741 | rdr->typ=R_CCCAM;
|
---|
1742 | // strcpy(value, "1");
|
---|
1743 | // chk_caidtab(value, &rdr->ctab); // this is a MAJOR hack for auto multiple caid support (not currently working due to ncd table issue)
|
---|
1744 | return;
|
---|
1745 | }
|
---|
1746 | if (!strcmp(value, "radegast")) { rdr->typ=R_RADEGAST; return; }
|
---|
1747 | if (!strcmp(value, "newcamd") ||
|
---|
1748 | !strcmp(value, "newcamd525")) {rdr->typ=R_NEWCAMD;
|
---|
1749 | rdr->ncd_proto=NCD_525; return; }
|
---|
1750 | if (!strcmp(value, "newcamd524")) {rdr->typ=R_NEWCAMD;
|
---|
1751 | rdr->ncd_proto=NCD_524; return; }
|
---|
1752 | fprintf(stderr, "WARNING: value '%s' in protocol-line not recognized, assuming MOUSE\n",value);
|
---|
1753 | rdr->typ=R_MOUSE;
|
---|
1754 | return;
|
---|
1755 | }
|
---|
1756 | if (!strcmp(token, "loadbalanced")) { rdr->loadbalanced=atoi(value); return; }
|
---|
1757 | if (!strcmp(token, "ident")) { chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid"); return; }
|
---|
1758 | if (!strcmp(token, "class")) { chk_cltab(value, &rdr->cltab); return; }
|
---|
1759 | if (!strcmp(token, "chid")) { chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid"); return; }
|
---|
1760 | if (!strcmp(token, "showcls")) { rdr->show_cls = atoi(value); return; }
|
---|
1761 | if (!strcmp(token, "maxqlen"))
|
---|
1762 | {
|
---|
1763 | rdr->maxqlen = atoi(value);
|
---|
1764 | if( rdr->maxqlen<0 || rdr->maxqlen>CS_MAXQLEN )
|
---|
1765 | rdr->maxqlen=CS_MAXQLEN;
|
---|
1766 | return;
|
---|
1767 | }
|
---|
1768 | if (!strcmp(token, "group"))
|
---|
1769 | {
|
---|
1770 | for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
1771 | {
|
---|
1772 | int g;
|
---|
1773 | g=atoi(ptr);
|
---|
1774 | if ((g>0) && (g<33)) rdr->grp|=(1<<(g-1));
|
---|
1775 | }
|
---|
1776 | return;
|
---|
1777 | }
|
---|
1778 | if (!strcmp(token, "emmcache"))
|
---|
1779 | {
|
---|
1780 | for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
|
---|
1781 | switch(i)
|
---|
1782 | {
|
---|
1783 | case 0: rdr->cachemm=atoi(ptr); break;
|
---|
1784 | case 1: rdr->rewritemm=atoi(ptr); break;
|
---|
1785 | case 2: rdr->logemm=atoi(ptr); break;
|
---|
1786 | }
|
---|
1787 | if (rdr->rewritemm <=0) {
|
---|
1788 | fprintf(stderr, "Notice: Setting EMMCACHE to %i,1,%i instead of %i,%i,%i. Zero or negative number of rewrites is silly\n", rdr->cachemm,rdr->logemm,rdr->cachemm,rdr->rewritemm,rdr->logemm);
|
---|
1789 | rdr->rewritemm = 1;
|
---|
1790 | }
|
---|
1791 | return;
|
---|
1792 | }
|
---|
1793 |
|
---|
1794 | if (!strcmp(token, "blocknano"))
|
---|
1795 | {
|
---|
1796 | if (!strcmp(value,"all")) //wildcard is used
|
---|
1797 | for (i=0 ; i<256; i++)
|
---|
1798 | rdr->b_nano[i] |= 0x01; //set all lsb's to block all nanos
|
---|
1799 | else
|
---|
1800 | for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
1801 | if ((i=byte_atob(ptr))>=0)
|
---|
1802 | rdr->b_nano[i]|= 0x01; //lsb is set when to block nano
|
---|
1803 | return;
|
---|
1804 | }
|
---|
1805 | if (!strcmp(token, "savenano"))
|
---|
1806 | {
|
---|
1807 | if (!strcmp(value,"all")) //wildcard is used
|
---|
1808 | for (i=0 ; i<256; i++)
|
---|
1809 | rdr->b_nano[i] |= 0x02; //set all lsb+1 to save all nanos to file
|
---|
1810 | else
|
---|
1811 | for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
1812 | if ((i=byte_atob(ptr))>=0)
|
---|
1813 | rdr->b_nano[i]|= 0x02; //lsb+1 is set when to save nano to file
|
---|
1814 | return;
|
---|
1815 | }
|
---|
1816 | if (!strcmp(token, "cccversion")) { // cccam version
|
---|
1817 | if (strlen(value)>sizeof(rdr->cc_version)-1) {
|
---|
1818 | fprintf(stderr, "cccam config: version too long\n");
|
---|
1819 | exit(1);
|
---|
1820 | }
|
---|
1821 | bzero(rdr->cc_version, sizeof(rdr->cc_version));
|
---|
1822 | cs_strncpy(rdr->cc_version, value, sizeof(rdr->cc_version));
|
---|
1823 | return;
|
---|
1824 | }
|
---|
1825 | if (!strcmp(token, "cccbuild")) { // cccam build number
|
---|
1826 | if (strlen(value)>sizeof(rdr->cc_build)-1) {
|
---|
1827 | fprintf(stderr, "cccam config build number too long\n");
|
---|
1828 | exit(1);
|
---|
1829 | }
|
---|
1830 | bzero(rdr->cc_build, sizeof(rdr->cc_build));
|
---|
1831 | cs_strncpy(rdr->cc_build, value, sizeof(rdr->cc_build));
|
---|
1832 | return;
|
---|
1833 | }
|
---|
1834 | if (!strcmp(token, "cccmaxhop")) { // cccam max card distance
|
---|
1835 | rdr->cc_maxhop = atoi(value);
|
---|
1836 | return;
|
---|
1837 | }
|
---|
1838 | if (!strcmp(token, "deprecated")) { rdr->deprecated=atoi(value); return; }
|
---|
1839 | if (token[0] != '#')
|
---|
1840 | fprintf(stderr, "Warning: keyword '%s' in reader section not recognized\n",token);
|
---|
1841 | }
|
---|
1842 |
|
---|
1843 | int init_readerdb()
|
---|
1844 | {
|
---|
1845 | int tag=0, nr;
|
---|
1846 | FILE *fp;
|
---|
1847 | char *value;
|
---|
1848 |
|
---|
1849 | sprintf(token, "%s%s", cs_confdir, cs_srvr);
|
---|
1850 | if (!(fp=fopen(token, "r")))
|
---|
1851 | {
|
---|
1852 | cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
|
---|
1853 | return(1);
|
---|
1854 | }
|
---|
1855 | nr=0;
|
---|
1856 | while (fgets(token, sizeof(token), fp))
|
---|
1857 | {
|
---|
1858 | int i, l;
|
---|
1859 | if ((l=strlen(trim(token)))<3) continue;
|
---|
1860 | if ((token[0]=='[') && (token[l-1]==']'))
|
---|
1861 | {
|
---|
1862 | token[l-1]=0;
|
---|
1863 | tag=(!strcmp("reader", strtolower(token+1)));
|
---|
1864 | if (reader[nr].label[0] && reader[nr].typ) nr++;
|
---|
1865 | memset(&reader[nr], 0, sizeof(struct s_reader));
|
---|
1866 | reader[nr].enable = 1;
|
---|
1867 | reader[nr].tcp_rto = 30;
|
---|
1868 | reader[nr].show_cls = 10;
|
---|
1869 | reader[nr].maxqlen = CS_MAXQLEN;
|
---|
1870 | reader[nr].mhz = 357;
|
---|
1871 | reader[nr].cardmhz = 357;
|
---|
1872 | reader[nr].deprecated = 0;
|
---|
1873 | strcpy(reader[nr].pincode, "none");
|
---|
1874 | for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff);
|
---|
1875 | continue;
|
---|
1876 | }
|
---|
1877 | if (!tag) continue;
|
---|
1878 | if (!(value=strchr(token, '='))) continue;
|
---|
1879 | *value++='\0';
|
---|
1880 | chk_reader(trim(strtolower(token)), trim(value), &reader[nr]);
|
---|
1881 | }
|
---|
1882 | fclose(fp);
|
---|
1883 | return(0);
|
---|
1884 | }
|
---|
1885 |
|
---|
1886 | /*
|
---|
1887 | int init_irdeto_guess_tab()
|
---|
1888 | {
|
---|
1889 | int i, j, skip;
|
---|
1890 | int b47;
|
---|
1891 | FILE *fp;
|
---|
1892 | char token[128], *value, *ptr;
|
---|
1893 | char zSid[5];
|
---|
1894 | uchar b3;
|
---|
1895 | ushort caid, sid;
|
---|
1896 | struct s_irdeto_quess *ird_row, *head;
|
---|
1897 |
|
---|
1898 | memset(cfg->itab, 0, sizeof(cfg->itab));
|
---|
1899 | sprintf(token, "%s%s", cs_confdir, cs_ird);
|
---|
1900 | if (!(fp=fopen(token, "r")))
|
---|
1901 | {
|
---|
1902 | cs_log("can't open file \"%s\" (errno=%d) irdeto guessing not loaded",
|
---|
1903 | token, errno);
|
---|
1904 | return(1);
|
---|
1905 | }
|
---|
1906 | while (fgets(token, sizeof(token), fp))
|
---|
1907 | {
|
---|
1908 | if( strlen(token)<20 ) continue;
|
---|
1909 | for( i=b3=b47=caid=sid=skip=0, ptr=strtok(token, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
|
---|
1910 | {
|
---|
1911 | trim(ptr);
|
---|
1912 | if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
|
---|
1913 | skip=1;
|
---|
1914 | break;
|
---|
1915 | }
|
---|
1916 | switch(i)
|
---|
1917 | {
|
---|
1918 | case 0: b3 = a2i(ptr, 2); break;
|
---|
1919 | case 1: b47 = a2i(ptr, 8); break;
|
---|
1920 | case 2: caid = a2i(ptr, 4); break;
|
---|
1921 | case 3:
|
---|
1922 | for( j=0; j<4; j++ )
|
---|
1923 | zSid[j]=ptr[j];
|
---|
1924 | zSid[4]=0;
|
---|
1925 | sid = a2i(zSid, 4);
|
---|
1926 | break;
|
---|
1927 | }
|
---|
1928 | }
|
---|
1929 | if( !skip )
|
---|
1930 | {
|
---|
1931 | if (!(ird_row=(struct s_irdeto_quess*)malloc(sizeof(struct s_irdeto_quess))))
|
---|
1932 | {
|
---|
1933 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
1934 | return;
|
---|
1935 | }
|
---|
1936 | ird_row->b47 = b47;
|
---|
1937 | ird_row->caid = caid;
|
---|
1938 | ird_row->sid = sid;
|
---|
1939 | ird_row->next = 0;
|
---|
1940 |
|
---|
1941 | head = cfg->itab[b3];
|
---|
1942 | if( head ) {
|
---|
1943 | while( head->next )
|
---|
1944 | head=head->next;
|
---|
1945 | head->next=ird_row;
|
---|
1946 | }
|
---|
1947 | else
|
---|
1948 | cfg->itab[b3]=ird_row;
|
---|
1949 |
|
---|
1950 | //cs_debug("%02X:%08X:%04X:%04X", b3, b47, caid, sid);
|
---|
1951 | }
|
---|
1952 | }
|
---|
1953 | fclose(fp);
|
---|
1954 |
|
---|
1955 | for( i=0; i<0xff; i++ )
|
---|
1956 | {
|
---|
1957 | head=cfg->itab[i];
|
---|
1958 | while(head)
|
---|
1959 | {
|
---|
1960 | cs_debug("itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
|
---|
1961 | i, head->b47, head->caid, head->sid);
|
---|
1962 | head=head->next;
|
---|
1963 | }
|
---|
1964 | }
|
---|
1965 | return(0);
|
---|
1966 | }
|
---|
1967 | */
|
---|
1968 |
|
---|
1969 | #ifdef CS_ANTICASC
|
---|
1970 | void init_ac()
|
---|
1971 | {
|
---|
1972 | int nr;
|
---|
1973 | FILE *fp;
|
---|
1974 | //char *value;
|
---|
1975 |
|
---|
1976 | sprintf(token, "%s%s", cs_confdir, cs_ac);
|
---|
1977 | if (!(fp=fopen(token, "r")))
|
---|
1978 | {
|
---|
1979 | cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
|
---|
1980 | token, errno);
|
---|
1981 | return;
|
---|
1982 | }
|
---|
1983 |
|
---|
1984 | for(nr=0; fgets(token, sizeof(token), fp);)
|
---|
1985 | {
|
---|
1986 | int i, skip;
|
---|
1987 | ushort caid, sid, chid, dwtime;
|
---|
1988 | ulong provid;
|
---|
1989 | char *ptr, *ptr1;
|
---|
1990 | struct s_cpmap *ptr_cpmap;
|
---|
1991 | static struct s_cpmap *cpmap=(struct s_cpmap *)0;
|
---|
1992 |
|
---|
1993 | if( strlen(token)<4 ) continue;
|
---|
1994 |
|
---|
1995 | caid=sid=chid=dwtime=0;
|
---|
1996 | provid=0;
|
---|
1997 | skip=0;
|
---|
1998 | ptr1=0;
|
---|
1999 | for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
|
---|
2000 | {
|
---|
2001 | trim(ptr);
|
---|
2002 | if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
|
---|
2003 | skip=1;
|
---|
2004 | break;
|
---|
2005 | }
|
---|
2006 | switch( i )
|
---|
2007 | {
|
---|
2008 | case 0:
|
---|
2009 | ptr1=ptr;
|
---|
2010 | break;
|
---|
2011 | case 1:
|
---|
2012 | dwtime = atoi(ptr);
|
---|
2013 | break;
|
---|
2014 | }
|
---|
2015 | }
|
---|
2016 |
|
---|
2017 | if( !skip )
|
---|
2018 | {
|
---|
2019 | for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
|
---|
2020 | {
|
---|
2021 | trim(ptr);
|
---|
2022 | switch( i )
|
---|
2023 | {
|
---|
2024 | case 0:
|
---|
2025 | if( *ptr=='*' ) caid = 0;
|
---|
2026 | else caid = a2i(ptr, 4);
|
---|
2027 | break;
|
---|
2028 | case 1:
|
---|
2029 | if( *ptr=='*' ) provid = 0;
|
---|
2030 | else provid = a2i(ptr, 6);
|
---|
2031 | break;
|
---|
2032 | case 2:
|
---|
2033 | if( *ptr=='*' ) sid = 0;
|
---|
2034 | else sid = a2i(ptr, 4);
|
---|
2035 | break;
|
---|
2036 | case 3:
|
---|
2037 | if( *ptr=='*' ) chid = 0;
|
---|
2038 | else chid = a2i(ptr, 4);
|
---|
2039 | break;
|
---|
2040 | }
|
---|
2041 | }
|
---|
2042 | if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
|
---|
2043 | {
|
---|
2044 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
2045 | return;
|
---|
2046 | }
|
---|
2047 | if( cpmap )
|
---|
2048 | cpmap->next=ptr_cpmap;
|
---|
2049 | else
|
---|
2050 | cfg->cpmap=ptr_cpmap;
|
---|
2051 | cpmap=ptr_cpmap;
|
---|
2052 |
|
---|
2053 | cpmap->caid = caid;
|
---|
2054 | cpmap->provid = provid;
|
---|
2055 | cpmap->sid = sid;
|
---|
2056 | cpmap->chid = chid;
|
---|
2057 | cpmap->dwtime = dwtime;
|
---|
2058 | cpmap->next = 0;
|
---|
2059 |
|
---|
2060 | cs_debug("nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
|
---|
2061 | nr, caid, provid, sid, chid, dwtime);
|
---|
2062 | nr++;
|
---|
2063 | }
|
---|
2064 | }
|
---|
2065 | fclose(fp);
|
---|
2066 | //cs_log("%d lengths for caid guessing loaded", nr);
|
---|
2067 | return;
|
---|
2068 | }
|
---|
2069 | #endif
|
---|
2070 |
|
---|
2071 | /*
|
---|
2072 | * makes a char ready to write a token into config or webIf
|
---|
2073 | */
|
---|
2074 | char *mk_t_caidtab(CAIDTAB *ctab){
|
---|
2075 | int i = 0, needed = 1, pos = 0;
|
---|
2076 | while(ctab->caid[i]){
|
---|
2077 | if(ctab->mask[i]) needed += 10;
|
---|
2078 | else needed += 5;
|
---|
2079 | if(ctab->cmap[i]) needed += 5;
|
---|
2080 | ++i;
|
---|
2081 | }
|
---|
2082 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
2083 | i = 0;
|
---|
2084 | while(ctab->caid[i]) {
|
---|
2085 | if(i == 0) {
|
---|
2086 | sprintf(value + pos, "%04X", ctab->caid[i]);
|
---|
2087 | pos += 4;
|
---|
2088 | } else {
|
---|
2089 | sprintf(value + pos, ",%04X", ctab->caid[i]);
|
---|
2090 | pos += 5;
|
---|
2091 | }
|
---|
2092 | if(ctab->mask[i]){
|
---|
2093 | sprintf(value + pos, "&%04X", ctab->mask[i]);
|
---|
2094 | pos += 5;
|
---|
2095 | }
|
---|
2096 | if(ctab->cmap[i]){
|
---|
2097 | sprintf(value + pos, ":%04X", ctab->cmap[i]);
|
---|
2098 | pos += 5;
|
---|
2099 | }
|
---|
2100 | ++i;
|
---|
2101 | }
|
---|
2102 | value[pos] = '\0';
|
---|
2103 | return value;
|
---|
2104 | }
|
---|
2105 |
|
---|
2106 | /*
|
---|
2107 | * makes a char ready to write a token into config or webIf
|
---|
2108 | */
|
---|
2109 | char *mk_t_tuntab(TUNTAB *ttab){
|
---|
2110 | int i = 0, needed = 1, pos = 0;
|
---|
2111 | while(ttab->bt_caidfrom[i]){
|
---|
2112 | if(ttab->bt_srvid[i]) needed += 10;
|
---|
2113 | else needed += 5;
|
---|
2114 | if(ttab->bt_caidto[i]) needed += 5;
|
---|
2115 | ++i;
|
---|
2116 | }
|
---|
2117 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
2118 | i = 0;
|
---|
2119 | while(ttab->bt_caidfrom[i]) {
|
---|
2120 | if(i == 0) {
|
---|
2121 | sprintf(value + pos, "%04X", ttab->bt_caidfrom[i]);
|
---|
2122 | pos += 4;
|
---|
2123 | } else {
|
---|
2124 | sprintf(value + pos, ",%04X", ttab->bt_caidfrom[i]);
|
---|
2125 | pos += 5;
|
---|
2126 | }
|
---|
2127 | if(ttab->bt_srvid[i]){
|
---|
2128 | sprintf(value + pos, ".%04X", ttab->bt_srvid[i]);
|
---|
2129 | pos += 5;
|
---|
2130 | }
|
---|
2131 | if(ttab->bt_caidto[i]){
|
---|
2132 | sprintf(value + pos, ":%04X", ttab->bt_caidto[i]);
|
---|
2133 | pos += 5;
|
---|
2134 | }
|
---|
2135 | ++i;
|
---|
2136 | }
|
---|
2137 | value[pos] = '\0';
|
---|
2138 | return value;
|
---|
2139 | }
|
---|
2140 |
|
---|
2141 | /*
|
---|
2142 | * makes a char ready to write a token into config or webIf
|
---|
2143 | */
|
---|
2144 | char *mk_t_group(ulong *grp){
|
---|
2145 | int i = 0, needed = 1, pos = 0, dot = 0;
|
---|
2146 | char grpbit[33];
|
---|
2147 | long2bitchar((long) grp, grpbit);
|
---|
2148 |
|
---|
2149 | for(i = 0; i < 32; i++){
|
---|
2150 | if (grpbit[i] == '1'){
|
---|
2151 | needed += 2;
|
---|
2152 | if(i > 9) needed += 1;
|
---|
2153 | }
|
---|
2154 | }
|
---|
2155 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
2156 |
|
---|
2157 | for(i = 0; i < 32; i++){
|
---|
2158 | if (grpbit[i] == '1'){
|
---|
2159 | if (dot == 0){
|
---|
2160 | sprintf(value + pos, "%d", i+1);
|
---|
2161 | if (i > 9)pos += 2;
|
---|
2162 | else pos += 1;
|
---|
2163 | dot = 1;
|
---|
2164 | } else {
|
---|
2165 | sprintf(value + pos, ",%d", i+1);
|
---|
2166 | if (i > 9)pos += 3;
|
---|
2167 | else pos += 2;
|
---|
2168 | }
|
---|
2169 | }
|
---|
2170 | }
|
---|
2171 | value[pos] = '\0';
|
---|
2172 | return value;
|
---|
2173 | }
|
---|
2174 |
|
---|
2175 | /*
|
---|
2176 | * makes a char ready to write a token into config or webIf
|
---|
2177 | */
|
---|
2178 | char *mk_t_ftab(FTAB *ftab){
|
---|
2179 | int i = 0, j = 0, needed = 1, pos = 0;
|
---|
2180 |
|
---|
2181 | needed = ftab->nfilts * 5;
|
---|
2182 | for (i = 0; i < ftab->nfilts; ++i)
|
---|
2183 | needed += ftab->filts[i].nprids * 7;
|
---|
2184 |
|
---|
2185 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
2186 |
|
---|
2187 | char *dot="";
|
---|
2188 | for (i = 0; i < ftab->nfilts; ++i){
|
---|
2189 | sprintf(value + pos, "%s%04X", dot, ftab->filts[i].caid);
|
---|
2190 | pos += 4;
|
---|
2191 | if (i > 0) pos += 1;
|
---|
2192 | dot=":";
|
---|
2193 | for (j = 0; j < ftab->filts[i].nprids; ++j) {
|
---|
2194 | sprintf(value + pos, "%s%06lX", dot, ftab->filts[i].prids[j]);
|
---|
2195 | pos += 7;
|
---|
2196 | dot=",";
|
---|
2197 | }
|
---|
2198 | dot=";";
|
---|
2199 | }
|
---|
2200 |
|
---|
2201 | value[pos] = '\0';
|
---|
2202 | return value;
|
---|
2203 | }
|
---|