revert breaks some stupid old compilers
[oscam.git] / oscam-config-global.c
blob222ca005e9ae7b2aec562e2f8fca419067aa5233
1 #define MODULE_LOG_PREFIX "config"
3 #include "globals.h"
4 #include "module-dvbapi.h"
5 #include "module-gbox.h"
6 #include "oscam-array.h"
7 #include "oscam-conf.h"
8 #include "oscam-conf-chk.h"
9 #include "oscam-conf-mk.h"
10 #include "oscam-config.h"
11 #include "oscam-net.h"
12 #include "oscam-string.h"
14 #define cs_conf "oscam.conf"
16 #define DEFAULT_HTTP_PORT 8888
17 #define DEFAULT_HTTP_ALLOW "127.0.0.1,192.168.0.0-192.168.255.255,10.0.0.0-10.255.255.255,::1"
19 static void disablelog_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
21 if(value)
23 cs_disable_log(strToIntVal(value, 0));
24 return;
26 if(cfg.disablelog || cfg.http_full_cfg)
27 { fprintf_conf(f, token, "%d\n", cfg.disablelog); }
30 #if defined(WEBIF) || defined(MODULE_MONITOR)
31 static void loghistorylines_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
33 if(value)
35 uint32_t newsize = strToUIntVal(value, 256);
36 if(newsize < 64 && newsize != 0)
38 fprintf(stderr, "WARNING: loghistorylines is too small, adjusted to 64\n");
39 newsize = 64;
41 cs_reinit_loghist(newsize);
42 return;
44 if(cfg.loghistorylines != 256 || cfg.http_full_cfg)
45 { fprintf_conf(f, token, "%u\n", cfg.loghistorylines); }
47 #endif
49 static void serverip_fn(const char *token, char *value, void *setting, FILE *f)
51 IN_ADDR_T srvip = *(IN_ADDR_T *)setting;
52 if(value)
54 if(strlen(value) == 0)
56 set_null_ip((IN_ADDR_T *)setting);
58 else
60 cs_inet_addr(value, (IN_ADDR_T *)setting);
62 return;
64 if(IP_ISSET(srvip) || cfg.http_full_cfg)
65 { fprintf_conf(f, token, "%s\n", cs_inet_ntoa(srvip)); }
68 void iprange_fn(const char *token, char *value, void *setting, FILE *f)
70 struct s_ip **ip = setting;
71 if(value)
73 if(strlen(value) == 0)
75 clear_sip(ip);
77 else
79 chk_iprange(value, ip);
81 return;
83 value = mk_t_iprange(*ip);
84 if(strlen(value) > 0 || cfg.http_full_cfg)
85 { fprintf_conf(f, token, "%s\n", value); }
86 free_mk_t(value);
89 void iprange_free_fn(void *setting)
91 clear_sip(setting);
94 static void logfile_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
96 if(value)
98 char *saveptr1 = NULL;
99 cfg.logtostdout = 0;
100 cfg.logtosyslog = 0;
101 NULLFREE(cfg.logfile);
102 if(strlen(value) > 0)
104 char *pch;
105 for(pch = strtok_r(value, ";", &saveptr1); pch != NULL; pch = strtok_r(NULL, ";", &saveptr1))
107 pch = trim(pch);
108 if(!strcmp(pch, "stdout")) { cfg.logtostdout = 1; }
109 else if(!strcmp(pch, "syslog")) { cfg.logtosyslog = 1; }
110 else
112 NULLFREE(cfg.logfile);
113 if(!(cfg.logfile = cs_strdup(pch)))
114 { continue; }
118 else
120 if(!(cfg.logfile = cs_strdup(CS_LOGFILE)))
121 { cfg.logtostdout = 1; }
123 return;
125 if(cfg.logfile || cfg.logtostdout == 1 || cfg.logtosyslog == 1 || cfg.http_full_cfg)
127 value = mk_t_logfile();
128 fprintf_conf(f, token, "%s\n", value);
129 free_mk_t(value);
133 void check_caidtab_fn(const char *token, char *value, void *setting, FILE *f)
135 CAIDTAB *caid_table = setting;
136 if(value)
138 if(strlen(value)) {
139 chk_caidtab(value, caid_table);
140 } else {
141 caidtab_clear(caid_table);
143 return;
145 if(caid_table->ctnum || cfg.http_full_cfg)
147 value = mk_t_caidtab(caid_table);
148 fprintf_conf(f, token, "%s\n", value);
149 free_mk_t(value);
153 void chk_ftab_fn(const char *token, char *value, void *setting, FILE *f)
155 FTAB *ftab = setting;
156 if(value)
158 if(strlen(value))
159 chk_ftab(value, ftab);
160 else
161 ftab_clear(ftab);
162 return;
164 value = mk_t_ftab(ftab);
165 if(strlen(value) > 0 || cfg.http_full_cfg)
166 { fprintf_conf(f, token, "%s\n", value); }
167 free_mk_t(value);
171 void caidvaluetab_fn(const char *token, char *value, void *setting, FILE *f)
173 CAIDVALUETAB *caid_value_table = setting;
174 if(value)
176 if (strlen(value)) {
177 chk_caidvaluetab(value, caid_value_table);
178 if (streq(token, "lb_retrylimits"))
180 int32_t i;
181 for (i = 0; i < caid_value_table->cvnum; i++)
183 if (caid_value_table->cvdata[i].value < 50)
184 caid_value_table->cvdata[i].value = 50;
187 } else {
188 caidvaluetab_clear(caid_value_table);
190 return;
192 if(caid_value_table->cvnum || cfg.http_full_cfg)
194 value = mk_t_caidvaluetab(caid_value_table);
195 fprintf_conf(f, token, "%s\n", value);
196 free_mk_t(value);
200 #ifdef CS_CACHEEX
201 void cacheex_valuetab_fn(const char *token, char *value, void *setting, FILE *f)
203 CECSPVALUETAB *cacheex_value_table = setting;
204 if(value)
206 if(strlen(value) == 0)
207 { clear_cacheextab(cacheex_value_table); }
208 else
209 { chk_cacheex_valuetab(value, cacheex_value_table); }
210 return;
212 if(cacheex_value_table->cevnum || cfg.http_full_cfg)
214 value = mk_t_cacheex_valuetab(cacheex_value_table);
215 fprintf_conf(f, token, "%s\n", value);
216 free_mk_t(value);
220 void cacheex_cwcheck_tab_fn(const char *token, char *value, void *setting, FILE *f)
222 CWCHECKTAB *cacheex_value_table = setting;
223 if(value)
225 if(strlen(value) == 0)
227 cacheex_value_table->cwchecknum = 0;
228 NULLFREE(cacheex_value_table->cwcheckdata);
230 else
232 chk_cacheex_cwcheck_valuetab(value, cacheex_value_table);
234 return;
237 if(cacheex_value_table->cwchecknum || cfg.http_full_cfg)
239 value = mk_t_cacheex_cwcheck_valuetab(cacheex_value_table);
240 fprintf_conf(f, token, "%s\n", value);
241 free_mk_t(value);
245 void cacheex_hitvaluetab_fn(const char *token, char *value, void *setting, FILE *f)
247 CECSPVALUETAB *cacheex_value_table = setting;
248 if(value)
250 if(strlen(value) == 0)
251 { clear_cacheextab(cacheex_value_table); }
252 else
253 { chk_cacheex_hitvaluetab(value, cacheex_value_table); }
254 return;
256 if(cacheex_value_table->cevnum || cfg.http_full_cfg)
258 value = mk_t_cacheex_hitvaluetab(cacheex_value_table);
259 fprintf_conf(f, token, "%s\n", value);
260 free_mk_t(value);
263 #endif
265 #ifdef __CYGWIN__
266 #include <windows.h>
267 #else
268 #include <sys/resource.h> // for setpriority
269 #endif
271 void global_fixups_fn(void *UNUSED(var))
273 if(!cfg.usrfile) { cfg.disableuserfile = 1; }
274 if(!cfg.mailfile) { cfg.disablemail = 1; }
275 if(cfg.ctimeout < 10) { cfg.ctimeout = cfg.ctimeout * 1000; } // save always in ms
277 if(cfg.nice < -20 || cfg.nice > 20) { cfg.nice = 99; }
278 if(cfg.nice != 99)
280 #ifndef __CYGWIN__
281 setpriority(PRIO_PROCESS, 0, cfg.nice);
282 #else
283 HANDLE WinId;
284 uint32_t wprio;
285 switch((cfg.nice + 20) / 10)
287 case 0:
288 wprio = REALTIME_PRIORITY_CLASS;
289 break;
290 case 1:
291 wprio = HIGH_PRIORITY_CLASS;
292 break;
293 case 2:
294 wprio = NORMAL_PRIORITY_CLASS;
295 break;
296 default:
297 wprio = IDLE_PRIORITY_CLASS;
298 break;
300 WinId = GetCurrentProcess();
301 SetPriorityClass(WinId, wprio);
302 #endif
304 if(cfg.netprio <= 0 || cfg.netprio > 20) { cfg.netprio = 0; }
305 if(cfg.max_log_size != 0 && cfg.max_log_size <= 10) { cfg.max_log_size = 10; }
306 #ifdef WITH_LB
307 if(cfg.lb_save > 0 && cfg.lb_save < 100) { cfg.lb_save = 100; }
308 if(cfg.lb_nbest_readers < 2) { cfg.lb_nbest_readers = DEFAULT_NBEST; }
309 #endif
312 #define OFS(X) offsetof(struct s_config, X)
313 #define SIZEOF(X) sizeof(((struct s_config *)0)->X)
315 static const struct config_list global_opts[] =
317 DEF_OPT_FIXUP_FUNC(global_fixups_fn),
318 #ifdef LEDSUPPORT
319 DEF_OPT_INT8("enableled" , OFS(enableled), 0),
320 #endif
321 DEF_OPT_FUNC("disablelog" , OFS(disablelog), disablelog_fn),
322 #if defined(WEBIF) || defined(MODULE_MONITOR)
323 DEF_OPT_FUNC("loghistorylines" , OFS(loghistorylines), loghistorylines_fn),
324 #endif
325 DEF_OPT_FUNC("serverip" , OFS(srvip), serverip_fn),
326 DEF_OPT_FUNC("logfile" , OFS(logfile), logfile_fn),
327 DEF_OPT_INT32("initial_debuglevel" , OFS(initial_debuglevel), 0),
328 DEF_OPT_STR("sysloghost" , OFS(sysloghost), NULL),
329 DEF_OPT_INT32("syslogport" , OFS(syslogport), 514),
330 DEF_OPT_INT8("logduplicatelines" , OFS(logduplicatelines), 0),
331 DEF_OPT_STR("pidfile" , OFS(pidfile), NULL),
332 DEF_OPT_INT8("disableuserfile" , OFS(disableuserfile), 1),
333 DEF_OPT_INT8("disablemail" , OFS(disablemail), 1),
334 DEF_OPT_INT8("usrfileflag" , OFS(usrfileflag), 0),
335 DEF_OPT_UINT32("clienttimeout" , OFS(ctimeout), CS_CLIENT_TIMEOUT),
336 DEF_OPT_UINT32("fallbacktimeout" , OFS(ftimeout), CS_CLIENT_TIMEOUT / 2),
337 DEF_OPT_FUNC("fallbacktimeout_percaid" , OFS(ftimeouttab), caidvaluetab_fn),
338 DEF_OPT_UINT32("clientmaxidle" , OFS(cmaxidle), CS_CLIENT_MAXIDLE),
339 DEF_OPT_INT32("bindwait" , OFS(bindwait), CS_BIND_TIMEOUT),
340 DEF_OPT_UINT32("netprio" , OFS(netprio), 0),
341 DEF_OPT_INT32("sleep" , OFS(tosleep), 0),
342 DEF_OPT_INT32("unlockparental" , OFS(ulparent), 0),
343 DEF_OPT_INT32("nice" , OFS(nice), 99),
344 DEF_OPT_INT32("maxlogsize" , OFS(max_log_size), 10),
345 DEF_OPT_INT8("waitforcards" , OFS(waitforcards), 1),
346 DEF_OPT_INT32("waitforcards_extra_delay", OFS(waitforcards_extra_delay), 500),
347 DEF_OPT_INT8("preferlocalcards" , OFS(preferlocalcards), 0),
348 DEF_OPT_INT32("readerrestartseconds" , OFS(reader_restart_seconds), 5),
349 DEF_OPT_INT8("dropdups" , OFS(dropdups), 0),
350 DEF_OPT_INT8("reload_useraccounts" , OFS(reload_useraccounts), 0),
351 DEF_OPT_INT8("reload_readers" , OFS(reload_readers), 0),
352 DEF_OPT_INT8("reload_provid" , OFS(reload_provid), 0),
353 DEF_OPT_INT8("reload_services_ids" , OFS(reload_services_ids), 0),
354 DEF_OPT_INT8("reload_tier_ids" , OFS(reload_tier_ids), 0),
355 DEF_OPT_INT8("reload_fakecws" , OFS(reload_fakecws), 0),
356 DEF_OPT_INT8("reload_ac_stat" , OFS(reload_ac_stat), 0),
357 DEF_OPT_INT8("reload_log" , OFS(reload_log), 0),
358 DEF_OPT_INT8("block_same_ip" , OFS(block_same_ip), 1),
359 DEF_OPT_INT8("block_same_name" , OFS(block_same_name), 1),
360 DEF_OPT_STR("usrfile" , OFS(usrfile), NULL),
361 DEF_OPT_STR("mailfile" , OFS(mailfile), NULL),
362 DEF_OPT_STR("cwlogdir" , OFS(cwlogdir), NULL),
363 DEF_OPT_STR("emmlogdir" , OFS(emmlogdir), NULL),
364 #ifdef WITH_LB
365 DEF_OPT_INT32("lb_mode" , OFS(lb_mode), DEFAULT_LB_MODE),
366 DEF_OPT_INT32("lb_save" , OFS(lb_save), 0),
367 DEF_OPT_INT32("lb_nbest_readers" , OFS(lb_nbest_readers), DEFAULT_NBEST),
368 DEF_OPT_INT32("lb_nfb_readers" , OFS(lb_nfb_readers), DEFAULT_NFB),
369 DEF_OPT_INT32("lb_min_ecmcount" , OFS(lb_min_ecmcount), DEFAULT_MIN_ECM_COUNT),
370 DEF_OPT_INT32("lb_max_ecmcount" , OFS(lb_max_ecmcount), DEFAULT_MAX_ECM_COUNT),
371 DEF_OPT_INT32("lb_reopen_seconds" , OFS(lb_reopen_seconds), DEFAULT_REOPEN_SECONDS),
372 DEF_OPT_INT8("lb_reopen_invalid" , OFS(lb_reopen_invalid), 1),
373 DEF_OPT_INT8("lb_force_reopen_always" , OFS(lb_force_reopen_always), 0),
374 DEF_OPT_INT32("lb_retrylimit" , OFS(lb_retrylimit), DEFAULT_RETRYLIMIT),
375 DEF_OPT_INT32("lb_stat_cleanup" , OFS(lb_stat_cleanup), DEFAULT_LB_STAT_CLEANUP),
376 DEF_OPT_INT32("lb_max_readers" , OFS(lb_max_readers), 0),
377 DEF_OPT_INT32("lb_auto_betatunnel" , OFS(lb_auto_betatunnel), DEFAULT_LB_AUTO_BETATUNNEL),
378 DEF_OPT_INT32("lb_auto_betatunnel_mode" , OFS(lb_auto_betatunnel_mode), DEFAULT_LB_AUTO_BETATUNNEL_MODE),
379 DEF_OPT_INT32("lb_auto_betatunnel_prefer_beta" , OFS(lb_auto_betatunnel_prefer_beta), DEFAULT_LB_AUTO_BETATUNNEL_PREFER_BETA),
380 DEF_OPT_STR("lb_savepath" , OFS(lb_savepath), NULL),
381 DEF_OPT_FUNC("lb_retrylimits" , OFS(lb_retrylimittab), caidvaluetab_fn),
382 DEF_OPT_FUNC("lb_nbest_percaid" , OFS(lb_nbest_readers_tab), caidvaluetab_fn),
383 DEF_OPT_FUNC("lb_noproviderforcaid" , OFS(lb_noproviderforcaid), check_caidtab_fn),
384 DEF_OPT_INT32("lb_auto_timeout" , OFS(lb_auto_timeout), DEFAULT_LB_AUTO_TIMEOUT),
385 DEF_OPT_INT32("lb_auto_timeout_p" , OFS(lb_auto_timeout_p), DEFAULT_LB_AUTO_TIMEOUT_P),
386 DEF_OPT_INT32("lb_auto_timeout_t" , OFS(lb_auto_timeout_t), DEFAULT_LB_AUTO_TIMEOUT_T),
387 #endif
388 DEF_OPT_FUNC("double_check_caid" , OFS(double_check_caid), check_caidtab_fn),
389 DEF_OPT_STR("ecmfmt" , OFS(ecmfmt), NULL),
390 DEF_OPT_INT32("resolvegethostbyname" , OFS(resolve_gethostbyname), 0),
391 DEF_OPT_INT32("failbantime" , OFS(failbantime), 0),
392 DEF_OPT_INT32("failbancount" , OFS(failbancount), 0),
393 DEF_OPT_INT8("suppresscmd08" , OFS(c35_suppresscmd08), 0),
394 DEF_OPT_INT8("getblockemmauprovid" , OFS(getblockemmauprovid), 0),
395 DEF_OPT_INT8("double_check" , OFS(double_check), 0),
396 DEF_OPT_INT8("disablecrccws" , OFS(disablecrccws), 0),
397 DEF_OPT_FUNC("disablecrccws_only_for" , OFS(disablecrccws_only_for), chk_ftab_fn),
398 DEF_LAST_OPT
401 #ifdef CS_ANTICASC
402 static void anticasc_fixups_fn(void *UNUSED(var))
404 if(cfg.ac_users < 0) { cfg.ac_users = 0; }
405 if(cfg.ac_stime < 0) { cfg.ac_stime = 2; }
406 if(cfg.ac_samples < 2 || cfg.ac_samples > 10) { cfg.ac_samples = 10; }
407 if(cfg.ac_penalty < 0 || cfg.ac_penalty > 3) { cfg.ac_penalty = 0; }
408 if(cfg.ac_fakedelay < 100 || cfg.ac_fakedelay > 3000) { cfg.ac_fakedelay = 1000; }
409 if(cfg.ac_denysamples < 2 || cfg.ac_denysamples > cfg.ac_samples - 1) { cfg.ac_denysamples = cfg.ac_samples - 1; }
410 if(cfg.ac_denysamples + 1 > cfg.ac_samples) { cfg.ac_denysamples = cfg.ac_samples - 1; }
411 if(cfg.acosc_max_active_sids < 0) { cfg.acosc_max_active_sids = 0; }
412 if(cfg.acosc_zap_limit < 0) { cfg.acosc_zap_limit = 0; }
413 if(cfg.acosc_penalty < 0 || cfg.acosc_penalty > 3) { cfg.acosc_penalty = 0; }
414 if(cfg.acosc_penalty_duration < 0) { cfg.acosc_penalty_duration = 0; }
415 if(cfg.acosc_delay < 0 || cfg.acosc_delay > 4000) { cfg.acosc_delay = 0; }
418 static bool anticasc_should_save_fn(void *UNUSED(var))
420 return cfg.ac_enabled || cfg.acosc_enabled;
423 static const struct config_list anticasc_opts[] =
425 DEF_OPT_SAVE_FUNC(anticasc_should_save_fn),
426 DEF_OPT_FIXUP_FUNC(anticasc_fixups_fn),
427 DEF_OPT_INT8("enabled" , OFS(ac_enabled), 0),
428 DEF_OPT_INT32("numusers" , OFS(ac_users), 0),
429 DEF_OPT_INT32("sampletime" , OFS(ac_stime), 2),
430 DEF_OPT_INT32("samples" , OFS(ac_samples), 10),
431 DEF_OPT_INT8("penalty" , OFS(ac_penalty), 0),
432 DEF_OPT_STR("aclogfile" , OFS(ac_logfile), NULL),
433 DEF_OPT_INT32("fakedelay" , OFS(ac_fakedelay), 3000),
434 DEF_OPT_INT32("denysamples" , OFS(ac_denysamples), 8),
435 DEF_OPT_INT8("acosc_enabled" , OFS(acosc_enabled), 0 ),
436 DEF_OPT_INT8("acosc_max_active_sids" , OFS(acosc_max_active_sids), 0 ),
437 DEF_OPT_INT8("acosc_zap_limit" , OFS(acosc_zap_limit), 0 ),
438 DEF_OPT_INT8("acosc_penalty" , OFS(acosc_penalty), 0 ),
439 DEF_OPT_INT32("acosc_penalty_duration" , OFS(acosc_penalty_duration), 0 ),
440 DEF_OPT_INT32("acosc_delay" , OFS(acosc_delay), 0 ),
441 DEF_LAST_OPT
443 #else
444 static const struct config_list anticasc_opts[] = { DEF_LAST_OPT };
445 #endif
447 #ifdef MODULE_MONITOR
448 static bool monitor_should_save_fn(void *UNUSED(var))
450 return cfg.mon_port;
453 static const struct config_list monitor_opts[] =
455 DEF_OPT_SAVE_FUNC(monitor_should_save_fn),
456 DEF_OPT_INT32("port" , OFS(mon_port), 0),
457 DEF_OPT_FUNC("serverip" , OFS(mon_srvip), serverip_fn),
458 DEF_OPT_FUNC("nocrypt" , OFS(mon_allowed), iprange_fn, .free_value = iprange_free_fn),
459 DEF_OPT_INT32("aulow" , OFS(aulow), 30),
460 DEF_OPT_UINT8("monlevel" , OFS(mon_level), 2),
461 DEF_OPT_INT32("hideclient_to" , OFS(hideclient_to), 25),
462 DEF_LAST_OPT
464 #else
465 static const struct config_list monitor_opts[] = { DEF_LAST_OPT };
466 #endif
468 #ifdef WEBIF
469 static void http_port_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
471 if(value)
473 cfg.http_port = 0;
474 if(value[0])
476 if(value[0] == '+')
478 if(config_enabled(WITH_SSL))
480 cfg.http_use_ssl = 1;
482 else
484 fprintf(stderr, "Warning: OSCam compiled without SSL support.\n");
486 cfg.http_port = strtoul(value + 1, NULL, 10);
488 else
490 cfg.http_port = strtoul(value, NULL, 10);
493 return;
495 fprintf_conf(f, token, "%s%d\n", cfg.http_use_ssl ? "+" : "", cfg.http_port);
498 static void http_dyndns_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
500 int i;
501 if(value)
503 char *ptr, *saveptr1 = NULL;
504 memset(cfg.http_dyndns, 0, sizeof(cfg.http_dyndns));
505 for(i = 0, ptr = strtok_r(value, ",", &saveptr1); (i < MAX_HTTP_DYNDNS) && (ptr); ptr = strtok_r(NULL, ",", &saveptr1), i++)
507 trim(ptr);
508 cs_strncpy((char *)cfg.http_dyndns[i], ptr, sizeof(cfg.http_dyndns[i]));
510 return;
512 if(strlen((const char *)(cfg.http_dyndns[0])) > 0 || cfg.http_full_cfg)
514 fprintf_conf(f, token, "%s", ""); // it should not have \n at the end
515 for(i = 0; i < MAX_HTTP_DYNDNS; i++)
517 if(cfg.http_dyndns[i][0])
519 fprintf(f, "%s%s", i > 0 ? "," : "", cfg.http_dyndns[i]);
522 fprintf(f, "\n");
526 static bool webif_should_save_fn(void *UNUSED(var))
528 return cfg.http_port;
531 static const struct config_list webif_opts[] =
533 DEF_OPT_SAVE_FUNC(webif_should_save_fn),
534 DEF_OPT_FUNC("httpport" , OFS(http_port) , http_port_fn),
535 DEF_OPT_FUNC("serverip" , OFS(http_srvip) , serverip_fn),
536 DEF_OPT_STR("httpuser" , OFS(http_user) , NULL),
537 DEF_OPT_STR("httppwd" , OFS(http_pwd) , NULL),
538 DEF_OPT_STR("httpcss" , OFS(http_css) , NULL),
539 DEF_OPT_STR("httpjscript" , OFS(http_jscript) , NULL),
540 DEF_OPT_STR("httpscript" , OFS(http_script) , NULL),
541 DEF_OPT_STR("httptpl" , OFS(http_tpl) , NULL),
542 DEF_OPT_STR("httppiconpath" , OFS(http_piconpath) , NULL),
543 DEF_OPT_STR("httphelplang" , OFS(http_help_lang) , "en"),
544 DEF_OPT_STR("httplocale" , OFS(http_locale) , NULL),
545 DEF_OPT_INT8("http_prepend_embedded_css" , OFS(http_prepend_embedded_css) , 0),
546 DEF_OPT_INT32("httprefresh" , OFS(http_refresh) , 0),
547 DEF_OPT_INT32("httppollrefresh" , OFS(poll_refresh) , 60),
548 DEF_OPT_INT8("httphideidleclients" , OFS(http_hide_idle_clients) , 1),
549 DEF_OPT_STR("httphidetype" , OFS(http_hide_type) , NULL),
550 DEF_OPT_INT8("httpshowpicons" , OFS(http_showpicons) , 0),
551 DEF_OPT_INT8("httppiconsize" , OFS(http_picon_size) , 0),
552 DEF_OPT_INT8("httpshowmeminfo" , OFS(http_showmeminfo) , 0),
553 DEF_OPT_INT8("httpshowuserinfo" , OFS(http_showuserinfo) , 0),
554 DEF_OPT_INT8("httpshowreaderinfo" , OFS(http_showreaderinfo) , 0),
555 DEF_OPT_INT8("httpshowcacheexinfo" , OFS(http_showcacheexinfo) , 0),
556 DEF_OPT_INT8("httpshowecminfo" , OFS(http_showecminfo) , 0),
557 DEF_OPT_INT8("httpshowloadinfo" , OFS(http_showloadinfo) , 0),
558 DEF_OPT_FUNC("httpallowed" , OFS(http_allowed) , iprange_fn, .free_value = iprange_free_fn),
559 DEF_OPT_INT8("httpreadonly" , OFS(http_readonly) , 0),
560 DEF_OPT_INT8("httpsavefullcfg" , OFS(http_full_cfg) , 0),
561 DEF_OPT_INT8("httpoverwritebakfile" , OFS(http_overwrite_bak_file) , 0),
562 DEF_OPT_STR("httpcert" , OFS(http_cert) , NULL),
563 DEF_OPT_INT8("https_force_secure_mode" , OFS(https_force_secure_mode) , 1),
564 DEF_OPT_FUNC("httpdyndns" , OFS(http_dyndns) , http_dyndns_fn),
565 DEF_OPT_INT32("aulow" , OFS(aulow) , 30),
566 DEF_OPT_INT32("hideclient_to" , OFS(hideclient_to) , 25),
567 DEF_OPT_STR("httposcamlabel" , OFS(http_oscam_label) , "OSCam"),
568 DEF_OPT_INT32("httpemmuclean" , OFS(http_emmu_clean) , 256),
569 DEF_OPT_INT32("httpemmsclean" , OFS(http_emms_clean) , -1),
570 DEF_OPT_INT32("httpemmgclean" , OFS(http_emmg_clean) , -1),
571 #ifdef WEBIF_LIVELOG
572 DEF_OPT_INT8("http_status_log" , OFS(http_status_log) , 0),
573 #else
574 DEF_OPT_INT8("http_status_log" , OFS(http_status_log) , 1),
575 #endif
576 #ifndef WEBIF_JQUERY
577 DEF_OPT_STR("http_extern_jquery" , OFS(http_extern_jquery) , "//code.jquery.com/jquery-1.12.4.min.js"),
578 #endif
579 DEF_LAST_OPT
581 #else
582 static const struct config_list webif_opts[] = { DEF_LAST_OPT };
583 #endif
585 #ifdef MODULE_CAMD33
586 static bool camd33_should_save_fn(void *UNUSED(var))
588 return cfg.c33_port;
591 static const struct config_list camd33_opts[] =
593 DEF_OPT_SAVE_FUNC(camd33_should_save_fn),
594 DEF_OPT_INT32("port" , OFS(c33_port), 0),
595 DEF_OPT_FUNC("serverip" , OFS(c33_srvip), serverip_fn),
596 DEF_OPT_FUNC("nocrypt" , OFS(c33_plain), iprange_fn, .free_value = iprange_free_fn),
597 DEF_OPT_INT32("passive" , OFS(c33_passive), 0),
598 DEF_OPT_HEX("key" , OFS(c33_key), SIZEOF(c33_key)),
599 DEF_LAST_OPT
601 #else
602 static const struct config_list camd33_opts[] = { DEF_LAST_OPT };
603 #endif
606 void cache_fixups_fn(void *UNUSED(var))
608 if(cfg.max_cache_time < ((int32_t)(cfg.ctimeout + 500) / 1000 + 3)) { cfg.max_cache_time = ((cfg.ctimeout + 500) / 1000 + 3); }
609 #ifdef CW_CYCLE_CHECK
610 if(cfg.maxcyclelist > 4000) { cfg.maxcyclelist = 4000; }
611 if(cfg.keepcycletime > 240) { cfg.keepcycletime = 240; }
612 if(cfg.cwcycle_sensitive > 4) { cfg.cwcycle_sensitive = 4; }
613 if(cfg.cwcycle_sensitive == 1) { cfg.cwcycle_sensitive = 2; }
614 #endif
617 static bool cache_should_save_fn(void *UNUSED(var))
619 return cfg.delay > 0 || cfg.max_cache_time != 15
620 #ifdef CS_CACHEEX
621 || cfg.cacheex_wait_timetab.cevnum || cfg.cacheex_enable_stats > 0 || cfg.csp_port || cfg.csp.filter_caidtab.cevnum || cfg.csp.allow_request == 0 || cfg.csp.allow_reforward > 0
622 #endif
623 #ifdef CW_CYCLE_CHECK
624 || cfg.cwcycle_check_enable || cfg.cwcycle_check_caidtab.ctnum || cfg.maxcyclelist != 500 || cfg.keepcycletime || cfg.onbadcycle || cfg.cwcycle_dropold || cfg.cwcycle_sensitive || cfg.cwcycle_allowbadfromffb || cfg.cwcycle_usecwcfromce
625 #endif
629 static const struct config_list cache_opts[] =
631 DEF_OPT_SAVE_FUNC(cache_should_save_fn),
632 DEF_OPT_FIXUP_FUNC(cache_fixups_fn),
633 DEF_OPT_UINT32("delay" , OFS(delay), CS_DELAY),
634 DEF_OPT_INT32("max_time" , OFS(max_cache_time), DEFAULT_MAX_CACHE_TIME),
635 #ifdef CS_CACHEEX
636 DEF_OPT_INT32("max_hit_time" , OFS(max_hitcache_time), DEFAULT_MAX_HITCACHE_TIME),
637 DEF_OPT_FUNC("wait_time" , OFS(cacheex_wait_timetab), cacheex_valuetab_fn),
638 DEF_OPT_FUNC("cacheex_mode1_delay" , OFS(cacheex_mode1_delay_tab), caidvaluetab_fn),
639 DEF_OPT_UINT8("cacheexenablestats" , OFS(cacheex_enable_stats), 0),
640 DEF_OPT_INT32("csp_port" , OFS(csp_port), 0),
641 DEF_OPT_FUNC("csp_serverip" , OFS(csp_srvip), serverip_fn),
642 DEF_OPT_FUNC("csp_ecm_filter" , OFS(csp.filter_caidtab), cacheex_hitvaluetab_fn),
643 DEF_OPT_UINT8("csp_allow_request" , OFS(csp.allow_request), 1),
644 DEF_OPT_UINT8("csp_allow_reforward" , OFS(csp.allow_reforward), 0),
645 DEF_OPT_FUNC("cacheex_cw_check" , OFS(cacheex_cwcheck_tab), cacheex_cwcheck_tab_fn),
646 DEF_OPT_UINT8("wait_until_ctimeout" , OFS(wait_until_ctimeout), 0),
647 DEF_OPT_UINT8("csp_block_fakecws" , OFS(csp.block_fakecws), 0),
648 #endif
649 #ifdef CW_CYCLE_CHECK
650 DEF_OPT_INT8("cwcycle_check_enable" , OFS(cwcycle_check_enable), 0),
651 DEF_OPT_FUNC("cwcycle_check_caid" , OFS(cwcycle_check_caidtab), check_caidtab_fn),
652 DEF_OPT_INT32("cwcycle_maxlist" , OFS(maxcyclelist), 500),
653 DEF_OPT_INT32("cwcycle_keeptime" , OFS(keepcycletime), 15),
654 DEF_OPT_INT8("cwcycle_onbad" , OFS(onbadcycle), 1),
655 DEF_OPT_INT8("cwcycle_dropold" , OFS(cwcycle_dropold), 1),
656 DEF_OPT_INT8("cwcycle_sensitive" , OFS(cwcycle_sensitive), 4),
657 DEF_OPT_INT8("cwcycle_allowbadfromffb" , OFS(cwcycle_allowbadfromffb), 0),
658 DEF_OPT_INT8("cwcycle_usecwcfromce" , OFS(cwcycle_usecwcfromce), 0),
659 #endif
660 DEF_LAST_OPT
663 #ifdef MODULE_CAMD35
664 static bool camd35_should_save_fn(void *UNUSED(var))
666 return cfg.c35_port;
669 static const struct config_list camd35_opts[] =
671 DEF_OPT_SAVE_FUNC(camd35_should_save_fn),
672 DEF_OPT_INT32("port" , OFS(c35_port), 0),
673 DEF_OPT_FUNC("serverip" , OFS(c35_srvip), serverip_fn),
674 DEF_OPT_INT8("suppresscmd08" , OFS(c35_udp_suppresscmd08), 0),
675 DEF_LAST_OPT
677 #else
678 static const struct config_list camd35_opts[] = { DEF_LAST_OPT };
679 #endif
681 #ifdef MODULE_NEWCAMD
682 static void porttab_fn(const char *token, char *value, void *setting, FILE *f)
684 PTAB *ptab = setting;
685 if(value)
687 if(strlen(value) == 0)
689 clear_ptab(ptab);
691 else
693 chk_port_tab(value, ptab);
695 return;
697 value = mk_t_newcamd_port();
698 fprintf_conf(f, token, "%s\n", value);
699 free_mk_t(value);
701 #endif
703 #ifdef MODULE_CAMD35_TCP
704 static void porttab_camd35_fn(const char *token, char *value, void *setting, FILE *f)
706 PTAB *ptab = setting;
707 if(value)
709 if(strlen(value) == 0)
711 clear_ptab(ptab);
713 else
715 chk_port_camd35_tab(value, ptab);
717 return;
719 value = mk_t_camd35tcp_port();
720 fprintf_conf(f, token, "%s\n", value);
721 free_mk_t(value);
723 #endif
725 #if defined(MODULE_NEWCAMD) || defined(MODULE_CAMD35_TCP)
726 static void porttab_free_fn(void *setting)
728 clear_ptab(setting);
730 #endif
732 #ifdef MODULE_CAMD35_TCP
733 static bool cs378x_should_save_fn(void *UNUSED(var))
735 return cfg.c35_tcp_ptab.nports && cfg.c35_tcp_ptab.ports[0].s_port;
738 static const struct config_list cs378x_opts[] =
740 DEF_OPT_SAVE_FUNC(cs378x_should_save_fn),
741 DEF_OPT_FUNC("port" , OFS(c35_tcp_ptab) , porttab_camd35_fn , .free_value = porttab_free_fn),
742 DEF_OPT_FUNC("serverip" , OFS(c35_tcp_srvip) , serverip_fn),
743 DEF_OPT_INT8("suppresscmd08" , OFS(c35_tcp_suppresscmd08), 0),
744 DEF_LAST_OPT
746 #else
747 static const struct config_list cs378x_opts[] = { DEF_LAST_OPT };
748 #endif
750 #ifdef MODULE_NEWCAMD
751 static bool newcamd_should_save_fn(void *UNUSED(var))
753 return cfg.ncd_ptab.nports && cfg.ncd_ptab.ports[0].s_port;
756 static const struct config_list newcamd_opts[] =
758 DEF_OPT_SAVE_FUNC(newcamd_should_save_fn),
759 DEF_OPT_FUNC("port" , OFS(ncd_ptab) , porttab_fn, .free_value = porttab_free_fn),
760 DEF_OPT_FUNC("serverip" , OFS(ncd_srvip) , serverip_fn),
761 DEF_OPT_FUNC("allowed" , OFS(ncd_allowed) , iprange_fn, .free_value = iprange_free_fn),
762 DEF_OPT_HEX("key" , OFS(ncd_key) , SIZEOF(ncd_key)),
763 DEF_OPT_INT8("keepalive" , OFS(ncd_keepalive), DEFAULT_NCD_KEEPALIVE),
764 DEF_OPT_INT8("mgclient" , OFS(ncd_mgclient) , 0),
765 DEF_LAST_OPT
767 #else
768 static const struct config_list newcamd_opts[] = { DEF_LAST_OPT };
769 #endif
771 #ifdef MODULE_CCCAM
772 static void cccam_port_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
774 if(value)
776 int i;
777 char *ptr, *saveptr1 = NULL;
778 memset(cfg.cc_port, 0, sizeof(cfg.cc_port));
779 for(i = 0, ptr = strtok_r(value, ",", &saveptr1); ptr && i < CS_MAXPORTS; ptr = strtok_r(NULL, ",", &saveptr1))
781 cfg.cc_port[i] = strtoul(ptr, NULL, 10);
782 if(cfg.cc_port[i])
783 { i++; }
785 return;
787 value = mk_t_cccam_port();
788 fprintf_conf(f, token, "%s\n", value);
789 free_mk_t(value);
792 static bool cccam_should_save_fn(void *UNUSED(var))
794 return cfg.cc_port[0];
797 static const struct config_list cccam_opts[] =
799 DEF_OPT_SAVE_FUNC(cccam_should_save_fn),
800 DEF_OPT_FUNC("port" , OFS(cc_port), cccam_port_fn),
801 DEF_OPT_FUNC("serverip" , OFS(cc_srvip), serverip_fn),
802 DEF_OPT_HEX("nodeid" , OFS(cc_fixed_nodeid), SIZEOF(cc_fixed_nodeid)),
803 DEF_OPT_SSTR("version" , OFS(cc_version), "", SIZEOF(cc_version)),
804 DEF_OPT_INT8("reshare" , OFS(cc_reshare), 10),
805 DEF_OPT_INT8("reshare_mode" , OFS(cc_reshare_services), 4),
806 DEF_OPT_INT8("ignorereshare" , OFS(cc_ignore_reshare), 0),
807 DEF_OPT_INT8("forward_origin_card" , OFS(cc_forward_origin_card), 0),
808 DEF_OPT_INT8("stealth" , OFS(cc_stealth), 0),
809 DEF_OPT_INT32("updateinterval" , OFS(cc_update_interval), DEFAULT_UPDATEINTERVAL),
810 DEF_OPT_INT8("minimizecards" , OFS(cc_minimize_cards), 0),
811 DEF_OPT_INT8("keepconnected" , OFS(cc_keep_connected), 1),
812 DEF_OPT_UINT32("recv_timeout" , OFS(cc_recv_timeout), DEFAULT_CC_RECV_TIMEOUT),
813 DEF_LAST_OPT
815 #else
816 static const struct config_list cccam_opts[] = { DEF_LAST_OPT };
817 #endif
819 #ifdef MODULE_PANDORA
820 static bool pandora_should_save_fn(void *UNUSED(var))
822 return cfg.pand_port;
825 static const struct config_list pandora_opts[] =
827 DEF_OPT_SAVE_FUNC(pandora_should_save_fn),
828 DEF_OPT_INT32("pand_port" , OFS(pand_port), 0),
829 DEF_OPT_FUNC("pand_srvid" , OFS(pand_srvip), serverip_fn),
830 DEF_OPT_STR("pand_usr" , OFS(pand_usr), NULL),
831 DEF_OPT_STR("pand_pass" , OFS(pand_pass), NULL),
832 DEF_OPT_INT8("pand_ecm" , OFS(pand_ecm), 0),
833 DEF_OPT_INT8("pand_skip_send_dw" , OFS(pand_skip_send_dw), 0),
834 DEF_OPT_FUNC("pand_allowed" , OFS(pand_allowed), iprange_fn, .free_value = iprange_free_fn),
835 DEF_LAST_OPT
837 #else
838 static const struct config_list pandora_opts[] = { DEF_LAST_OPT };
839 #endif
841 #ifdef MODULE_SCAM
842 static bool scam_should_save_fn(void *UNUSED(var))
844 return cfg.scam_port;
846 static const struct config_list scam_opts[] =
848 DEF_OPT_SAVE_FUNC(scam_should_save_fn),
849 DEF_OPT_INT32("port" , OFS(scam_port), 0),
850 DEF_OPT_FUNC("serverip" , OFS(scam_srvip), serverip_fn),
851 DEF_OPT_FUNC("allowed" , OFS(scam_allowed), iprange_fn, .free_value = iprange_free_fn),
852 DEF_LAST_OPT
854 #else
855 static const struct config_list scam_opts[] = { DEF_LAST_OPT };
856 #endif
857 #ifdef MODULE_RADEGAST
858 static bool radegast_should_save_fn(void *UNUSED(var))
860 return cfg.rad_port;
863 static const struct config_list radegast_opts[] =
865 DEF_OPT_SAVE_FUNC(radegast_should_save_fn),
866 DEF_OPT_INT32("port" , OFS(rad_port), 0),
867 DEF_OPT_FUNC("serverip" , OFS(rad_srvip), serverip_fn),
868 DEF_OPT_FUNC("allowed" , OFS(rad_allowed), iprange_fn, .free_value = iprange_free_fn),
869 DEF_OPT_STR("user" , OFS(rad_usr), NULL),
870 DEF_LAST_OPT
872 #else
873 static const struct config_list radegast_opts[] = { DEF_LAST_OPT };
874 #endif
876 #ifdef MODULE_SERIAL
877 static bool serial_should_save_fn(void *UNUSED(var))
879 return cfg.ser_device != NULL;
882 static const struct config_list serial_opts[] =
884 DEF_OPT_SAVE_FUNC(serial_should_save_fn),
885 DEF_OPT_STR("device" , OFS(ser_device), NULL),
886 DEF_LAST_OPT
888 #else
889 static const struct config_list serial_opts[] = { DEF_LAST_OPT };
890 #endif
892 #ifdef MODULE_GBOX
894 static void gbox_password_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
896 if (value)
898 const char *s;
899 s=value;
900 if (s[strspn(s, "0123456789abcdefABCDEF")] == 0)
902 /* valid Hexa symbol */
903 cfg.gbox_password = a2i(value, 8);
904 return;
906 else
908 cfg.gbox_password = 0;
911 if (cfg.gbox_password != 0)
913 fprintf_conf(f, token, "%08X\n", cfg.gbox_password);
917 static void gbox_block_ecm_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
919 if (value)
921 char *ptr1, *saveptr1 = NULL;
922 const char *s;
923 memset(cfg.gbox_block_ecm, 0, sizeof(cfg.gbox_block_ecm));
924 int n = 0, i;
925 for (i = 0, ptr1 = strtok_r(value, ",", &saveptr1); (i < 4) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1))
927 s=ptr1;
928 if ((n < GBOX_MAX_BLOCKED_ECM) && (s[strspn(s, "0123456789abcdefABCDEF")] == 0))
929 { cfg.gbox_block_ecm[n++] = a2i(ptr1, 4); }
931 cfg.gbox_block_ecm_num = n;
932 return;
934 if (cfg.gbox_block_ecm_num > 0)
936 value = mk_t_gbox_block_ecm();
937 fprintf_conf(f, token, "%s\n", value);
938 free_mk_t(value);
942 static void accept_remm_peer_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
944 if (value)
946 char *ptr1, *saveptr1 = NULL;
947 const char *s;
948 memset(cfg.accept_remm_peer, 0, sizeof(cfg.accept_remm_peer));
949 int n = 0, i;
950 for (i = 0, ptr1 = strtok_r(value, ",", &saveptr1); (i < 4) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1))
952 s=ptr1;
953 if ((n < GBOX_MAX_REMM_PEERS) && (s[strspn(s, "0123456789abcdefABCDEF")] == 0))
954 { cfg.accept_remm_peer[n++] = a2i(ptr1, 4); }
956 cfg.accept_remm_peer_num = n;
957 return;
959 if (cfg.accept_remm_peer_num > 0)
961 value = mk_t_accept_remm_peer();
962 fprintf_conf(f, token, "%s\n", value);
963 free_mk_t(value);
967 static void gbox_ignored_peer_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
969 if (value)
971 char *ptr1, *saveptr1 = NULL;
972 const char *s;
973 memset(cfg.gbox_ignored_peer, 0, sizeof(cfg.gbox_ignored_peer));
974 int n = 0, i;
975 for (i = 0, ptr1 = strtok_r(value, ",", &saveptr1); (i < 4) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1))
977 s=ptr1;
978 if ((n < GBOX_MAX_IGNORED_PEERS) && (s[strspn(s, "0123456789abcdefABCDEF")] == 0))
979 { cfg.gbox_ignored_peer[n++] = a2i(ptr1, 4); }
981 cfg.gbox_ignored_peer_num = n;
982 return;
984 if (cfg.gbox_ignored_peer_num > 0)
986 value = mk_t_gbox_ignored_peer();
987 fprintf_conf(f, token, "%s\n", value);
988 free_mk_t(value);
992 static void gbox_proxy_card_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
994 if (value)
996 char *ptr1, *saveptr1 = NULL;
997 const char *s;
998 memset(cfg.gbox_proxy_card, 0, sizeof(cfg.gbox_proxy_card));
999 int n = 0, i;
1000 for (i = 0, ptr1 = strtok_r(value, ",", &saveptr1); (i < 8) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1))
1002 s=ptr1;
1003 if ((n < GBOX_MAX_PROXY_CARDS) && (s[strspn(s, "0123456789abcdefABCDEF")] == 0))
1004 { cfg.gbox_proxy_card[n++] = a2i(ptr1, 8); }
1006 cfg.gbox_proxy_cards_num = n;
1007 return;
1010 if (cfg.gbox_proxy_cards_num > 0)
1012 value = mk_t_gbox_proxy_card();
1013 fprintf_conf(f, token, "%s\n", value);
1014 free_mk_t(value);
1018 static void gbox_port_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
1020 if(value)
1022 int i;
1023 char *ptr, *saveptr1 = NULL;
1024 memset(cfg.gbox_port, 0, sizeof(cfg.gbox_port));
1025 for(i = 0, ptr = strtok_r(value, ",", &saveptr1); ptr && i < CS_MAXPORTS; ptr = strtok_r(NULL, ",", &saveptr1))
1027 cfg.gbox_port[i] = strtoul(ptr, NULL, 10);
1028 if(cfg.gbox_port[i])
1029 { i++; }
1031 return;
1033 value = mk_t_gbox_port();
1034 fprintf_conf(f, token, "%s\n", value);
1035 free_mk_t(value);
1038 static void gbox_my_vers_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
1040 if(value)
1042 const char *s;
1043 s=value;
1044 int32_t len = strlen(value);
1045 if ((s[strspn(s, "0123456789abcdefABCDEF")] != 0) || (len == 0) || (len > 2))
1047 cfg.gbox_my_vers = GBOX_MY_VERS_DEF;
1049 else
1051 cfg.gbox_my_vers = a2i(value,1);
1052 return;
1056 if(cfg.gbox_my_vers != GBOX_MY_VERS_DEF)
1058 fprintf_conf(f, token, "%02X\n", cfg.gbox_my_vers);
1060 else if(cfg.http_full_cfg)
1062 fprintf_conf(f, token, "%02X\n", GBOX_MY_VERS_DEF);
1066 static void gbox_my_cpu_api_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
1068 if(value)
1070 const char *s;
1071 s=value;
1072 int32_t len = strlen(value);
1073 if ((s[strspn(s, "0123456789abcdefABCDEF")] != 0) || (len == 0) || (len > 2))
1075 cfg.gbox_my_cpu_api = GBOX_MY_CPU_API_DEF;
1077 else
1079 cfg.gbox_my_cpu_api = a2i(value,1);
1080 return;
1084 if(cfg.gbox_my_cpu_api != GBOX_MY_CPU_API_DEF)
1086 fprintf_conf(f, token, "%02X\n", cfg.gbox_my_cpu_api);
1088 else if(cfg.http_full_cfg)
1089 { fprintf_conf(f, token, "%02X\n", GBOX_MY_CPU_API_DEF); }
1092 static void gbox_dest_peers_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
1094 if (value)
1096 char *ptr1, *saveptr1 = NULL;
1097 const char *s;
1098 memset(cfg.gbox_dest_peers, 0, sizeof(cfg.gbox_dest_peers));
1099 int n = 0;
1100 for (ptr1 = strtok_r(value, ",", &saveptr1); (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1))
1102 s=trim(ptr1);
1103 if ((n < GBOX_MAX_DEST_PEERS) && (s[strspn(s, "0123456789abcdefABCDEF")] == 0))
1104 { cfg.gbox_dest_peers[n++] = a2i(trim(ptr1), strlen(trim(ptr1))); }
1106 cfg.gbox_dest_peers_num = n;
1107 return;
1109 if ((cfg.gbox_dest_peers_num > 0) && cfg.gbox_save_gsms)
1111 value = mk_t_gbox_dest_peers();
1112 fprintf_conf(f, token, "%s\n", value);
1113 free_mk_t(value);
1117 static void gbox_msg_txt_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
1119 int len = 0;
1120 if (value)
1122 len = strlen(value);
1123 if (len > GBOX_MAX_MSG_TXT) { len = GBOX_MAX_MSG_TXT; }
1124 cs_strncpy(cfg.gbox_msg_txt,value, len+1);
1125 return;
1127 if ((cfg.gbox_msg_txt[0]!='\0') && cfg.gbox_save_gsms)
1129 fprintf_conf(f, token, "%s\n", cfg.gbox_msg_txt);
1133 static bool gbox_should_save_fn(void *UNUSED(var))
1135 return cfg.gbox_port[0];
1138 static const struct config_list gbox_opts[] =
1140 DEF_OPT_SAVE_FUNC(gbox_should_save_fn),
1141 DEF_OPT_FUNC("port" , OFS(gbox_port) , gbox_port_fn),
1142 DEF_OPT_STR("hostname" , OFS(gbox_hostname) , NULL),
1143 DEF_OPT_FUNC("my_password" , OFS(gbox_password) , gbox_password_fn ),
1144 DEF_OPT_UINT32("gbox_reconnect" , OFS(gbox_reconnect) , DEFAULT_GBOX_RECONNECT),
1145 DEF_OPT_FUNC("my_vers" , OFS(gbox_my_vers) , gbox_my_vers_fn),
1146 DEF_OPT_FUNC("my_cpu_api" , OFS(gbox_my_cpu_api) , gbox_my_cpu_api_fn),
1147 DEF_OPT_UINT8("ccc_reshare" , OFS(ccc_reshare) , 0),
1148 DEF_OPT_UINT8("gsms_disable" , OFS(gsms_dis) , 1),
1149 DEF_OPT_UINT8("dis_attack_txt" , OFS(dis_attack_txt) , 0),
1150 DEF_OPT_UINT8("log_hello" , OFS(log_hello) , 1),
1151 DEF_OPT_STR("tmp_dir" , OFS(gbox_tmp_dir) , NULL ),
1152 DEF_OPT_FUNC("ignore_peer" , OFS(gbox_ignored_peer), gbox_ignored_peer_fn ),
1153 DEF_OPT_FUNC("accept_remm_peer" , OFS(accept_remm_peer), accept_remm_peer_fn ),
1154 DEF_OPT_FUNC("block_ecm" , OFS(gbox_block_ecm) , gbox_block_ecm_fn ),
1155 DEF_OPT_FUNC("proxy_card" , OFS(gbox_proxy_card) , gbox_proxy_card_fn ),
1156 DEF_OPT_UINT8("gbox_save_gsms" , OFS(gbox_save_gsms) , 0),
1157 DEF_OPT_UINT8("gbox_msg_type" , OFS(gbox_msg_type) , 0),
1158 DEF_OPT_FUNC("gbox_dest_peers" , OFS(gbox_dest_peers) , gbox_dest_peers_fn ),
1159 DEF_OPT_FUNC("gbox_msg_txt" , OFS(gbox_msg_txt) , gbox_msg_txt_fn ),
1160 DEF_LAST_OPT
1162 #else
1163 static const struct config_list gbox_opts[] = { DEF_LAST_OPT };
1164 #endif
1166 #ifdef HAVE_DVBAPI
1167 extern const char *boxdesc[];
1169 static void dvbapi_boxtype_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
1171 if(value)
1173 int i;
1174 cfg.dvbapi_boxtype = 0;
1175 for(i = 1; i <= BOXTYPES; i++)
1177 if(streq(value, boxdesc[i]))
1179 cfg.dvbapi_boxtype = i;
1180 break;
1183 return;
1185 if(cfg.dvbapi_boxtype)
1186 { fprintf_conf(f, token, "%s\n", boxdesc[cfg.dvbapi_boxtype]); }
1189 static void dvbapi_services_fn(const char *UNUSED(token), char *value, void *UNUSED(setting), FILE *UNUSED(f))
1191 if(value)
1192 { chk_services(value, &cfg.dvbapi_sidtabs); }
1193 // THIS OPTION IS NOT SAVED
1196 extern struct s_dvbapi_priority *dvbapi_priority;
1198 static void dvbapi_caidtab_fn(const char *UNUSED(token), char *caidasc, void *UNUSED(setting), long cmd, FILE *UNUSED(f))
1200 char *ptr1, *ptr3, *saveptr1 = NULL;
1201 if(!caidasc)
1202 { return; }
1203 char type = (char)cmd;
1204 for(ptr1 = strtok_r(caidasc, ",", &saveptr1); (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1))
1206 uint32_t caid, prov;
1207 if((ptr3 = strchr(trim(ptr1), ':')))
1208 { * ptr3++ = '\0'; }
1209 else
1210 { ptr3 = ""; }
1211 if(((caid = a2i(ptr1, 2)) | (prov = a2i(ptr3, 3))))
1213 struct s_dvbapi_priority *entry;
1214 if(!cs_malloc(&entry, sizeof(struct s_dvbapi_priority)))
1215 { return; }
1216 entry->caid = caid;
1217 if(type == 'd')
1219 char tmp1[5];
1220 snprintf(tmp1, sizeof(tmp1), "%04X", (uint)prov);
1221 int32_t cw_delay = strtol(tmp1, NULL, 10);
1222 entry->delay = cw_delay;
1224 else
1226 entry->provid = prov;
1228 entry->type = type;
1229 entry->next = NULL;
1230 if(!dvbapi_priority)
1232 dvbapi_priority = entry;
1234 else
1236 struct s_dvbapi_priority *p;
1237 for(p = dvbapi_priority; p->next != NULL; p = p->next)
1238 { ; }
1239 p->next = entry;
1243 // THIS OPTION IS NOT SAVED
1246 static bool dvbapi_should_save_fn(void *UNUSED(var))
1248 return cfg.dvbapi_enabled;
1251 static const struct config_list dvbapi_opts[] =
1253 DEF_OPT_SAVE_FUNC(dvbapi_should_save_fn),
1254 DEF_OPT_INT8("enabled" , OFS(dvbapi_enabled), 0),
1255 DEF_OPT_INT8("au" , OFS(dvbapi_au), 0),
1256 DEF_OPT_INT8("pmt_mode" , OFS(dvbapi_pmtmode), 0),
1257 DEF_OPT_INT8("request_mode" , OFS(dvbapi_requestmode), 0),
1258 DEF_OPT_INT32("listen_port" , OFS(dvbapi_listenport), 0),
1259 DEF_OPT_INT32("delayer" , OFS(dvbapi_delayer), 0),
1260 DEF_OPT_INT8("ecminfo_type" , OFS(dvbapi_ecminfo_type), 0),
1261 DEF_OPT_STR("user" , OFS(dvbapi_usr), NULL),
1262 DEF_OPT_INT8("read_sdt" , OFS(dvbapi_read_sdt), 0),
1263 DEF_OPT_INT8("write_sdt_prov", OFS(dvbapi_write_sdt_prov), 0),
1264 DEF_OPT_INT8("extended_cw_api", OFS(dvbapi_extended_cw_api), 0),
1265 DEF_OPT_FUNC("boxtype" , OFS(dvbapi_boxtype), dvbapi_boxtype_fn),
1266 DEF_OPT_FUNC("services" , OFS(dvbapi_sidtabs.ok), dvbapi_services_fn),
1267 // OBSOLETE OPTIONS
1268 DEF_OPT_FUNC_X("priority" , 0, dvbapi_caidtab_fn, 'p'),
1269 DEF_OPT_FUNC_X("ignore" , 0, dvbapi_caidtab_fn, 'i'),
1270 DEF_OPT_FUNC_X("cw_delay" , 0, dvbapi_caidtab_fn, 'd'),
1271 DEF_LAST_OPT
1273 #else
1274 static const struct config_list dvbapi_opts[] = { DEF_LAST_OPT };
1275 #endif
1277 #ifdef LCDSUPPORT
1278 static void lcd_fixups_fn(void *UNUSED(var))
1280 if(cfg.lcd_write_intervall < 5) { cfg.lcd_write_intervall = 5; }
1283 static bool lcd_should_save_fn(void *UNUSED(var))
1285 return cfg.enablelcd;
1288 static const struct config_list lcd_opts[] =
1290 DEF_OPT_SAVE_FUNC(lcd_should_save_fn),
1291 DEF_OPT_FIXUP_FUNC(lcd_fixups_fn),
1292 DEF_OPT_INT8("enablelcd" , OFS(enablelcd), 0),
1293 DEF_OPT_STR("lcd_outputpath" , OFS(lcd_output_path), NULL),
1294 DEF_OPT_INT32("lcd_hideidle" , OFS(lcd_hide_idle), 0),
1295 DEF_OPT_INT32("lcd_writeintervall" , OFS(lcd_write_intervall), 10),
1296 DEF_LAST_OPT
1298 #else
1299 static const struct config_list lcd_opts[] = { DEF_LAST_OPT };
1300 #endif
1302 static const struct config_sections oscam_conf[] =
1304 { "global", global_opts }, // *** MUST BE FIRST ***
1305 { "anticasc", anticasc_opts },
1306 { "cache", cache_opts },
1307 { "lcd", lcd_opts },
1308 { "camd33", camd33_opts },
1309 { "cs357x", camd35_opts },
1310 { "cs378x", cs378x_opts },
1311 { "newcamd", newcamd_opts },
1312 { "radegast", radegast_opts },
1313 { "serial", serial_opts },
1314 { "gbox", gbox_opts },
1315 { "cccam", cccam_opts },
1316 { "pandora", pandora_opts },
1317 { "scam", scam_opts },
1318 { "dvbapi", dvbapi_opts },
1319 { "monitor", monitor_opts },
1320 { "webif", webif_opts },
1321 { NULL, NULL }
1324 void config_set(char *section, const char *token, char *value)
1326 config_set_value(oscam_conf, section, token, value, &cfg);
1329 void config_free(void)
1331 config_sections_free(oscam_conf, &cfg);
1332 caidvaluetab_clear(&cfg.ftimeouttab);
1333 caidtab_clear(&cfg.double_check_caid);
1334 ftab_clear(&cfg.disablecrccws_only_for);
1335 #ifdef WITH_LB
1336 caidvaluetab_clear(&cfg.lb_retrylimittab);
1337 caidvaluetab_clear(&cfg.lb_nbest_readers_tab);
1338 caidtab_clear(&cfg.lb_noproviderforcaid);
1339 #endif
1340 #ifdef CS_CACHEEX
1341 caidvaluetab_clear(&cfg.cacheex_mode1_delay_tab);
1342 cecspvaluetab_clear(&cfg.cacheex_wait_timetab);
1343 #endif
1344 #ifdef CW_CYCLE_CHECK
1345 caidtab_clear(&cfg.cwcycle_check_caidtab);
1346 #endif
1349 int32_t init_config(void)
1351 FILE *fp;
1353 if(config_enabled(WEBIF))
1355 fp = open_config_file(cs_conf);
1357 else
1359 fp = open_config_file_or_die(cs_conf);
1362 const struct config_sections *cur_section = oscam_conf; // Global
1363 char *token;
1365 config_sections_set_defaults(oscam_conf, &cfg);
1367 if(!fp)
1369 // no oscam.conf but webif is included in build, set it up for lan access and tweak defaults
1370 #ifdef WEBIF
1371 cfg.http_port = DEFAULT_HTTP_PORT;
1372 char *default_allowed;
1373 if ((default_allowed = cs_strdup(DEFAULT_HTTP_ALLOW)))
1375 chk_iprange(default_allowed, &cfg.http_allowed);
1376 free(default_allowed);
1378 #endif
1379 NULLFREE(cfg.logfile);
1380 cfg.logtostdout = 1;
1381 #ifdef HAVE_DVBAPI
1382 cfg.dvbapi_enabled = 1;
1383 #endif
1384 return 0;
1387 if(!cs_malloc(&token, MAXLINESIZE))
1388 { return 1; }
1390 int line = 0;
1391 int valid_section = 1;
1392 while(fgets(token, MAXLINESIZE, fp))
1394 ++line;
1395 int len = strlen(trim(token));
1396 if(len < 3) // a=b or [a] are at least 3 chars
1397 { continue; }
1398 if(token[0] == '#') // Skip comments
1399 { continue; }
1400 if(token[0] == '[' && token[len - 1] == ']')
1402 token[len - 1] = '\0';
1403 valid_section = 0;
1404 const struct config_sections *newconf = config_find_section(oscam_conf, token + 1);
1405 if(config_section_is_active(newconf) && cur_section)
1407 config_list_apply_fixups(cur_section->config, &cfg);
1408 cur_section = newconf;
1409 valid_section = 1;
1411 if(!newconf)
1413 fprintf(stderr, "WARNING: %s line %d unknown section [%s].\n",
1414 cs_conf, line, token + 1);
1415 continue;
1417 if(!config_section_is_active(newconf))
1419 fprintf(stderr, "WARNING: %s line %d section [%s] is ignored (support not compiled in).\n",
1420 cs_conf, line, newconf->section);
1422 continue;
1425 if(!valid_section)
1426 { continue; }
1427 char *value = strchr(token, '=');
1428 if(!value) // No = found, well go on
1429 { continue; }
1430 *value++ = '\0';
1431 char *tvalue = trim(value);
1432 char *ttoken = trim(strtolower(token));
1433 if(cur_section && !config_list_parse(cur_section->config, ttoken, tvalue, &cfg))
1435 fprintf(stderr, "WARNING: %s line %d section [%s] contains unknown setting '%s=%s'\n",
1436 cs_conf, line, cur_section->section, ttoken, tvalue);
1439 NULLFREE(token);
1440 fclose(fp);
1441 if(cur_section) { config_list_apply_fixups(cur_section->config, &cfg); }
1442 return 0;
1445 int32_t write_config(void)
1447 FILE *f = create_config_file(cs_conf);
1448 if(!f)
1449 { return 1; }
1450 config_sections_save(oscam_conf, f, &cfg);
1451 return flush_config_file(f, cs_conf);