ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilRadiusSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  private $ref_id;
16 
24  public function __construct($a_auth_ref_id)
25  {
26  global $lng,$ilCtrl,$tpl,$ilTabs;
27 
28  $this->ctrl = $ilCtrl;
29  $this->tabs_gui = $ilTabs;
30  $this->lng = $lng;
31  $this->lng->loadLanguageModule('registration');
32  $this->lng->loadLanguageModule('auth');
33 
34  $this->tpl = $tpl;
35  $this->ref_id = $a_auth_ref_id;
36 
37  $this->initSettings();
38  }
39 
47  public function executeCommand()
48  {
49  global $ilAccess,$ilErr,$ilCtrl;
50 
51  $next_class = $this->ctrl->getNextClass($this);
52  $cmd = $this->ctrl->getCmd("settings");
53 
54  if(!$ilAccess->checkAccess('read','',$this->ref_id))
55  {
56  $ilErr->raiseError($this->lng->txt('msg_no_perm_write'),$ilErr->WARNING);
57  }
58 
59  if(!$ilAccess->checkAccess('write','',$this->ref_id) && $cmd != "settings")
60  {
61  ilUtil::sendFailure($this->lng->txt('msg_no_perm_write'), true);
62  $ilCtrl->redirect($this, "settings");
63  }
64 
65 
66  switch($next_class)
67  {
68  default:
69  if(!$cmd)
70  {
71  $cmd = "settings";
72  }
73  $this->$cmd();
74  break;
75  }
76  return true;
77 
78  }
79 
87  public function settings()
88  {
89  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
90 
91  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.settings.html','Services/Radius');
92 
93  $this->lng->loadLanguageModule('auth');
94 
95  $form = new ilPropertyFormGUI();
96  $form->setFormAction($this->ctrl->getFormAction($this));
97  $form->setTitle($this->lng->txt('auth_radius_configure'));
98 
99  // Form checkbox
100  $check = new ilCheckboxInputGUI($this->lng->txt('auth_radius_enable'),'active');
101  $check->setChecked($this->settings->isActive() ? 1 : 0);
102  $check->setValue(1);
103  $form->addItem($check);
104 
105  $text = new ilTextInputGUI($this->lng->txt('auth_radius_name'),'name');
106  $text->setRequired(true);
107  $text->setInfo($this->lng->txt('auth_radius_name_desc'));
108  $text->setValue($this->settings->getName());
109  $text->setSize(32);
110  $text->setMaxLength(64);
111  $form->addItem($text);
112 
113  $text = new ilTextInputGUI($this->lng->txt('auth_radius_server'),'servers');
114  $text->setRequired(true);
115  $text->setInfo($this->lng->txt('auth_radius_server_desc'));
116  $text->setValue($this->settings->getServersAsString());
117  $text->setSize(64);
118  $text->setMaxLength(255);
119  $form->addItem($text);
120 
121 
122  $text = new ilTextInputGUI($this->lng->txt('auth_radius_port'),'port');
123  $text->setRequired(true);
124  $text->setValue($this->settings->getPort());
125  $text->setSize(5);
126  $text->setMaxLength(5);
127  $form->addItem($text);
128 
129  $text = new ilTextInputGUI($this->lng->txt('auth_radius_shared_secret'),'secret');
130  $text->setRequired(true);
131  $text->setValue($this->settings->getSecret());
132  $text->setSize(16);
133  $text->setMaxLength(32);
134  $form->addItem($text);
135 
136  $encoding = new ilSelectInputGUI($this->lng->txt('auth_radius_charset'),'charset');
137  $encoding->setRequired(true);
138  $encoding->setOptions($this->prepareCharsetSelection());
139  $encoding->setValue($this->settings->getCharset());
140  $encoding->setInfo($this->lng->txt('auth_radius_charset_info'));
141  $form->addItem($encoding);
142 
143  // User synchronization
144  // 0: Disabled
145  // 1: Radius
146  // 2: LDAP
147  $sync = new ilRadioGroupInputGUI($this->lng->txt('auth_radius_sync'), 'sync');
148  $sync->setRequired(true);
149  #$sync->setInfo($this->lng->txt('auth_radius_sync_info'));
150  $form->addItem($sync);
151 
152  // Disabled
153  $dis = new ilRadioOption(
154  $this->lng->txt('disabled'),
156  ''
157  );
158  #$dis->setInfo($this->lng->txt('auth_radius_sync_disabled_info'));
159  $sync->addOption($dis);
160 
161  // Radius
162  $rad = new ilRadioOption(
163  $this->lng->txt('auth_radius_sync_rad'),
165  ''
166  );
167  $rad->setInfo($this->lng->txt('auth_radius_sync_rad_info'));
168  $sync->addOption($rad);
169 
170  $select = new ilSelectInputGUI($this->lng->txt('auth_radius_role_select'),'role');
171  $select->setOptions($this->prepareRoleSelection());
172  $select->setValue($this->settings->getDefaultRole());
173  $rad->addSubItem($select);
174 
175  $migr = new ilCheckboxInputGUI($this->lng->txt('auth_rad_migration'),'migration');
176  $migr->setInfo($this->lng->txt('auth_rad_migration_info'));
177  $migr->setChecked($this->settings->isAccountMigrationEnabled() ? 1 : 0);
178  $migr->setValue(1);
179  $rad->addSubItem($migr);
180 
181  // LDAP
182  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
184 
185  if(count($server_ids))
186  {
187  $ldap = new ilRadioOption(
188  $this->lng->txt('auth_radius_ldap'),
190  ''
191  );
192  $ldap->setInfo($this->lng->txt('auth_radius_ldap_info'));
193  $sync->addOption($ldap);
194 
195  $ldap_server_select = new ilSelectInputGUI($this->lng->txt('auth_ldap_server_ds'), 'ldap_sid');
196  $options[0] = $this->lng->txt('select_one');
197  foreach($server_ids as $ldap_sid)
198  {
199  $ldap_server = new ilLDAPServer($ldap_sid);
200  $options[$ldap_sid] = $ldap_server->getName();
201  }
202  $ldap_server_select->setOptions($options);
203  $ldap_server_select->setRequired(true);
205  $ldap_server_select->setValue($ds);
206 
207  $ldap->addSubItem($ldap_server_select);
208  }
209 
211  {
212  $sync->setValue(ilRadiusSettings::SYNC_LDAP);
213  }
214  else
215  {
216  $sync->setValue(
217  $this->settings->enabledCreation() ?
220  }
221 
222  $form->addCommandButton('save',$this->lng->txt('save'));
223  $this->tpl->setVariable('SETTINGS_TABLE',$form->getHTML());
224  }
225 
232  public function save()
233  {
234  $this->settings->setActive((int) $_POST['active']);
235  $this->settings->setName(ilUtil::stripSlashes($_POST['name']));
236  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
237  $this->settings->setSecret(ilUtil::stripSlashes($_POST['secret']));
238  $this->settings->setServerString(ilUtil::stripSlashes($_POST['servers']));
239  $this->settings->setDefaultRole((int) $_POST['role']);
240  $this->settings->enableAccountMigration((int) $_POST['migration']);
241  $this->settings->setCharset((int) $_POST['charset']);
242  $this->settings->enableCreation(((int) $_POST['sync'] == ilRadiusSettings::SYNC_RADIUS) ? true : false);
243 
244  if(!$this->settings->validateRequired())
245  {
246  ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields"));
247  $this->settings();
248  return false;
249  }
250  if(!$this->settings->validatePort())
251  {
252  ilUtil::sendFailure($this->lng->txt("err_invalid_port"));
253  $this->settings();
254  return false;
255  }
256  if(!$this->settings->validateServers())
257  {
258  ilUtil::sendFailure($this->lng->txt("err_invalid_server"));
259  $this->settings();
260  return false;
261  }
262 
263  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
264  switch((int) $_POST['sync'])
265  {
268  break;
269 
272  break;
273 
275  if(!(int) $_REQUEST['ldap_sid'])
276  {
277  ilUtil::sendFailure($this->lng->txt('err_check_input'));
278  $this->settings();
279  return false;
280  }
281 
282  ilLDAPServer::toggleDataSource((int) $_REQUEST['ldap_sid'], AUTH_RADIUS,true);
283  break;
284  }
285 
286  $this->settings->save();
287  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
288  $this->settings();
289  return true;
290  }
291 
292 
299  private function initSettings()
300  {
301  include_once('Services/Radius/classes/class.ilRadiusSettings.php');
303 
304 
305  }
306 
307  private function prepareRoleSelection()
308  {
309  global $rbacreview,$ilObjDataCache;
310 
311  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
312  'object_data',
313  'title',
314  'obj_id');
315 
316  $select[0] = $this->lng->txt('links_select_one');
317  foreach($global_roles as $role_id)
318  {
319  $select[$role_id] = ilObject::_lookupTitle($role_id);
320  }
321 
322  return $select;
323  }
324 
331  private function prepareCharsetSelection()
332  {
333  return $select = array(ilRadiusSettings::RADIUS_CHARSET_UTF8 => 'UTF-8',
335  }
336 
337 }
338 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
global $ilErr
Definition: raiseError.php:16
This class represents an option in a radio group.
This class represents a selection list property in a property form.
prepareCharsetSelection()
Get charset options.
This class represents a property form user interface.
__construct($a_auth_ref_id)
Constructor.
$cmd
Definition: sahs_server.php:35
static getAvailableDataSources($a_auth_mode)
This class represents a checkbox property in a property form.
executeCommand()
Execute command.
static _lookupTitle($a_id)
lookup object title
setInfo($a_info)
Set Info.
static disableDataSourceForAuthMode($a_authmode)
Disable data source.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
setChecked($a_checked)
Set Checked.
This class represents a property in a property form.
static isDataSourceActive($a_auth_mode)
Check if a data source is active for a specific auth mode ilDB $ilDB.
if(!is_array($argv)) $options
static _sortIds($a_ids, $a_table, $a_field, $a_id_name)
Function that sorts ids by a given table field using WHERE IN E.g: __sort(array(6,7),&#39;usr_data&#39;,&#39;lastname&#39;,&#39;usr_id&#39;) => sorts by lastname.
static _getInstance()
singleton get instance
This class represents a text property in a property form.
static getDataSource($a_auth_mode)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
setOptions($a_options)
Set Options.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:17
$text
initSettings()
Init Server settings.
$_POST["username"]
setRequired($a_required)
Set Required.
static toggleDataSource($a_ldap_server_id, $a_auth_mode, $a_status)
Toggle Data Source.
const AUTH_RADIUS