Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00032 class ilRadiusSettings
00033 {
00034 const RADIUS_CHARSET_UTF8 = 0;
00035 const RADIUS_CHARSET_LATIN1 = 1;
00036
00037
00038 private $settings;
00039 private $db;
00040 private static $instance = null;
00041
00042 private $account_migration = false;
00043
00044 private $servers = array();
00045
00052 private function __construct()
00053 {
00054 global $ilSetting,$ilDB;
00055
00056 $this->settings = $ilSetting;
00057 $this->db = $ilDB;
00058
00059 $this->read();
00060 }
00061
00069 public static function _getInstance()
00070 {
00071 if(isset(self::$instance) and self::$instance)
00072 {
00073 return self::$instance;
00074 }
00075 return self::$instance = new ilRadiusSettings();
00076 }
00077
00078 public function isActive()
00079 {
00080 return $this->active ? true : false;
00081 }
00082 public function setActive($a_status)
00083 {
00084 $this->active = $a_status;
00085 }
00086 public function setPort($a_port)
00087 {
00088 $this->port = $a_port;
00089 }
00090 public function getPort()
00091 {
00092 return $this->port;
00093 }
00094 public function setSecret($a_secret)
00095 {
00096 $this->secret = $a_secret;
00097 }
00098 public function getSecret()
00099 {
00100 return $this->secret;
00101 }
00102 public function setServerString($a_server_string)
00103 {
00104 $this->server_string = $a_server_string;
00105 $this->servers = explode(',',$this->server_string);
00106 }
00107 public function getServersAsString()
00108 {
00109 return implode(',',$this->servers);
00110 }
00111 public function getServers()
00112 {
00113 return $this->servers ? $this->servers : array();
00114 }
00115 public function setName($a_name)
00116 {
00117 $this->name = $a_name;
00118 }
00119 public function getName()
00120 {
00121 return $this->name;
00122 }
00123
00130 public function toPearAuthArray()
00131 {
00132 foreach($this->getServers() as $server)
00133 {
00134 $auth_params['servers'][] = array($server,$this->getPort(),$this->getSecret());
00135 }
00136 return $auth_params ? $auth_params : array();
00137 }
00138
00146 public function getDefaultRole()
00147 {
00148 return $this->default_role;
00149 }
00150
00151 public function setDefaultRole($a_role)
00152 {
00153 $this->default_role = $a_role;
00154 }
00155
00162 public function enabledCreation()
00163 {
00164 return $this->creation;
00165 }
00166
00174 public function enableCreation($a_status)
00175 {
00176 $this->creation = $a_status;
00177 }
00178
00186 public function enableAccountMigration($a_status)
00187 {
00188 $this->account_migration = $a_status;
00189 }
00190
00197 public function isAccountMigrationEnabled()
00198 {
00199 return $this->account_migration ? true : false;
00200 }
00201
00208 public function getCharset()
00209 {
00210 return $this->charset ? 1 : 0;
00211 }
00212
00220 public function setCharset($a_charset)
00221 {
00222 $this->charset = $a_charset;
00223 }
00224
00231 public function save()
00232 {
00233
00234 $query = "DELETE FROM settings WHERE keyword LIKE('radius_server%')";
00235 $this->db->query($query);
00236
00237 $this->settings->set('radius_active',$this->isActive() ? 1 : 0);
00238 $this->settings->set('radius_port',$this->getPort());
00239 $this->settings->set('radius_shared_secret',$this->getSecret());
00240 $this->settings->set('radius_name',$this->getName());
00241 $this->settings->set('radius_creation',$this->enabledCreation() ? 1 : 0);
00242 $this->settings->set('radius_migration',$this->isAccountMigrationEnabled() ? 1 : 0);
00243 $this->settings->set('radius_charset',$this->getCharset() ? 1 : 0);
00244
00245 $counter = 0;
00246 foreach($this->getServers() as $server)
00247 {
00248 if(++$counter == 1)
00249 {
00250 $this->settings->set('radius_server',trim($server));
00251 }
00252 else
00253 {
00254 $this->settings->set('radius_server'.$counter,trim($server));
00255 }
00256 }
00257
00258 include_once('classes/class.ilObjRole.php');
00259 ilObjRole::_resetAuthMode('radius');
00260
00261 if($this->getDefaultRole())
00262 {
00263 ilObjRole::_updateAuthMode(array($this->getDefaultRole() => 'radius'));
00264 }
00265 return true;
00266 }
00267
00274 public function validateRequired()
00275 {
00276 $ok = strlen($this->getServersAsString()) and strlen($this->getPort()) and strlen($this->getSecret()) and strlen($this->getName());
00277
00278 $role_ok = true;
00279 if($this->enabledCreation() and !$this->getDefaultRole())
00280 {
00281 $role_ok = false;
00282 }
00283 return $ok and $role_ok;
00284 }
00285
00292 public function validatePort()
00293 {
00294 return preg_match("/^[0-9]{0,5}$/",$this->getPort()) == 1;
00295 }
00296
00303 public function validateServers()
00304 {
00305 $servers = explode(",",$this->server_string);
00306
00307 foreach ($servers as $server)
00308 {
00309 $server = trim($server);
00310
00311 if (!ilUtil::isIPv4($server) and !ilUtil::isDN($server))
00312 {
00313 return false;
00314 }
00315 }
00316 return true;
00317 }
00318
00319
00326 private function read()
00327 {
00328 $all_settings = $this->settings->getAll();
00329
00330 $this->setActive($all_settings['radius_active']);
00331 $this->setPort($all_settings['radius_port']);
00332 $this->setSecret($all_settings['radius_shared_secret']);
00333 $this->setName($all_settings['radius_name']);
00334 $this->enableCreation($all_settings['radius_creation']);
00335 $this->enableAccountMigration($all_settings['radius_migration']);
00336 $this->setCharset($all_settings['radius_charset']);
00337
00338 $query = "SELECT value FROM settings WHERE keyword LIKE 'radius_server%' ORDER BY keyword ASC";
00339 $res = $this->db->query($query);
00340
00341 while ($row = $res->fetchRow())
00342 {
00343 $this->servers[] = $row[0];
00344 }
00345
00346 include_once('classes/class.ilObjRole.php');
00347 $roles = ilObjRole::_getRolesByAuthMode('radius');
00348 $this->default_role = $roles[0] ? $roles[0] : 0;
00349 }
00350 }
00351
00352
00353 ?>