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