ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  var $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  {
78  return self::$instance;
79  }
80  return self::$instance = new ilRadiusSettings();
81  }
82 
83  public function isActive()
84  {
85  return $this->active ? true : false;
86  }
87  public function setActive($a_status)
88  {
89  $this->active = $a_status;
90  }
91  public function setPort($a_port)
92  {
93  $this->port = $a_port;
94  }
95  public function getPort()
96  {
97  return $this->port;
98  }
99  public function setSecret($a_secret)
100  {
101  $this->secret = $a_secret;
102  }
103  public function getSecret()
104  {
105  return $this->secret;
106  }
107  public function setServerString($a_server_string)
108  {
109  $this->server_string = $a_server_string;
110  $this->servers = explode(',',$this->server_string);
111  }
112  public function getServersAsString()
113  {
114  return implode(',',$this->servers);
115  }
116  public function getServers()
117  {
118  return $this->servers ? $this->servers : array();
119  }
120  public function setName($a_name)
121  {
122  $this->name = $a_name;
123  }
124  public function getName()
125  {
126  return $this->name;
127  }
128 
135  public function toPearAuthArray()
136  {
137  foreach($this->getServers() as $server)
138  {
139  $auth_params['servers'][] = array($server,$this->getPort(),$this->getSecret());
140  }
141  return $auth_params ? $auth_params : array();
142  }
143 
151  public function getDefaultRole()
152  {
153  return $this->default_role;
154  }
155 
156  public function setDefaultRole($a_role)
157  {
158  $this->default_role = $a_role;
159  }
160 
167  public function enabledCreation()
168  {
169  return $this->creation;
170  }
171 
179  public function enableCreation($a_status)
180  {
181  $this->creation = $a_status;
182  }
183 
191  public function enableAccountMigration($a_status)
192  {
193  $this->account_migration = $a_status;
194  }
195 
202  public function isAccountMigrationEnabled()
203  {
204  return $this->account_migration ? true : false;
205  }
206 
213  public function getCharset()
214  {
215  return $this->charset ? 1 : 0;
216  }
217 
225  public function setCharset($a_charset)
226  {
227  $this->charset = $a_charset;
228  }
229 
236  public function save()
237  {
238  // first delete old servers
239  $this->settings->deleteLike('radius_server%');
240 
241  $this->settings->set('radius_active',$this->isActive() ? 1 : 0);
242  $this->settings->set('radius_port',$this->getPort());
243  $this->settings->set('radius_shared_secret',$this->getSecret());
244  $this->settings->set('radius_name',$this->getName());
245  $this->settings->set('radius_creation',$this->enabledCreation() ? 1 : 0);
246  $this->settings->set('radius_migration',$this->isAccountMigrationEnabled() ? 1 : 0);
247  $this->settings->set('radius_charset',$this->getCharset() ? 1 : 0);
248 
249  $counter = 0;
250  foreach($this->getServers() as $server)
251  {
252  if(++$counter == 1)
253  {
254  $this->settings->set('radius_server',trim($server));
255  }
256  else
257  {
258  $this->settings->set('radius_server'.$counter,trim($server));
259  }
260  }
261 
262  include_once('./Services/AccessControl/classes/class.ilObjRole.php');
263  ilObjRole::_resetAuthMode('radius');
264 
265  if($this->getDefaultRole())
266  {
267  ilObjRole::_updateAuthMode(array($this->getDefaultRole() => 'radius'));
268  }
269  return true;
270  }
271 
278  public function validateRequired()
279  {
280  $ok = strlen($this->getServersAsString()) and strlen($this->getPort()) and strlen($this->getSecret()) and strlen($this->getName());
281 
282  $role_ok = true;
283  if($this->enabledCreation() and !$this->getDefaultRole())
284  {
285  $role_ok = false;
286  }
287  return $ok and $role_ok;
288  }
289 
296  public function validatePort()
297  {
298  return preg_match("/^[0-9]{0,5}$/",$this->getPort()) == 1;
299  }
300 
307  public function validateServers()
308  {
309  $servers = explode(",",$this->server_string);
310 
311  foreach ($servers as $server)
312  {
313  $server = trim($server);
314 
315  if (!ilUtil::isIPv4($server) and !ilUtil::isDN($server))
316  {
317  return false;
318  }
319  }
320  return true;
321  }
322 
323 
330  private function read()
331  {
332  $all_settings = $this->settings->getAll();
333 
334  $sets = array("radius_active" => "setActive",
335  "radius_port" => "setPort",
336  "radius_shared_secret" => "setSecret",
337  "radius_name" => "setName",
338  "radius_creation" => "enableCreation",
339  "radius_migration" => "enableAccountMigration",
340  "radius_charset" => "setCharset"
341  );
342  foreach ($sets as $s => $m)
343  {
344  if (isset($all_settings[$s]))
345  {
346  $this->$m($all_settings[$s]);
347  }
348  }
349 
350  reset($all_settings);
351  foreach($all_settings as $k => $v)
352  {
353  if (substr($k, 0, 13) == "radius_server")
354  {
355  $this->servers[] = $v;
356  }
357  }
358 
359  include_once('./Services/AccessControl/classes/class.ilObjRole.php');
360  $roles = ilObjRole::_getRolesByAuthMode('radius');
361  $this->default_role = 0;
362  if (isset($roles[0]) && $roles[0])
363  {
364  $this->default_role = $roles[0];
365  }
366  }
367 }
368 
369 
370 ?>