ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjPrivacySecurityGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 include_once("./classes/class.ilObjectGUI.php");
4 include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
5 include_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
6 
19 {
20  private static $ERROR_MESSAGE;
26  public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
27  {
28  $this->type = 'ps';
29  parent::ilObjectGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
30 
31  $this->lng->loadLanguageModule('ps');
32 
34  ilSecuritySettings::$SECURITY_SETTINGS_ERR_CODE_AUTO_HTTPS => $this->lng->txt("ps_error_message_https_header_missing"),
35  ilSecuritySettings::$SECURITY_SETTINGS_ERR_CODE_HTTPS_NOT_AVAILABLE => $this->lng->txt('https_not_possible'),
36  ilSecuritySettings::$SECURITY_SETTINGS_ERR_CODE_HTTP_NOT_AVAILABLE => $this->lng->txt('http_not_possible'),
37  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MIN_LENGTH => $this->lng->txt('ps_error_message_invalid_password_min_length'),
38  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_LENGTH => $this->lng->txt('ps_error_message_invalid_password_max_length'),
39  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_AGE => $this->lng->txt('ps_error_message_invalid_password_max_age'),
40  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_LOGIN_MAX_ATTEMPTS => $this->lng->txt('ps_error_message_invalid_login_max_attempts'),
41  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN2 => $this->lng->txt('ps_error_message_password_min2_because_chars_numbers'),
42  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN3 => $this->lng->txt('ps_error_message_password_min3_because_chars_numbers_sc'),
43  ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MAX_LENGTH_LESS_MIN_LENGTH => $this->lng->txt('ps_error_message_password_max_less_min')
44  );
45  }
46 
53  public function executeCommand()
54  {
55  global $rbacsystem,$ilErr,$ilAccess;
56 
57  $next_class = $this->ctrl->getNextClass($this);
58  $cmd = $this->ctrl->getCmd();
59 
60  $this->prepareOutput();
61 
62  if(!$ilAccess->checkAccess('read','',$this->object->getRefId()))
63  {
64  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
65  }
66 
67  switch($next_class)
68  {
69  case 'ilpermissiongui':
70  $this->tabs_gui->setTabActive('perm_settings');
71  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
72  $perm_gui =& new ilPermissionGUI($this);
73  $ret =& $this->ctrl->forwardCommand($perm_gui);
74  break;
75 
76  default:
77  if(!$cmd || $cmd == 'view')
78  {
79  $cmd = "showPrivacy";
80  }
81 
82  $this->$cmd();
83  break;
84  }
85  return true;
86  }
87 
94  public function getAdminTabs()
95  {
96  global $rbacsystem;
97 
98  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
99  {
100  $this->tabs_gui->addTarget("show_privacy",
101  $this->ctrl->getLinkTarget($this, "showPrivacy"),
102  'showPrivacy');
103  $this->tabs_gui->addTarget("show_security",
104  $this->ctrl->getLinkTarget($this, "showSecurity"),
105  'showSecurity');
106 
107  }
108 
109  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
110  {
111  $this->tabs_gui->addTarget("perm_settings",
112  $this->ctrl->getLinkTargetByClass('ilpermissiongui',"perm"),
113  array(),'ilpermissiongui');
114  }
115  }
116 
122  public function showPrivacy()
123  {
124  $privacy = ilPrivacySettings::_getInstance();
125 
126  $this->tabs_gui->setTabActive('show_privacy');
127  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.show_privacy.html','Services/PrivacySecurity');
128 
129  include_once('Modules/Course/classes/class.ilCourseAgreement.php');
131  {
132  $this->tpl->setCurrentBlock('warning_modify');
133  $this->tpl->setVariable('TXT_WARNING',$this->lng->txt('ps_warning_modify'));
134  $this->tpl->parseCurrentBlock();
135  }
136 
137  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
138  $this->tpl->setVariable('TXT_PRIVACY_PROTECTION',$this->lng->txt('ps_privacy_protection'));
139  $this->tpl->setVariable('TXT_PROFILE_EXPORT',$this->lng->txt('ps_profile_export'));
140  $this->tpl->setVariable('TXT_EXPORT_COURSE',$this->lng->txt('ps_export_course'));
141  $this->tpl->setVariable('TXT_EXPORT_CONFIRM',$this->lng->txt('ps_export_confirm'));
142  $this->tpl->setVariable('TXT_GRP_ACCESS',$this->lng->txt('ps_show_grp_access'));
143  $this->tpl->setVariable('TXT_CRS_ACCESS',$this->lng->txt('ps_show_crs_access'));
144 
145  // Check export
146  $this->tpl->setVariable('CHECK_EXPORT_COURSE',ilUtil::formCheckbox($privacy->enabledExport() ? 1 : 0,'export_course',1));
147  $this->tpl->setVariable('CHECK_EXPORT_CONFIRM',ilUtil::formCheckbox($privacy->confirmationRequired() ? 1 : 0,'export_confirm',1));
148  $this->tpl->setVariable('CHECK_GRP_ACCESS',ilUtil::formCheckbox($privacy->enabledGroupAccessTimes() ? 1 : 0,'grp_access_times',1));
149  $this->tpl->setVariable('CHECK_CRS_ACCESS',ilUtil::formCheckbox($privacy->enabledCourseAccessTimes() ? 1 : 0,'crs_access_times',1));
150 
151  // Fora statistics
152  $this->tpl->setVariable('TXT_STATISTICS',$this->lng->txt('enable_fora_statistics'));
153  $this->tpl->setVariable('TXT_FORA_STATISTICS',$this->lng->txt('enable_fora_statistics_desc'));
154  $this->tpl->setVariable('CHECK_FORA_STATISTICS',ilUtil::formCheckbox($privacy->enabledForaStatistics() ? 1 : 0,'fora_statistics',1));
155 
156  // Anonymous Fora enabled
157  $this->tpl->setVariable('TXT_ANONYMITY',$this->lng->txt('disable_anonymous_fora'));
158  $this->tpl->setVariable('TXT_ANONYMOUS_FORA',$this->lng->txt('disable_anonymous_fora_desc'));
159  $this->tpl->setVariable('CHECK_ANONYMOUS_FORA',ilUtil::formCheckbox($privacy->disabledAnonymousFora() ? 1 : 0,'anonymous_fora',1));
160 
161 
162  $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('save'));
163  }
164 
165 
171  public function showSecurity()
172  {
173  global $ilSetting;
174 
175  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
176 
177  $security = ilSecuritySettings::_getInstance();
178  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.show_security.html','Services/PrivacySecurity');
179 
180  $this->tabs_gui->setTabActive('show_security');
181 
182  $form = new ilPropertyFormGUI();
183  $form->setFormAction($this->ctrl->getFormAction($this));
184  $form->setTitle($this->lng->txt('ps_security_protection'));
185 
186  // Form checkbox
187  $check = new ilCheckboxInputGUI($this->lng->txt('ps_auto_https'),'auto_https_detect_enabled');
188  $check->setOptionTitle($this->lng->txt('ps_auto_https_description'));
189  $check->setChecked($security->isAutomaticHTTPSEnabled() ? 1 : 0);
190  $check->setValue(1);
191 
192  $text = new ilTextInputGUI($this->lng->txt('ps_auto_https_header_name'),'auto_https_detect_header_name');
193  $text->setValue($security->getAutomaticHTTPSHeaderName());
194  $text->setSize(24);
195  $text->setMaxLength(64);
196  $check->addSubItem($text);
197 
198  $text = new ilTextInputGUI($this->lng->txt('ps_auto_https_header_value'),'auto_https_detect_header_value');
199  $text->setValue($security->getAutomaticHTTPSHeaderValue());
200  $text->setSize(24);
201  $text->setMaxLength(64);
202  $check->addSubItem($text);
203 
204  $form->addItem($check);
205 
206  $check2 = new ilCheckboxInputGUI($this->lng->txt('activate_https'),'https_enabled');
207  $check2->setChecked($security->isHTTPSEnabled() ? 1 : 0);
208  $check2->setValue(1);
209  $form->addItem($check2);
210 
211  $radio_group = new ilRadioGroupInputGUI($this->lng->txt('ps_account_security_mode'), 'account_security_mode' );
212  $radio_group->setValue($security->getAccountSecurityMode());
213 
214  $radio_opt = new ilRadioOption($this->lng->txt('ps_account_security_mode_default'),ilSecuritySettings::ACCOUNT_SECURITY_MODE_DEFAULT);
215  $radio_group->addOption($radio_opt);
216 
217  $radio_opt = new ilRadioOption($this->lng->txt('ps_account_security_mode_customized'),ilSecuritySettings::ACCOUNT_SECURITY_MODE_CUSTOMIZED);
218 
219  $check = new ilCheckboxInputGUI($this->lng->txt('ps_password_chars_and_numbers_enabled'),'password_chars_and_numbers_enabled');
220  $check->setChecked( $security->isPasswordCharsAndNumbersEnabled() ? 1 : 0 );
221  //$check->setOptionTitle($this->lng->txt('ps_password_chars_and_numbers_enabled'));
222  $check->setInfo($this->lng->txt('ps_password_chars_and_numbers_enabled_info'));
223  $radio_opt->addSubItem($check);
224 
225  $check = new ilCheckboxInputGUI($this->lng->txt('ps_password_special_chars_enabled'),'password_special_chars_enabled');
226  $check->setChecked( $security->isPasswordSpecialCharsEnabled() ? 1 : 0 );
227  //$check->setOptionTitle($this->lng->txt('ps_password_special_chars_enabled'));
228  $check->setInfo($this->lng->txt('ps_password_special_chars_enabled_info'));
229  $radio_opt->addSubItem($check);
230 
231  $text = new ilTextInputGUI($this->lng->txt('ps_password_min_length'),'password_min_length');
232  $text->setInfo($this->lng->txt('ps_password_min_length_info'));
233  $text->setValue( $security->getPasswordMinLength() );
234  $text->setSize(1);
235  $text->setMaxLength(2);
236  $radio_opt->addSubItem($text);
237 
238  $text = new ilTextInputGUI($this->lng->txt('ps_password_max_length'),'password_max_length');
239  $text->setInfo($this->lng->txt('ps_password_max_length_info'));
240  $text->setValue( $security->getPasswordMaxLength() );
241  $text->setSize(2);
242  $text->setMaxLength(3);
243  $radio_opt->addSubItem($text);
244 
245  $text = new ilTextInputGUI($this->lng->txt('ps_password_max_age'),'password_max_age');
246  $text->setInfo($this->lng->txt('ps_password_max_age_info'));
247  $text->setValue( $security->getPasswordMaxAge() );
248  $text->setSize(2);
249  $text->setMaxLength(3);
250  $radio_opt->addSubItem($text);
251 
252  $text = new ilTextInputGUI($this->lng->txt('ps_login_max_attempts'),'login_max_attempts');
253  $text->setInfo($this->lng->txt('ps_login_max_attempts_info'));
254  $text->setValue( $security->getLoginMaxAttempts() );
255  $text->setSize(1);
256  $text->setMaxLength(2);
257  $radio_opt->addSubItem($text);
258 
259  $radio_group->addOption($radio_opt);
260  $form->addItem($radio_group);
261 
262  $check = new ilCheckboxInputGUI($this->lng->txt('ps_password_change_on_first_login_enabled'),'password_change_on_first_login_enabled');
263  $check->setInfo($this->lng->txt('ps_password_change_on_first_login_enabled_info'));
264  $check->setChecked( $security->isPasswordChangeOnFirstLoginEnabled() ? 1 : 0 );
265  $form->addItem($check);
266 
267  // file suffix replacement
268  $ti = new ilTextInputGUI($this->lng->txt("file_suffix_repl"), "suffix_repl_additional");
269  $ti->setMaxLength(200);
270  $ti->setSize(40);
271  $ti->setInfo($this->lng->txt("file_suffix_repl_info")." ".SUFFIX_REPL_DEFAULT);
272  $ti->setValue($ilSetting->get("suffix_repl_additional"));
273  $form->addItem($ti);
274 
275  // prevent login from multiple pcs at the same time
276  $objCb = new ilCheckboxInputGUI($this->lng->txt('ps_prevent_simultaneous_logins'), 'ps_prevent_simultaneous_logins');
277  $objCb->setChecked((int)$security->isPreventionOfSimultaneousLoginsEnabled());
278  $objCb->setValue(1);
279  $objCb->setOptionTitle($this->lng->txt('ps_prevent_simultaneous_logins_info'));
280  $form->addItem($objCb);
281 
282 
283  $form->addCommandButton('save_security',$this->lng->txt('save'));
284  $this->tpl->setVariable('NEW_FORM',$form->getHTML());
285  }
286 
293  public function save_privacy()
294  {
295  global $ilErr,$ilAccess, $ilSetting;
296 
297  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
298  {
299  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
300  }
301 
302 
303  $privacy = ilPrivacySettings::_getInstance();
304  $privacy->enableExport((int) $_POST['export_course']);
305  $privacy->setConfirmationRequired((int) $_POST['export_confirm']);
306  $privacy->enableForaStatistics ((int) $_POST['fora_statistics']);
307  $privacy->disableAnonymousFora ((int) $_POST['anonymous_fora']);
308  $privacy->showGroupAccessTimes((int) $_POST['grp_access_times']);
309  $privacy->showCourseAccessTimes((int) $_POST['crs_access_times']);
310 
311  // validate settings
312  $code = $privacy->validate();
313 
314  // if error code != 0, display error and do not save
315  if ($code != 0)
316  {
317  $msg = $this->getErrorMessage ($code);
318  ilUtil::sendFailure($msg);
319  }
320  else
321  {
322  $privacy->save();
323  include_once('Modules/Course/classes/class.ilCourseAgreement.php');
325  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
326  }
327 
328  $this->showPrivacy();
329  }
330 
337  public function save_security()
338  {
339  global $ilErr,$ilAccess, $ilSetting;
340 
341  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
342  {
343  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
344  }
345 
346 
347  $security = ilSecuritySettings::_getInstance();
348 
349  // auto https detection settings
350  $security->setAutomaticHTTPSEnabled((int) $_POST["auto_https_detect_enabled"]);
351  $security->setAutomaticHTTPSHeaderName(ilUtil::stripSlashes($_POST["auto_https_detect_header_name"]));
352  $security->setAutomaticHTTPSHeaderValue(ilUtil::stripSlashes($_POST["auto_https_detect_header_value"]));
353 
354  // prevention of simultaneous logins with the same account
355  $security->setPreventionOfSimultaneousLogins((bool)$_POST['ps_prevent_simultaneous_logins']);
356 
357  // ilias https handling settings
358  $security->setHTTPSEnabled($_POST["https_enabled"]);
359 
360  // account security settings
361  $security->setAccountSecurityMode((int) $_POST["account_security_mode"]);
362  $security->setPasswordCharsAndNumbersEnabled((bool) $_POST["password_chars_and_numbers_enabled"]);
363  $security->setPasswordSpecialCharsEnabled((bool) $_POST["password_special_chars_enabled"]);
364  $security->setPasswordMinLength((int) $_POST["password_min_length"]);
365  $security->setPasswordMaxLength((int) $_POST["password_max_length"]);
366  $security->setPasswordMaxAge((int) $_POST["password_max_age"]);
367  $security->setLoginMaxAttempts((int) $_POST["login_max_attempts"]);
368 
369  // change password on first login settings
370  $security->setPasswordChangeOnFirstLoginEnabled((bool) $_POST['password_change_on_first_login_enabled']);
371 
372  // file suffic replacements
373  $ilSetting->set("suffix_repl_additional", $_POST["suffix_repl_additional"]);
374 
375  // validate settings
376  $code = $security->validate();
377 
378  // if error code != 0, display error and do not save
379  if ($code != 0)
380  {
381  $msg = $this->getErrorMessage ($code);
382  ilUtil::sendFailure($msg);
383  } else
384  {
385  $security->save();
386  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
387  }
388 
389  $this->showSecurity();
390  }
391 
392 
400  private static function getErrorMessage ($code) {
402  }
403 }
404 ?>