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 )
|
|
|
8 |
import_request_variables('GPC');
|
|
|
9 |
# If using sessions set use_session to 1 to also cache the config file
|
|
|
10 |
#
|
|
|
11 |
$use_session = 0;
|
|
|
12 |
unset($config);
|
|
|
13 |
unset($nas_list);
|
|
|
14 |
if ($use_session){
|
|
|
15 |
// Start session
|
|
|
16 |
@session_start();
|
|
|
17 |
if (isset($_SESSION['config']))
|
|
|
18 |
$config = $_SESSION['config'];
|
|
|
19 |
if (isset($_SESSION['nas_list']))
|
|
|
20 |
$nas_list = $_SESSION['nas_list'];
|
|
|
21 |
}
|
|
|
22 |
if (!isset($config)){
|
|
|
23 |
$ARR=file("/etc/freeradius-web/admin.conf");
|
|
|
24 |
$EXTRA_ARR = array();
|
|
|
25 |
foreach($ARR as $val) {
|
|
|
26 |
$val=chop($val);
|
|
|
27 |
if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
|
|
|
28 |
continue;
|
|
|
29 |
list($key,$v)=split(":[[:space:]]*",$val,2);
|
|
|
30 |
if (preg_match("/%\{(.+)\}/",$v,$matches)){
|
|
|
31 |
$val=$config[$matches[1]];
|
|
|
32 |
$v=preg_replace("/%\{$matches[1]\}/",$val,$v);
|
|
|
33 |
}
|
|
|
34 |
if (preg_match("/^nas(\d+)_(\w+)$/",$key,$matches))
|
|
|
35 |
$nas_list[$matches[1]][$matches[2]] = $v;
|
|
|
36 |
if ($key == 'INCLUDE'){
|
|
|
37 |
if (is_readable($v))
|
|
|
38 |
array_push($EXTRA_ARR,file($v));
|
|
|
39 |
else
|
|
|
40 |
echo "<b>Error: File '$v' does not exist or is not readable</b><br>\n";
|
|
|
41 |
}
|
|
|
42 |
else
|
|
|
43 |
$config["$key"]="$v";
|
|
|
44 |
}
|
|
|
45 |
foreach($EXTRA_ARR as $val1) {
|
|
|
46 |
foreach($val1 as $val){
|
|
|
47 |
$val=chop($val);
|
|
|
48 |
if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
|
|
|
49 |
continue;
|
|
|
50 |
list($key,$v)=split(":[[:space:]]*",$val,2);
|
|
|
51 |
if (preg_match("/%\{(.+)\}/",$v,$matches)){
|
|
|
52 |
$val=$config[$matches[1]];
|
|
|
53 |
$v=preg_replace("/%\{$matches[1]\}/",$val,$v);
|
|
|
54 |
}
|
|
|
55 |
if (preg_match("/^nas(\d+)_(\w+)$/",$key,$matches))
|
|
|
56 |
$nas_list[$matches[1]][$matches[2]] = $v;
|
|
|
57 |
$config["$key"]="$v";
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
if ($use_session){
|
|
|
61 |
session_register('config');
|
|
|
62 |
session_register('nas_list');
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
}
|
|
|
66 |
if ($use_session == 0 && $config['general_use_session'] == 'yes'){
|
|
|
67 |
// Start session
|
|
|
68 |
@session_start();
|
|
|
69 |
if (isset($nas_list))
|
|
|
70 |
session_register('nas_list');
|
|
|
71 |
}
|
|
|
72 |
//Make sure we are only passed allowed strings in username
|
|
|
73 |
if (isset($login)){
|
|
|
74 |
if ($login != '')
|
|
|
75 |
$login = preg_replace("/[^\w\.\/\@\:\-]/",'',$login);
|
|
|
76 |
if ($login != '' && $config['general_strip_realms'] == 'yes'){
|
|
|
77 |
$realm_del = ($config['general_realm_delimiter'] != '') ? $config['general_realm_delimiter'] : '@';
|
|
|
78 |
$realm_for = ($config['general_realm_format'] != '') ? $config['general_realm_format'] : 'suffix';
|
|
|
79 |
$new = explode($realm_del,$login,2);
|
|
|
80 |
if (count($new) == 2)
|
|
|
81 |
$login = ($realm_for == 'suffix') ? $new[0] : $new[1];
|
|
|
82 |
}
|
|
|
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 (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
|
|
|
92 |
continue;
|
|
|
93 |
list($key,$realm,$v)=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 = 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 |
//Include missing.php if needed
|
|
|
112 |
if (!function_exists('array_change_key_case'))
|
|
|
113 |
include_once('../lib/missing.php');
|
|
|
114 |
@header('Content-type: text/html; charset='.$config['general_charset'].';');
|
|
|
115 |
?>
|