ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
19 private $dic;
20
21 private $ref_id;
22
30 public function __construct($a_auth_ref_id)
31 {
32 global $DIC;
33
34 $this->dic = $DIC;
35 $this->ctrl = $this->dic->ctrl();
36 $this->tabs_gui = $this->dic->tabs();
37 $this->lng = $this->dic->language();
38 $this->lng->loadLanguageModule('registration');
39 $this->lng->loadLanguageModule('auth');
40
41 $this->tpl = $this->dic['tpl'];
42 $this->ref_id = $a_auth_ref_id;
43
44 $this->initSettings();
45 }
46
54 public function executeCommand()
55 {
56 global $ilErr;
57
58 $next_class = $this->ctrl->getNextClass($this);
59 $cmd = $this->ctrl->getCmd("settings");
60
61 if (!$this->dic->rbac()->system()->checkAccess("visible,read", $this->ref_id)) {
62 $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->WARNING);
63 $this->dic->ctrl()->redirect($this, "settings");
64 }
65
66 switch ($next_class) {
67 default:
68 if (!$cmd) {
69 $cmd = "settings";
70 }
71 $this->$cmd();
72 break;
73 }
74 return true;
75 }
76
84 public function settings()
85 {
86 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
87
88 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.settings.html', 'Services/Radius');
89
90 $this->lng->loadLanguageModule('auth');
91
92 $form = new ilPropertyFormGUI();
93 $form->setFormAction($this->ctrl->getFormAction($this));
94 $form->setTitle($this->lng->txt('auth_radius_configure'));
95
96 // Form checkbox
97 $check = new ilCheckboxInputGUI($this->lng->txt('auth_radius_enable'), 'active');
98 $check->setChecked($this->settings->isActive() ? 1 : 0);
99 $check->setValue(1);
100 $form->addItem($check);
101
102 $text = new ilTextInputGUI($this->lng->txt('auth_radius_name'), 'name');
103 $text->setRequired(true);
104 $text->setInfo($this->lng->txt('auth_radius_name_desc'));
105 $text->setValue($this->settings->getName());
106 $text->setSize(32);
107 $text->setMaxLength(64);
108 $form->addItem($text);
109
110 $text = new ilTextInputGUI($this->lng->txt('auth_radius_server'), 'servers');
111 $text->setRequired(true);
112 $text->setInfo($this->lng->txt('auth_radius_server_desc'));
113 $text->setValue($this->settings->getServersAsString());
114 $text->setSize(64);
115 $text->setMaxLength(255);
116 $form->addItem($text);
117
118
119 $text = new ilTextInputGUI($this->lng->txt('auth_radius_port'), 'port');
120 $text->setRequired(true);
121 $text->setValue($this->settings->getPort());
122 $text->setSize(5);
123 $text->setMaxLength(5);
124 $form->addItem($text);
125
126 $text = new ilTextInputGUI($this->lng->txt('auth_radius_shared_secret'), 'secret');
127 $text->setRequired(true);
128 $text->setValue($this->settings->getSecret());
129 $text->setSize(16);
130 $text->setMaxLength(32);
131 $form->addItem($text);
132
133 $encoding = new ilSelectInputGUI($this->lng->txt('auth_radius_charset'), 'charset');
134 $encoding->setRequired(true);
135 $encoding->setOptions($this->prepareCharsetSelection());
136 $encoding->setValue($this->settings->getCharset());
137 $encoding->setInfo($this->lng->txt('auth_radius_charset_info'));
138 $form->addItem($encoding);
139
140 // User synchronization
141 // 0: Disabled
142 // 1: Radius
143 // 2: LDAP
144 $sync = new ilRadioGroupInputGUI($this->lng->txt('auth_radius_sync'), 'sync');
145 $sync->setRequired(true);
146 #$sync->setInfo($this->lng->txt('auth_radius_sync_info'));
147 $form->addItem($sync);
148
149 // Disabled
150 $dis = new ilRadioOption(
151 $this->lng->txt('disabled'),
153 ''
154 );
155 #$dis->setInfo($this->lng->txt('auth_radius_sync_disabled_info'));
156 $sync->addOption($dis);
157
158 // Radius
159 $rad = new ilRadioOption(
160 $this->lng->txt('auth_radius_sync_rad'),
162 ''
163 );
164 $rad->setInfo($this->lng->txt('auth_radius_sync_rad_info'));
165 $sync->addOption($rad);
166
167 $select = new ilSelectInputGUI($this->lng->txt('auth_radius_role_select'), 'role');
168 $select->setOptions($this->prepareRoleSelection());
169 $select->setValue($this->settings->getDefaultRole());
170 $rad->addSubItem($select);
171
172 $migr = new ilCheckboxInputGUI($this->lng->txt('auth_rad_migration'), 'migration');
173 $migr->setInfo($this->lng->txt('auth_rad_migration_info'));
174 $migr->setChecked($this->settings->isAccountMigrationEnabled() ? 1 : 0);
175 $migr->setValue(1);
176 $rad->addSubItem($migr);
177
178 // LDAP
179 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
181
182 if (count($server_ids)) {
183 $ldap = new ilRadioOption(
184 $this->lng->txt('auth_radius_ldap'),
186 ''
187 );
188 $ldap->setInfo($this->lng->txt('auth_radius_ldap_info'));
189 $sync->addOption($ldap);
190
191 $ldap_server_select = new ilSelectInputGUI($this->lng->txt('auth_ldap_server_ds'), 'ldap_sid');
192 $options[0] = $this->lng->txt('select_one');
193 foreach ($server_ids as $ldap_sid) {
194 $ldap_server = new ilLDAPServer($ldap_sid);
195 $options[$ldap_sid] = $ldap_server->getName();
196 }
197 $ldap_server_select->setOptions($options);
198 $ldap_server_select->setRequired(true);
200 $ldap_server_select->setValue($ds);
201
202 $ldap->addSubItem($ldap_server_select);
203 }
204
206 $sync->setValue(ilRadiusSettings::SYNC_LDAP);
207 } else {
208 $sync->setValue(
209 $this->settings->enabledCreation() ?
212 );
213 }
214
215 if ($this->dic->rbac()->system()->checkAccess('write', $this->ref_id)) {
216 $form->addCommandButton('save', $this->lng->txt('save'));
217 }
218 $this->tpl->setVariable('SETTINGS_TABLE', $form->getHTML());
219 }
220
227 public function save()
228 {
229 $this->settings->setActive((int) $_POST['active']);
230 $this->settings->setName(ilUtil::stripSlashes($_POST['name']));
231 $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
232 $this->settings->setSecret(ilUtil::stripSlashes($_POST['secret']));
233 $this->settings->setServerString(ilUtil::stripSlashes($_POST['servers']));
234 $this->settings->setDefaultRole((int) $_POST['role']);
235 $this->settings->enableAccountMigration((int) $_POST['migration']);
236 $this->settings->setCharset((int) $_POST['charset']);
237 $this->settings->enableCreation(((int) $_POST['sync'] == ilRadiusSettings::SYNC_RADIUS) ? true : false);
238
239 if (!$this->settings->validateRequired()) {
240 ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields"));
241 $this->settings();
242 return false;
243 }
244 if (!$this->settings->validatePort()) {
245 ilUtil::sendFailure($this->lng->txt("err_invalid_port"));
246 $this->settings();
247 return false;
248 }
249 if (!$this->settings->validateServers()) {
250 ilUtil::sendFailure($this->lng->txt("err_invalid_server"));
251 $this->settings();
252 return false;
253 }
254
255 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
256 switch ((int) $_POST['sync']) {
259 break;
260
263 break;
264
266 if (!(int) $_REQUEST['ldap_sid']) {
267 ilUtil::sendFailure($this->lng->txt('err_check_input'));
268 $this->settings();
269 return false;
270 }
271
272 ilLDAPServer::toggleDataSource((int) $_REQUEST['ldap_sid'], AUTH_RADIUS, true);
273 break;
274 }
275
276 $this->settings->save();
277 ilUtil::sendSuccess($this->lng->txt('settings_saved'));
278 $this->settings();
279 return true;
280 }
281
282
289 private function initSettings()
290 {
291 include_once('Services/Radius/classes/class.ilRadiusSettings.php');
293 }
294
295 private function prepareRoleSelection()
296 {
297 global $rbacreview,$ilObjDataCache;
298
299 $global_roles = ilUtil::_sortIds(
300 $rbacreview->getGlobalRoles(),
301 'object_data',
302 'title',
303 'obj_id'
304 );
305
306 $select[0] = $this->lng->txt('links_select_one');
307 foreach ($global_roles as $role_id) {
308 $select[$role_id] = ilObject::_lookupTitle($role_id);
309 }
310
311 return $select;
312 }
313
320 private function prepareCharsetSelection()
321 {
322 return $select = array(ilRadiusSettings::RADIUS_CHARSET_UTF8 => 'UTF-8',
324 }
325}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const AUTH_RADIUS
This class represents a checkbox property in a property form.
static getDataSource($a_auth_mode)
static disableDataSourceForAuthMode($a_authmode)
Disable data source.
static isDataSourceActive($a_auth_mode)
Check if a data source is active for a specific auth mode @global ilDB $ilDB.
static toggleDataSource($a_ldap_server_id, $a_auth_mode, $a_status)
Toggle Data Source.
static getAvailableDataSources($a_auth_mode)
static _lookupTitle($a_id)
lookup object title
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
__construct($a_auth_ref_id)
Constructor.
prepareCharsetSelection()
Get charset options.
initSettings()
Init Server settings.
executeCommand()
Execute command.
static _getInstance()
singleton get instance
This class represents a selection list property in a property form.
This class represents a text property in a property 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,...
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$ilErr
Definition: raiseError.php:18
$DIC
Definition: xapitoken.php:46