Subversion Repositories ALCASAR

Rev

Rev 1805 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1805 clement.si 1
<?php
2
#
3
# Things should work even if register_globals is set to off
4
#
5
 
6
$testVer=intval(str_replace(".", "",'4.1.0'));
7
$curVer=intval(str_replace(".", "",phpversion()));
8
if( $curVer >= $testVer )
9
	import_request_variables('GPC');
10
# If using sessions set use_session to 1 to also cache the config file
11
#
12
$use_session = 0;
13
unset($config);
14
unset($nas_list);
15
if ($use_session){
16
	// Start session
17
	@session_start();
18
	if (isset($_SESSION['config']))
19
		$config = $_SESSION['config'];
20
	if (isset($_SESSION['nas_list']))
21
		$nas_list = $_SESSION['nas_list'];
22
}
23
if (!isset($config)){
24
	$ARR=file("/etc/freeradius-web/admin.conf");
25
	$EXTRA_ARR = array();
26
	foreach($ARR as $val) {
27
		$val=chop($val);
28
		if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val))
29
			continue;
30
		list($key,$v)=preg_split("/:[[:space:]]*/",$val,2);
31
		if (preg_match("/%\{(.+)\}/",$v,$matches)){
32
			$val=$config[$matches[1]];
33
			$v=preg_replace("/%\{$matches[1]\}/",$val,$v);
34
		}
35
		if (preg_match("/^nas(\d+)_(\w+)$/",$key,$matches))
36
			$nas_list[$matches[1]][$matches[2]] = $v;
37
		if ($key == 'INCLUDE'){
38
			if (is_readable($v))
39
				array_push($EXTRA_ARR,file($v));
40
			else
41
				echo "<b>Error: File '$v' does not exist or is not readable</b><br>\n";
42
		}
43
		else
44
			$config["$key"]="$v";
45
	}
46
	foreach($EXTRA_ARR as $val1) {
47
		foreach($val1 as $val){
48
			$val=chop($val);
49
			if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val))
50
				continue;
51
			list($key,$v)=preg_split("/:[[:space:]]*/",$val,2);
52
			if (preg_match("/%\{(.+)\}/",$v,$matches)){
53
				$val=$config[$matches[1]];
54
				$v=preg_replace("/%\{$matches[1]\}/",$val,$v);
55
			}
56
			if (preg_match("/^nas(\d+)_(\w+)$/",$key,$matches))
57
				$nas_list[$matches[1]][$matches[2]] = $v;
58
			$config["$key"]="$v";
59
		}
60
	}
61
	if ($use_session){
62
		session_register('config');
63
		session_register('nas_list');
64
	}
65
 
66
}
67
if ($use_session == 0 && $config[general_use_session] == 'yes'){
68
	// Start session
69
	@session_start();
70
	if (isset($nas_list))
71
		session_register('nas_list');
72
}
73
//Make sure we are only passed allowed strings in username
74
if ($login != '')
75
	$login = preg_replace("/[^\w\.\/\@\:\-]/",'',$login);
76
 
77
if ($login != '' && $config[general_strip_realms] == 'yes'){
78
	$realm_del = ($config[general_realm_delimiter] != '') ? $config[general_realm_delimiter] : '@';
79
	$realm_for = ($config[general_realm_format] != '') ? $config[general_realm_format] : 'suffix';
80
	$new = explode($realm_del,$login,2);
81
	if (count($new) == 2)
82
		$login = ($realm_for == 'suffix') ? $new[0] : $new[1];
83
}
84
unset($mappings);
85
if (isset($_SESSION['mappings']))
86
	$mappings = $_SESSION['mappings'];
87
if (!isset($mappings) && $config[general_username_mappings_file] != ''){
88
	$ARR = file($config[general_username_mappings_file]);
89
	foreach($ARR as $val){
90
		$val=chop($val);
91
		if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val))
92
			continue;
93
		list($key,$realm,$v)=preg_split("/:[[:space:]]*/",$val,3);
94
		if ($realm == 'accounting' || $realm == 'userdb' || $realm == 'nasdb' || $realm == 'nasadmin')
95
			$mappings["$key"][$realm] = $v;
96
		if ($realm == 'nasdb'){
97
			$NAS_ARR = array();
98
			$NAS_ARR = preg_split('/,/',$v);
99
			foreach ($nas_list as $key => $nas){
100
				foreach ($NAS_ARR as $nas_check){
101
					if ($nas_check == $nas[name])
102
						unset($nas_list[$key]);
103
				}
104
			}
105
		}
106
	}
107
	if ($config[general_use_session] == 'yes')
108
		session_register('mappings');
109
}
110
 
111
date_default_timezone_set($config[timezone]);
112
 
113
//Include missing.php if needed
114
if (!function_exists('array_change_key_case'))
115
	include_once('../lib/missing.php');
116
@header('Content-type: text/html; charset='.$config[general_charset].';');
117
?>