/dialup_admin/conf/config.php

https://github.com/artisdom/freeradius-server · PHP · 117 lines · 103 code · 5 blank · 9 comment · 54 complexity · fd3d5c1bd0888d04642d36bd46161c54 MD5 · raw file

  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 (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 ($login != '')
  73. $login = preg_replace("/[^\w\.\/\@\:\-]/",'',$login);
  74. if ($login != '' && $config[general_strip_realms] == 'yes'){
  75. $realm_del = ($config[general_realm_delimiter] != '') ? $config[general_realm_delimiter] : '@';
  76. $realm_for = ($config[general_realm_format] != '') ? $config[general_realm_format] : 'suffix';
  77. $new = explode($realm_del,$login,2);
  78. if (count($new) == 2)
  79. $login = ($realm_for == 'suffix') ? $new[0] : $new[1];
  80. }
  81. unset($mappings);
  82. if (isset($_SESSION['mappings']))
  83. $mappings = $_SESSION['mappings'];
  84. if (!isset($mappings) && $config[general_username_mappings_file] != ''){
  85. $ARR = file($config[general_username_mappings_file]);
  86. foreach($ARR as $val){
  87. $val=chop($val);
  88. if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val))
  89. continue;
  90. list($key,$realm,$v)=preg_split("/:[[:space:]]*/",$val,3);
  91. if ($realm == 'accounting' || $realm == 'userdb' || $realm == 'nasdb' || $realm == 'nasadmin')
  92. $mappings["$key"][$realm] = $v;
  93. if ($realm == 'nasdb'){
  94. $NAS_ARR = array();
  95. $NAS_ARR = preg_split('/,/',$v);
  96. foreach ($nas_list as $key => $nas){
  97. foreach ($NAS_ARR as $nas_check){
  98. if ($nas_check == $nas[name])
  99. unset($nas_list[$key]);
  100. }
  101. }
  102. }
  103. }
  104. if ($config[general_use_session] == 'yes')
  105. session_register('mappings');
  106. }
  107. date_default_timezone_set($config[timezone]);
  108. //Include missing.php if needed
  109. if (!function_exists('array_change_key_case'))
  110. include_once('../lib/missing.php');
  111. @header('Content-type: text/html; charset='.$config[general_charset].';');
  112. ?>