1<?php
2/*
3$Id: config.php.in 684 2018-11-07 19:26:36Z bhockney $
4(C) 2003-2018 by Bob Hockney <zeus@ix.netcom.com>
5
6config file parser
7
8This code is distributed under the terms of GNU GPL
9*/
10
11$conffile = "@sysconfdir@/webfwlog.conf";
12if (!($fp = fopen("$conffile", "r"))) die("Cannot open config file $conffile");
13
14While (!feof($fp)) {
15	$buffer = fgets($fp, 1024);
16	$cptr = strpos($buffer, "#");
17	if ($cptr !== false and strlen($buffer) and $buffer = substr($buffer, 0, $cptr))
18	if (!strlen($buffer)) continue;
19	$params[] = explode("=", "$buffer", 2);
20}
21fclose($fp);
22
23// Failsafe defaults
24
25$config["db"] = "none";
26$config["pgsql_wfwl_schema"] = "public";
27$config["pgsql_geoip2_schema"] = "public";
28$config["wfwl_syslog"] = "@bindir@/wfwl_syslog";
29$config["syslog_dir"] = "/var/log";
30$config["syslog_filespec"] = "messages";
31$config["verbosity_level"] = 2;
32$config["default_data_source"] = "db";
33$config["title"] = "Firewall Log Report";
34$config["refresh"] = 0;
35$config["dformat"] = "m/d/Y h:i:sA";
36$config["timezone"] = "";
37$config["geoip_php_lookup"] = false;
38$config["geoip2_locale"] = "en";
39$config["geoip2_file"] = "";
40$config["report_order"] = "last_accessed";
41$config["show_select_data_source"] = 0;
42$config["allow_raw_sql"] = 0;
43$config["allow_be_verbose"] = 0;
44$config["debug"] = 0;
45
46foreach ($params as $param) {
47	switch (trim("{$param[0]}")) {
48		case "db":
49		case "mysql_server":
50		case "mysql_user":
51		case "mysql_pass":
52		case "mysql_db":
53		case "mysql_table":
54		case "mysql_ulog_db":
55		case "mysql_ulog_table":
56		case "mysql_data_db":
57		case "mysql_data_table":
58		case "mysql_wfwl_db":
59		case "pgsql_server":
60		case "pgsql_user":
61		case "pgsql_pass":
62		case "pgsql_db":
63		case "pgsql_table":
64		case "pgsql_ulog_schema":
65		case "pgsql_ulog_table":
66		case "pgsql_data_schema":
67		case "pgsql_data_table":
68		case "pgsql_wfwl_schema":
69		case "pgsql_geoip2_schema":
70        case "pgsql_join_collapse_limit":
71		case "wfwl_syslog":
72		case "syslog_dir":
73		case "syslog_filespec":
74		case "log_formats";
75		case "verbosity_level":
76		case "default_data_source":
77		case "data_source":
78		case "geoip_php_lookup":
79        case "geoip2_locale":
80        case "geoip2_file":
81		case "title":
82		case "refresh":
83		case "dformat":
84		case "timezone":
85		case "report_order":
86		case "show_select_data_source":
87		case "allow_show_sql":
88		case "allow_additional_where":
89		case "allow_raw_sql":
90		case "allow_be_verbose":
91		case "php_max_memory":
92		case "php_timeout":
93		case "php_update_timeout":
94		case "session_save_path":
95		case "debug":
96			$config[trim("{$param[0]}")] = trim(trim("{$param[1]}"), "\"'");
97			break;
98		default:
99			if (!substr(trim("{$param[0]}"), 0, 7) == "format.")
100				break;
101			$config[trim("{$param[0]}")] = trim(trim("{$param[1]}"), "\"'");
102			break;
103	}
104
105}
106unset ($params);
107
108if (!isset($config["mysql_data_db"])) {
109	if (isset($config["mysql_ulog_db"])) {
110		$config["mysql_data_db"] = $config["mysql_ulog_db"];
111	} elseif (isset($config["mysql_db"])) {
112		$config["mysql_data_db"] = $config["mysql_db"];
113	} else
114		$config["mysql_data_db"] = "";
115}
116if (!isset($config["mysql_data_table"])) {
117	if(isset($config["mysql_table"])) {
118		$config["mysql_data_table"] = $config["mysql_table"];
119	} elseif (isset($config["mysql_table"])) {
120		$config["mysql_data_table"] = $config["mysql_table"];
121	} else
122		$config["mysql_data_table"] = "ulog";
123}
124if (!isset($config["mysql_wfwl_db"]) and isset($config["mysql_db"])) {
125	$config["mysql_wfwl_db"] = $config["mysql_db"];
126} elseif (!isset($config["mysql_wfwl_db"])) {
127	$config["mysql_wfwl_db"] = "";
128}
129if (!isset($config["pgsql_data_table"])) {
130	if (isset($config["pgsql_ulog_table"])) {
131		$config["pgsql_data_table"] = $config["pgsql_ulog_table"];
132	} elseif (isset($config["pgsql_table"])) {
133		$config["pgsql_data_table"] = $config["pgsql_table"];
134	} else
135		$config["pgsql_data_table"] = "ulog";
136}
137if (!isset($config["pgsql_data_schema"]) and isset($config["pgsql_ulog_schema"])) {
138	$config["pgsql_data_schema"] = $config["pgsql_ulog_schema"];
139} elseif (!isset($config["pgsql_data_schema"])) {
140	$config["pgsql_data_schema"] = "public";
141}
142
143$config["have_cast"] = 0;
144
145switch ("{$config["db"]}") {
146	case "mysql":
147		$database = $config["mysql_wfwl_db"];
148		$data_d = "{$config["mysql_data_db"]}";
149		foreach (preg_split("/ +/","{$config["mysql_data_table"]}") as $v)
150			$data_t[] = "$data_d.$v";
151		$reports = "{$config["mysql_wfwl_db"]}.reports";
152		$hostnames = "{$config["mysql_wfwl_db"]}.hostnames";
153		$services = "{$config["mysql_wfwl_db"]}.services";
154		$update = "{$config["mysql_wfwl_db"]}.tmp_update";
155		$tmp_output = "{$config["mysql_wfwl_db"]}.tmp_output";
156		$allrows = "{$config["mysql_wfwl_db"]}.allrows";
157		$output = "{$config["mysql_wfwl_db"]}.output";
158		$q = "`";
159		$regexp = "REGEXP";
160		$inet_aton="inet_aton";
161		$inet_ntoa="inet_ntoa";
162		$inet_pton="wfwl_inet_pton";
163		$inet_ntop="wfwl_inet_ntop";
164		$inet_contains="wfwl_inet_contains";
165		$true = "1";
166		$config['cast_int'] = "UNSIGNED";
167		$config['tcast'] = "";
168		break;
169	case "pgsql":
170		$database = $config["pgsql_db"];
171		$data_d = "{$config["pgsql_data_schema"]}";
172		$allrows = "allrows";
173		$output = "output";
174		$tmp_output = "tmp_output";
175		$q = "\"";
176		$regexp = "~";
177		$true = "TRUE";
178		$config["have_cast"] = 1;
179		$config['cast_int'] = "INTEGER";
180		$config['cast_char'] = "char(32)";
181		$config['tcast'] = "::text";
182		$inet_pton="";
183		$inet_ntop="";
184		$inet_contains="";
185		break;
186	default:
187		$database = "none";
188		$data_d = "";
189		$data_t = "";
190		$reports = "";
191		$hostnames = "";
192		$services = "";
193		$tmp_output = "";
194		$output = "";
195		$inet_aton = "";
196		$inet_pton="";
197		$inet_ntop="";
198		$inet_contains="";
199		$true = "1";
200		break;
201}
202
203// show_sql is deprecated
204if (isset($config["allow_show_sql"])) {
205	$config["allow_be_verbose"] = "{$config["allow_show_sql"]}";
206	unset ($config["allow_show_sql"]);
207}
208
209// allow_additional_where is deprecated
210if (isset($config["allow_additional_where"])) {
211	$config["allow_raw_sql"] = "{$config["allow_additional_where"]}";
212	unset ($config["allow_additional_where"]);
213}
214
215if (isset($config["data_source"])) {
216	$config["default_data_source"] = "{$config["data_source"]}";
217	unset ($config["data_source"]);
218}
219
220if (isset($config["php_max_memory"])) {
221	ini_set("memory_limit", "{$config["php_max_memory"]}");
222}
223
224if (isset($config["php_timeout"])) {
225	set_time_limit("{$config["php_timeout"]}");
226}
227
228// Named constants
229if (! defined("AF_INET"))
230	define ("AF_INET", @WFWL_AF_INET@);
231if (! defined("AF_INET6"))
232	define ("AF_INET6", @WFWL_AF_INET6@);
233
234$webfwlog_version = "@PACKAGE_VERSION@";
235
236// vim:set ts=4:
237
238?>
239