ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilRadiusSettings.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 {
36 
37  const SYNC_DISABLED = 0;
38  const SYNC_RADIUS = 1;
39  const SYNC_LDAP = 2;
40 
41 
42  private $settings;
43  private $db;
44  private static $instance = null;
45 
46  private $account_migration = false;
47 
48  private $servers = array();
49  public $active = false;
50 
57  private function __construct()
58  {
59  global $ilSetting,$ilDB;
60 
61  $this->settings = $ilSetting;
62  $this->db = $ilDB;
63 
64  $this->read();
65  }
66 
74  public static function _getInstance()
75  {
76  if (isset(self::$instance) and self::$instance) {
77  return self::$instance;
78  }
79  return self::$instance = new ilRadiusSettings();
80  }
81 
82  public function isActive()
83  {
84  return $this->active ? true : false;
85  }
86  public function setActive($a_status)
87  {
88  $this->active = $a_status;
89  }
90  public function setPort($a_port)
91  {
92  $this->port = $a_port;
93  }
94  public function getPort()
95  {
96  return $this->port;
97  }
98  public function setSecret($a_secret)
99  {
100  $this->secret = $a_secret;
101  }
102  public function getSecret()
103  {
104  return $this->secret;
105  }
106  public function setServerString($a_server_string)
107  {
108  $this->server_string = $a_server_string;
109  $this->servers = explode(',', $this->server_string);
110  }
111  public function getServersAsString()
112  {
113  return implode(',', $this->servers);
114  }
115  public function getServers()
116  {
117  return $this->servers ? $this->servers : array();
118  }
119  public function setName($a_name)
120  {
121  $this->name = $a_name;
122  }
123  public function getName()
124  {
125  return $this->name;
126  }
127 
134  public function toPearAuthArray()
135  {
136  foreach ($this->getServers() as $server) {
137  $auth_params['servers'][] = array($server,$this->getPort(),$this->getSecret());
138  }
139  return $auth_params ? $auth_params : array();
140  }
141 
149  public function getDefaultRole()
150  {
151  return $this->default_role;
152  }
153 
154  public function setDefaultRole($a_role)
155  {
156  $this->default_role = $a_role;
157  }
158 
165  public function enabledCreation()
166  {
167  return $this->creation;
168  }
169 
177  public function enableCreation($a_status)
178  {
179  $this->creation = $a_status;
180  }
181 
189  public function enableAccountMigration($a_status)
190  {
191  $this->account_migration = $a_status;
192  }
193 
200  public function isAccountMigrationEnabled()
201  {
202  return $this->account_migration ? true : false;
203  }
204 
211  public function getCharset()
212  {
213  return $this->charset ? 1 : 0;
214  }
215 
223  public function setCharset($a_charset)
224  {
225  $this->charset = $a_charset;
226  }
227 
234  public function save()
235  {
236  // first delete old servers
237  $this->settings->deleteLike('radius_server%');
238 
239  $this->settings->set('radius_active', $this->isActive() ? 1 : 0);
240  $this->settings->set('radius_port', $this->getPort());
241  $this->settings->set('radius_shared_secret', $this->getSecret());
242  $this->settings->set('radius_name', $this->getName());
243  $this->settings->set('radius_creation', $this->enabledCreation() ? 1 : 0);
244  $this->settings->set('radius_migration', $this->isAccountMigrationEnabled() ? 1 : 0);
245  $this->settings->set('radius_charset', $this->getCharset() ? 1 : 0);
246 
247  $counter = 0;
248  foreach ($this->getServers() as $server) {
249  if (++$counter == 1) {
250  $this->settings->set('radius_server', trim($server));
251  } else {
252  $this->settings->set('radius_server' . $counter, trim($server));
253  }
254  }
255 
256  include_once('./Services/AccessControl/classes/class.ilObjRole.php');
257  ilObjRole::_resetAuthMode('radius');
258 
259  if ($this->getDefaultRole()) {
260  ilObjRole::_updateAuthMode(array($this->getDefaultRole() => 'radius'));
261  }
262  return true;
263  }
264 
271  public function validateRequired()
272  {
273  $ok = strlen($this->getServersAsString()) and strlen($this->getPort()) and strlen($this->getSecret()) and strlen($this->getName());
274 
275  $role_ok = true;
276  if ($this->enabledCreation() and !$this->getDefaultRole()) {
277  $role_ok = false;
278  }
279  return $ok and $role_ok;
280  }
281 
288  public function validatePort()
289  {
290  return preg_match("/^[0-9]{0,5}$/", $this->getPort()) == 1;
291  }
292 
299  public function validateServers()
300  {
301  $servers = explode(",", $this->server_string);
302 
303  foreach ($servers as $server) {
304  $server = trim($server);
305 
306  if (!ilUtil::isIPv4($server) and !ilUtil::isDN($server)) {
307  return false;
308  }
309  }
310  return true;
311  }
312 
313 
320  private function read()
321  {
322  $all_settings = $this->settings->getAll();
323 
324  $sets = array("radius_active" => "setActive",
325  "radius_port" => "setPort",
326  "radius_shared_secret" => "setSecret",
327  "radius_name" => "setName",
328  "radius_creation" => "enableCreation",
329  "radius_migration" => "enableAccountMigration",
330  "radius_charset" => "setCharset"
331  );
332  foreach ($sets as $s => $m) {
333  if (isset($all_settings[$s])) {
334  $this->$m($all_settings[$s]);
335  }
336  }
337 
338  reset($all_settings);
339  foreach ($all_settings as $k => $v) {
340  if (substr($k, 0, 13) == "radius_server") {
341  $this->servers[] = $v;
342  }
343  }
344 
345  include_once('./Services/AccessControl/classes/class.ilObjRole.php');
346  $roles = ilObjRole::_getRolesByAuthMode('radius');
347  $this->default_role = 0;
348  if (isset($roles[0]) && $roles[0]) {
349  $this->default_role = $roles[0];
350  }
351  }
352 }
toPearAuthArray()
Create options array for PEAR Auth constructor.
validatePort()
Validate port.
enableCreation($a_status)
Enable creation.
static isDN($a_str)
$secret
Definition: demo.php:27
validateRequired()
Validate required.
static _updateAuthMode($a_roles)
$s
Definition: pwgen.php:45
static isIPv4($a_str)
static _resetAuthMode($a_auth_mode)
Reset auth mode to default.
setServerString($a_server_string)
isAccountMigrationEnabled()
enabled account migration
$counter
__construct()
singleton constructor
if($format !==null) $name
Definition: metadata.php:146
getDefaultRole()
Get default role for new radius users.
static _getInstance()
singleton get instance
enabledCreation()
Enable creation of users.
static _getRolesByAuthMode($a_auth_mode)
Get roles by auth mode.
validateServers()
Validate servers.
Create styles array
The data for the language used.
$server
Definition: getUserInfo.php:12
$sets
Definition: fetch.php:11
setCharset($a_charset)
set charset
settings()
Definition: settings.php:2
enableAccountMigration($a_status)
Enable account migration.
global $ilSetting
Definition: privfeed.php:17
global $ilDB