import from branch_1_1:
[freeradius.git] / dialup_admin / conf / config.php3
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("../conf/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 ($login != '')
74         $login = preg_replace("/[^\w\.\/\@\:\-]/",'',$login);
75
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 unset($mappings);
84 if (isset($_SESSION['mappings']))
85         $mappings = $_SESSION['mappings'];
86 if (!isset($mappings) && $config[general_username_mappings_file] != ''){
87         $ARR = file($config[general_username_mappings_file]);
88         foreach($ARR as $val){
89                 $val=chop($val);
90                 if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
91                         continue;
92                 list($key,$realm,$v)=split(":[[:space:]]*",$val,3);
93                 if ($realm == 'accounting' || $realm == 'userdb' || $realm == 'nasdb' || $realm == 'nasadmin')
94                         $mappings["$key"][$realm] = $v;
95                 if ($realm == 'nasdb'){
96                         $NAS_ARR = array();
97                         $NAS_ARR = split(',',$v);
98                         foreach ($nas_list as $key => $nas){
99                                 foreach ($NAS_ARR as $nas_check){
100                                         if ($nas_check == $nas[name])
101                                                 unset($nas_list[$key]);
102                                 }
103                         }
104                 }
105         }
106         if ($config[general_use_session] == 'yes')
107                 session_register('mappings');
108 }
109
110 //Include missing.php3 if needed
111 if (!function_exists('array_change_key_case'))
112         include_once('../lib/missing.php3');
113 @header('Content-type: text/html; charset='.$config[general_charset].';');
114 ?>