[8] | 1 | #include "globals.h"
|
---|
| 2 | #ifdef CS_WITH_BOXKEYS
|
---|
[21] | 3 | # include "oscam-boxkeys.np"
|
---|
[8] | 4 | #endif
|
---|
| 5 |
|
---|
[1104] | 6 | #define CONFVARWIDTH 16
|
---|
| 7 |
|
---|
[21] | 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";
|
---|
[8] | 16 | #ifdef CS_ANTICASC
|
---|
[21] | 17 | static char *cs_ac="oscam.ac";
|
---|
[8] | 18 | #endif
|
---|
| 19 |
|
---|
| 20 | static char token[4096];
|
---|
| 21 |
|
---|
| 22 | typedef enum cs_proto_type
|
---|
| 23 | {
|
---|
[647] | 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
|
---|
[8] | 30 | TAG_SERIAL, // serial (static)
|
---|
| 31 | TAG_CS357X, // camd 3.5x UDP
|
---|
[1135] | 32 | TAG_CS378X, // camd 3.5x TCP
|
---|
[1169] | 33 | #ifdef CS_WITH_GBOX
|
---|
[1135] | 34 | TAG_GBOX, // gbox
|
---|
| 35 | #endif
|
---|
[1020] | 36 | TAG_CCCAM, // cccam
|
---|
| 37 | TAG_DVBAPI
|
---|
[8] | 38 | #ifdef CS_ANTICASC
|
---|
| 39 | ,TAG_ANTICASC // anti-cascading
|
---|
| 40 | #endif
|
---|
| 41 | } cs_proto_type_t;
|
---|
| 42 |
|
---|
[1169] | 43 | static char *cctag[]={"global", "monitor", "camd33", "camd35",
|
---|
[1154] | 44 | "newcamd", "radegast", "serial", "cs357x", "cs378x",
|
---|
[1169] | 45 | #ifdef CS_WITH_GBOX
|
---|
[1154] | 46 | "gbox",
|
---|
| 47 | #endif
|
---|
| 48 | "cccam", "dvbapi",
|
---|
[8] | 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 |
|
---|
[973] | 78 | void chk_iprange(char *value, struct s_ip **base)
|
---|
[8] | 79 | {
|
---|
[1046] | 80 | int i = 0;
|
---|
[8] | 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 | {
|
---|
[1046] | 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 | }
|
---|
[8] | 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);
|
---|
[1046] | 116 | lip = cip;
|
---|
[8] | 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[827] | 120 | void chk_caidtab(char *caidasc, CAIDTAB *ctab)
|
---|
[8] | 121 | {
|
---|
| 122 | int i;
|
---|
[1046] | 123 | char *ptr1, *ptr2, *ptr3;
|
---|
[994] | 124 |
|
---|
[1046] | 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 |
|
---|
[8] | 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 |
|
---|
[827] | 154 | void chk_tuntab(char *tunasc, TUNTAB *ttab)
|
---|
[41] | 155 | {
|
---|
| 156 | int i;
|
---|
[1046] | 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 |
|
---|
[994] | 166 | for (i=0, ptr1=strtok(tunasc, ","); (i<CS_MAXTUNTAB) && (ptr1); ptr1=strtok(NULL, ","))
|
---|
[41] | 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 |
|
---|
[827] | 188 | void chk_services(char *labels, ulong *sidok, ulong *sidno)
|
---|
[8] | 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 |
|
---|
[827] | 202 | void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName)
|
---|
[8] | 203 | {
|
---|
| 204 | int i,j;
|
---|
| 205 | char *ptr1,*ptr2,*ptr3;
|
---|
| 206 | char *ptr[CS_MAXFILTERS] = {0};
|
---|
[827] | 207 |
|
---|
[8] | 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;
|
---|
[827] | 213 | if( (ptr2=strchr(trim(ptr1), ':')) )
|
---|
[8] | 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);
|
---|
[827] | 231 | for( i=0; i<ftab->nfilts; i++ )
|
---|
[8] | 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 |
|
---|
[827] | 244 | void chk_cltab(char *classasc, CLASSTAB *clstab)
|
---|
[8] | 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 |
|
---|
[973] | 258 | void chk_port_tab(char *portasc, PTAB *ptab)
|
---|
[8] | 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};
|
---|
[18] | 264 | int previous_nports = ptab->nports;
|
---|
[8] | 265 |
|
---|
[18] | 266 | for (nfilts=i=previous_nports, ptr1=strtok(portasc, ";"); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ";"), i++)
|
---|
[8] | 267 | {
|
---|
| 268 | ptr[i] = ptr1;
|
---|
[827] | 269 | if( (ptr2=strchr(trim(ptr1), '@')) )
|
---|
[8] | 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 |
|
---|
[18] | 285 | iport=ifilt = previous_nports;
|
---|
[827] | 286 | for (i=previous_nports; i<nfilts; i++)
|
---|
[8] | 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 | {
|
---|
[827] | 291 | if( (ptr2=strchr(trim(ptr3), ':')) )
|
---|
[8] | 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 |
|
---|
[973] | 316 | void chk_t_global(char *token, char *value)
|
---|
[8] | 317 | {
|
---|
[467] | 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; }
|
---|
[827] | 323 | if (!strcmp(token, "clienttimeout"))
|
---|
[93] | 324 | {
|
---|
| 325 | cfg->ctimeout = atoi(value);
|
---|
| 326 | if (cfg->ctimeout < 100)
|
---|
| 327 | cfg->ctimeout *= 1000;
|
---|
[467] | 328 | return;
|
---|
[93] | 329 | }
|
---|
[827] | 330 | if (!strcmp(token, "fallbacktimeout"))
|
---|
[93] | 331 | {
|
---|
| 332 | cfg->ftimeout = atoi(value);
|
---|
| 333 | if (cfg->ftimeout < 100)
|
---|
| 334 | cfg->ftimeout *= 1000;
|
---|
[467] | 335 | return;
|
---|
[93] | 336 | }
|
---|
| 337 |
|
---|
[467] | 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; }
|
---|
[8] | 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
|
---|
[467] | 350 | return;
|
---|
[8] | 351 | }
|
---|
[827] | 352 | if (!strcmp(token, "serialreadertimeout"))
|
---|
[8] | 353 | {
|
---|
[93] | 354 | if (cfg->srtimeout < 100)
|
---|
| 355 | cfg->srtimeout = atoi(value) * 1000;
|
---|
| 356 | else
|
---|
| 357 | cfg->srtimeout = atoi(value);
|
---|
[8] | 358 | if( cfg->srtimeout <=0 )
|
---|
| 359 | cfg->srtimeout=1500;
|
---|
[467] | 360 | return;
|
---|
[8] | 361 | }
|
---|
[827] | 362 | if (!strcmp(token, "maxlogsize"))
|
---|
[8] | 363 | {
|
---|
| 364 | cfg->max_log_size=atoi(value);
|
---|
| 365 | if( cfg->max_log_size <=10 )
|
---|
| 366 | cfg->max_log_size=10;
|
---|
[467] | 367 | return;
|
---|
[8] | 368 | }
|
---|
[467] | 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);
|
---|
[8] | 374 | }
|
---|
| 375 |
|
---|
| 376 | #ifdef CS_ANTICASC
|
---|
[973] | 377 | void chk_t_ac(char *token, char *value)
|
---|
[8] | 378 | {
|
---|
[827] | 379 | if (!strcmp(token, "enabled"))
|
---|
[8] | 380 | {
|
---|
| 381 | cfg->ac_enabled=atoi(value);
|
---|
| 382 | if( cfg->ac_enabled<=0 ) cfg->ac_enabled=0;
|
---|
| 383 | else cfg->ac_enabled=1;
|
---|
[467] | 384 | return;
|
---|
[8] | 385 | }
|
---|
| 386 |
|
---|
[827] | 387 | if (!strcmp(token, "numusers"))
|
---|
[8] | 388 | {
|
---|
| 389 | cfg->ac_users=atoi(value);
|
---|
| 390 | if( cfg->ac_users<0 ) cfg->ac_users=0;
|
---|
[467] | 391 | return;
|
---|
[8] | 392 | }
|
---|
[827] | 393 | if (!strcmp(token, "sampletime"))
|
---|
[8] | 394 | {
|
---|
| 395 | cfg->ac_stime=atoi(value);
|
---|
| 396 | if( cfg->ac_stime<0 ) cfg->ac_stime=2;
|
---|
[467] | 397 | return;
|
---|
[8] | 398 | }
|
---|
[827] | 399 | if (!strcmp(token, "samples"))
|
---|
[8] | 400 | {
|
---|
| 401 | cfg->ac_samples=atoi(value);
|
---|
| 402 | if( cfg->ac_samples<2 || cfg->ac_samples>10) cfg->ac_samples=10;
|
---|
[467] | 403 | return;
|
---|
[8] | 404 | }
|
---|
[827] | 405 | if (!strcmp(token, "penalty"))
|
---|
[8] | 406 | {
|
---|
| 407 | cfg->ac_penalty=atoi(value);
|
---|
| 408 | if( cfg->ac_penalty<0 ) cfg->ac_penalty=0;
|
---|
[467] | 409 | return;
|
---|
[8] | 410 | }
|
---|
[467] | 411 | if (!strcmp(token, "aclogfile"))
|
---|
| 412 | {
|
---|
[8] | 413 | strncpy(cfg->ac_logfile, value, sizeof(cfg->ac_logfile)-1);
|
---|
[467] | 414 | return;
|
---|
| 415 | }
|
---|
[8] | 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;
|
---|
[467] | 421 | return;
|
---|
[8] | 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;
|
---|
[467] | 428 | return;
|
---|
[8] | 429 | }
|
---|
[467] | 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 | }
|
---|
[8] | 434 | #endif
|
---|
| 435 |
|
---|
[973] | 436 | void chk_t_monitor(char *token, char *value)
|
---|
[8] | 437 | {
|
---|
[467] | 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; }
|
---|
[928] | 443 | if (!strcmp(token, "httpport")) { cfg->http_port=atoi(value); return; }
|
---|
[960] | 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; }
|
---|
[965] | 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; }
|
---|
[1024] | 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; }
|
---|
[1046] | 448 | if (!strcmp(token, "httprefresh")) { cfg->http_refresh=atoi(value); return; }
|
---|
[1036] | 449 | if (!strcmp(token, "httphideidleclients")) { cfg->http_hide_idle_clients=atoi(value); return; }
|
---|
[467] | 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);
|
---|
[8] | 453 | }
|
---|
[1046] | 454 |
|
---|
[973] | 455 | void chk_t_camd33(char *token, char *value)
|
---|
[8] | 456 | {
|
---|
[467] | 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; }
|
---|
[8] | 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;
|
---|
[467] | 469 | return;
|
---|
[8] | 470 | }
|
---|
[467] | 471 | if (token[0] != '#')
|
---|
| 472 | fprintf(stderr, "Warning: keyword '%s' in camd33 section not recognized\n",token);
|
---|
[8] | 473 | }
|
---|
| 474 |
|
---|
[973] | 475 | void chk_t_camd35(char *token, char *value)
|
---|
[8] | 476 | {
|
---|
[467] | 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);
|
---|
[8] | 481 | }
|
---|
| 482 |
|
---|
[973] | 483 | void chk_t_camd35_tcp(char *token, char *value)
|
---|
[8] | 484 | {
|
---|
[467] | 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);
|
---|
[8] | 489 | }
|
---|
| 490 |
|
---|
[973] | 491 | void chk_t_newcamd(char *token, char *value)
|
---|
[8] | 492 | {
|
---|
[467] | 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; }
|
---|
[8] | 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 | }
|
---|
[467] | 502 | return;
|
---|
[8] | 503 | }
|
---|
[467] | 504 | if (token[0] != '#')
|
---|
| 505 | fprintf(stderr, "Warning: keyword '%s' in newcamd section not recognized\n",token);
|
---|
[8] | 506 | }
|
---|
| 507 |
|
---|
[973] | 508 | void chk_t_radegast(char *token, char *value)
|
---|
[8] | 509 | {
|
---|
[467] | 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);
|
---|
[8] | 516 | }
|
---|
| 517 |
|
---|
[973] | 518 | void chk_t_serial(char *token, char *value)
|
---|
[8] | 519 | {
|
---|
| 520 | if (!strcmp(token, "device"))
|
---|
| 521 | {
|
---|
| 522 | int l;
|
---|
| 523 | l=strlen(cfg->ser_device);
|
---|
[647] | 524 | if (l) cfg->ser_device[l++]=1; // use ctrl-a as delimiter
|
---|
[8] | 525 | strncpy(cfg->ser_device+l, value, sizeof(cfg->ser_device)-1-l);
|
---|
[467] | 526 | return;
|
---|
[8] | 527 | }
|
---|
[467] | 528 | if (token[0] != '#')
|
---|
| 529 | fprintf(stderr, "Warning: keyword '%s' in serial section not recognized\n",token);
|
---|
[8] | 530 | }
|
---|
[1135] | 531 |
|
---|
| 532 | #ifdef CS_WITH_GBOX
|
---|
[1154] | 533 | static void chk_t_gbox(char *token, char *value)
|
---|
[8] | 534 | {
|
---|
| 535 | // if (!strcmp(token, "password")) strncpy(cfg->gbox_pwd, i2b(4, a2i(value, 4)), 4);
|
---|
[467] | 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; }
|
---|
[8] | 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;
|
---|
[467] | 551 | return;
|
---|
[8] | 552 | }
|
---|
[467] | 553 | if (token[0] != '#')
|
---|
| 554 | fprintf(stderr, "Warning: keyword '%s' in gbox section not recognized\n",token);
|
---|
[8] | 555 | }
|
---|
[1135] | 556 | #endif
|
---|
[8] | 557 |
|
---|
[973] | 558 | void chk_t_cccam(char *token, char *value)
|
---|
[647] | 559 | {
|
---|
| 560 | // placeholder for ccam server support
|
---|
[1126] | 561 | fprintf(stderr, "Warning: OSCam have no cccam server support yet. Parametr %s = %s\n", token, value);
|
---|
[647] | 562 | }
|
---|
| 563 |
|
---|
[1126] | 564 | #ifdef HAVE_DVBAPI
|
---|
[1130] | 565 | void chk_t_dvbapi(char *token, char *value)
|
---|
[1020] | 566 | {
|
---|
| 567 | if (!strcmp(token, "enabled")) { cfg->dvbapi_enabled=atoi(value); return; }
|
---|
[1035] | 568 | if (!strcmp(token, "au")) { cfg->dvbapi_au=atoi(value); return; }
|
---|
[1081] | 569 | if (!strcmp(token, "boxtype")) { strncpy(cfg->dvbapi_boxtype, value, sizeof(cfg->dvbapi_boxtype)-1); return; }
|
---|
[1020] | 570 | if (!strcmp(token, "user")) { strncpy(cfg->dvbapi_usr, value, sizeof(cfg->dvbapi_usr)-1); return; }
|
---|
[1189] | 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; }
|
---|
[1195] | 573 |
|
---|
[1020] | 574 | if (token[0] != '#')
|
---|
| 575 | fprintf(stderr, "Warning: keyword '%s' in dvbapi section not recognized\n",token);
|
---|
[1126] | 576 | }
|
---|
[1020] | 577 | #endif
|
---|
| 578 |
|
---|
[8] | 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;
|
---|
[827] | 586 | case TAG_CAMD35 :
|
---|
[8] | 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;
|
---|
[1135] | 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
|
---|
[647] | 595 | case TAG_CCCAM : chk_t_cccam(token, value); break;
|
---|
[1126] | 596 | #ifdef HAVE_DVBAPI
|
---|
[1020] | 597 | case TAG_DVBAPI : chk_t_dvbapi(token, value); break;
|
---|
[1126] | 598 | #else
|
---|
| 599 | case TAG_DVBAPI : fprintf(stderr, "Warning: OSCam compiled without DVB API support.\n"); break;
|
---|
| 600 | #endif
|
---|
[8] | 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 |
|
---|
[1126] | 638 | int search_boxkey(ushort caid, char *key)
|
---|
[8] | 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);
|
---|
[1117] | 645 | fp=fopen(c_caid, "r");
|
---|
| 646 | if (fp)
|
---|
[8] | 647 | {
|
---|
| 648 | for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);)
|
---|
| 649 | {
|
---|
| 650 | char *c_provid, *c_key;
|
---|
[1117] | 651 |
|
---|
| 652 | c_provid=strchr(c_caid, '#');
|
---|
| 653 | if (c_provid) *c_provid='\0';
|
---|
[8] | 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;
|
---|
[70] | 660 | if (cs_atob((uchar *)key, c_key, i)<0)
|
---|
[8] | 661 | {
|
---|
| 662 | cs_log("wrong key in \"%s\"", cs_cert);
|
---|
| 663 | continue;
|
---|
| 664 | }
|
---|
| 665 | rc=1;
|
---|
| 666 | }
|
---|
| 667 | fclose(fp);
|
---|
| 668 | }
|
---|
[21] | 669 | #ifdef OSCAM_INBUILD_KEYS
|
---|
[8] | 670 | for(i=0; (!rc) && (npkey[i].keylen); i++)
|
---|
[1126] | 671 | if (rc=((caid==npkey[i].caid) && (npkey[i].provid==0)))
|
---|
[8] | 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;
|
---|
[93] | 692 | cfg->ftimeout=CS_CLIENT_TIMEOUT / 2;
|
---|
[8] | 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;
|
---|
[57] | 700 | cfg->ulparent=0;
|
---|
[960] | 701 | strcpy(cfg->http_user, "");
|
---|
| 702 | strcpy(cfg->http_pwd, "");
|
---|
[986] | 703 | strcpy(cfg->http_css, "");
|
---|
[1046] | 704 | cfg->http_refresh=0;
|
---|
| 705 | cfg->http_hide_idle_clients=0;
|
---|
[1024] | 706 | strcpy(cfg->http_tpl, "");
|
---|
[8] | 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;
|
---|
[21] | 714 | strcpy(cfg->ac_logfile, "./oscam_ac.log");
|
---|
[8] | 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 | {
|
---|
[93] | 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);
|
---|
[8] | 744 | }
|
---|
[93] | 745 | if(cfg->ftimeout < cfg->srtimeout)
|
---|
[8] | 746 | {
|
---|
[93] | 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);
|
---|
[8] | 749 | }
|
---|
[93] | 750 | if(cfg->ctimeout < cfg->srtimeout)
|
---|
[8] | 751 | {
|
---|
[93] | 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);
|
---|
[8] | 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 |
|
---|
[973] | 765 | void chk_account(char *token, char *value, struct s_auth *account)
|
---|
[8] | 766 | {
|
---|
| 767 | int i;
|
---|
[1149] | 768 | char *ptr1;//, *ptr2;
|
---|
| 769 |
|
---|
[467] | 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; }
|
---|
[1143] | 772 | if (!strcmp(token, "hostname")) { strncpy((char *)account->dyndns, value, sizeof(account->dyndns)-1);return; }
|
---|
[467] | 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; }
|
---|
[8] | 778 | /*
|
---|
[647] | 779 | * case insensitive
|
---|
[8] | 780 | */
|
---|
| 781 | strtolower(value);
|
---|
| 782 | if (!strcmp(token, "au"))
|
---|
[1046] | 783 | {
|
---|
| 784 | //set default values for usage during runtime from Webif
|
---|
| 785 | account->au=-1;
|
---|
| 786 | account->autoau=0;
|
---|
| 787 |
|
---|
[504] | 788 | if(value && value[0]=='1') account->autoau=1;
|
---|
[8] | 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;
|
---|
[467] | 793 | return;
|
---|
| 794 | }
|
---|
[1210] | 795 | if (!strcmp(token, "group")) {
|
---|
| 796 | account->grp = 0;
|
---|
[8] | 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 | }
|
---|
[467] | 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; }
|
---|
[8] | 809 |
|
---|
[980] | 810 | if (!strcmp(token, "expdate"))
|
---|
[1046] | 811 | {
|
---|
[1149] | 812 | if (!value[0]) {
|
---|
| 813 | account->expirationdate=(time_t)NULL;
|
---|
| 814 | return;
|
---|
| 815 | }
|
---|
[980] | 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 | }
|
---|
[981] | 826 | }
|
---|
[1046] | 827 | account->expirationdate=mktime(&cstime);
|
---|
[980] | 828 | return;
|
---|
| 829 | }
|
---|
| 830 |
|
---|
[8] | 831 | #ifdef CS_ANTICASC
|
---|
| 832 | if( !strcmp(token, "numusers") )
|
---|
[467] | 833 | {
|
---|
[8] | 834 | account->ac_users = atoi(value);
|
---|
[467] | 835 | return;
|
---|
| 836 | }
|
---|
[827] | 837 | if( !strcmp(token, "penalty") )
|
---|
[467] | 838 | {
|
---|
[8] | 839 | account->ac_penalty = atoi(value);
|
---|
[467] | 840 | return;
|
---|
| 841 | }
|
---|
[8] | 842 | #endif
|
---|
[467] | 843 | if (token[0] != '#')
|
---|
| 844 | fprintf(stderr, "Warning: keyword '%s' in account section not recognized\n",token);
|
---|
[8] | 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 | }
|
---|
[1046] | 865 |
|
---|
[1104] | 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 |
|
---|
[1046] | 912 | int write_config()
|
---|
| 913 | {
|
---|
[1050] | 914 | int i,j;
|
---|
[1046] | 915 | FILE *f;
|
---|
[1050] | 916 | char *dot = "", *dot1 = "", *dot2 = ""; //flags for delimiters
|
---|
[1046] | 917 | char tmpfile[256];
|
---|
| 918 | char destfile[256];
|
---|
[1091] | 919 | char bakfile[256];
|
---|
[1046] | 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");
|
---|
[1104] | 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);
|
---|
[1108] | 938 | fprintf_conf(f, CONFVARWIDTH, "clienttimeout", "%ld\n", cfg->ctimeout/1000);
|
---|
| 939 | fprintf_conf(f, CONFVARWIDTH, "fallbacktimeout", "%ld\n", cfg->ftimeout/1000);
|
---|
[1104] | 940 | fprintf_conf(f, CONFVARWIDTH, "clientmaxidle", "%d\n", cfg->cmaxidle);
|
---|
[1108] | 941 | fprintf_conf(f, CONFVARWIDTH, "cachedelay", "%ld\n", cfg->delay/1000);
|
---|
[1104] | 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);
|
---|
[1046] | 954 |
|
---|
| 955 | /*monitor settings*/
|
---|
| 956 | fprintf(f,"[monitor]\n");
|
---|
[1104] | 957 | fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->mon_port);
|
---|
[1105] | 958 | fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip));
|
---|
[1046] | 959 |
|
---|
[1104] | 960 | fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
|
---|
[1046] | 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 | }
|
---|
[1130] | 967 | fputc((int)'\n', f);
|
---|
[1104] | 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);
|
---|
[1046] | 978 |
|
---|
| 979 | /*newcamd*/
|
---|
[1063] | 980 | if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)){
|
---|
[1065] | 981 | fprintf(f,"[newcamd]\n");
|
---|
[1104] | 982 | fprintf_conf(f, CONFVARWIDTH, "port", "");
|
---|
[1065] | 983 | dot1 = "";
|
---|
[1063] | 984 | for(i = 0; i < cfg->ncd_ptab.nports; ++i){
|
---|
[1046] | 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){
|
---|
[1091] | 987 | fprintf(f,":");
|
---|
| 988 | dot2 = "";
|
---|
[1065] | 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 = ",";
|
---|
[1046] | 992 | }
|
---|
| 993 | }
|
---|
| 994 | dot1=";";
|
---|
[1091] | 995 | }
|
---|
| 996 |
|
---|
[1104] | 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", "");
|
---|
[1046] | 1000 | for (i=0;i<14;i++) fprintf(f,"%02X", cfg->ncd_key[i]);
|
---|
| 1001 | fprintf(f,"\n\n");
|
---|
| 1002 | }
|
---|
| 1003 |
|
---|
[1091] | 1004 | /*camd3.3*/
|
---|
| 1005 | if ( cfg->c33_port > 0) {
|
---|
| 1006 | fprintf(f,"[camd33]\n");
|
---|
[1104] | 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));
|
---|
[1141] | 1009 | fprintf_conf(f, CONFVARWIDTH, "passive", "%d\n", cfg->c33_passive);
|
---|
[1142] | 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);
|
---|
[1104] | 1011 | fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
|
---|
[1091] | 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 |
|
---|
[1046] | 1021 | /*camd3.5*/
|
---|
| 1022 | if ( cfg->c35_port > 0) {
|
---|
| 1023 | fprintf(f,"[cs357x]\n");
|
---|
[1104] | 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));
|
---|
[1065] | 1026 | fprintf(f,"\n\n");
|
---|
[1046] | 1027 | }
|
---|
| 1028 |
|
---|
[1091] | 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");
|
---|
[1104] | 1032 | fprintf_conf(f, CONFVARWIDTH, "port", "");
|
---|
[1091] | 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 |
|
---|
[1104] | 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);
|
---|
[1091] | 1050 | }
|
---|
| 1051 |
|
---|
[1046] | 1052 | /*Radegast*/
|
---|
| 1053 | if ( cfg->rad_port > 0) {
|
---|
| 1054 | fprintf(f,"[radegast]\n");
|
---|
[1104] | 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", "");
|
---|
[1046] | 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 | }
|
---|
[1135] | 1067 |
|
---|
| 1068 | #ifdef CS_WITH_GBOX
|
---|
[1091] | 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");
|
---|
[1104] | 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", "");
|
---|
[1091] | 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");
|
---|
[1050] | 1084 | }
|
---|
[1135] | 1085 | #endif
|
---|
[1046] | 1086 |
|
---|
[1091] | 1087 | /*serial*/
|
---|
| 1088 |
|
---|
| 1089 |
|
---|
| 1090 | /*cccam placeholder*/
|
---|
| 1091 |
|
---|
[1139] | 1092 | #ifdef HAVE_DVBAPI
|
---|
[1091] | 1093 | /*dvb-api*/
|
---|
| 1094 | if (cfg->dvbapi_enabled > 0) {
|
---|
| 1095 | fprintf(f,"[dvbapi]\n");
|
---|
[1104] | 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);
|
---|
[1091] | 1101 | }
|
---|
| 1102 | #endif
|
---|
| 1103 |
|
---|
| 1104 | #ifdef CS_ANTICASC
|
---|
| 1105 | if (cfg->ac_enabled > 0){
|
---|
[1104] | 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);
|
---|
[1091] | 1115 | }
|
---|
| 1116 | #endif
|
---|
| 1117 |
|
---|
[1046] | 1118 | fclose(f);
|
---|
| 1119 |
|
---|
[1104] | 1120 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
[1046] | 1121 | }
|
---|
| 1122 |
|
---|
[986] | 1123 | int write_userdb()
|
---|
| 1124 | {
|
---|
| 1125 | int i;
|
---|
[1046] | 1126 | FILE *f;
|
---|
[986] | 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");
|
---|
[1104] | 1146 | fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", account->usr);
|
---|
| 1147 | fprintf_conf(f, CONFVARWIDTH, "pwd", "%s\n", account->pwd);
|
---|
[1046] | 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"))
|
---|
[1104] | 1152 | fprintf_conf(f, CONFVARWIDTH, "expdate", "%s\n", buf);
|
---|
[1046] | 1153 | else
|
---|
[1104] | 1154 | fprintf_conf(f, CONFVARWIDTH, "expdate", "\n");
|
---|
[1172] | 1155 |
|
---|
| 1156 | //group
|
---|
[1195] | 1157 | char *value = mk_t_group((ulong*)account->grp);
|
---|
[1172] | 1158 | fprintf_conf(f, CONFVARWIDTH, "group", "%s\n", value);
|
---|
| 1159 | free(value);
|
---|
| 1160 |
|
---|
[1143] | 1161 | fprintf_conf(f, CONFVARWIDTH, "hostname", "%s\n", account->dyndns);
|
---|
[1104] | 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);
|
---|
[8] | 1165 |
|
---|
[1046] | 1166 | if (account->au > -1)
|
---|
| 1167 | if (account->au < CS_MAXREADER)
|
---|
[1104] | 1168 | fprintf_conf(f, CONFVARWIDTH, "au", "%s\n", reader[account->au].label);
|
---|
| 1169 | if (account->autoau == 1) fprintf_conf(f, CONFVARWIDTH, "au", "1\n");
|
---|
[1046] | 1170 |
|
---|
[1104] | 1171 | fprintf_conf(f, CONFVARWIDTH, "services", "");
|
---|
[986] | 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){
|
---|
[994] | 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++;
|
---|
[986] | 1180 | }
|
---|
[1104] | 1181 | fputc((int)'\n', f);
|
---|
[1169] | 1182 |
|
---|
| 1183 | //CAID
|
---|
[1172] | 1184 | value = mk_t_caidtab(&account->ctab);
|
---|
[1169] | 1185 | fprintf_conf(f, CONFVARWIDTH, "caid", "%s\n", value);
|
---|
| 1186 | free(value);
|
---|
| 1187 |
|
---|
[1176] | 1188 | //betatunnel
|
---|
[1169] | 1189 | value = mk_t_tuntab(&account->ttab);
|
---|
| 1190 | fprintf_conf(f, CONFVARWIDTH, "betatunnel", "%s\n", value);
|
---|
| 1191 | free(value);
|
---|
[1176] | 1192 |
|
---|
| 1193 | //ident
|
---|
| 1194 | value = mk_t_ftab(&account->ftab);
|
---|
| 1195 | fprintf_conf(f, CONFVARWIDTH, "ident", "%s\n", value);
|
---|
| 1196 | free(value);
|
---|
[1046] | 1197 |
|
---|
[986] | 1198 | #ifdef CS_ANTICASC
|
---|
[1104] | 1199 | fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", account->ac_users);
|
---|
| 1200 | fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", account->ac_penalty);
|
---|
[986] | 1201 | #endif
|
---|
[1104] | 1202 | fputc((int)'\n', f);
|
---|
[986] | 1203 | }
|
---|
| 1204 | fclose(f);
|
---|
| 1205 |
|
---|
[1104] | 1206 | return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
|
---|
[986] | 1207 | }
|
---|
| 1208 |
|
---|
[8] | 1209 | int init_userdb()
|
---|
[1210] | 1210 | {
|
---|
[980] | 1211 | int tag=0, nr, nro, expired;
|
---|
[8] | 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);
|
---|
[41] | 1256 | for (i=1; i<CS_MAXTUNTAB; account->ttab.bt_srvid[i++]=0x0000);
|
---|
[8] | 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);
|
---|
[980] | 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);
|
---|
[8] | 1279 | return(0);
|
---|
| 1280 | }
|
---|
| 1281 |
|
---|
[573] | 1282 | static void chk_entry4sidtab(char *value, struct s_sidtab *sidtab, int what)
|
---|
[8] | 1283 | {
|
---|
| 1284 | int i, b;
|
---|
| 1285 | char *ptr;
|
---|
| 1286 | ushort *slist=(ushort *) 0;
|
---|
| 1287 | ulong *llist=(ulong *) 0;
|
---|
| 1288 | ulong caid;
|
---|
[1091] | 1289 | char buf[strlen(value) + 1];
|
---|
[8] | 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 | }
|
---|
[573] | 1297 | //if (!i) return(0);
|
---|
[8] | 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 |
|
---|
[1095] | 1326 | void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab)
|
---|
[8] | 1327 | {
|
---|
[467] | 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);
|
---|
[8] | 1334 | }
|
---|
| 1335 |
|
---|
| 1336 | int init_sidtab()
|
---|
| 1337 | {
|
---|
[470] | 1338 | int nr, nro;
|
---|
[8] | 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 | {
|
---|
[470] | 1363 | int l;
|
---|
[8] | 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 |
|
---|
[1232] | 1398 | int init_srvid()
|
---|
| 1399 | {
|
---|
| 1400 | int nr;
|
---|
| 1401 | FILE *fp;
|
---|
| 1402 | char *payload;
|
---|
| 1403 | static struct s_srvid *srvid=(struct s_srvid *)0;
|
---|
| 1404 | sprintf(token, "%s%s", cs_confdir, cs_srid);
|
---|
| 1405 |
|
---|
| 1406 | if (!(fp=fopen(token, "r"))) {
|
---|
| 1407 | cs_log("can't open file \"%s\" (err=%d), no service-id's loaded", token, errno);
|
---|
| 1408 | return(0);
|
---|
| 1409 | }
|
---|
| 1410 |
|
---|
| 1411 | nr=0;
|
---|
| 1412 | while (fgets(token, sizeof(token), fp)) {
|
---|
| 1413 |
|
---|
| 1414 | int l;
|
---|
| 1415 | void *ptr;
|
---|
[1238] | 1416 | char *tmp;
|
---|
| 1417 | tmp = trim(token);
|
---|
| 1418 |
|
---|
| 1419 | if (tmp[0] == '#') continue;
|
---|
| 1420 | if ((l=strlen(tmp)) < 6) continue;
|
---|
[1232] | 1421 | if (!(payload=strchr(token, '|'))) continue;
|
---|
| 1422 | *payload++ = '\0';
|
---|
| 1423 |
|
---|
| 1424 | if (!(ptr = malloc(sizeof(struct s_srvid)))) {
|
---|
| 1425 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
| 1426 | return(1);
|
---|
| 1427 | }
|
---|
| 1428 |
|
---|
| 1429 | if (srvid)
|
---|
| 1430 | srvid->next = ptr;
|
---|
| 1431 | else
|
---|
| 1432 | cfg->srvid = ptr;
|
---|
| 1433 |
|
---|
| 1434 | srvid = ptr;
|
---|
| 1435 | memset(srvid, 0, sizeof(struct s_srvid));
|
---|
| 1436 |
|
---|
| 1437 | int i;
|
---|
| 1438 | char *ptr1;
|
---|
| 1439 | for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
|
---|
| 1440 | switch(i){
|
---|
| 1441 | case 0:
|
---|
| 1442 | strncpy(srvid->prov, trim(ptr1), sizeof(srvid->prov)-1);
|
---|
| 1443 | break;
|
---|
| 1444 | case 1:
|
---|
| 1445 | strncpy(srvid->name, trim(ptr1), sizeof(srvid->name)-1);
|
---|
| 1446 | break;
|
---|
| 1447 | case 2:
|
---|
| 1448 | strncpy(srvid->type, trim(ptr1), sizeof(srvid->type)-1);
|
---|
| 1449 | break;
|
---|
| 1450 | case 3:
|
---|
| 1451 | strncpy(srvid->desc, trim(ptr1), sizeof(srvid->desc)-1);
|
---|
| 1452 | break;
|
---|
| 1453 | }
|
---|
| 1454 | }
|
---|
| 1455 |
|
---|
| 1456 | char *srvidasc = strchr(token, ':');
|
---|
| 1457 | *srvidasc++ = '\0';
|
---|
| 1458 | srvid->srvid = word_atob(srvidasc);
|
---|
| 1459 |
|
---|
| 1460 | srvid->ncaid = 0;
|
---|
| 1461 | for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
|
---|
| 1462 | srvid->caid[i] = word_atob(ptr1);
|
---|
| 1463 | srvid->ncaid = i+1;
|
---|
| 1464 | }
|
---|
| 1465 | nr++;
|
---|
| 1466 | }
|
---|
| 1467 |
|
---|
| 1468 | fclose(fp);
|
---|
| 1469 | if (nr>0)
|
---|
| 1470 | cs_log("%d service-id's loaded", nr);
|
---|
| 1471 | else{
|
---|
| 1472 | cs_log("oscam.srvid loading FAILED -> old format");
|
---|
| 1473 | cs_log("New: caid[,caid]:srvid|providername|channelname|type|comment");
|
---|
| 1474 | cs_log("See: http://streamboard.gmc.to/wiki/index.php/Srvid#microMon.srvid");
|
---|
| 1475 | }
|
---|
| 1476 | return(0);
|
---|
[8] | 1477 | }
|
---|
| 1478 |
|
---|
| 1479 | static void chk_reader(char *token, char *value, struct s_reader *rdr)
|
---|
| 1480 | {
|
---|
| 1481 | int i;
|
---|
| 1482 | char *ptr;
|
---|
| 1483 | /*
|
---|
[647] | 1484 | * case sensitive first
|
---|
[8] | 1485 | */
|
---|
| 1486 | if (!strcmp(token, "device"))
|
---|
[467] | 1487 | {
|
---|
[8] | 1488 | for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
|
---|
| 1489 | {
|
---|
| 1490 | trim(ptr);
|
---|
| 1491 | switch(i)
|
---|
| 1492 | {
|
---|
| 1493 | case 0: strncpy(rdr->device, ptr, sizeof(rdr->device)-1); break;
|
---|
| 1494 | case 1: rdr->r_port=atoi(ptr); break;
|
---|
| 1495 | case 2: rdr->l_port=atoi(ptr); break;
|
---|
| 1496 | }
|
---|
| 1497 | }
|
---|
[467] | 1498 | return;
|
---|
| 1499 | }
|
---|
[8] | 1500 | if (!strcmp(token, "key"))
|
---|
| 1501 | {
|
---|
| 1502 | if (key_atob14(value, rdr->ncd_key))
|
---|
| 1503 | {
|
---|
| 1504 | fprintf(stderr, "Configuration newcamd: Error in Key\n");
|
---|
| 1505 | exit(1);
|
---|
| 1506 | }
|
---|
[467] | 1507 | return;
|
---|
[1149] | 1508 | }
|
---|
| 1509 | #ifdef CS_WITH_GBOX
|
---|
[467] | 1510 | if (!strcmp(token, "password")) { strncpy((char *)rdr->gbox_pwd, (const char *)i2b(4, a2i(value, 4)), 4); return; }
|
---|
[1149] | 1511 | if (!strcmp(token, "premium")) { rdr->gbox_prem=1; return; }
|
---|
| 1512 | #endif
|
---|
[8] | 1513 | if (!strcmp(token, "account"))
|
---|
[467] | 1514 | {
|
---|
[8] | 1515 | for (i=0, ptr=strtok(value, ","); (i<2)&&(ptr); ptr=strtok(NULL, ","), i++)
|
---|
| 1516 | {
|
---|
| 1517 | trim(ptr);
|
---|
| 1518 | switch(i)
|
---|
| 1519 | {
|
---|
| 1520 | case 0: strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr)-1); break;
|
---|
| 1521 | case 1: strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd)-1); break;
|
---|
| 1522 | }
|
---|
| 1523 | }
|
---|
[467] | 1524 | return;
|
---|
| 1525 | }
|
---|
| 1526 | if( !strcmp(token, "pincode")) { strncpy(rdr->pincode, value, sizeof(rdr->pincode)-1); return; }
|
---|
| 1527 | if (!strcmp(token, "readnano")) { strncpy((char *)rdr->emmfile, value, sizeof(rdr->emmfile)-1); return; }
|
---|
[8] | 1528 | /*
|
---|
[647] | 1529 | * case insensitive
|
---|
[8] | 1530 | */
|
---|
| 1531 | strtolower(value);
|
---|
| 1532 |
|
---|
[467] | 1533 | if (!strcmp(token, "services")) { chk_services(value, &rdr->sidtabok, &rdr->sidtabno); return; }
|
---|
| 1534 | if (!strcmp(token, "inactivitytimeout")) { rdr->tcp_ito = atoi(value); return; }
|
---|
| 1535 | if (!strcmp(token, "reconnecttimeout")) { rdr->tcp_rto = atoi(value); return; }
|
---|
| 1536 | if (!strcmp(token, "disableserverfilter")) { rdr->ncd_disable_server_filt = atoi(value); return; }
|
---|
[8] | 1537 |
|
---|
[467] | 1538 | if (!strcmp(token, "label")) { strncpy(rdr->label, value, sizeof(rdr->label)-1); return; }
|
---|
| 1539 | if (!strcmp(token, "fallback")) { rdr->fallback=atoi(value) ? 1 : 0; return; }
|
---|
| 1540 | if (!strcmp(token, "logport")) { rdr->log_port=atoi(value); return; }
|
---|
| 1541 | if (!strcmp(token, "caid")) { chk_caidtab(value, &rdr->ctab); return; }
|
---|
| 1542 | if (!strcmp(token, "boxid")) { rdr->boxid=a2i(value,4); return; }
|
---|
[89] | 1543 | if (!strcmp(token, "aeskey"))
|
---|
| 1544 | {
|
---|
| 1545 | if (key_atob(value, rdr->aes_key))
|
---|
| 1546 | {
|
---|
| 1547 | fprintf(stderr, "Configuration reader: Error in AES Key\n");
|
---|
| 1548 | exit(1);
|
---|
| 1549 | }
|
---|
[467] | 1550 | return;
|
---|
[89] | 1551 | }
|
---|
[1210] | 1552 | if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey")) )
|
---|
[597] | 1553 | {
|
---|
[1210] | 1554 | rdr->has_rsa=1;
|
---|
[597] | 1555 | if (key_atob_l(value, rdr->rsa_mod, 128))
|
---|
| 1556 | {
|
---|
[1210] | 1557 | fprintf(stderr, "Configuration reader: Error in rsakey\n");
|
---|
[597] | 1558 | exit(1);
|
---|
| 1559 | }
|
---|
| 1560 | return;
|
---|
| 1561 | }
|
---|
[1078] | 1562 | if (!strcmp(token, "tiger_rsakey"))
|
---|
| 1563 | {
|
---|
| 1564 | if (key_atob_l(value, rdr->rsa_mod, 240))
|
---|
| 1565 | {
|
---|
| 1566 | fprintf(stderr, "Configuration reader: Error in tiger_rsakey\n");
|
---|
| 1567 | exit(1);
|
---|
| 1568 | }
|
---|
| 1569 | return;
|
---|
| 1570 | }
|
---|
[1210] | 1571 | if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey")))
|
---|
[597] | 1572 | {
|
---|
| 1573 | if (key_atob_l(value, rdr->nagra_boxkey, 16))
|
---|
| 1574 | {
|
---|
[1210] | 1575 | fprintf(stderr, "Configuration reader: Error in boxkey\n");
|
---|
[597] | 1576 | exit(1);
|
---|
| 1577 | }
|
---|
| 1578 | return;
|
---|
| 1579 | }
|
---|
[8] | 1580 | if (!strcmp(token, "detect"))
|
---|
[467] | 1581 | {
|
---|
[8] | 1582 | for (i=0; RDR_CD_TXT[i]; i++)
|
---|
| 1583 | {
|
---|
| 1584 | if (!strcmp(value, RDR_CD_TXT[i]))
|
---|
| 1585 | rdr->detect=i;
|
---|
| 1586 | else
|
---|
| 1587 | if ((value[0]=='!') && (!strcmp(value+1, RDR_CD_TXT[i])))
|
---|
| 1588 | rdr->detect=i|0x80;
|
---|
| 1589 | }
|
---|
[467] | 1590 | return;
|
---|
| 1591 | }
|
---|
[621] | 1592 | if (!strcmp(token, "mhz")) { rdr->mhz=atoi(value); return; }
|
---|
[615] | 1593 | if (!strcmp(token, "cardmhz")) { rdr->cardmhz=atoi(value); return; }
|
---|
[8] | 1594 | if (!strcmp(token, "protocol"))
|
---|
| 1595 | {
|
---|
[470] | 1596 | if (!strcmp(value, "mouse")) { rdr->typ=R_MOUSE; return; }
|
---|
| 1597 | if (!strcmp(value, "smartreader")) { rdr->typ=R_SMART; return; }
|
---|
[802] | 1598 | if (!strcmp(value, "internal")) { rdr->typ=R_INTERNAL; return; }
|
---|
[776] | 1599 | #ifdef HAVE_PCSC
|
---|
| 1600 | if (!strcmp(value, "pcsc")) { rdr->typ=R_PCSC; return; }
|
---|
| 1601 | #endif
|
---|
[470] | 1602 | if (!strcmp(value, "serial")) { rdr->typ=R_SERIAL; return; }
|
---|
| 1603 | if (!strcmp(value, "camd35")) { rdr->typ=R_CAMD35; return; }
|
---|
| 1604 | if (!strcmp(value, "cs378x")) { rdr->typ=R_CS378X; return; }
|
---|
| 1605 | if (!strcmp(value, "cs357x")) { rdr->typ=R_CAMD35; return; }
|
---|
| 1606 | if (!strcmp(value, "gbox")) { rdr->typ=R_GBOX; return; }
|
---|
[719] | 1607 | if (!strcmp(value, "cccam")) {
|
---|
| 1608 | rdr->typ=R_CCCAM;
|
---|
| 1609 | // strcpy(value, "1");
|
---|
| 1610 | // chk_caidtab(value, &rdr->ctab); // this is a MAJOR hack for auto multiple caid support (not currently working due to ncd table issue)
|
---|
| 1611 | return;
|
---|
| 1612 | }
|
---|
[647] | 1613 | if (!strcmp(value, "radegast")) { rdr->typ=R_RADEGAST; return; }
|
---|
[827] | 1614 | if (!strcmp(value, "newcamd") ||
|
---|
| 1615 | !strcmp(value, "newcamd525")) {rdr->typ=R_NEWCAMD;
|
---|
[470] | 1616 | rdr->ncd_proto=NCD_525; return; }
|
---|
[827] | 1617 | if (!strcmp(value, "newcamd524")) {rdr->typ=R_NEWCAMD;
|
---|
[470] | 1618 | rdr->ncd_proto=NCD_524; return; }
|
---|
[478] | 1619 | fprintf(stderr, "WARNING: value '%s' in protocol-line not recognized, assuming MOUSE\n",value);
|
---|
| 1620 | rdr->typ=R_MOUSE;
|
---|
[467] | 1621 | return;
|
---|
[8] | 1622 | }
|
---|
[467] | 1623 | if (!strcmp(token, "ident")) { chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid"); return; }
|
---|
| 1624 | if (!strcmp(token, "class")) { chk_cltab(value, &rdr->cltab); return; }
|
---|
| 1625 | if (!strcmp(token, "chid")) { chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid"); return; }
|
---|
| 1626 | if (!strcmp(token, "showcls")) { rdr->show_cls = atoi(value); return; }
|
---|
| 1627 | if (!strcmp(token, "maxqlen"))
|
---|
| 1628 | {
|
---|
| 1629 | rdr->maxqlen = atoi(value);
|
---|
| 1630 | if( rdr->maxqlen<0 || rdr->maxqlen>CS_MAXQLEN )
|
---|
| 1631 | rdr->maxqlen=CS_MAXQLEN;
|
---|
| 1632 | return;
|
---|
| 1633 | }
|
---|
[8] | 1634 | if (!strcmp(token, "group"))
|
---|
[467] | 1635 | {
|
---|
[8] | 1636 | for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
| 1637 | {
|
---|
| 1638 | int g;
|
---|
| 1639 | g=atoi(ptr);
|
---|
| 1640 | if ((g>0) && (g<33)) rdr->grp|=(1<<(g-1));
|
---|
| 1641 | }
|
---|
[467] | 1642 | return;
|
---|
| 1643 | }
|
---|
[8] | 1644 | if (!strcmp(token, "emmcache"))
|
---|
[467] | 1645 | {
|
---|
[8] | 1646 | for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
|
---|
| 1647 | switch(i)
|
---|
| 1648 | {
|
---|
| 1649 | case 0: rdr->cachemm=atoi(ptr); break;
|
---|
| 1650 | case 1: rdr->rewritemm=atoi(ptr); break;
|
---|
| 1651 | case 2: rdr->logemm=atoi(ptr); break;
|
---|
| 1652 | }
|
---|
[508] | 1653 | if (rdr->rewritemm <=0) {
|
---|
| 1654 | 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);
|
---|
| 1655 | rdr->rewritemm = 1;
|
---|
| 1656 | }
|
---|
[467] | 1657 | return;
|
---|
| 1658 | }
|
---|
[452] | 1659 |
|
---|
[8] | 1660 | if (!strcmp(token, "blocknano"))
|
---|
[467] | 1661 | {
|
---|
[452] | 1662 | if (!strcmp(value,"all")) //wildcard is used
|
---|
| 1663 | for (i=0 ; i<256; i++)
|
---|
[647] | 1664 | rdr->b_nano[i] |= 0x01; //set all lsb's to block all nanos
|
---|
[452] | 1665 | else
|
---|
| 1666 | for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
[647] | 1667 | if ((i=byte_atob(ptr))>=0)
|
---|
| 1668 | rdr->b_nano[i]|= 0x01; //lsb is set when to block nano
|
---|
[467] | 1669 | return;
|
---|
| 1670 | }
|
---|
[452] | 1671 | if (!strcmp(token, "savenano"))
|
---|
[467] | 1672 | {
|
---|
[452] | 1673 | if (!strcmp(value,"all")) //wildcard is used
|
---|
| 1674 | for (i=0 ; i<256; i++)
|
---|
[647] | 1675 | rdr->b_nano[i] |= 0x02; //set all lsb+1 to save all nanos to file
|
---|
[452] | 1676 | else
|
---|
| 1677 | for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
[647] | 1678 | if ((i=byte_atob(ptr))>=0)
|
---|
| 1679 | rdr->b_nano[i]|= 0x02; //lsb+1 is set when to save nano to file
|
---|
[467] | 1680 | return;
|
---|
| 1681 | }
|
---|
[667] | 1682 | if (!strcmp(token, "cccversion")) { // cccam version
|
---|
[647] | 1683 | if (strlen(value)>sizeof(rdr->cc_version)-1) {
|
---|
| 1684 | fprintf(stderr, "cccam config: version too long\n");
|
---|
| 1685 | exit(1);
|
---|
| 1686 | }
|
---|
| 1687 | bzero(rdr->cc_version, sizeof(rdr->cc_version));
|
---|
| 1688 | strncpy(rdr->cc_version, value, sizeof(rdr->cc_version)-1);
|
---|
| 1689 | return;
|
---|
| 1690 | }
|
---|
[667] | 1691 | if (!strcmp(token, "cccbuild")) { // cccam build number
|
---|
[647] | 1692 | if (strlen(value)>sizeof(rdr->cc_build)-1) {
|
---|
| 1693 | fprintf(stderr, "cccam config build number too long\n");
|
---|
| 1694 | exit(1);
|
---|
| 1695 | }
|
---|
| 1696 | bzero(rdr->cc_build, sizeof(rdr->cc_build));
|
---|
| 1697 | strncpy(rdr->cc_build, value, sizeof(rdr->cc_build)-1);
|
---|
| 1698 | return;
|
---|
| 1699 | }
|
---|
[885] | 1700 | if (!strcmp(token, "cccmaxhop")) { // cccam max card distance
|
---|
| 1701 | rdr->cc_maxhop = atoi(value);
|
---|
| 1702 | return;
|
---|
| 1703 | }
|
---|
[467] | 1704 | if (token[0] != '#')
|
---|
| 1705 | fprintf(stderr, "Warning: keyword '%s' in reader section not recognized\n",token);
|
---|
[8] | 1706 | }
|
---|
| 1707 |
|
---|
| 1708 | int init_readerdb()
|
---|
| 1709 | {
|
---|
| 1710 | int tag=0, nr;
|
---|
| 1711 | FILE *fp;
|
---|
| 1712 | char *value;
|
---|
| 1713 |
|
---|
| 1714 | sprintf(token, "%s%s", cs_confdir, cs_srvr);
|
---|
| 1715 | if (!(fp=fopen(token, "r")))
|
---|
| 1716 | {
|
---|
| 1717 | cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
|
---|
| 1718 | return(1);
|
---|
| 1719 | }
|
---|
| 1720 | nr=0;
|
---|
| 1721 | while (fgets(token, sizeof(token), fp))
|
---|
| 1722 | {
|
---|
| 1723 | int i, l;
|
---|
| 1724 | if ((l=strlen(trim(token)))<3) continue;
|
---|
| 1725 | if ((token[0]=='[') && (token[l-1]==']'))
|
---|
| 1726 | {
|
---|
| 1727 | token[l-1]=0;
|
---|
| 1728 | tag=(!strcmp("reader", strtolower(token+1)));
|
---|
| 1729 | if (reader[nr].label[0] && reader[nr].typ) nr++;
|
---|
| 1730 | memset(&reader[nr], 0, sizeof(struct s_reader));
|
---|
[827] | 1731 | reader[nr].tcp_rto = 30;
|
---|
[8] | 1732 | reader[nr].show_cls = 10;
|
---|
| 1733 | reader[nr].maxqlen = CS_MAXQLEN;
|
---|
[9] | 1734 | reader[nr].mhz = 357;
|
---|
[615] | 1735 | reader[nr].cardmhz = 357;
|
---|
[38] | 1736 | strcpy(reader[nr].pincode, "none");
|
---|
[8] | 1737 | for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff);
|
---|
| 1738 | continue;
|
---|
| 1739 | }
|
---|
| 1740 | if (!tag) continue;
|
---|
| 1741 | if (!(value=strchr(token, '='))) continue;
|
---|
| 1742 | *value++='\0';
|
---|
| 1743 | chk_reader(trim(strtolower(token)), trim(value), &reader[nr]);
|
---|
| 1744 | }
|
---|
| 1745 | fclose(fp);
|
---|
| 1746 | return(0);
|
---|
| 1747 | }
|
---|
| 1748 |
|
---|
| 1749 | /*
|
---|
| 1750 | int init_irdeto_guess_tab()
|
---|
| 1751 | {
|
---|
| 1752 | int i, j, skip;
|
---|
| 1753 | int b47;
|
---|
| 1754 | FILE *fp;
|
---|
| 1755 | char token[128], *value, *ptr;
|
---|
| 1756 | char zSid[5];
|
---|
| 1757 | uchar b3;
|
---|
| 1758 | ushort caid, sid;
|
---|
| 1759 | struct s_irdeto_quess *ird_row, *head;
|
---|
| 1760 |
|
---|
| 1761 | memset(cfg->itab, 0, sizeof(cfg->itab));
|
---|
| 1762 | sprintf(token, "%s%s", cs_confdir, cs_ird);
|
---|
| 1763 | if (!(fp=fopen(token, "r")))
|
---|
| 1764 | {
|
---|
[827] | 1765 | cs_log("can't open file \"%s\" (errno=%d) irdeto guessing not loaded",
|
---|
[8] | 1766 | token, errno);
|
---|
| 1767 | return(1);
|
---|
| 1768 | }
|
---|
| 1769 | while (fgets(token, sizeof(token), fp))
|
---|
| 1770 | {
|
---|
| 1771 | if( strlen(token)<20 ) continue;
|
---|
| 1772 | for( i=b3=b47=caid=sid=skip=0, ptr=strtok(token, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
|
---|
| 1773 | {
|
---|
| 1774 | trim(ptr);
|
---|
| 1775 | if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
|
---|
| 1776 | skip=1;
|
---|
| 1777 | break;
|
---|
| 1778 | }
|
---|
| 1779 | switch(i)
|
---|
| 1780 | {
|
---|
| 1781 | case 0: b3 = a2i(ptr, 2); break;
|
---|
| 1782 | case 1: b47 = a2i(ptr, 8); break;
|
---|
| 1783 | case 2: caid = a2i(ptr, 4); break;
|
---|
[827] | 1784 | case 3:
|
---|
[8] | 1785 | for( j=0; j<4; j++ )
|
---|
| 1786 | zSid[j]=ptr[j];
|
---|
| 1787 | zSid[4]=0;
|
---|
[827] | 1788 | sid = a2i(zSid, 4);
|
---|
[8] | 1789 | break;
|
---|
| 1790 | }
|
---|
| 1791 | }
|
---|
[827] | 1792 | if( !skip )
|
---|
[8] | 1793 | {
|
---|
| 1794 | if (!(ird_row=(struct s_irdeto_quess*)malloc(sizeof(struct s_irdeto_quess))))
|
---|
| 1795 | {
|
---|
| 1796 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
| 1797 | return;
|
---|
| 1798 | }
|
---|
| 1799 | ird_row->b47 = b47;
|
---|
| 1800 | ird_row->caid = caid;
|
---|
| 1801 | ird_row->sid = sid;
|
---|
| 1802 | ird_row->next = 0;
|
---|
| 1803 |
|
---|
| 1804 | head = cfg->itab[b3];
|
---|
| 1805 | if( head ) {
|
---|
| 1806 | while( head->next )
|
---|
| 1807 | head=head->next;
|
---|
| 1808 | head->next=ird_row;
|
---|
| 1809 | }
|
---|
| 1810 | else
|
---|
| 1811 | cfg->itab[b3]=ird_row;
|
---|
| 1812 |
|
---|
| 1813 | //cs_debug("%02X:%08X:%04X:%04X", b3, b47, caid, sid);
|
---|
| 1814 | }
|
---|
| 1815 | }
|
---|
| 1816 | fclose(fp);
|
---|
| 1817 |
|
---|
| 1818 | for( i=0; i<0xff; i++ )
|
---|
| 1819 | {
|
---|
| 1820 | head=cfg->itab[i];
|
---|
| 1821 | while(head)
|
---|
| 1822 | {
|
---|
| 1823 | cs_debug("itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
|
---|
| 1824 | i, head->b47, head->caid, head->sid);
|
---|
| 1825 | head=head->next;
|
---|
| 1826 | }
|
---|
| 1827 | }
|
---|
| 1828 | return(0);
|
---|
| 1829 | }
|
---|
| 1830 | */
|
---|
| 1831 |
|
---|
| 1832 | #ifdef CS_ANTICASC
|
---|
| 1833 | void init_ac()
|
---|
| 1834 | {
|
---|
| 1835 | int nr;
|
---|
| 1836 | FILE *fp;
|
---|
| 1837 | //char *value;
|
---|
| 1838 |
|
---|
| 1839 | sprintf(token, "%s%s", cs_confdir, cs_ac);
|
---|
| 1840 | if (!(fp=fopen(token, "r")))
|
---|
| 1841 | {
|
---|
[827] | 1842 | cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
|
---|
[8] | 1843 | token, errno);
|
---|
| 1844 | return;
|
---|
| 1845 | }
|
---|
| 1846 |
|
---|
| 1847 | for(nr=0; fgets(token, sizeof(token), fp);)
|
---|
| 1848 | {
|
---|
| 1849 | int i, skip;
|
---|
| 1850 | ushort caid, sid, chid, dwtime;
|
---|
| 1851 | ulong provid;
|
---|
| 1852 | char *ptr, *ptr1;
|
---|
| 1853 | struct s_cpmap *ptr_cpmap;
|
---|
| 1854 | static struct s_cpmap *cpmap=(struct s_cpmap *)0;
|
---|
| 1855 |
|
---|
| 1856 | if( strlen(token)<4 ) continue;
|
---|
| 1857 |
|
---|
| 1858 | caid=sid=chid=dwtime=0;
|
---|
| 1859 | provid=0;
|
---|
| 1860 | skip=0;
|
---|
| 1861 | ptr1=0;
|
---|
| 1862 | for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
|
---|
| 1863 | {
|
---|
| 1864 | trim(ptr);
|
---|
| 1865 | if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
|
---|
| 1866 | skip=1;
|
---|
| 1867 | break;
|
---|
| 1868 | }
|
---|
| 1869 | switch( i )
|
---|
| 1870 | {
|
---|
| 1871 | case 0:
|
---|
| 1872 | ptr1=ptr;
|
---|
| 1873 | break;
|
---|
[827] | 1874 | case 1:
|
---|
[8] | 1875 | dwtime = atoi(ptr);
|
---|
| 1876 | break;
|
---|
| 1877 | }
|
---|
| 1878 | }
|
---|
| 1879 |
|
---|
| 1880 | if( !skip )
|
---|
| 1881 | {
|
---|
| 1882 | for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
|
---|
| 1883 | {
|
---|
| 1884 | trim(ptr);
|
---|
| 1885 | switch( i )
|
---|
| 1886 | {
|
---|
[827] | 1887 | case 0:
|
---|
[8] | 1888 | if( *ptr=='*' ) caid = 0;
|
---|
[827] | 1889 | else caid = a2i(ptr, 4);
|
---|
[8] | 1890 | break;
|
---|
[827] | 1891 | case 1:
|
---|
[8] | 1892 | if( *ptr=='*' ) provid = 0;
|
---|
[827] | 1893 | else provid = a2i(ptr, 6);
|
---|
[8] | 1894 | break;
|
---|
[827] | 1895 | case 2:
|
---|
[8] | 1896 | if( *ptr=='*' ) sid = 0;
|
---|
[827] | 1897 | else sid = a2i(ptr, 4);
|
---|
[8] | 1898 | break;
|
---|
[827] | 1899 | case 3:
|
---|
[8] | 1900 | if( *ptr=='*' ) chid = 0;
|
---|
[827] | 1901 | else chid = a2i(ptr, 4);
|
---|
[8] | 1902 | break;
|
---|
| 1903 | }
|
---|
| 1904 | }
|
---|
| 1905 | if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
|
---|
| 1906 | {
|
---|
| 1907 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
| 1908 | return;
|
---|
| 1909 | }
|
---|
| 1910 | if( cpmap )
|
---|
| 1911 | cpmap->next=ptr_cpmap;
|
---|
| 1912 | else
|
---|
| 1913 | cfg->cpmap=ptr_cpmap;
|
---|
| 1914 | cpmap=ptr_cpmap;
|
---|
| 1915 |
|
---|
| 1916 | cpmap->caid = caid;
|
---|
| 1917 | cpmap->provid = provid;
|
---|
| 1918 | cpmap->sid = sid;
|
---|
| 1919 | cpmap->chid = chid;
|
---|
| 1920 | cpmap->dwtime = dwtime;
|
---|
| 1921 | cpmap->next = 0;
|
---|
| 1922 |
|
---|
[827] | 1923 | cs_debug("nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
|
---|
[8] | 1924 | nr, caid, provid, sid, chid, dwtime);
|
---|
| 1925 | nr++;
|
---|
| 1926 | }
|
---|
| 1927 | }
|
---|
| 1928 | fclose(fp);
|
---|
| 1929 | //cs_log("%d lengths for caid guessing loaded", nr);
|
---|
| 1930 | return;
|
---|
| 1931 | }
|
---|
[1169] | 1932 | #endif
|
---|
| 1933 |
|
---|
[1180] | 1934 | /*
|
---|
| 1935 | * makes a char ready to write a token into config or webIf
|
---|
| 1936 | */
|
---|
[1169] | 1937 | char *mk_t_caidtab(CAIDTAB *ctab){
|
---|
| 1938 | int i = 0, needed = 1, pos = 0;
|
---|
| 1939 | while(ctab->caid[i]){
|
---|
| 1940 | if(ctab->mask[i]) needed += 10;
|
---|
| 1941 | else needed += 5;
|
---|
| 1942 | if(ctab->cmap[i]) needed += 5;
|
---|
| 1943 | ++i;
|
---|
| 1944 | }
|
---|
| 1945 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
| 1946 | i = 0;
|
---|
| 1947 | while(ctab->caid[i]) {
|
---|
| 1948 | if(i == 0) {
|
---|
| 1949 | sprintf(value + pos, "%04X", ctab->caid[i]);
|
---|
| 1950 | pos += 4;
|
---|
| 1951 | } else {
|
---|
| 1952 | sprintf(value + pos, ",%04X", ctab->caid[i]);
|
---|
| 1953 | pos += 5;
|
---|
| 1954 | }
|
---|
| 1955 | if(ctab->mask[i]){
|
---|
| 1956 | sprintf(value + pos, "&%04X", ctab->mask[i]);
|
---|
| 1957 | pos += 5;
|
---|
| 1958 | }
|
---|
| 1959 | if(ctab->cmap[i]){
|
---|
| 1960 | sprintf(value + pos, ":%04X", ctab->cmap[i]);
|
---|
| 1961 | pos += 5;
|
---|
| 1962 | }
|
---|
| 1963 | ++i;
|
---|
| 1964 | }
|
---|
| 1965 | value[pos] = '\0';
|
---|
| 1966 | return value;
|
---|
| 1967 | }
|
---|
| 1968 |
|
---|
[1180] | 1969 | /*
|
---|
| 1970 | * makes a char ready to write a token into config or webIf
|
---|
| 1971 | */
|
---|
[1169] | 1972 | char *mk_t_tuntab(TUNTAB *ttab){
|
---|
| 1973 | int i = 0, needed = 1, pos = 0;
|
---|
| 1974 | while(ttab->bt_caidfrom[i]){
|
---|
| 1975 | if(ttab->bt_srvid[i]) needed += 10;
|
---|
| 1976 | else needed += 5;
|
---|
| 1977 | if(ttab->bt_caidto[i]) needed += 5;
|
---|
| 1978 | ++i;
|
---|
| 1979 | }
|
---|
| 1980 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
| 1981 | i = 0;
|
---|
| 1982 | while(ttab->bt_caidfrom[i]) {
|
---|
| 1983 | if(i == 0) {
|
---|
| 1984 | sprintf(value + pos, "%04X", ttab->bt_caidfrom[i]);
|
---|
| 1985 | pos += 4;
|
---|
| 1986 | } else {
|
---|
| 1987 | sprintf(value + pos, ",%04X", ttab->bt_caidfrom[i]);
|
---|
| 1988 | pos += 5;
|
---|
| 1989 | }
|
---|
| 1990 | if(ttab->bt_srvid[i]){
|
---|
| 1991 | sprintf(value + pos, ".%04X", ttab->bt_srvid[i]);
|
---|
| 1992 | pos += 5;
|
---|
| 1993 | }
|
---|
| 1994 | if(ttab->bt_caidto[i]){
|
---|
| 1995 | sprintf(value + pos, ":%04X", ttab->bt_caidto[i]);
|
---|
| 1996 | pos += 5;
|
---|
| 1997 | }
|
---|
| 1998 | ++i;
|
---|
| 1999 | }
|
---|
| 2000 | value[pos] = '\0';
|
---|
| 2001 | return value;
|
---|
| 2002 | }
|
---|
[1172] | 2003 |
|
---|
[1180] | 2004 | /*
|
---|
| 2005 | * makes a char ready to write a token into config or webIf
|
---|
| 2006 | */
|
---|
[1172] | 2007 | char *mk_t_group(ulong *grp){
|
---|
[1175] | 2008 | int i = 0, needed = 1, pos = 0, dot = 0;
|
---|
[1172] | 2009 | char grpbit[33];
|
---|
| 2010 | long2bitchar((long) grp, grpbit);
|
---|
| 2011 |
|
---|
| 2012 | for(i = 0; i < 32; i++){
|
---|
| 2013 | if (grpbit[i] == '1'){
|
---|
| 2014 | needed += 2;
|
---|
| 2015 | if(i > 9) needed += 1;
|
---|
| 2016 | }
|
---|
| 2017 | }
|
---|
| 2018 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
| 2019 |
|
---|
| 2020 | for(i = 0; i < 32; i++){
|
---|
| 2021 | if (grpbit[i] == '1'){
|
---|
[1175] | 2022 | if (dot == 0){
|
---|
[1172] | 2023 | sprintf(value + pos, "%d", i+1);
|
---|
| 2024 | if (i > 9)pos += 2;
|
---|
| 2025 | else pos += 1;
|
---|
[1175] | 2026 | dot = 1;
|
---|
[1172] | 2027 | } else {
|
---|
| 2028 | sprintf(value + pos, ",%d", i+1);
|
---|
| 2029 | if (i > 9)pos += 3;
|
---|
| 2030 | else pos += 2;
|
---|
| 2031 | }
|
---|
| 2032 | }
|
---|
| 2033 | }
|
---|
| 2034 | value[pos] = '\0';
|
---|
| 2035 | return value;
|
---|
| 2036 | }
|
---|
[1176] | 2037 |
|
---|
[1180] | 2038 | /*
|
---|
| 2039 | * makes a char ready to write a token into config or webIf
|
---|
| 2040 | */
|
---|
[1176] | 2041 | char *mk_t_ftab(FTAB *ftab){
|
---|
| 2042 | int i = 0, j = 0, needed = 1, pos = 0;
|
---|
| 2043 |
|
---|
| 2044 | needed = ftab->nfilts * 5;
|
---|
| 2045 | for (i = 0; i < ftab->nfilts; ++i)
|
---|
| 2046 | needed += ftab->filts[i].nprids * 7;
|
---|
| 2047 |
|
---|
| 2048 | char *value = (char *) malloc(needed * sizeof(char));
|
---|
| 2049 |
|
---|
| 2050 | char *dot="";
|
---|
| 2051 | for (i = 0; i < ftab->nfilts; ++i){
|
---|
| 2052 | sprintf(value + pos, "%s%04X", dot, ftab->filts[i].caid);
|
---|
| 2053 | pos += 4;
|
---|
| 2054 | if (i > 0) pos += 1;
|
---|
| 2055 | dot=":";
|
---|
| 2056 | for (j = 0; j < ftab->filts[i].nprids; ++j) {
|
---|
| 2057 | sprintf(value + pos, "%s%06lX", dot, ftab->filts[i].prids[j]);
|
---|
| 2058 | pos += 7;
|
---|
| 2059 | dot=",";
|
---|
| 2060 | }
|
---|
| 2061 | dot=";";
|
---|
| 2062 | }
|
---|
| 2063 |
|
---|
| 2064 | value[pos] = '\0';
|
---|
| 2065 | return value;
|
---|
| 2066 | }
|
---|