Changeset 1680
- Timestamp:
- 02/25/10 01:05:38 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/monitor-improvement/oscam-config.c
r1679 r1680 22 22 typedef enum cs_proto_type 23 23 { 24 TAG_GLOBAL,// must be first !25 TAG_MONITOR,// monitor26 TAG_CAMD33,// camd 3.3x27 TAG_CAMD35,// camd 3.5x UDP28 TAG_NEWCAMD,// newcamd29 TAG_RADEGAST,// radegast30 TAG_SERIAL,// serial (static)31 TAG_CS357X,// camd 3.5x UDP32 TAG_CS378X,// camd 3.5x TCP24 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 33 #ifdef CS_WITH_GBOX 34 TAG_GBOX,// gbox35 #endif 36 TAG_CCCAM,// cccam37 34 TAG_GBOX, // gbox 35 #endif 36 TAG_CCCAM, // cccam 37 TAG_DVBAPI 38 38 #ifdef CS_ANTICASC 39 ,TAG_ANTICASC// anti-cascading39 ,TAG_ANTICASC // anti-cascading 40 40 #endif 41 41 } cs_proto_type_t; 42 42 43 43 static char *cctag[]={"global", "monitor", "camd33", "camd35", 44 44 "newcamd", "radegast", "serial", "cs357x", "cs378x", 45 45 #ifdef CS_WITH_GBOX 46 46 "gbox", 47 47 #endif 48 48 "cccam", "dvbapi", 49 49 #ifdef CS_ANTICASC 50 50 "anticasc", 51 51 #endif 52 52 NULL}; 53 53 54 54 #ifdef DEBUG_SIDTAB … … 78 78 void chk_iprange(char *value, struct s_ip **base) 79 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 } 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 fprintf(stderr, "Error allocating memory (errno=%d)\n", errno); 88 exit(1); 89 } 90 if (*base) 91 lip->next = cip; 92 else 93 *base = cip; 94 95 memset(cip, 0, sizeof(struct s_ip)); 96 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) { 97 if (i == 0) 98 ++i; 99 else { 100 if (!(cip=malloc(sizeof(struct s_ip)))) { 101 fprintf(stderr, "Error allocating memory (errno=%d)\n", errno); 102 exit(1); 103 } 104 lip->next = cip; 105 memset(cip, 0, sizeof(struct s_ip)); 106 } 107 108 if( (ptr2=strchr(trim(ptr1), '-')) ) { 109 *ptr2++ ='\0'; 110 cip->ip[0]=cs_inet_addr(trim(ptr1)); 111 cip->ip[1]=cs_inet_addr(trim(ptr2)); 112 } else { 113 cip->ip[0]=cip->ip[1]=cs_inet_addr(ptr1); 114 } 115 lip = cip; 116 } 118 117 } 119 118 … … 959 958 void chk_t_serial(char *token, char *value) 960 959 { 961 if (!strcmp(token, "device")) 962 { 963 int l;964 l=strlen(cfg->ser_device); 965 if (l)cfg->ser_device[l++]=1; // use ctrl-a as delimiter966 967 968 969 970 fprintf(stderr, "Warning: keyword '%s' in serial section not recognized\n",token);960 if (!strcmp(token, "device")) { 961 int l; 962 l = strlen(cfg->ser_device); 963 if (l) 964 cfg->ser_device[l++]=1; // use ctrl-a as delimiter 965 cs_strncpy(cfg->ser_device+l, value, sizeof(cfg->ser_device)-l); 966 return; 967 } 968 if (token[0] != '#') 969 cs_log( "Warning: keyword '%s' in serial section not recognized", token); 971 970 } 972 971 … … 1208 1207 void chk_account(char *token, char *value, struct s_auth *account) 1209 1208 { 1210 int i; 1211 char *ptr1;//, *ptr2; 1212 1213 if (!strcmp(token, "user")) { cs_strncpy(account->usr, value, sizeof(account->usr)); return; } 1214 if (!strcmp(token, "pwd")) { cs_strncpy(account->pwd, value, sizeof(account->pwd)); return; } 1215 if (!strcmp(token, "hostname")) { cs_strncpy((char *)account->dyndns, value, sizeof(account->dyndns));return; } 1216 1217 if (!strcmp(token, "betatunnel")) { 1209 int i; 1210 char *ptr1; 1211 1212 if (!strcmp(token, "user")) { 1213 cs_strncpy(account->usr, value, sizeof(account->usr)); 1214 return; 1215 } 1216 1217 if (!strcmp(token, "pwd")) { 1218 cs_strncpy(account->pwd, value, sizeof(account->pwd)); 1219 return; 1220 } 1221 1222 if (!strcmp(token, "hostname")) { 1223 cs_strncpy((char *)account->dyndns, value, sizeof(account->dyndns)); 1224 return; 1225 } 1226 1227 if (!strcmp(token, "betatunnel")) { 1218 1228 if(strlen(value) == 0) { 1219 1229 clear_tuntab(&account->ttab); … … 1225 1235 } 1226 1236 1227 if (!strcmp(token, "uniq")) { account->uniq=atoi(value); return; } 1228 if (!strcmp(token, "sleep")) { account->tosleep=atoi(value); return; } 1229 if (!strcmp(token, "monlevel")) { account->monlvl=atoi(value); return; } 1230 1231 if (!strcmp(token, "caid")) { 1237 if (!strcmp(token, "uniq")) { 1238 if(strlen(value) == 0) { 1239 account->uniq = 0; 1240 return; 1241 } else { 1242 account->uniq = atoi(value); 1243 return; 1244 } 1245 } 1246 1247 if (!strcmp(token, "sleep")) { 1248 if(strlen(value) == 0) { 1249 account->tosleep = 0; 1250 return; 1251 } else { 1252 account->tosleep=atoi(value); 1253 return; 1254 } 1255 } 1256 1257 if (!strcmp(token, "monlevel")) { 1258 if(strlen(value) == 0) { 1259 account->monlvl = 0; 1260 return; 1261 } else { 1262 account->monlvl = atoi(value); 1263 return; 1264 } 1265 } 1266 1267 if (!strcmp(token, "caid")) { 1232 1268 if(strlen(value) == 0) { 1233 1269 clear_caidtab(&account->ctab); … … 1239 1275 } 1240 1276 1241 if (!strcmp(token, "disabled")) { account->disabled=atoi(value); return; } 1242 if (!strcmp(token, "suppresscmd08")) { account->c35_suppresscmd08=atoi(value); return; } 1243 if (!strcmp(token, "keepalive")) 1244 { 1245 account->ncd_keepalive = atoi(value); 1246 return; 1247 } 1248 /* 1249 * case insensitive 1250 */ 1251 strtolower(value); 1252 if (!strcmp(token, "au")) 1253 { 1254 //set default values for usage during runtime from Webif 1255 account->au=-1; 1256 account->autoau=0; 1257 1258 if(value && value[0]=='1') account->autoau=1; 1259 for (i=0; i<CS_MAXREADER; i++) 1260 if ((reader[i].label[0]) && 1261 (!strncmp(reader[i].label, value, strlen(reader[i].label)))) 1262 account->au=i; 1263 return; 1264 } 1265 if (!strcmp(token, "group")) { 1266 account->grp = 0; 1267 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) 1268 { 1269 int g; 1270 g=atoi(ptr1); 1271 if ((g>0) && (g<33)) account->grp|=(1<<(g-1)); 1272 } 1273 return; 1274 } 1275 if(!strcmp(token, "services")) { chk_services(value, &account->sidtabok, &account->sidtabno); return; } 1276 if(!strcmp(token, "ident")) { chk_ftab(value, &account->ftab, "user", account->usr, "provid"); return; } 1277 if(!strcmp(token, "class")) { chk_cltab(value, &account->cltab); return; } 1278 if(!strcmp(token, "chid")) { chk_ftab(value, &account->fchid, "user", account->usr, "chid"); return; } 1277 if (!strcmp(token, "disabled")) { 1278 if(strlen(value) == 0) { 1279 account->disabled = 0; 1280 return; 1281 } else { 1282 account->disabled = atoi(value); 1283 return; 1284 } 1285 } 1286 1287 if (!strcmp(token, "suppresscmd08")) { 1288 if(strlen(value) == 0) { 1289 account->c35_suppresscmd08 = 0; 1290 return; 1291 } else { 1292 account->c35_suppresscmd08=atoi(value); 1293 return; 1294 } 1295 } 1296 1297 if (!strcmp(token, "keepalive")) { 1298 if(strlen(value) == 0) { 1299 account->ncd_keepalive = 1; 1300 return; 1301 } else { 1302 account->ncd_keepalive = atoi(value); 1303 return; 1304 } 1305 } 1306 /* 1307 * case insensitive 1308 */ 1309 strtolower(value); 1310 1311 if (!strcmp(token, "au")) { 1312 //set default values for usage during runtime from Webif 1313 account->au=-1; 1314 account->autoau=0; 1315 1316 if(value && value[0]=='1') account->autoau=1; 1317 for (i=0; i<CS_MAXREADER; i++) 1318 if ((reader[i].label[0]) && (!strncmp(reader[i].label, value, strlen(reader[i].label)))) 1319 account->au=i; 1320 return; 1321 } 1322 1323 if (!strcmp(token, "group")) { 1324 account->grp = 0; 1325 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) { 1326 int g; 1327 g = atoi(ptr1); 1328 if ((g>0) && (g < 33)) account->grp|=(1<<(g-1)); 1329 } 1330 return; 1331 } 1332 1333 if(!strcmp(token, "services")) { 1334 chk_services(value, &account->sidtabok, &account->sidtabno); 1335 return; 1336 } 1337 1338 if(!strcmp(token, "ident")) { /*ToDo ftab clear*/ 1339 chk_ftab(value, &account->ftab, "user", account->usr, "provid"); 1340 return; 1341 } 1342 1343 if(!strcmp(token, "class")) { 1344 chk_cltab(value, &account->cltab); 1345 return; 1346 } 1347 1348 if(!strcmp(token, "chid")) { 1349 chk_ftab(value, &account->fchid, "user", account->usr, "chid"); 1350 return; 1351 } 1279 1352 1280 1353 if (!strcmp(token, "expdate")) { … … 1297 1370 1298 1371 #ifdef CS_ANTICASC 1299 if( !strcmp(token, "numusers") ) 1300 { 1301 account->ac_users = atoi(value); 1302 return; 1303 } 1304 if( !strcmp(token, "penalty") ) 1305 { 1306 account->ac_penalty = atoi(value); 1307 return; 1308 } 1309 #endif 1310 if (token[0] != '#') 1311 fprintf(stderr, "Warning: keyword '%s' in account section not recognized\n",token); 1312 1313 // if (!strcmp(token, "caid")) 1314 // { 1315 // for (i=0, ptr1=strtok(value, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ",")) 1316 // { 1317 // ulong caid, mask; 1318 // if (ptr2=strchr(trim(ptr1), '&')) 1319 // *ptr2++='\0'; 1320 // else 1321 // ptr2=""; 1322 // if (((caid=a2i(ptr1, 2))|(mask=a2i(ptr2,-2))) < 0x10000) 1323 // { 1324 // account->caidtab[i][0]=caid; 1325 // account->caidtab[i++][1]=mask; 1326 // } 1327 // else 1328 // cs_log("WARNING: wrong CAID in %s -> ignored", cs_user); 1329 // } 1330 // } 1372 if( !strcmp(token, "numusers") ) { 1373 account->ac_users = atoi(value); 1374 return; 1375 } 1376 1377 if( !strcmp(token, "penalty") ) { 1378 account->ac_penalty = atoi(value); 1379 return; 1380 } 1381 #endif 1382 1383 if (token[0] != '#') 1384 cs_log( "Warning: keyword '%s' in account section not recognized",token); 1331 1385 } 1332 1386 … … 2229 2283 int init_readerdb() 2230 2284 { 2231 int tag=0, nr; 2232 FILE *fp; 2233 char *value; 2234 2235 sprintf(token, "%s%s", cs_confdir, cs_srvr); 2236 if (!(fp=fopen(token, "r"))) 2237 { 2238 cs_log("can't open file \"%s\" (errno=%d)\n", token, errno); 2239 return(1); 2240 } 2241 nr=0; 2242 while (fgets(token, sizeof(token), fp)) 2243 { 2244 int i, l; 2245 if ((l=strlen(trim(token)))<3) continue; 2246 if ((token[0]=='[') && (token[l-1]==']')) 2247 { 2248 token[l-1]=0; 2249 tag=(!strcmp("reader", strtolower(token+1))); 2250 if (reader[nr].label[0] && reader[nr].typ) nr++; 2251 memset(&reader[nr], 0, sizeof(struct s_reader)); 2252 reader[nr].enable = 1; 2253 reader[nr].tcp_rto = 30; 2254 reader[nr].show_cls = 10; 2255 reader[nr].maxqlen = CS_MAXQLEN; 2256 reader[nr].mhz = 357; 2257 reader[nr].cardmhz = 357; 2285 int tag = 0, nr; 2286 FILE *fp; 2287 char *value; 2288 2289 sprintf(token, "%s%s", cs_confdir, cs_srvr); 2290 if (!(fp=fopen(token, "r"))) { 2291 cs_log("can't open file \"%s\" (errno=%d)\n", token, errno); 2292 return(1); 2293 } 2294 nr = 0; 2295 while (fgets(token, sizeof(token), fp)) { 2296 int i, l; 2297 if ((l = strlen(trim(token))) < 3) 2298 continue; 2299 if ((token[0] == '[') && (token[l-1] == ']')) { 2300 token[l-1] = 0; 2301 tag = (!strcmp("reader", strtolower(token+1))); 2302 if (reader[nr].label[0] && reader[nr].typ) nr++; 2303 memset(&reader[nr], 0, sizeof(struct s_reader)); 2304 reader[nr].enable = 1; 2305 reader[nr].tcp_rto = 30; 2306 reader[nr].show_cls = 10; 2307 reader[nr].maxqlen = CS_MAXQLEN; 2308 reader[nr].mhz = 357; 2309 reader[nr].cardmhz = 357; 2258 2310 reader[nr].deprecated = 0; 2259 strcpy(reader[nr].pincode, "none"); 2260 for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff); 2261 continue; 2262 } 2263 if (!tag) continue; 2264 if (!(value=strchr(token, '='))) continue; 2265 *value++='\0'; 2266 chk_reader(trim(strtolower(token)), trim(value), &reader[nr]); 2267 } 2268 fclose(fp); 2269 return(0); 2311 strcpy(reader[nr].pincode, "none"); 2312 for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff); 2313 continue; 2314 } 2315 2316 if (!tag) 2317 continue; 2318 if (!(value=strchr(token, '='))) 2319 continue; 2320 *value++ ='\0'; 2321 chk_reader(trim(strtolower(token)), trim(value), &reader[nr]); 2322 } 2323 fclose(fp); 2324 return(0); 2270 2325 } 2271 2326
Note:
See TracChangeset
for help on using the changeset viewer.