ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  // TODO Handle more than one LDAP configuration
196  }
197 
199  {
200  $sync->setValue(ilRadiusSettings::SYNC_LDAP);
201  }
202  else
203  {
204  $sync->setValue(
205  $this->settings->enabledCreation() ?
208  }
209 
210  $form->addCommandButton('save',$this->lng->txt('save'));
211  $this->tpl->setVariable('SETTINGS_TABLE',$form->getHTML());
212  }
213 
220  public function save()
221  {
222  $this->settings->setActive((int) $_POST['active']);
223  $this->settings->setName(ilUtil::stripSlashes($_POST['name']));
224  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
225  $this->settings->setSecret(ilUtil::stripSlashes($_POST['secret']));
226  $this->settings->setServerString(ilUtil::stripSlashes($_POST['servers']));
227  $this->settings->setDefaultRole((int) $_POST['role']);
228  $this->settings->enableAccountMigration((int) $_POST['migration']);
229  $this->settings->setCharset((int) $_POST['charset']);
230  $this->settings->enableCreation(((int) $_POST['sync'] == ilRadiusSettings::SYNC_RADIUS) ? true : false);
231 
232  if(!$this->settings->validateRequired())
233  {
234  ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields"));
235  $this->settings();
236  return false;
237  }
238  if(!$this->settings->validatePort())
239  {
240  ilUtil::sendFailure($this->lng->txt("err_invalid_port"));
241  $this->settings();
242  return false;
243  }
244  if(!$this->settings->validateServers())
245  {
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'])
253  {
256  break;
257 
260  break;
261 
263  // TODO: handle multiple ldap configurations
265  break;
266  }
267 
268  $this->settings->save();
269  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
270  $this->settings();
271  return true;
272  }
273 
274 
281  private function initSettings()
282  {
283  include_once('Services/Radius/classes/class.ilRadiusSettings.php');
285 
286 
287  }
288 
289  private function prepareRoleSelection()
290  {
291  global $rbacreview,$ilObjDataCache;
292 
293  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
294  'object_data',
295  'title',
296  'obj_id');
297 
298  $select[0] = $this->lng->txt('links_select_one');
299  foreach($global_roles as $role_id)
300  {
301  $select[$role_id] = ilObject::_lookupTitle($role_id);
302  }
303 
304  return $select;
305  }
306 
313  private function prepareCharsetSelection()
314  {
315  return $select = array(ilRadiusSettings::RADIUS_CHARSET_UTF8 => 'UTF-8',
317  }
318 
319 }
320 ?>