ILIAS  Release_4_0_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  $form = new ilPropertyFormGUI();
94  $form->setFormAction($this->ctrl->getFormAction($this));
95  $form->setTitle($this->lng->txt('auth_radius_configure'));
96 
97  // Form checkbox
98  $check = new ilCheckboxInputGUI($this->lng->txt('auth_radius_enable'),'active');
99  $check->setChecked($this->settings->isActive() ? 1 : 0);
100  $check->setValue(1);
101  $form->addItem($check);
102 
103  $text = new ilTextInputGUI($this->lng->txt('auth_radius_name'),'name');
104  $text->setRequired(true);
105  $text->setInfo($this->lng->txt('auth_radius_name_desc'));
106  $text->setValue($this->settings->getName());
107  $text->setSize(32);
108  $text->setMaxLength(64);
109  $form->addItem($text);
110 
111  $text = new ilTextInputGUI($this->lng->txt('auth_radius_server'),'servers');
112  $text->setRequired(true);
113  $text->setInfo($this->lng->txt('auth_radius_server_desc'));
114  $text->setValue($this->settings->getServersAsString());
115  $text->setSize(64);
116  $text->setMaxLength(255);
117  $form->addItem($text);
118 
119 
120  $text = new ilTextInputGUI($this->lng->txt('auth_radius_port'),'port');
121  $text->setRequired(true);
122  $text->setValue($this->settings->getPort());
123  $text->setSize(5);
124  $text->setMaxLength(5);
125  $form->addItem($text);
126 
127  $text = new ilTextInputGUI($this->lng->txt('auth_radius_shared_secret'),'secret');
128  $text->setRequired(true);
129  $text->setValue($this->settings->getSecret());
130  $text->setSize(16);
131  $text->setMaxLength(32);
132  $form->addItem($text);
133 
134  $encoding = new ilSelectInputGUI($this->lng->txt('auth_radius_charset'),'charset');
135  $encoding->setRequired(true);
136  $encoding->setOptions($this->prepareCharsetSelection());
137  $encoding->setValue($this->settings->getCharset());
138  $encoding->setInfo($this->lng->txt('auth_radius_charset_info'));
139  $form->addItem($encoding);
140 
141 
142  $check = new ilCheckboxInputGUI($this->lng->txt('auth_radius_sync'),'sync');
143  $check->setInfo($this->lng->txt('auth_radius_sync_info'));
144  $check->setChecked($this->settings->enabledCreation() ? 1 : 0);
145  $check->setValue(1);
146 
147 
148  $select = new ilSelectInputGUI($this->lng->txt('auth_radius_role_select'),'role');
149  $select->setOptions($this->prepareRoleSelection());
150  $select->setValue($this->settings->getDefaultRole());
151  $check->addSubItem($select);
152 
153  $migr = new ilCheckboxInputGUI($this->lng->txt('auth_rad_migration'),'migration');
154  $migr->setInfo($this->lng->txt('auth_rad_migration_info'));
155  $migr->setChecked($this->settings->isAccountMigrationEnabled() ? 1 : 0);
156  $migr->setValue(1);
157  $check->addSubItem($migr);
158  $form->addItem($check);
159 
160  $form->addCommandButton('save',$this->lng->txt('save'));
161  $this->tpl->setVariable('SETTINGS_TABLE',$form->getHTML());
162  }
163 
170  public function save()
171  {
172  $this->settings->setActive((int) $_POST['active']);
173  $this->settings->setName(ilUtil::stripSlashes($_POST['name']));
174  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
175  $this->settings->setSecret(ilUtil::stripSlashes($_POST['secret']));
176  $this->settings->setServerString(ilUtil::stripSlashes($_POST['servers']));
177  $this->settings->setDefaultRole((int) $_POST['role']);
178  $this->settings->enableCreation((int) $_POST['sync']);
179  $this->settings->enableAccountMigration((int) $_POST['migration']);
180  $this->settings->setCharset((int) $_POST['charset']);
181 
182  if(!$this->settings->validateRequired())
183  {
184  ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields"));
185  $this->settings();
186  return false;
187  }
188  if(!$this->settings->validatePort())
189  {
190  ilUtil::sendFailure($this->lng->txt("err_invalid_port"));
191  $this->settings();
192  return false;
193  }
194  if(!$this->settings->validateServers())
195  {
196  ilUtil::sendFailure($this->lng->txt("err_invalid_server"));
197  $this->settings();
198  return false;
199  }
200  $this->settings->save();
201  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
202  $this->settings();
203  return true;
204  }
205 
206 
213  private function initSettings()
214  {
215  include_once('Services/Radius/classes/class.ilRadiusSettings.php');
217 
218 
219  }
220 
221  private function prepareRoleSelection()
222  {
223  global $rbacreview,$ilObjDataCache;
224 
225  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
226  'object_data',
227  'title',
228  'obj_id');
229 
230  $select[0] = $this->lng->txt('links_select_one');
231  foreach($global_roles as $role_id)
232  {
233  $select[$role_id] = ilObject::_lookupTitle($role_id);
234  }
235 
236  return $select;
237  }
238 
245  private function prepareCharsetSelection()
246  {
247  return $select = array(ilRadiusSettings::RADIUS_CHARSET_UTF8 => 'UTF-8',
249  }
250 
251 }
252 ?>