ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $ilErr->raiseError($this->lng->txt('msg_no_perm_write'), $ilErr->WARNING);
56  }
57 
58  if (!$ilAccess->checkAccess('write', '', $this->ref_id) && $cmd != "settings") {
59  ilUtil::sendFailure($this->lng->txt('msg_no_perm_write'), true);
60  $ilCtrl->redirect($this, "settings");
61  }
62 
63 
64  switch ($next_class) {
65  default:
66  if (!$cmd) {
67  $cmd = "settings";
68  }
69  $this->$cmd();
70  break;
71  }
72  return true;
73  }
74 
82  public function settings()
83  {
84  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
85 
86  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.settings.html', 'Services/Radius');
87 
88  $this->lng->loadLanguageModule('auth');
89 
90  $form = new ilPropertyFormGUI();
91  $form->setFormAction($this->ctrl->getFormAction($this));
92  $form->setTitle($this->lng->txt('auth_radius_configure'));
93 
94  // Form checkbox
95  $check = new ilCheckboxInputGUI($this->lng->txt('auth_radius_enable'), 'active');
96  $check->setChecked($this->settings->isActive() ? 1 : 0);
97  $check->setValue(1);
98  $form->addItem($check);
99 
100  $text = new ilTextInputGUI($this->lng->txt('auth_radius_name'), 'name');
101  $text->setRequired(true);
102  $text->setInfo($this->lng->txt('auth_radius_name_desc'));
103  $text->setValue($this->settings->getName());
104  $text->setSize(32);
105  $text->setMaxLength(64);
106  $form->addItem($text);
107 
108  $text = new ilTextInputGUI($this->lng->txt('auth_radius_server'), 'servers');
109  $text->setRequired(true);
110  $text->setInfo($this->lng->txt('auth_radius_server_desc'));
111  $text->setValue($this->settings->getServersAsString());
112  $text->setSize(64);
113  $text->setMaxLength(255);
114  $form->addItem($text);
115 
116 
117  $text = new ilTextInputGUI($this->lng->txt('auth_radius_port'), 'port');
118  $text->setRequired(true);
119  $text->setValue($this->settings->getPort());
120  $text->setSize(5);
121  $text->setMaxLength(5);
122  $form->addItem($text);
123 
124  $text = new ilTextInputGUI($this->lng->txt('auth_radius_shared_secret'), 'secret');
125  $text->setRequired(true);
126  $text->setValue($this->settings->getSecret());
127  $text->setSize(16);
128  $text->setMaxLength(32);
129  $form->addItem($text);
130 
131  $encoding = new ilSelectInputGUI($this->lng->txt('auth_radius_charset'), 'charset');
132  $encoding->setRequired(true);
133  $encoding->setOptions($this->prepareCharsetSelection());
134  $encoding->setValue($this->settings->getCharset());
135  $encoding->setInfo($this->lng->txt('auth_radius_charset_info'));
136  $form->addItem($encoding);
137 
138  // User synchronization
139  // 0: Disabled
140  // 1: Radius
141  // 2: LDAP
142  $sync = new ilRadioGroupInputGUI($this->lng->txt('auth_radius_sync'), 'sync');
143  $sync->setRequired(true);
144  #$sync->setInfo($this->lng->txt('auth_radius_sync_info'));
145  $form->addItem($sync);
146 
147  // Disabled
148  $dis = new ilRadioOption(
149  $this->lng->txt('disabled'),
151  ''
152  );
153  #$dis->setInfo($this->lng->txt('auth_radius_sync_disabled_info'));
154  $sync->addOption($dis);
155 
156  // Radius
157  $rad = new ilRadioOption(
158  $this->lng->txt('auth_radius_sync_rad'),
160  ''
161  );
162  $rad->setInfo($this->lng->txt('auth_radius_sync_rad_info'));
163  $sync->addOption($rad);
164 
165  $select = new ilSelectInputGUI($this->lng->txt('auth_radius_role_select'), 'role');
166  $select->setOptions($this->prepareRoleSelection());
167  $select->setValue($this->settings->getDefaultRole());
168  $rad->addSubItem($select);
169 
170  $migr = new ilCheckboxInputGUI($this->lng->txt('auth_rad_migration'), 'migration');
171  $migr->setInfo($this->lng->txt('auth_rad_migration_info'));
172  $migr->setChecked($this->settings->isAccountMigrationEnabled() ? 1 : 0);
173  $migr->setValue(1);
174  $rad->addSubItem($migr);
175 
176  // LDAP
177  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
179 
180  if (count($server_ids)) {
181  $ldap = new ilRadioOption(
182  $this->lng->txt('auth_radius_ldap'),
184  ''
185  );
186  $ldap->setInfo($this->lng->txt('auth_radius_ldap_info'));
187  $sync->addOption($ldap);
188 
189  $ldap_server_select = new ilSelectInputGUI($this->lng->txt('auth_ldap_server_ds'), 'ldap_sid');
190  $options[0] = $this->lng->txt('select_one');
191  foreach ($server_ids as $ldap_sid) {
192  $ldap_server = new ilLDAPServer($ldap_sid);
193  $options[$ldap_sid] = $ldap_server->getName();
194  }
195  $ldap_server_select->setOptions($options);
196  $ldap_server_select->setRequired(true);
198  $ldap_server_select->setValue($ds);
199 
200  $ldap->addSubItem($ldap_server_select);
201  }
202 
205  } else {
206  $sync->setValue(
207  $this->settings->enabledCreation() ?
210  );
211  }
212 
213  $form->addCommandButton('save', $this->lng->txt('save'));
214  $this->tpl->setVariable('SETTINGS_TABLE', $form->getHTML());
215  }
216 
223  public function save()
224  {
225  $this->settings->setActive((int) $_POST['active']);
226  $this->settings->setName(ilUtil::stripSlashes($_POST['name']));
227  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
228  $this->settings->setSecret(ilUtil::stripSlashes($_POST['secret']));
229  $this->settings->setServerString(ilUtil::stripSlashes($_POST['servers']));
230  $this->settings->setDefaultRole((int) $_POST['role']);
231  $this->settings->enableAccountMigration((int) $_POST['migration']);
232  $this->settings->setCharset((int) $_POST['charset']);
233  $this->settings->enableCreation(((int) $_POST['sync'] == ilRadiusSettings::SYNC_RADIUS) ? true : false);
234 
235  if (!$this->settings->validateRequired()) {
236  ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields"));
237  $this->settings();
238  return false;
239  }
240  if (!$this->settings->validatePort()) {
241  ilUtil::sendFailure($this->lng->txt("err_invalid_port"));
242  $this->settings();
243  return false;
244  }
245  if (!$this->settings->validateServers()) {
246  ilUtil::sendFailure($this->lng->txt("err_invalid_server"));
247  $this->settings();
248  return false;
249  }
250 
251  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
252  switch ((int) $_POST['sync']) {
255  break;
256 
259  break;
260 
262  if (!(int) $_REQUEST['ldap_sid']) {
263  ilUtil::sendFailure($this->lng->txt('err_check_input'));
264  $this->settings();
265  return false;
266  }
267 
268  ilLDAPServer::toggleDataSource((int) $_REQUEST['ldap_sid'], AUTH_RADIUS, true);
269  break;
270  }
271 
272  $this->settings->save();
273  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
274  $this->settings();
275  return true;
276  }
277 
278 
285  private function initSettings()
286  {
287  include_once('Services/Radius/classes/class.ilRadiusSettings.php');
289  }
290 
291  private function prepareRoleSelection()
292  {
293  global $rbacreview,$ilObjDataCache;
294 
295  $global_roles = ilUtil::_sortIds(
296  $rbacreview->getGlobalRoles(),
297  'object_data',
298  'title',
299  'obj_id'
300  );
301 
302  $select[0] = $this->lng->txt('links_select_one');
303  foreach ($global_roles as $role_id) {
304  $select[$role_id] = ilObject::_lookupTitle($role_id);
305  }
306 
307  return $select;
308  }
309 
316  private function prepareCharsetSelection()
317  {
318  return $select = array(ilRadiusSettings::RADIUS_CHARSET_UTF8 => 'UTF-8',
320  }
321 }
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.
$tpl
Definition: ilias.php:10
__construct($a_auth_ref_id)
Constructor.
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 $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(isset($_POST['submit'])) $form
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
$text
Definition: errorreport.php:18
This class represents a text property in a property form.
$sync
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
initSettings()
Init Server settings.
$_POST["username"]
setRequired($a_required)
Set Required.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
static toggleDataSource($a_ldap_server_id, $a_auth_mode, $a_status)
Toggle Data Source.
const AUTH_RADIUS