1805 |
clement.si |
1 |
<?php
|
3173 |
rexy |
2 |
|
|
|
3 |
extract($_GET);
|
|
|
4 |
extract($_POST);
|
|
|
5 |
extract($_COOKIE);
|
1805 |
clement.si |
6 |
foreach($_POST as $key => $value){
|
|
|
7 |
${$key} = $value;
|
|
|
8 |
}
|
|
|
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 (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val))
|
|
|
28 |
continue;
|
|
|
29 |
list($key,$v)=preg_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 (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val))
|
|
|
49 |
continue;
|
|
|
50 |
list($key,$v)=preg_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 |
if ($use_session == 0 && $config['general_use_session'] == 'yes'){
|
|
|
66 |
// Start session
|
|
|
67 |
@session_start();
|
|
|
68 |
if (isset($nas_list))
|
|
|
69 |
session_register('nas_list');
|
|
|
70 |
}
|
|
|
71 |
//Make sure we are only passed allowed strings in username
|
|
|
72 |
if (isset($login)){
|
|
|
73 |
if ($login != '')
|
1836 |
raphael.pi |
74 |
{
|
|
|
75 |
$accent = "âêôûéàèùîáâãäçèéêëìíîïñòóôõöùúûü";
|
|
|
76 |
$login = preg_replace("/[^\w$accent\.\/\@\:\-]/",'',$login);
|
|
|
77 |
}
|
1805 |
clement.si |
78 |
if ($login != '' && $config['general_strip_realms'] == 'yes'){
|
|
|
79 |
$realm_del = ($config['general_realm_delimiter'] != '') ? $config['general_realm_delimiter'] : '@';
|
|
|
80 |
$realm_for = ($config['general_realm_format'] != '') ? $config['general_realm_format'] : 'suffix';
|
|
|
81 |
$new = explode($realm_del,$login,2);
|
|
|
82 |
if (count($new) == 2)
|
|
|
83 |
$login = ($realm_for == 'suffix') ? $new[0] : $new[1];
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
unset($mappings);
|
|
|
87 |
if (isset($_SESSION['mappings']))
|
|
|
88 |
$mappings = $_SESSION['mappings'];
|
|
|
89 |
if (!isset($mappings) && $config['general_username_mappings_file'] != ''){
|
|
|
90 |
$ARR = file($config['general_username_mappings_file']);
|
|
|
91 |
foreach($ARR as $val){
|
|
|
92 |
$val=chop($val);
|
|
|
93 |
if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val))
|
|
|
94 |
continue;
|
|
|
95 |
list($key,$realm,$v)=preg_split("/:[[:space:]]*/",$val,3);
|
|
|
96 |
if ($realm == 'accounting' || $realm == 'userdb' || $realm == 'nasdb' || $realm == 'nasadmin')
|
|
|
97 |
$mappings["$key"][$realm] = $v;
|
|
|
98 |
if ($realm == 'nasdb'){
|
|
|
99 |
$NAS_ARR = array();
|
|
|
100 |
$NAS_ARR = explode(',',$v);
|
|
|
101 |
foreach ($nas_list as $key => $nas){
|
|
|
102 |
foreach ($NAS_ARR as $nas_check){
|
|
|
103 |
if ($nas_check == $nas['name'])
|
|
|
104 |
unset($nas_list[$key]);
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
if ($config['general_use_session'] == 'yes')
|
|
|
110 |
session_register('mappings');
|
|
|
111 |
}
|
|
|
112 |
@header('Content-type: text/html; charset='.$config['general_charset'].';');
|
|
|
113 |
?>
|