Subversion Repositories ALCASAR

Rev

Rev 1279 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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