summaryrefslogtreecommitdiffstats
path: root/web/lib/confparser.inc.php
blob: cb51e02abe9bfee0315084f1c3397af28a65e2dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

function config_load() {
	global $AUR_CONFIG;

	if (!isset($AUR_CONFIG)) {
		$path = getenv('AUR_CONFIG');
		if (!$path) {
			$path = "/etc/aurweb/config";
		}
		$defaults_path = getenv('AUR_CONFIG_DEFAULTS');
		if (!$defaults_path) {
			$defaults_path = path . ".defaults";
		}
		if (file_exists($defaults_path)) {
			$default_config = parse_ini_file($defaults_path, true, INI_SCANNER_RAW);
		} else {
			$default_config = [];
		}
		if (file_exists($path)) {
			$config = parse_ini_file($path, true, INI_SCANNER_RAW);
		} else {
			die("aurweb config file not found");
		}
		$AUR_CONFIG = array_replace_recursive($default_config, $config);
	}
}

function config_get($section, $key) {
	global $AUR_CONFIG;
	config_load();

	return $AUR_CONFIG[$section][$key];
}

function config_get_int($section, $key) {
	return intval(config_get($section, $key));
}

function config_get_bool($section, $key) {
	$val = strtolower(config_get($section, $key));
	return ($val == 'yes' || $val == 'true' || $val == '1');
}

function config_items($section) {
	global $AUR_CONFIG;
	config_load();

	return $AUR_CONFIG[$section];
}

function config_section_exists($key) {
	global $AUR_CONFIG;
	config_load();

	return array_key_exists($key, $AUR_CONFIG);
}