ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRadiusSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
35  private $ref_id;
36 
44  public function __construct($a_auth_ref_id)
45  {
46  global $lng,$ilCtrl,$tpl,$ilTabs;
47 
48  $this->ctrl = $ilCtrl;
49  $this->tabs_gui = $ilTabs;
50  $this->lng = $lng;
51  $this->lng->loadLanguageModule('registration');
52  $this->lng->loadLanguageModule('auth');
53 
54  $this->tpl = $tpl;
55  $this->ref_id = $a_auth_ref_id;
56 
57  $this->initSettings();
58  }
59 
67  public function executeCommand()
68  {
69  global $ilAccess,$ilErr;
70 
71  if(!$ilAccess->checkAccess('write','',$this->ref_id))
72  {
73  $ilErr->raiseError($this->lng->txt('msg_no_perm_write'),$ilErr->WARNING);
74  }
75 
76  $next_class = $this->ctrl->getNextClass($this);
77  $cmd = $this->ctrl->getCmd();
78 
79  switch($next_class)
80  {
81  default:
82  if(!$cmd)
83  {
84  $cmd = "settings";
85  }
86  $this->$cmd();
87  break;
88  }
89  return true;
90 
91  }
92 
100  public function settings()
101  {
102  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
103 
104  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.settings.html','Services/Radius');
105 
106  $form = new ilPropertyFormGUI();
107  $form->setFormAction($this->ctrl->getFormAction($this));
108  $form->setTitle($this->lng->txt('auth_radius_configure'));
109 
110  // Form checkbox
111  $check = new ilCheckboxInputGUI($this->lng->txt('auth_radius_enable'),'active');
112  $check->setChecked($this->settings->isActive() ? 1 : 0);
113  $check->setValue(1);
114  $form->addItem($check);
115 
116  $text = new ilTextInputGUI($this->lng->txt('auth_radius_name'),'name');
117  $text->setRequired(true);
118  $text->setInfo($this->lng->txt('auth_radius_name_desc'));
119  $text->setValue($this->settings->getName());
120  $text->setSize(32);
121  $text->setMaxLength(64);
122  $form->addItem($text);
123 
124  $text = new ilTextInputGUI($this->lng->txt('auth_radius_server'),'servers');
125  $text->setRequired(true);
126  $text->setInfo($this->lng->txt('auth_radius_server_desc'));
127  $text->setValue($this->settings->getServersAsString());
128  $text->setSize(64);
129  $text->setMaxLength(255);
130  $form->addItem($text);
131 
132 
133  $text = new ilTextInputGUI($this->lng->txt('auth_radius_port'),'port');
134  $text->setRequired(true);
135  $text->setValue($this->settings->getPort());
136  $text->setSize(5);
137  $text->setMaxLength(5);
138  $form->addItem($text);
139 
140  $text = new ilTextInputGUI($this->lng->txt('auth_radius_shared_secret'),'secret');
141  $text->setRequired(true);
142  $text->setValue($this->settings->getSecret());
143  $text->setSize(16);
144  $text->setMaxLength(32);
145  $form->addItem($text);
146 
147  $encoding = new ilSelectInputGUI($this->lng->txt('auth_radius_charset'),'charset');
148  $encoding->setRequired(true);
149  $encoding->setOptions($this->prepareCharsetSelection());
150  $encoding->setValue($this->settings->getCharset());
151  $encoding->setInfo($this->lng->txt('auth_radius_charset_info'));
152  $form->addItem($encoding);
153 
154 
155  $check = new ilCheckboxInputGUI($this->lng->txt('auth_radius_sync'),'sync');
156  $check->setInfo($this->lng->txt('auth_radius_sync_info'));
157  $check->setChecked($this->settings->enabledCreation() ? 1 : 0);
158  $check->setValue(1);
159 
160 
161  $select = new ilSelectInputGUI($this->lng->txt('auth_radius_role_select'),'role');
162  $select->setOptions($this->prepareRoleSelection());
163  $select->setValue($this->settings->getDefaultRole());
164  $check->addSubItem($select);
165 
166  $migr = new ilCheckboxInputGUI($this->lng->txt('auth_rad_migration'),'migration');
167  $migr->setInfo($this->lng->txt('auth_rad_migration_info'));
168  $migr->setChecked($this->settings->isAccountMigrationEnabled() ? 1 : 0);
169  $migr->setValue(1);
170  $check->addSubItem($migr);
171  $form->addItem($check);
172 
173 
174 
175  $form->addCommandButton('save',$this->lng->txt('save'));
176  $form->addCommandButton('cancel',$this->lng->txt('cancel'));
177  $this->tpl->setVariable('SETTINGS_TABLE',$form->getHTML());
178  }
179 
186  public function save()
187  {
188  $this->settings->setActive((int) $_POST['active']);
189  $this->settings->setName(ilUtil::stripSlashes($_POST['name']));
190  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
191  $this->settings->setSecret(ilUtil::stripSlashes($_POST['secret']));
192  $this->settings->setServerString(ilUtil::stripSlashes($_POST['servers']));
193  $this->settings->setDefaultRole((int) $_POST['role']);
194  $this->settings->enableCreation((int) $_POST['sync']);
195  $this->settings->enableAccountMigration((int) $_POST['migration']);
196  $this->settings->setCharset((int) $_POST['charset']);
197 
198  if(!$this->settings->validateRequired())
199  {
200  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields"));
201  $this->settings();
202  return false;
203  }
204  if(!$this->settings->validatePort())
205  {
206  ilUtil::sendInfo($this->lng->txt("err_invalid_port"));
207  $this->settings();
208  return false;
209  }
210  if(!$this->settings->validateServers())
211  {
212  ilUtil::sendInfo($this->lng->txt("err_invalid_server"));
213  $this->settings();
214  return false;
215  }
216  $this->settings->save();
217  ilUtil::sendInfo($this->lng->txt('settings_saved'));
218  $this->settings();
219  return true;
220  }
221 
222 
229  private function initSettings()
230  {
231  include_once('Services/Radius/classes/class.ilRadiusSettings.php');
233 
234 
235  }
236 
237  private function prepareRoleSelection()
238  {
239  global $rbacreview,$ilObjDataCache;
240 
241  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
242  'object_data',
243  'title',
244  'obj_id');
245 
246  $select[0] = $this->lng->txt('links_select_one');
247  foreach($global_roles as $role_id)
248  {
249  $select[$role_id] = ilObject::_lookupTitle($role_id);
250  }
251 
252  return $select;
253  }
254 
261  private function prepareCharsetSelection()
262  {
263  return $select = array(ilRadiusSettings::RADIUS_CHARSET_UTF8 => 'UTF-8',
265  }
266 
267 }
268 ?>