ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjPrivacySecurityGUI.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 include_once("./classes/class.ilObjectGUI.php");
24 include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
25 include_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
26 
39 {
40  private static $ERROR_MESSAGE;
46  public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
47  {
48  $this->type = 'ps';
49  parent::ilObjectGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
50 
51  $this->lng->loadLanguageModule('ps');
52 
54  ilSecuritySettings::$SECURITY_SETTINGS_ERR_CODE_AUTO_HTTPS => $this->lng->txt("ps_error_message_https_header_missing"),
55  ilSecuritySettings::$SECURITY_SETTINGS_ERR_CODE_HTTPS_NOT_AVAILABLE => $this->lng->txt('https_not_possible'),
56  ilSecuritySettings::$SECURITY_SETTINGS_ERR_CODE_HTTP_NOT_AVAILABLE => $this->lng->txt('http_not_possible'),
57  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MIN_LENGTH => $this->lng->txt('ps_error_message_invalid_password_min_length'),
58  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_LENGTH => $this->lng->txt('ps_error_message_invalid_password_max_length'),
59  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_AGE => $this->lng->txt('ps_error_message_invalid_password_max_age'),
60  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_LOGIN_MAX_ATTEMPTS => $this->lng->txt('ps_error_message_invalid_login_max_attempts'),
61  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN2 => $this->lng->txt('ps_error_message_password_min2_because_chars_numbers'),
62  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN3 => $this->lng->txt('ps_error_message_password_min3_because_chars_numbers_specialchars'),
63  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MAX_LENGTH_LESS_MIN_LENGTH => $this->lng->txt('ps_error_message_password_max_less_min')
64  );
65  }
66 
73  public function executeCommand()
74  {
75  global $rbacsystem,$ilErr,$ilAccess;
76 
77  $next_class = $this->ctrl->getNextClass($this);
78  $cmd = $this->ctrl->getCmd();
79 
80  $this->prepareOutput();
81 
82  if(!$ilAccess->checkAccess('read','',$this->object->getRefId()))
83  {
84  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
85  }
86 
87  switch($next_class)
88  {
89  case 'ilpermissiongui':
90  $this->tabs_gui->setTabActive('perm_settings');
91  include_once("./classes/class.ilPermissionGUI.php");
92  $perm_gui =& new ilPermissionGUI($this);
93  $ret =& $this->ctrl->forwardCommand($perm_gui);
94  break;
95 
96  default:
97  if(!$cmd || $cmd == 'view')
98  {
99  $cmd = "showPrivacy";
100  }
101 
102  $this->$cmd();
103  break;
104  }
105  return true;
106  }
107 
114  public function getAdminTabs()
115  {
116  global $rbacsystem;
117 
118  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
119  {
120  $this->tabs_gui->addTarget("show_privacy",
121  $this->ctrl->getLinkTarget($this, "showPrivacy"),
122  'showPrivacy');
123  $this->tabs_gui->addTarget("show_security",
124  $this->ctrl->getLinkTarget($this, "showSecurity"),
125  'showSecurity');
126 
127  }
128 
129  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
130  {
131  $this->tabs_gui->addTarget("perm_settings",
132  $this->ctrl->getLinkTargetByClass('ilpermissiongui',"perm"),
133  array(),'ilpermissiongui');
134  }
135  }
136 
142  public function showPrivacy()
143  {
144  $privacy = ilPrivacySettings::_getInstance();
145 
146  $this->tabs_gui->setTabActive('show_privacy');
147  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.show_privacy.html','Services/PrivacySecurity');
148 
149  include_once('Modules/Course/classes/class.ilCourseAgreement.php');
151  {
152  $this->tpl->setCurrentBlock('warning_modify');
153  $this->tpl->setVariable('TXT_WARNING',$this->lng->txt('ps_warning_modify'));
154  $this->tpl->parseCurrentBlock();
155  }
156 
157  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
158  $this->tpl->setVariable('TXT_PRIVACY_PROTECTION',$this->lng->txt('ps_privacy_protection'));
159  $this->tpl->setVariable('TXT_PROFILE_EXPORT',$this->lng->txt('ps_profile_export'));
160  $this->tpl->setVariable('TXT_EXPORT_COURSE',$this->lng->txt('ps_export_course'));
161  $this->tpl->setVariable('TXT_EXPORT_CONFIRM',$this->lng->txt('ps_export_confirm'));
162  $this->tpl->setVariable('TXT_GRP_ACCESS',$this->lng->txt('ps_show_grp_access'));
163  $this->tpl->setVariable('TXT_CRS_ACCESS',$this->lng->txt('ps_show_crs_access'));
164 
165  // Check export
166  $this->tpl->setVariable('CHECK_EXPORT_COURSE',ilUtil::formCheckbox($privacy->enabledExport() ? 1 : 0,'export_course',1));
167  $this->tpl->setVariable('CHECK_EXPORT_CONFIRM',ilUtil::formCheckbox($privacy->confirmationRequired() ? 1 : 0,'export_confirm',1));
168  $this->tpl->setVariable('CHECK_GRP_ACCESS',ilUtil::formCheckbox($privacy->enabledGroupAccessTimes() ? 1 : 0,'grp_access_times',1));
169  $this->tpl->setVariable('CHECK_CRS_ACCESS',ilUtil::formCheckbox($privacy->enabledCourseAccessTimes() ? 1 : 0,'crs_access_times',1));
170 
171  // Fora statistics
172  $this->tpl->setVariable('TXT_STATISTICS',$this->lng->txt('enable_fora_statistics'));
173  $this->tpl->setVariable('TXT_FORA_STATISTICS',$this->lng->txt('enable_fora_statistics_desc'));
174  $this->tpl->setVariable('CHECK_FORA_STATISTICS',ilUtil::formCheckbox($privacy->enabledForaStatistics() ? 1 : 0,'fora_statistics',1));
175 
176  // Anonymous Fora enabled
177  $this->tpl->setVariable('TXT_ANONYMITY',$this->lng->txt('disable_anonymous_fora'));
178  $this->tpl->setVariable('TXT_ANONYMOUS_FORA',$this->lng->txt('disable_anonymous_fora_desc'));
179  $this->tpl->setVariable('CHECK_ANONYMOUS_FORA',ilUtil::formCheckbox($privacy->disabledAnonymousFora() ? 1 : 0,'anonymous_fora',1));
180 
181 
182  $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('save'));
183  }
184 
185 
191  public function showSecurity()
192  {
193 
194  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
195 
196  $security = ilSecuritySettings::_getInstance();
197  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.show_security.html','Services/PrivacySecurity');
198 
199  $this->tabs_gui->setTabActive('show_security');
200 
201  $form = new ilPropertyFormGUI();
202  $form->setFormAction($this->ctrl->getFormAction($this));
203  $form->setTitle($this->lng->txt('ps_security_protection'));
204 
205  // Form checkbox
206  $check = new ilCheckboxInputGUI($this->lng->txt('ps_auto_https'),'auto_https_detect_enabled');
207  $check->setOptionTitle($this->lng->txt('ps_auto_https_description'));
208  $check->setChecked($security->isAutomaticHTTPSEnabled() ? 1 : 0);
209  $check->setValue(1);
210 
211  $text = new ilTextInputGUI($this->lng->txt('ps_auto_https_header_name'),'auto_https_detect_header_name');
212  $text->setValue($security->getAutomaticHTTPSHeaderName());
213  $text->setSize(24);
214  $text->setMaxLength(64);
215  $check->addSubItem($text);
216 
217  $text = new ilTextInputGUI($this->lng->txt('ps_auto_https_header_value'),'auto_https_detect_header_value');
218  $text->setValue($security->getAutomaticHTTPSHeaderValue());
219  $text->setSize(24);
220  $text->setMaxLength(64);
221  $check->addSubItem($text);
222 
223  $form->addItem($check);
224 
225  $check2 = new ilCheckboxInputGUI($this->lng->txt('activate_https'),'https_enabled');
226  $check2->setChecked($security->isHTTPSEnabled() ? 1 : 0);
227  $check2->setValue(1);
228  $form->addItem($check2);
229 
230  $radio_group = new ilRadioGroupInputGUI($this->lng->txt('ps_account_security_mode'), 'account_security_mode' );
231  $radio_group->setValue($security->getAccountSecurityMode());
232 
233  $radio_opt = new ilRadioOption($this->lng->txt('ps_account_security_mode_default'),ilSecuritySettings::ACCOUNT_SECURITY_MODE_DEFAULT);
234  $radio_group->addOption($radio_opt);
235 
236  $radio_opt = new ilRadioOption($this->lng->txt('ps_account_security_mode_customized'),ilSecuritySettings::ACCOUNT_SECURITY_MODE_CUSTOMIZED);
237 
238  $check = new ilCheckboxInputGUI($this->lng->txt('ps_password_chars_and_numbers_enabled'),'password_chars_and_numbers_enabled');
239  $check->setChecked( $security->isPasswordCharsAndNumbersEnabled() ? 1 : 0 );
240  //$check->setOptionTitle($this->lng->txt('ps_password_chars_and_numbers_enabled'));
241  $check->setInfo($this->lng->txt('ps_password_chars_and_numbers_enabled_info'));
242  $radio_opt->addSubItem($check);
243 
244  $check = new ilCheckboxInputGUI($this->lng->txt('ps_password_special_chars_enabled'),'password_special_chars_enabled');
245  $check->setChecked( $security->isPasswordSpecialCharsEnabled() ? 1 : 0 );
246  //$check->setOptionTitle($this->lng->txt('ps_password_special_chars_enabled'));
247  $check->setInfo($this->lng->txt('ps_password_special_chars_enabled_info'));
248  $radio_opt->addSubItem($check);
249 
250  $text = new ilTextInputGUI($this->lng->txt('ps_password_min_length'),'password_min_length');
251  $text->setInfo($this->lng->txt('ps_password_min_length_info'));
252  $text->setValue( $security->getPasswordMinLength() );
253  $text->setSize(1);
254  $text->setMaxLength(2);
255  $radio_opt->addSubItem($text);
256 
257  $text = new ilTextInputGUI($this->lng->txt('ps_password_max_length'),'password_max_length');
258  $text->setInfo($this->lng->txt('ps_password_max_length_info'));
259  $text->setValue( $security->getPasswordMaxLength() );
260  $text->setSize(1);
261  $text->setMaxLength(2);
262  $radio_opt->addSubItem($text);
263 
264  $text = new ilTextInputGUI($this->lng->txt('ps_password_max_age'),'password_max_age');
265  $text->setInfo($this->lng->txt('ps_password_max_age_info'));
266  $text->setValue( $security->getPasswordMaxAge() );
267  $text->setSize(1);
268  $text->setMaxLength(2);
269  $radio_opt->addSubItem($text);
270 
271  $text = new ilTextInputGUI($this->lng->txt('ps_login_max_attempts'),'login_max_attempts');
272  $text->setInfo($this->lng->txt('ps_login_max_attempts_info'));
273  $text->setValue( $security->getLoginMaxAttempts() );
274  $text->setSize(1);
275  $text->setMaxLength(2);
276  $radio_opt->addSubItem($text);
277 
278  $radio_group->addOption($radio_opt);
279  $form->addItem($radio_group);
280 
281  $check = new ilCheckboxInputGUI($this->lng->txt('ps_password_change_on_first_login_enabled'),'password_change_on_first_login_enabled');
282  $check->setInfo($this->lng->txt('ps_password_change_on_first_login_enabled_info'));
283  $check->setChecked( $security->isPasswordChangeOnFirstLoginEnabled() ? 1 : 0 );
284  $form->addItem($check);
285 
286 
287  $form->addCommandButton('save_security',$this->lng->txt('save'));
288  $this->tpl->setVariable('NEW_FORM',$form->getHTML());
289  }
290 
297  public function save_privacy()
298  {
299  global $ilErr,$ilAccess;
300 
301  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
302  {
303  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
304  }
305 
306 
307  $privacy = ilPrivacySettings::_getInstance();
308  $privacy->enableExport((int) $_POST['export_course']);
309  $privacy->setConfirmationRequired((int) $_POST['export_confirm']);
310  $privacy->enableForaStatistics ((int) $_POST['fora_statistics']);
311  $privacy->disableAnonymousFora ((int) $_POST['anonymous_fora']);
312  $privacy->showGroupAccessTimes((int) $_POST['grp_access_times']);
313  $privacy->showCourseAccessTimes((int) $_POST['crs_access_times']);
314 
315  // validate settings
316  $code = $privacy->validate();
317 
318  // if error code != 0, display error and do not save
319  if ($code != 0)
320  {
321  $msg = $this->getErrorMessage ($code);
322  ilUtil::sendInfo($msg);
323  }
324  else
325  {
326  $privacy->save();
327  include_once('Modules/Course/classes/class.ilCourseAgreement.php');
329  ilUtil::sendInfo($this->lng->txt('settings_saved'));
330  }
331 
332  $this->showPrivacy();
333  }
334 
341  public function save_security()
342  {
343  global $ilErr,$ilAccess;
344 
345  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
346  {
347  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
348  }
349 
350 
351  $security = ilSecuritySettings::_getInstance();
352 
353  // auto https detection settings
354  $security->setAutomaticHTTPSEnabled((int) $_POST["auto_https_detect_enabled"]);
355  $security->setAutomaticHTTPSHeaderName($_POST["auto_https_detect_header_name"]);
356  $security->setAutomaticHTTPSHeaderValue($_POST["auto_https_detect_header_value"]);
357 
358  // ilias https handling settings
359  $security->setHTTPSEnabled($_POST["https_enabled"]);
360 
361  // account security settings
362  $security->setAccountSecurityMode((int) $_POST["account_security_mode"]);
363  $security->setPasswordCharsAndNumbersEnabled((bool) $_POST["password_chars_and_numbers_enabled"]);
364  $security->setPasswordSpecialCharsEnabled((bool) $_POST["password_special_chars_enabled"]);
365  $security->setPasswordMinLength((int) $_POST["password_min_length"]);
366  $security->setPasswordMaxLength((int) $_POST["password_max_length"]);
367  $security->setPasswordMaxAge((int) $_POST["password_max_age"]);
368  $security->setLoginMaxAttempts((int) $_POST["login_max_attempts"]);
369 
370  // change password on first login settings
371  $security->setPasswordChangeOnFirstLoginEnabled((bool) $_POST['password_change_on_first_login_enabled']);
372 
373 
374  // validate settings
375  $code = $security->validate();
376 
377  // if error code != 0, display error and do not save
378  if ($code != 0)
379  {
380  $msg = $this->getErrorMessage ($code);
381  ilUtil::sendInfo($msg);
382  } else
383  {
384  $security->save();
385  ilUtil::sendInfo($this->lng->txt('settings_saved'));
386  }
387 
388  $this->showSecurity();
389  }
390 
391 
399  private static function getErrorMessage ($code) {
401  }
402 }
403 ?>