Subversion Repositories ALCASAR

Rev

Rev 1709 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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