import from HEAD
[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 if ($use_session){
13         // Start session
14         @session_start();
15 }
16 if (!isset($config)){
17         unset($nas_list);
18         $ARR=file("../conf/admin.conf");
19         $EXTRA_ARR = array();
20         foreach($ARR as $val) {
21                 $val=chop($val);
22                 if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
23                         continue;
24                 list($key,$v)=split(":[[:space:]]*",$val,2);
25                 if (preg_match("/%\{(.+)\}/",$v,$matches)){
26                         $val=$config[$matches[1]];
27                         $v=preg_replace("/%\{$matches[1]\}/",$val,$v);
28                 }
29                 if (preg_match("/^nas(\d+)_(\w+)$/",$key,$matches))
30                         $nas_list[$matches[1]][$matches[2]] = $v;
31                 if ($key == 'INCLUDE'){
32                         if (is_readable($v))
33                                 array_push($EXTRA_ARR,file($v));
34                         else
35                                 echo "<b>Error: File '$v' does not exist or is not readable</b><br>\n";
36                 }
37                 else
38                         $config["$key"]="$v";
39         }
40         foreach($EXTRA_ARR as $val1) {
41                 foreach($val1 as $val){
42                         $val=chop($val);
43                         if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
44                                 continue;
45                         list($key,$v)=split(":[[:space:]]*",$val,2);
46                         if (preg_match("/%\{(.+)\}/",$v,$matches)){
47                                 $val=$config[$matches[1]];
48                                 $v=preg_replace("/%\{$matches[1]\}/",$val,$v);
49                         }
50                         if (preg_match("/^nas(\d+)_(\w+)$/",$key,$matches))
51                                 $nas_list[$matches[1]][$matches[2]] = $v;
52                         $config["$key"]="$v";
53                 }
54         }
55         if ($use_session){
56                 session_register('config');
57                 session_register('nas_list');
58         }
59
60 }
61 if ($use_session == 0 && $config[general_use_session] == 'yes'){
62         // Start session
63         @session_start();
64 }
65 //Make sure we are only passed allowed strings in username
66 if ($login != '')
67         $login = preg_replace("/[^\w\s\.\/\@\:]\-i\=/",'',$login);
68
69 if ($login != '' && $config[general_strip_realms] == 'yes'){
70         $realm_del = ($config[general_realm_delimiter] != '') ? $config[general_realm_delimiter] : '@';
71         $realm_for = ($config[general_realm_format] != '') ? $config[general_realm_format] : 'suffix';
72         $new = explode($realm_del,$login,2);
73         if (count($new) == 2)
74                 $login = ($realm_for == 'suffix') ? $new[0] : $new[1];
75 }
76 if (!isset($mappings) && $config[general_username_mappings_file] != ''){
77         $ARR = file($config[general_username_mappings_file]);
78         foreach($ARR as $val){
79                 $val=chop($val);
80                 if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
81                         continue;
82                 list($key,$realm,$v)=split(":[[:space:]]*",$val,2);
83                 if ($realm == 'accounting' || $realm == 'userdb')
84                         $mappings["$key"][$realm] = $v;
85         }
86         if ($config[general_use_session] == 'yes')
87                 session_register('mappings');
88 }
89 ?>