- Add support of ORF P4 Irdeto mode
[oscam.git] / oscam-config-global.c
blob6ae8ff859fe4b06db9d7734db958906266620c97
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);
154 void caidvaluetab_fn(const char *token, char *value, void *setting, FILE *f)
156 CAIDVALUETAB *caid_value_table = setting;
157 if(value)
159 if (strlen(value)) {
160 chk_caidvaluetab(value, caid_value_table);
161 if (streq(token, "lb_retrylimits"))
163 int32_t i;
164 for (i = 0; i < caid_value_table->cvnum; i++)
166 if (caid_value_table->cvdata[i].value < 50)
167 caid_value_table->cvdata[i].value = 50;
170 } else {
171 caidvaluetab_clear(caid_value_table);
173 return;
175 if(caid_value_table->cvnum || cfg.http_full_cfg)
177 value = mk_t_caidvaluetab(caid_value_table);
178 fprintf_conf(f, token, "%s\n", value);
179 free_mk_t(value);
183 #ifdef CS_CACHEEX
184 void cacheex_valuetab_fn(const char *token, char *value, void *setting, FILE *f)
186 CECSPVALUETAB *cacheex_value_table = setting;
187 if(value)
189 if(strlen(value) == 0)
190 { clear_cacheextab(cacheex_value_table); }
191 else
192 { chk_cacheex_valuetab(value, cacheex_value_table); }
193 return;
195 if(cacheex_value_table->cevnum || cfg.http_full_cfg)
197 value = mk_t_cacheex_valuetab(cacheex_value_table);
198 fprintf_conf(f, token, "%s\n", value);
199 free_mk_t(value);
203 void cacheex_cwcheck_tab_fn(const char *token, char *value, void *setting, FILE *f)
205 CWCHECKTAB *cacheex_value_table = setting;
206 if(value)
208 if(strlen(value) == 0)
210 cacheex_value_table->cwchecknum = 0;
211 NULLFREE(cacheex_value_table->cwcheckdata);
213 else
215 chk_cacheex_cwcheck_valuetab(value, cacheex_value_table);
217 return;
220 if(cacheex_value_table->cwchecknum || cfg.http_full_cfg)
222 value = mk_t_cacheex_cwcheck_valuetab(cacheex_value_table);
223 fprintf_conf(f, token, "%s\n", value);
224 free_mk_t(value);
228 void cacheex_hitvaluetab_fn(const char *token, char *value, void *setting, FILE *f)
230 CECSPVALUETAB *cacheex_value_table = setting;
231 if(value)
233 if(strlen(value) == 0)
234 { clear_cacheextab(cacheex_value_table); }
235 else
236 { chk_cacheex_hitvaluetab(value, cacheex_value_table); }
237 return;
239 if(cacheex_value_table->cevnum || cfg.http_full_cfg)
241 value = mk_t_cacheex_hitvaluetab(cacheex_value_table);
242 fprintf_conf(f, token, "%s\n", value);
243 free_mk_t(value);
246 #endif
248 #ifdef __CYGWIN__
249 #include <windows.h>
250 #else
251 #include <sys/resource.h> // for setpriority
252 #endif
254 void global_fixups_fn(void *UNUSED(var))
256 if(!cfg.usrfile) { cfg.disableuserfile = 1; }
257 if(!cfg.mailfile) { cfg.disablemail = 1; }
258 if(cfg.ctimeout < 10) { cfg.ctimeout = cfg.ctimeout * 1000; } // save always in ms
260 if(cfg.nice < -20 || cfg.nice > 20) { cfg.nice = 99; }
261 if(cfg.nice != 99)
263 #ifndef __CYGWIN__
264 setpriority(PRIO_PROCESS, 0, cfg.nice);
265 #else
266 HANDLE WinId;
267 uint32_t wprio;
268 switch((cfg.nice + 20) / 10)
270 case 0:
271 wprio = REALTIME_PRIORITY_CLASS;
272 break;
273 case 1:
274 wprio = HIGH_PRIORITY_CLASS;
275 break;
276 case 2:
277 wprio = NORMAL_PRIORITY_CLASS;
278 break;
279 default:
280 wprio = IDLE_PRIORITY_CLASS;
281 break;
283 WinId = GetCurrentProcess();
284 SetPriorityClass(WinId, wprio);
285 #endif
287 if(cfg.max_log_size != 0 && cfg.max_log_size <= 10) { cfg.max_log_size = 10; }
288 #ifdef WITH_LB
289 if(cfg.lb_save > 0 && cfg.lb_save < 100) { cfg.lb_save = 100; }
290 if(cfg.lb_nbest_readers < 2) { cfg.lb_nbest_readers = DEFAULT_NBEST; }
291 #endif
294 #define OFS(X) offsetof(struct s_config, X)
295 #define SIZEOF(X) sizeof(((struct s_config *)0)->X)
297 static const struct config_list global_opts[] =
299 DEF_OPT_FIXUP_FUNC(global_fixups_fn),
300 #ifdef LEDSUPPORT
301 DEF_OPT_INT8("enableled" , OFS(enableled), 0),
302 #endif
303 DEF_OPT_FUNC("disablelog" , OFS(disablelog), disablelog_fn),
304 #if defined(WEBIF) || defined(MODULE_MONITOR)
305 DEF_OPT_FUNC("loghistorylines" , OFS(loghistorylines), loghistorylines_fn),
306 #endif
307 DEF_OPT_FUNC("serverip" , OFS(srvip), serverip_fn),
308 DEF_OPT_FUNC("logfile" , OFS(logfile), logfile_fn),
309 DEF_OPT_INT32("initial_debuglevel" , OFS(initial_debuglevel), 0),
310 DEF_OPT_STR("sysloghost" , OFS(sysloghost), NULL),
311 DEF_OPT_INT32("syslogport" , OFS(syslogport), 514),
312 DEF_OPT_INT8("logduplicatelines" , OFS(logduplicatelines), 0),
313 DEF_OPT_STR("pidfile" , OFS(pidfile), NULL),
314 DEF_OPT_INT8("disableuserfile" , OFS(disableuserfile), 1),
315 DEF_OPT_INT8("disablemail" , OFS(disablemail), 1),
316 DEF_OPT_INT8("usrfileflag" , OFS(usrfileflag), 0),
317 DEF_OPT_UINT32("clienttimeout" , OFS(ctimeout), CS_CLIENT_TIMEOUT),
318 DEF_OPT_UINT32("fallbacktimeout" , OFS(ftimeout), CS_CLIENT_TIMEOUT / 2),
319 DEF_OPT_FUNC("fallbacktimeout_percaid" , OFS(ftimeouttab), caidvaluetab_fn),
320 DEF_OPT_UINT32("clientmaxidle" , OFS(cmaxidle), CS_CLIENT_MAXIDLE),
321 DEF_OPT_INT32("bindwait" , OFS(bindwait), CS_BIND_TIMEOUT),
322 DEF_OPT_UINT32("netprio" , OFS(netprio), 0),
323 DEF_OPT_INT32("sleep" , OFS(tosleep), 0),
324 DEF_OPT_INT32("unlockparental" , OFS(ulparent), 0),
325 DEF_OPT_INT32("nice" , OFS(nice), 99),
326 DEF_OPT_INT32("maxlogsize" , OFS(max_log_size), 10),
327 DEF_OPT_INT8("waitforcards" , OFS(waitforcards), 1),
328 DEF_OPT_INT32("waitforcards_extra_delay" , OFS(waitforcards_extra_delay), 500),
329 DEF_OPT_INT8("preferlocalcards" , OFS(preferlocalcards), 0),
330 DEF_OPT_INT32("readerrestartseconds" , OFS(reader_restart_seconds), 5),
331 DEF_OPT_INT8("dropdups" , OFS(dropdups), 0),
332 DEF_OPT_INT8("reload_useraccounts" , OFS(reload_useraccounts), 0),
333 DEF_OPT_INT8("reload_readers" , OFS(reload_readers), 0),
334 DEF_OPT_INT8("reload_provid" , OFS(reload_provid), 0),
335 DEF_OPT_INT8("reload_services_ids" , OFS(reload_services_ids), 0),
336 DEF_OPT_INT8("reload_tier_ids" , OFS(reload_tier_ids), 0),
337 DEF_OPT_INT8("reload_fakecws" , OFS(reload_fakecws), 0),
338 DEF_OPT_INT8("reload_ac_stat" , OFS(reload_ac_stat), 0),
339 DEF_OPT_INT8("reload_log" , OFS(reload_log), 0),
340 DEF_OPT_INT8("block_same_ip" , OFS(block_same_ip), 1),
341 DEF_OPT_INT8("block_same_name" , OFS(block_same_name), 1),
342 DEF_OPT_STR("usrfile" , OFS(usrfile), NULL),
343 DEF_OPT_STR("mailfile" , OFS(mailfile), NULL),
344 DEF_OPT_STR("cwlogdir" , OFS(cwlogdir), NULL),
345 DEF_OPT_STR("emmlogdir" , OFS(emmlogdir), NULL),
346 #ifdef WITH_LB
347 DEF_OPT_INT32("lb_mode" , OFS(lb_mode), DEFAULT_LB_MODE),
348 DEF_OPT_INT32("lb_save" , OFS(lb_save), 0),
349 DEF_OPT_INT32("lb_nbest_readers" , OFS(lb_nbest_readers), DEFAULT_NBEST),
350 DEF_OPT_INT32("lb_nfb_readers" , OFS(lb_nfb_readers), DEFAULT_NFB),
351 DEF_OPT_INT32("lb_min_ecmcount" , OFS(lb_min_ecmcount), DEFAULT_MIN_ECM_COUNT),
352 DEF_OPT_INT32("lb_max_ecmcount" , OFS(lb_max_ecmcount), DEFAULT_MAX_ECM_COUNT),
353 DEF_OPT_INT32("lb_reopen_seconds" , OFS(lb_reopen_seconds), DEFAULT_REOPEN_SECONDS),
354 DEF_OPT_INT8("lb_reopen_invalid" , OFS(lb_reopen_invalid), 1),
355 DEF_OPT_INT8("lb_force_reopen_always" , OFS(lb_force_reopen_always), 0),
356 DEF_OPT_INT32("lb_retrylimit" , OFS(lb_retrylimit), DEFAULT_RETRYLIMIT),
357 DEF_OPT_INT32("lb_stat_cleanup" , OFS(lb_stat_cleanup), DEFAULT_LB_STAT_CLEANUP),
358 DEF_OPT_INT32("lb_max_readers" , OFS(lb_max_readers), 0),
359 DEF_OPT_INT32("lb_auto_betatunnel" , OFS(lb_auto_betatunnel), DEFAULT_LB_AUTO_BETATUNNEL),
360 DEF_OPT_INT32("lb_auto_betatunnel_mode" , OFS(lb_auto_betatunnel_mode), DEFAULT_LB_AUTO_BETATUNNEL_MODE),
361 DEF_OPT_INT32("lb_auto_betatunnel_prefer_beta" , OFS(lb_auto_betatunnel_prefer_beta), DEFAULT_LB_AUTO_BETATUNNEL_PREFER_BETA),
362 DEF_OPT_STR("lb_savepath" , OFS(lb_savepath), NULL),
363 DEF_OPT_FUNC("lb_retrylimits" , OFS(lb_retrylimittab), caidvaluetab_fn),
364 DEF_OPT_FUNC("lb_nbest_percaid" , OFS(lb_nbest_readers_tab), caidvaluetab_fn),
365 DEF_OPT_FUNC("lb_noproviderforcaid" , OFS(lb_noproviderforcaid), check_caidtab_fn),
366 DEF_OPT_INT32("lb_auto_timeout" , OFS(lb_auto_timeout), DEFAULT_LB_AUTO_TIMEOUT),
367 DEF_OPT_INT32("lb_auto_timeout_p" , OFS(lb_auto_timeout_p), DEFAULT_LB_AUTO_TIMEOUT_P),
368 DEF_OPT_INT32("lb_auto_timeout_t" , OFS(lb_auto_timeout_t), DEFAULT_LB_AUTO_TIMEOUT_T),
369 #endif
370 DEF_OPT_FUNC("double_check_caid" , OFS(double_check_caid), check_caidtab_fn),
371 DEF_OPT_STR("ecmfmt" , OFS(ecmfmt), NULL),
372 DEF_OPT_INT32("resolvegethostbyname" , OFS(resolve_gethostbyname), 0),
373 DEF_OPT_INT32("failbantime" , OFS(failbantime), 0),
374 DEF_OPT_INT32("failbancount" , OFS(failbancount), 0),
375 DEF_OPT_INT8("suppresscmd08" , OFS(c35_suppresscmd08), 0),
376 DEF_OPT_INT8("getblockemmauprovid" , OFS(getblockemmauprovid), 0),
377 DEF_OPT_INT8("double_check" , OFS(double_check), 0),
378 DEF_LAST_OPT
381 #ifdef CS_ANTICASC
382 static void anticasc_fixups_fn(void *UNUSED(var))
384 if(cfg.ac_users < 0) { cfg.ac_users = 0; }
385 if(cfg.ac_stime < 0) { cfg.ac_stime = 2; }
386 if(cfg.ac_samples < 2 || cfg.ac_samples > 10) { cfg.ac_samples = 10; }
387 if(cfg.ac_penalty < 0 || cfg.ac_penalty > 3) { cfg.ac_penalty = 0; }
388 if(cfg.ac_fakedelay < 100 || cfg.ac_fakedelay > 3000) { cfg.ac_fakedelay = 1000; }
389 if(cfg.ac_denysamples < 2 || cfg.ac_denysamples > cfg.ac_samples - 1) { cfg.ac_denysamples = cfg.ac_samples - 1; }
390 if(cfg.ac_denysamples + 1 > cfg.ac_samples) { cfg.ac_denysamples = cfg.ac_samples - 1; }
391 if(cfg.acosc_max_active_sids < 0) { cfg.acosc_max_active_sids = 0; }
392 if(cfg.acosc_zap_limit < 0) { cfg.acosc_zap_limit = 0; }
393 if(cfg.acosc_penalty < 0 || cfg.acosc_penalty > 3) { cfg.acosc_penalty = 0; }
394 if(cfg.acosc_penalty_duration < 0) { cfg.acosc_penalty_duration = 0; }
395 if(cfg.acosc_delay < 0 || cfg.acosc_delay > 4000) { cfg.acosc_delay = 0; }
398 static bool anticasc_should_save_fn(void *UNUSED(var))
400 return cfg.ac_enabled || cfg.acosc_enabled;
403 static const struct config_list anticasc_opts[] =
405 DEF_OPT_SAVE_FUNC(anticasc_should_save_fn),
406 DEF_OPT_FIXUP_FUNC(anticasc_fixups_fn),
407 DEF_OPT_INT8("enabled" , OFS(ac_enabled), 0),
408 DEF_OPT_INT32("numusers" , OFS(ac_users), 0),
409 DEF_OPT_INT32("sampletime" , OFS(ac_stime), 2),
410 DEF_OPT_INT32("samples" , OFS(ac_samples), 10),
411 DEF_OPT_INT8("penalty" , OFS(ac_penalty), 0),
412 DEF_OPT_STR("aclogfile" , OFS(ac_logfile), NULL),
413 DEF_OPT_INT32("fakedelay" , OFS(ac_fakedelay), 3000),
414 DEF_OPT_INT32("denysamples" , OFS(ac_denysamples), 8),
415 DEF_OPT_INT8("acosc_enabled" , OFS(acosc_enabled), 0 ),
416 DEF_OPT_INT8("acosc_max_active_sids" , OFS(acosc_max_active_sids), 0 ),
417 DEF_OPT_INT8("acosc_zap_limit" , OFS(acosc_zap_limit), 0 ),
418 DEF_OPT_INT8("acosc_penalty" , OFS(acosc_penalty), 0 ),
419 DEF_OPT_INT32("acosc_penalty_duration" , OFS(acosc_penalty_duration), 0 ),
420 DEF_OPT_INT32("acosc_delay" , OFS(acosc_delay), 0 ),
421 DEF_LAST_OPT
423 #else
424 static const struct config_list anticasc_opts[] = { DEF_LAST_OPT };
425 #endif
427 #ifdef MODULE_MONITOR
428 static bool monitor_should_save_fn(void *UNUSED(var))
430 return cfg.mon_port;
433 static const struct config_list monitor_opts[] =
435 DEF_OPT_SAVE_FUNC(monitor_should_save_fn),
436 DEF_OPT_INT32("port" , OFS(mon_port), 0),
437 DEF_OPT_FUNC("serverip" , OFS(mon_srvip), serverip_fn),
438 DEF_OPT_FUNC("nocrypt" , OFS(mon_allowed), iprange_fn, .free_value = iprange_free_fn),
439 DEF_OPT_INT32("aulow" , OFS(aulow), 30),
440 DEF_OPT_UINT8("monlevel" , OFS(mon_level), 2),
441 DEF_OPT_INT32("hideclient_to" , OFS(hideclient_to), 25),
442 DEF_LAST_OPT
444 #else
445 static const struct config_list monitor_opts[] = { DEF_LAST_OPT };
446 #endif
448 #ifdef WEBIF
449 static void http_port_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
451 if(value)
453 cfg.http_port = 0;
454 if(value[0])
456 if(value[0] == '+')
458 if(config_enabled(WITH_SSL))
460 cfg.http_use_ssl = 1;
462 else
464 fprintf(stderr, "Warning: OSCam compiled without SSL support.\n");
466 cfg.http_port = strtoul(value + 1, NULL, 10);
468 else
470 cfg.http_port = strtoul(value, NULL, 10);
473 return;
475 fprintf_conf(f, token, "%s%d\n", cfg.http_use_ssl ? "+" : "", cfg.http_port);
478 static void http_dyndns_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
480 int i;
481 if(value)
483 char *ptr, *saveptr1 = NULL;
484 memset(cfg.http_dyndns, 0, sizeof(cfg.http_dyndns));
485 for(i = 0, ptr = strtok_r(value, ",", &saveptr1); (i < MAX_HTTP_DYNDNS) && (ptr); ptr = strtok_r(NULL, ",", &saveptr1), i++)
487 trim(ptr);
488 cs_strncpy((char *)cfg.http_dyndns[i], ptr, sizeof(cfg.http_dyndns[i]));
490 return;
492 if(strlen((const char *)(cfg.http_dyndns[0])) > 0 || cfg.http_full_cfg)
494 fprintf_conf(f, token, "%s", ""); // it should not have \n at the end
495 for(i = 0; i < MAX_HTTP_DYNDNS; i++)
497 if(cfg.http_dyndns[i][0])
499 fprintf(f, "%s%s", i > 0 ? "," : "", cfg.http_dyndns[i]);
502 fprintf(f, "\n");
506 static bool webif_should_save_fn(void *UNUSED(var))
508 return cfg.http_port;
511 static const struct config_list webif_opts[] =
513 DEF_OPT_SAVE_FUNC(webif_should_save_fn),
514 DEF_OPT_FUNC("httpport" , OFS(http_port), http_port_fn),
515 DEF_OPT_FUNC("serverip" , OFS(http_srvip), serverip_fn),
516 DEF_OPT_STR("httpuser" , OFS(http_user), NULL),
517 DEF_OPT_STR("httppwd" , OFS(http_pwd), NULL),
518 DEF_OPT_STR("httpcss" , OFS(http_css), NULL),
519 DEF_OPT_STR("httpjscript" , OFS(http_jscript), NULL),
520 DEF_OPT_STR("httpscript" , OFS(http_script), NULL),
521 DEF_OPT_STR("httptpl" , OFS(http_tpl), NULL),
522 DEF_OPT_STR("httppiconpath" , OFS(http_piconpath), NULL),
523 DEF_OPT_STR("httphelplang" , OFS(http_help_lang), "en"),
524 DEF_OPT_STR("httplocale" , OFS(http_locale), NULL),
525 DEF_OPT_INT8("http_prepend_embedded_css" , OFS(http_prepend_embedded_css), 0),
526 DEF_OPT_INT32("httprefresh" , OFS(http_refresh), 0),
527 DEF_OPT_INT32("httppollrefresh" , OFS(poll_refresh), 60),
528 DEF_OPT_INT8("httphideidleclients" , OFS(http_hide_idle_clients), 1),
529 DEF_OPT_STR("httphidetype" , OFS(http_hide_type), NULL),
530 DEF_OPT_INT8("httpshowpicons" , OFS(http_showpicons), 0),
531 DEF_OPT_INT8("httppiconsize" , OFS(http_picon_size), 0),
532 DEF_OPT_INT8("httpshowmeminfo" , OFS(http_showmeminfo), 0),
533 DEF_OPT_INT8("httpshowuserinfo" , OFS(http_showuserinfo), 0),
534 DEF_OPT_INT8("httpshowreaderinfo" , OFS(http_showreaderinfo), 0),
535 DEF_OPT_INT8("httpshowcacheexinfo" , OFS(http_showcacheexinfo), 0),
536 DEF_OPT_INT8("httpshowecminfo" , OFS(http_showecminfo), 0),
537 DEF_OPT_INT8("httpshowloadinfo" , OFS(http_showloadinfo), 0),
538 DEF_OPT_FUNC("httpallowed" , OFS(http_allowed), iprange_fn, .free_value = iprange_free_fn),
539 DEF_OPT_INT8("httpreadonly" , OFS(http_readonly), 0),
540 DEF_OPT_INT8("httpsavefullcfg" , OFS(http_full_cfg), 0),
541 DEF_OPT_INT8("httpoverwritebakfile" , OFS(http_overwrite_bak_file), 0),
542 DEF_OPT_STR("httpcert" , OFS(http_cert), NULL),
543 DEF_OPT_INT8("https_force_secure_mode" , OFS(https_force_secure_mode), 1),
544 DEF_OPT_FUNC("httpdyndns" , OFS(http_dyndns), http_dyndns_fn),
545 DEF_OPT_INT32("aulow" , OFS(aulow), 30),
546 DEF_OPT_INT32("hideclient_to" , OFS(hideclient_to), 25),
547 DEF_OPT_STR("httposcamlabel" , OFS(http_oscam_label), "OSCam"),
548 DEF_OPT_INT32("httpemmuclean" , OFS(http_emmu_clean), 256),
549 DEF_OPT_INT32("httpemmsclean" , OFS(http_emms_clean), -1),
550 DEF_OPT_INT32("httpemmgclean" , OFS(http_emmg_clean), -1),
551 #ifdef WEBIF_LIVELOG
552 DEF_OPT_INT8("http_status_log" , OFS(http_status_log), 0),
553 #else
554 DEF_OPT_INT8("http_status_log" , OFS(http_status_log), 1),
555 #endif
556 #ifndef WEBIF_JQUERY
557 DEF_OPT_STR("http_extern_jquery" , OFS(http_extern_jquery), "//code.jquery.com/jquery-1.11.0.min.js"),
558 #endif
559 DEF_LAST_OPT
561 #else
562 static const struct config_list webif_opts[] = { DEF_LAST_OPT };
563 #endif
565 #ifdef MODULE_CAMD33
566 static bool camd33_should_save_fn(void *UNUSED(var))
568 return cfg.c33_port;
571 static const struct config_list camd33_opts[] =
573 DEF_OPT_SAVE_FUNC(camd33_should_save_fn),
574 DEF_OPT_INT32("port" , OFS(c33_port), 0),
575 DEF_OPT_FUNC("serverip" , OFS(c33_srvip), serverip_fn),
576 DEF_OPT_FUNC("nocrypt" , OFS(c33_plain), iprange_fn, .free_value = iprange_free_fn),
577 DEF_OPT_INT32("passive" , OFS(c33_passive), 0),
578 DEF_OPT_HEX("key" , OFS(c33_key), SIZEOF(c33_key)),
579 DEF_LAST_OPT
581 #else
582 static const struct config_list camd33_opts[] = { DEF_LAST_OPT };
583 #endif
586 void cache_fixups_fn(void *UNUSED(var))
588 if(cfg.max_cache_time < ((int32_t)(cfg.ctimeout + 500) / 1000 + 3)) { cfg.max_cache_time = ((cfg.ctimeout + 500) / 1000 + 3); }
589 #ifdef CW_CYCLE_CHECK
590 if(cfg.maxcyclelist > 4000) { cfg.maxcyclelist = 4000; }
591 if(cfg.keepcycletime > 240) { cfg.keepcycletime = 240; }
592 if(cfg.cwcycle_sensitive > 4) { cfg.cwcycle_sensitive = 4; }
593 if(cfg.cwcycle_sensitive == 1) { cfg.cwcycle_sensitive = 2; }
594 #endif
597 static bool cache_should_save_fn(void *UNUSED(var))
599 return cfg.delay > 0 || cfg.max_cache_time != 15
600 #ifdef CS_CACHEEX
601 || 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
602 #endif
603 #ifdef CW_CYCLE_CHECK
604 || 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
605 #endif
609 static const struct config_list cache_opts[] =
611 DEF_OPT_SAVE_FUNC(cache_should_save_fn),
612 DEF_OPT_FIXUP_FUNC(cache_fixups_fn),
613 DEF_OPT_UINT32("delay" , OFS(delay), CS_DELAY),
614 DEF_OPT_INT32("max_time" , OFS(max_cache_time), DEFAULT_MAX_CACHE_TIME),
615 #ifdef CS_CACHEEX
616 DEF_OPT_INT32("max_hit_time" , OFS(max_hitcache_time), DEFAULT_MAX_HITCACHE_TIME),
617 DEF_OPT_FUNC("wait_time" , OFS(cacheex_wait_timetab), cacheex_valuetab_fn),
618 DEF_OPT_FUNC("cacheex_mode1_delay" , OFS(cacheex_mode1_delay_tab), caidvaluetab_fn),
619 DEF_OPT_UINT8("cacheexenablestats" , OFS(cacheex_enable_stats), 0),
620 DEF_OPT_INT32("csp_port" , OFS(csp_port), 0),
621 DEF_OPT_FUNC("csp_serverip" , OFS(csp_srvip), serverip_fn),
622 DEF_OPT_FUNC("csp_ecm_filter" , OFS(csp.filter_caidtab), cacheex_hitvaluetab_fn),
623 DEF_OPT_UINT8("csp_allow_request" , OFS(csp.allow_request), 1),
624 DEF_OPT_UINT8("csp_allow_reforward" , OFS(csp.allow_reforward), 0),
625 DEF_OPT_FUNC("cacheex_cw_check" , OFS(cacheex_cwcheck_tab), cacheex_cwcheck_tab_fn),
626 DEF_OPT_UINT8("wait_until_ctimeout" , OFS(wait_until_ctimeout), 0),
627 DEF_OPT_UINT8("csp_block_fakecws" , OFS(csp.block_fakecws), 0),
628 #endif
629 #ifdef CW_CYCLE_CHECK
630 DEF_OPT_INT8("cwcycle_check_enable" , OFS(cwcycle_check_enable), 0),
631 DEF_OPT_FUNC("cwcycle_check_caid" , OFS(cwcycle_check_caidtab), check_caidtab_fn),
632 DEF_OPT_INT32("cwcycle_maxlist" , OFS(maxcyclelist), 500),
633 DEF_OPT_INT32("cwcycle_keeptime" , OFS(keepcycletime), 15),
634 DEF_OPT_INT8("cwcycle_onbad" , OFS(onbadcycle), 1),
635 DEF_OPT_INT8("cwcycle_dropold" , OFS(cwcycle_dropold), 1),
636 DEF_OPT_INT8("cwcycle_sensitive" , OFS(cwcycle_sensitive), 4),
637 DEF_OPT_INT8("cwcycle_allowbadfromffb" , OFS(cwcycle_allowbadfromffb), 0),
638 DEF_OPT_INT8("cwcycle_usecwcfromce" , OFS(cwcycle_usecwcfromce), 0),
639 #endif
640 DEF_LAST_OPT
643 #ifdef MODULE_CAMD35
644 static bool camd35_should_save_fn(void *UNUSED(var))
646 return cfg.c35_port;
649 static const struct config_list camd35_opts[] =
651 DEF_OPT_SAVE_FUNC(camd35_should_save_fn),
652 DEF_OPT_INT32("port" , OFS(c35_port), 0),
653 DEF_OPT_FUNC("serverip" , OFS(c35_srvip), serverip_fn),
654 DEF_OPT_INT8("suppresscmd08" , OFS(c35_udp_suppresscmd08), 0),
655 DEF_LAST_OPT
657 #else
658 static const struct config_list camd35_opts[] = { DEF_LAST_OPT };
659 #endif
661 #if defined(MODULE_CAMD35_TCP) || defined(MODULE_NEWCAMD)
662 #define PORTTAB_CS378X 1
663 #define PORTTAB_NEWCAMD 2
664 static void porttab_fn(const char *token, char *value, void *setting, long type, FILE *f)
666 PTAB *ptab = setting;
667 if(value)
669 if(strlen(value) == 0)
671 clear_ptab(ptab);
673 else
675 chk_port_tab(value, ptab);
677 return;
679 value = (type == PORTTAB_CS378X) ? mk_t_camd35tcp_port() : mk_t_newcamd_port();
680 fprintf_conf(f, token, "%s\n", value);
681 free_mk_t(value);
684 static void porttab_free_fn(void *setting)
686 clear_ptab(setting);
688 #endif
690 #ifdef MODULE_CAMD35_TCP
691 static bool cs378x_should_save_fn(void *UNUSED(var))
693 return cfg.c35_tcp_ptab.nports && cfg.c35_tcp_ptab.ports[0].s_port;
696 static const struct config_list cs378x_opts[] =
698 DEF_OPT_SAVE_FUNC(cs378x_should_save_fn),
699 DEF_OPT_FUNC_X("port" , OFS(c35_tcp_ptab), porttab_fn, PORTTAB_CS378X, .free_value = porttab_free_fn),
700 DEF_OPT_FUNC("serverip" , OFS(c35_tcp_srvip), serverip_fn),
701 DEF_OPT_INT8("suppresscmd08" , OFS(c35_tcp_suppresscmd08), 0),
702 DEF_LAST_OPT
704 #else
705 static const struct config_list cs378x_opts[] = { DEF_LAST_OPT };
706 #endif
708 #ifdef MODULE_NEWCAMD
709 static bool newcamd_should_save_fn(void *UNUSED(var))
711 return cfg.ncd_ptab.nports && cfg.ncd_ptab.ports[0].s_port;
714 static const struct config_list newcamd_opts[] =
716 DEF_OPT_SAVE_FUNC(newcamd_should_save_fn),
717 DEF_OPT_FUNC_X("port" , OFS(ncd_ptab), porttab_fn, PORTTAB_NEWCAMD, .free_value = porttab_free_fn),
718 DEF_OPT_FUNC("serverip" , OFS(ncd_srvip), serverip_fn),
719 DEF_OPT_FUNC("allowed" , OFS(ncd_allowed), iprange_fn, .free_value = iprange_free_fn),
720 DEF_OPT_HEX("key" , OFS(ncd_key), SIZEOF(ncd_key)),
721 DEF_OPT_INT8("keepalive" , OFS(ncd_keepalive), DEFAULT_NCD_KEEPALIVE),
722 DEF_OPT_INT8("mgclient" , OFS(ncd_mgclient), 0),
723 DEF_LAST_OPT
725 #else
726 static const struct config_list newcamd_opts[] = { DEF_LAST_OPT };
727 #endif
729 #ifdef MODULE_CCCAM
730 static void cccam_port_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
732 if(value)
734 int i;
735 char *ptr, *saveptr1 = NULL;
736 memset(cfg.cc_port, 0, sizeof(cfg.cc_port));
737 for(i = 0, ptr = strtok_r(value, ",", &saveptr1); ptr && i < CS_MAXPORTS; ptr = strtok_r(NULL, ",", &saveptr1))
739 cfg.cc_port[i] = strtoul(ptr, NULL, 10);
740 if(cfg.cc_port[i])
741 { i++; }
743 return;
745 value = mk_t_cccam_port();
746 fprintf_conf(f, token, "%s\n", value);
747 free_mk_t(value);
750 static bool cccam_should_save_fn(void *UNUSED(var))
752 return cfg.cc_port[0];
755 static const struct config_list cccam_opts[] =
757 DEF_OPT_SAVE_FUNC(cccam_should_save_fn),
758 DEF_OPT_FUNC("port" , OFS(cc_port), cccam_port_fn),
759 DEF_OPT_FUNC("serverip" , OFS(cc_srvip), serverip_fn),
760 DEF_OPT_HEX("nodeid" , OFS(cc_fixed_nodeid), SIZEOF(cc_fixed_nodeid)),
761 DEF_OPT_SSTR("version" , OFS(cc_version), "", SIZEOF(cc_version)),
762 DEF_OPT_INT8("reshare" , OFS(cc_reshare), 10),
763 DEF_OPT_INT8("reshare_mode" , OFS(cc_reshare_services), 4),
764 DEF_OPT_INT8("ignorereshare" , OFS(cc_ignore_reshare), 0),
765 DEF_OPT_INT8("forward_origin_card" , OFS(cc_forward_origin_card), 0),
766 DEF_OPT_INT8("stealth" , OFS(cc_stealth), 0),
767 DEF_OPT_INT32("updateinterval" , OFS(cc_update_interval), DEFAULT_UPDATEINTERVAL),
768 DEF_OPT_INT8("minimizecards" , OFS(cc_minimize_cards), 0),
769 DEF_OPT_INT8("keepconnected" , OFS(cc_keep_connected), 1),
770 DEF_OPT_UINT32("recv_timeout" , OFS(cc_recv_timeout), DEFAULT_CC_RECV_TIMEOUT),
771 DEF_LAST_OPT
773 #else
774 static const struct config_list cccam_opts[] = { DEF_LAST_OPT };
775 #endif
777 #ifdef MODULE_PANDORA
778 static bool pandora_should_save_fn(void *UNUSED(var))
780 return cfg.pand_port;
783 static const struct config_list pandora_opts[] =
785 DEF_OPT_SAVE_FUNC(pandora_should_save_fn),
786 DEF_OPT_INT32("pand_port" , OFS(pand_port), 0),
787 DEF_OPT_FUNC("pand_srvid" , OFS(pand_srvip), serverip_fn),
788 DEF_OPT_STR("pand_usr" , OFS(pand_usr), NULL),
789 DEF_OPT_STR("pand_pass" , OFS(pand_pass), NULL),
790 DEF_OPT_INT8("pand_ecm" , OFS(pand_ecm), 0),
791 DEF_OPT_INT8("pand_skip_send_dw" , OFS(pand_skip_send_dw), 0),
792 DEF_OPT_FUNC("pand_allowed" , OFS(pand_allowed), iprange_fn, .free_value = iprange_free_fn),
793 DEF_LAST_OPT
795 #else
796 static const struct config_list pandora_opts[] = { DEF_LAST_OPT };
797 #endif
799 #ifdef MODULE_SCAM
800 static bool scam_should_save_fn(void *UNUSED(var))
802 return cfg.scam_port;
804 static const struct config_list scam_opts[] =
806 DEF_OPT_SAVE_FUNC(scam_should_save_fn),
807 DEF_OPT_INT32("port" , OFS(scam_port), 0),
808 DEF_OPT_FUNC("serverip" , OFS(scam_srvip), serverip_fn),
809 DEF_OPT_FUNC("allowed" , OFS(scam_allowed), iprange_fn, .free_value = iprange_free_fn),
810 DEF_LAST_OPT
812 #else
813 static const struct config_list scam_opts[] = { DEF_LAST_OPT };
814 #endif
815 #ifdef MODULE_RADEGAST
816 static bool radegast_should_save_fn(void *UNUSED(var))
818 return cfg.rad_port;
821 static const struct config_list radegast_opts[] =
823 DEF_OPT_SAVE_FUNC(radegast_should_save_fn),
824 DEF_OPT_INT32("port" , OFS(rad_port), 0),
825 DEF_OPT_FUNC("serverip" , OFS(rad_srvip), serverip_fn),
826 DEF_OPT_FUNC("allowed" , OFS(rad_allowed), iprange_fn, .free_value = iprange_free_fn),
827 DEF_OPT_STR("user" , OFS(rad_usr), NULL),
828 DEF_LAST_OPT
830 #else
831 static const struct config_list radegast_opts[] = { DEF_LAST_OPT };
832 #endif
834 #ifdef MODULE_SERIAL
835 static bool serial_should_save_fn(void *UNUSED(var))
837 return cfg.ser_device != NULL;
840 static const struct config_list serial_opts[] =
842 DEF_OPT_SAVE_FUNC(serial_should_save_fn),
843 DEF_OPT_STR("device" , OFS(ser_device), NULL),
844 DEF_LAST_OPT
846 #else
847 static const struct config_list serial_opts[] = { DEF_LAST_OPT };
848 #endif
850 #ifdef MODULE_GBOX
851 static void gbox_proxy_card_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
853 if (value)
855 char *ptr1, *saveptr1 = NULL;
856 memset(cfg.gbox_proxy_card, 0, sizeof(cfg.gbox_proxy_card));
857 int n = 0, i;
858 for (i = 0, ptr1 = strtok_r(value, ",", &saveptr1); (i < 8) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1))
860 cfg.gbox_proxy_card[n++] = a2i(ptr1, 8);
862 cfg.gbox_proxy_cards_num = n;
863 return;
865 if (cfg.gbox_proxy_cards_num > 0)
867 int i;
868 char *dot = "";
869 fprintf_conf(f, token, " ");
870 for (i = 0; i < cfg.gbox_proxy_cards_num; i++)
872 fprintf(f, "%s%08lX", dot, cfg.gbox_proxy_card[i]);
873 dot = ",";
875 fprintf(f, "\n");
879 static void gbox_port_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
881 if(value)
883 int i;
884 char *ptr, *saveptr1 = NULL;
885 memset(cfg.gbx_port, 0, sizeof(cfg.gbx_port));
886 for(i = 0, ptr = strtok_r(value, ",", &saveptr1); ptr && i < CS_MAXPORTS; ptr = strtok_r(NULL, ",", &saveptr1))
888 cfg.gbx_port[i] = strtoul(ptr, NULL, 10);
889 if(cfg.gbx_port[i])
890 { i++; }
892 return;
894 value = mk_t_gbox_port();
895 fprintf_conf(f, token, "%s\n", value);
896 free_mk_t(value);
899 static bool gbox_should_save_fn(void *UNUSED(var))
901 return cfg.gbx_port[0];
904 static const struct config_list gbox_opts[] =
906 DEF_OPT_SAVE_FUNC(gbox_should_save_fn),
907 DEF_OPT_FUNC("port" , OFS(gbx_port), gbox_port_fn),
908 DEF_OPT_STR("hostname" , OFS(gbox_hostname), NULL),
909 DEF_OPT_INT32("gbox_reconnect" , OFS(gbox_reconnect), DEFAULT_GBOX_RECONNECT),
910 DEF_OPT_FUNC("proxy_card" , OFS(gbox_proxy_card), gbox_proxy_card_fn ),
911 DEF_OPT_SSTR("my_password" , OFS(gbox_my_password), "", SIZEOF(gbox_my_password)),
912 DEF_OPT_SSTR("my_vers" , OFS(gbox_my_vers), "25", SIZEOF(gbox_my_vers)),
913 DEF_OPT_SSTR("my_cpu_api" , OFS(gbox_my_cpu_api), "40", SIZEOF(gbox_my_cpu_api)),
914 DEF_OPT_UINT8("gsms_disable" , OFS(gsms_dis), 0),
915 DEF_OPT_UINT8("ccc_reshare" , OFS(ccc_reshare), 0),
916 DEF_OPT_UINT8("log_hello" , OFS(log_hello), 1),
917 DEF_OPT_STR("tmp_dir" , OFS(gbox_tmp_dir), NULL),
918 DEF_LAST_OPT
920 #else
921 static const struct config_list gbox_opts[] = { DEF_LAST_OPT };
922 #endif
924 #ifdef HAVE_DVBAPI
925 extern const char *boxdesc[];
927 static void dvbapi_boxtype_fn(const char *token, char *value, void *UNUSED(setting), FILE *f)
929 if(value)
931 int i;
932 cfg.dvbapi_boxtype = 0;
933 for(i = 1; i <= BOXTYPES; i++)
935 if(streq(value, boxdesc[i]))
937 cfg.dvbapi_boxtype = i;
938 break;
941 return;
943 if(cfg.dvbapi_boxtype)
944 { fprintf_conf(f, token, "%s\n", boxdesc[cfg.dvbapi_boxtype]); }
947 static void dvbapi_services_fn(const char *UNUSED(token), char *value, void *UNUSED(setting), FILE *UNUSED(f))
949 if(value)
950 { chk_services(value, &cfg.dvbapi_sidtabs); }
951 // THIS OPTION IS NOT SAVED
954 extern struct s_dvbapi_priority *dvbapi_priority;
956 static void dvbapi_caidtab_fn(const char *UNUSED(token), char *caidasc, void *UNUSED(setting), long cmd, FILE *UNUSED(f))
958 char *ptr1, *ptr3, *saveptr1 = NULL;
959 if(!caidasc)
960 { return; }
961 char type = (char)cmd;
962 for(ptr1 = strtok_r(caidasc, ",", &saveptr1); (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1))
964 uint32_t caid, prov;
965 if((ptr3 = strchr(trim(ptr1), ':')))
966 { * ptr3++ = '\0'; }
967 else
968 { ptr3 = ""; }
969 if(((caid = a2i(ptr1, 2)) | (prov = a2i(ptr3, 3))))
971 struct s_dvbapi_priority *entry;
972 if(!cs_malloc(&entry, sizeof(struct s_dvbapi_priority)))
973 { return; }
974 entry->caid = caid;
975 if(type == 'd')
977 char tmp1[5];
978 snprintf(tmp1, sizeof(tmp1), "%04X", (uint)prov);
979 int32_t cw_delay = strtol(tmp1, NULL, 10);
980 entry->delay = cw_delay;
982 else
984 entry->provid = prov;
986 entry->type = type;
987 entry->next = NULL;
988 if(!dvbapi_priority)
990 dvbapi_priority = entry;
992 else
994 struct s_dvbapi_priority *p;
995 for(p = dvbapi_priority; p->next != NULL; p = p->next)
996 { ; }
997 p->next = entry;
1001 // THIS OPTION IS NOT SAVED
1004 static bool dvbapi_should_save_fn(void *UNUSED(var))
1006 return cfg.dvbapi_enabled;
1009 static const struct config_list dvbapi_opts[] =
1011 DEF_OPT_SAVE_FUNC(dvbapi_should_save_fn),
1012 DEF_OPT_INT8("enabled" , OFS(dvbapi_enabled), 0),
1013 DEF_OPT_INT8("au" , OFS(dvbapi_au), 0),
1014 DEF_OPT_INT8("pmt_mode" , OFS(dvbapi_pmtmode), 0),
1015 DEF_OPT_INT8("request_mode" , OFS(dvbapi_requestmode), 0),
1016 DEF_OPT_INT32("listen_port" , OFS(dvbapi_listenport), 0),
1017 DEF_OPT_INT32("delayer" , OFS(dvbapi_delayer), 0),
1018 DEF_OPT_INT8("ecminfo_type" , OFS(dvbapi_ecminfo_type), 0),
1019 DEF_OPT_STR("user" , OFS(dvbapi_usr), NULL),
1020 DEF_OPT_INT8("read_sdt" , OFS(dvbapi_read_sdt), 0),
1021 DEF_OPT_INT8("write_sdt_prov", OFS(dvbapi_write_sdt_prov), 0),
1022 DEF_OPT_INT8("extended_cw_api", OFS(dvbapi_extended_cw_api), 0),
1023 DEF_OPT_FUNC("boxtype" , OFS(dvbapi_boxtype), dvbapi_boxtype_fn),
1024 DEF_OPT_FUNC("services" , OFS(dvbapi_sidtabs.ok), dvbapi_services_fn),
1025 // OBSOLETE OPTIONS
1026 DEF_OPT_FUNC_X("priority" , 0, dvbapi_caidtab_fn, 'p'),
1027 DEF_OPT_FUNC_X("ignore" , 0, dvbapi_caidtab_fn, 'i'),
1028 DEF_OPT_FUNC_X("cw_delay" , 0, dvbapi_caidtab_fn, 'd'),
1029 DEF_LAST_OPT
1031 #else
1032 static const struct config_list dvbapi_opts[] = { DEF_LAST_OPT };
1033 #endif
1035 #ifdef LCDSUPPORT
1036 static void lcd_fixups_fn(void *UNUSED(var))
1038 if(cfg.lcd_write_intervall < 5) { cfg.lcd_write_intervall = 5; }
1041 static bool lcd_should_save_fn(void *UNUSED(var))
1043 return cfg.enablelcd;
1046 static const struct config_list lcd_opts[] =
1048 DEF_OPT_SAVE_FUNC(lcd_should_save_fn),
1049 DEF_OPT_FIXUP_FUNC(lcd_fixups_fn),
1050 DEF_OPT_INT8("enablelcd" , OFS(enablelcd), 0),
1051 DEF_OPT_STR("lcd_outputpath" , OFS(lcd_output_path), NULL),
1052 DEF_OPT_INT32("lcd_hideidle" , OFS(lcd_hide_idle), 0),
1053 DEF_OPT_INT32("lcd_writeintervall" , OFS(lcd_write_intervall), 10),
1054 DEF_LAST_OPT
1056 #else
1057 static const struct config_list lcd_opts[] = { DEF_LAST_OPT };
1058 #endif
1060 static const struct config_sections oscam_conf[] =
1062 { "global", global_opts }, // *** MUST BE FIRST ***
1063 { "anticasc", anticasc_opts },
1064 { "cache", cache_opts },
1065 { "lcd", lcd_opts },
1066 { "camd33", camd33_opts },
1067 { "cs357x", camd35_opts },
1068 { "cs378x", cs378x_opts },
1069 { "newcamd", newcamd_opts },
1070 { "radegast", radegast_opts },
1071 { "serial", serial_opts },
1072 { "gbox", gbox_opts },
1073 { "cccam", cccam_opts },
1074 { "pandora", pandora_opts },
1075 { "scam", scam_opts },
1076 { "dvbapi", dvbapi_opts },
1077 { "monitor", monitor_opts },
1078 { "webif", webif_opts },
1079 { NULL, NULL }
1082 void config_set(char *section, const char *token, char *value)
1084 config_set_value(oscam_conf, section, token, value, &cfg);
1087 void config_free(void)
1089 config_sections_free(oscam_conf, &cfg);
1090 caidvaluetab_clear(&cfg.ftimeouttab);
1091 caidtab_clear(&cfg.double_check_caid);
1092 #ifdef WITH_LB
1093 caidvaluetab_clear(&cfg.lb_retrylimittab);
1094 caidvaluetab_clear(&cfg.lb_nbest_readers_tab);
1095 caidtab_clear(&cfg.lb_noproviderforcaid);
1096 #endif
1097 #ifdef CS_CACHEEX
1098 caidvaluetab_clear(&cfg.cacheex_mode1_delay_tab);
1099 cecspvaluetab_clear(&cfg.cacheex_wait_timetab);
1100 #endif
1101 #ifdef CW_CYCLE_CHECK
1102 caidtab_clear(&cfg.cwcycle_check_caidtab);
1103 #endif
1106 int32_t init_config(void)
1108 FILE *fp;
1110 if(config_enabled(WEBIF))
1112 fp = open_config_file(cs_conf);
1114 else
1116 fp = open_config_file_or_die(cs_conf);
1119 const struct config_sections *cur_section = oscam_conf; // Global
1120 char *token;
1122 config_sections_set_defaults(oscam_conf, &cfg);
1124 if(!fp)
1126 // no oscam.conf but webif is included in build, set it up for lan access and tweak defaults
1127 #ifdef WEBIF
1128 cfg.http_port = DEFAULT_HTTP_PORT;
1129 char *default_allowed;
1130 if ((default_allowed = cs_strdup(DEFAULT_HTTP_ALLOW)))
1132 chk_iprange(default_allowed, &cfg.http_allowed);
1133 free(default_allowed);
1135 #endif
1136 NULLFREE(cfg.logfile);
1137 cfg.logtostdout = 1;
1138 #ifdef HAVE_DVBAPI
1139 cfg.dvbapi_enabled = 1;
1140 #endif
1141 return 0;
1144 if(!cs_malloc(&token, MAXLINESIZE))
1145 { return 1; }
1147 int line = 0;
1148 int valid_section = 1;
1149 while(fgets(token, MAXLINESIZE, fp))
1151 ++line;
1152 int len = strlen(trim(token));
1153 if(len < 3) // a=b or [a] are at least 3 chars
1154 { continue; }
1155 if(token[0] == '#') // Skip comments
1156 { continue; }
1157 if(token[0] == '[' && token[len - 1] == ']')
1159 token[len - 1] = '\0';
1160 valid_section = 0;
1161 const struct config_sections *newconf = config_find_section(oscam_conf, token + 1);
1162 if(config_section_is_active(newconf) && cur_section)
1164 config_list_apply_fixups(cur_section->config, &cfg);
1165 cur_section = newconf;
1166 valid_section = 1;
1168 if(!newconf)
1170 fprintf(stderr, "WARNING: %s line %d unknown section [%s].\n",
1171 cs_conf, line, token + 1);
1172 continue;
1174 if(!config_section_is_active(newconf))
1176 fprintf(stderr, "WARNING: %s line %d section [%s] is ignored (support not compiled in).\n",
1177 cs_conf, line, newconf->section);
1179 continue;
1182 if(!valid_section)
1183 { continue; }
1184 char *value = strchr(token, '=');
1185 if(!value) // No = found, well go on
1186 { continue; }
1187 *value++ = '\0';
1188 char *tvalue = trim(value);
1189 char *ttoken = trim(strtolower(token));
1190 if(cur_section && !config_list_parse(cur_section->config, ttoken, tvalue, &cfg))
1192 fprintf(stderr, "WARNING: %s line %d section [%s] contains unknown setting '%s=%s'\n",
1193 cs_conf, line, cur_section->section, ttoken, tvalue);
1196 NULLFREE(token);
1197 fclose(fp);
1198 if(cur_section) { config_list_apply_fixups(cur_section->config, &cfg); }
1199 return 0;
1202 int32_t write_config(void)
1204 FILE *f = create_config_file(cs_conf);
1205 if(!f)
1206 { return 1; }
1207 config_sections_save(oscam_conf, f, &cfg);
1208 return flush_config_file(f, cs_conf);