00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00033
00034
00035
00036
00037 if (isset($_GET["client_id"]))
00038 {
00039 setcookie("ilClientId",$_GET["client_id"]);
00040 $_COOKIE["ilClientId"] = $_GET["client_id"];
00041 }
00042
00043 require_once "include/inc.check_pear.php";
00044 require_once "include/inc.header.php";
00045
00046
00047
00048 if (! $ilias->getSetting("password_assistance") || AUTH_CURRENT != AUTH_LOCAL)
00049 {
00050 if (empty($_SESSION["AccountId"]) and $_SESSION["AccountId"] !== false)
00051 {
00052 $ilias->raiseError($lng->txt("permission_denied"),$ilias->error_obj->WARNING);
00053 }
00054 }
00055
00056
00057 if (!$ilias->getSetting("setup_ok"))
00058 {
00059 echo "setup is not completed. Please run setup routine again. (pwassist.php)";
00060 exit();
00061 }
00062
00063
00064
00065
00066 $lang = $_GET['lang'];
00067 if ($lang != null && $lang != "" && $lng->getLangKey() != $lang)
00068 {
00069 $lng = new ilLanguage($lang);
00070 }
00071 $lng->loadLanguageModule('pwassist');
00072
00073
00074 switch ($_GET["cmd"])
00075 {
00076 case "submitassign":
00077 submitAssignPasswordForm();
00078 break;
00079
00080 case "submitassist":
00081 submitAssistanceForm();
00082 break;
00083
00084 default :
00085 if (!empty($_GET["key"])) {
00086 showAssignPasswordForm();
00087 } else {
00088 showAssistanceForm();
00089 }
00090 break;
00091 }
00092
00093
00094 $ilias->auth->logout();
00095 session_destroy();
00096
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 function showAssistanceForm($message="", $username="", $email="")
00115 {
00116 global $tpl, $ilias, $lng;
00117
00118
00119 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_assistance.html");
00120 $tpl->setVariable("FORMACTION","pwassist.php?cmd=submitassist&lang=".$lng->getLangKey());
00121 $tpl->setVariable("TARGET","target=\"_parent\"");
00122 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00123 $tpl->setVariable("TXT_MESSAGE", str_replace("\\n","<br>",$message));
00124
00125 $contact_address = $ilias->getSetting("admin_email");
00126 $tpl->setVariable
00127 (
00128 "TXT_ENTER_USERNAME_AND_EMAIL",
00129 str_replace
00130 (
00131 "\\n","<br>",
00132 sprintf
00133 (
00134 $lng->txt("pwassist_enter_username_and_email"),
00135 "<a href=\"mailto:".$contact_address."\">".$contact_address."</a>"
00136 )
00137 )
00138 );
00139 $tpl->setVariable("TXT_USERNAME", $lng->txt("username"));
00140 $tpl->setVariable("TXT_EMAIL", $lng->txt("email"));
00141 $tpl->setVariable("USERNAME", $username);
00142 $tpl->setVariable("EMAIL", $email);
00143 $tpl->setVariable("TXT_SUBMIT", $lng->txt("submit"));
00144 $tpl->setVariable("BACK", $lng->txt("back"));
00145 $tpl->setVariable("LANG", $lng->getLangKey());
00146
00147 $tpl->show();
00148 }
00149
00162 function submitAssistanceForm()
00163 {
00164 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00165
00166 require_once "classes/class.ilObjUser.php";
00167 require_once "classes/class.ilUtil.php";
00168
00169
00170 $username = $_POST["username"];
00171 $email = $_POST["email"];
00172
00173
00174 $userObj = null;
00175 $userid = ilObjUser::getUserIdByLogin($username);
00176 if ($userid != 0)
00177 {
00178 $userObj = new ilObjUser($userid);
00179 if (strcasecmp($userObj->getEmail(), $email) != 0)
00180 {
00181 $userObj = null;
00182 }
00183 }
00184
00185
00186
00187 if ($userObj == null)
00188 {
00189 showAssistanceForm
00190 (
00191 $lng->txt("pwassist_invalid_username_or_email"),
00192 $username,
00193 $email
00194 );
00195 }
00196
00197
00198
00199
00200 else
00201 {
00202
00203
00204
00205
00206 if ($rbacreview->isAssigned($userObj->getID, ANONYMOUS_ROLE_ID)
00207 || $rbacreview->isAssigned($userObj->getID, SYSTEM_ROLE_ID)
00208 )
00209 {
00210 showAssistanceForm
00211 (
00212 $lng->txt("pwassist_not_permitted"),
00213 $username,
00214 $email
00215 );
00216 }
00217 else
00218 {
00219 sendPasswordAssistanceMail($userObj);
00220 showMessageForm
00221 (
00222 null,
00223 sprintf
00224 (
00225 $lng->txt("pwassist_mail_sent"),
00226 $email
00227 )
00228 );
00229 }
00230 }
00231 }
00232
00246 function sendPasswordAssistanceMail($userObj)
00247 {
00248 global $lng, $ilias;
00249
00250 include_once "classes/class.ilMailbox.php";
00251 include_once "classes/class.ilMimeMail.php";
00252 require_once "include/inc.pwassist_session_handler.php";
00253
00254
00255
00256 $pwassist_session = db_pwassist_session_find($userObj->getId());
00257 if (count($pwassist_session) == 0 || $pwassist_session["expires"] < time())
00258 {
00259
00260 $pwassist_session["pwassist_id"] = db_pwassist_create_id();
00261
00262 db_pwassist_session_write(
00263 $pwassist_session["pwassist_id"],
00264 3600,
00265 $userObj->getId()
00266 );
00267 }
00268
00269
00270 $server_url='http://'.$_SERVER['HTTP_HOST'].
00271 substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],'/')).
00272 '/';
00273 $pwassist_url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']
00274 ."?client_id=".$ilias->getClientId()
00275 ."&lang=".$lng->getLangKey()
00276 ."&key=".$pwassist_session["pwassist_id"];
00277 $contact_address=$ilias->getSetting("admin_email");
00278
00279 $mm = new ilMimeMail();
00280 $mm->Subject($lng->txt("pwassist_mail_subject"));
00281 $mm->From($contact_address);
00282 $mm->To($userObj->getEmail());
00283
00284 $mm->Body
00285 (
00286 str_replace
00287 (
00288 array("\\n","\\t"),
00289 array("\n","\t"),
00290 sprintf
00291 (
00292 $lng->txt("pwassist_mail_body"),
00293 $pwassist_url,
00294 $server_url,
00295 $_SERVER['REMOTE_ADDR'],
00296 $userObj->getLogin(),
00297 'mailto:'.$contact_address
00298 )
00299 )
00300 );
00301
00302 $mm->Send();
00303 }
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 function showAssignPasswordForm($message="", $username="", $password1="", $password2="", $pwassist_id="")
00325 {
00326 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00327
00328 require_once "include/inc.pwassist_session_handler.php";
00329 require_once "classes/class.ilLanguage.php";
00330
00331
00332 if ($pwassist_id == "")
00333 {
00334 $pwassist_id = $_GET["key"];
00335 }
00336
00337
00338 $pwassist_session = db_pwassist_session_read($pwassist_id);
00339 if (count($pwassist_session) == 0 || $pwassist_session["expires"] < time())
00340 {
00341 showAssistanceForm($lng->txt("pwassist_session_expired"));
00342 }
00343 else
00344 {
00345 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_assignpassword.html");
00346 $tpl->setVariable("FORMACTION","pwassist.php?cmd=submitassign&lang=".$lng->getLangKey());
00347 $tpl->setVariable("TARGET","target=\"_parent\"");
00348 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00349 $tpl->setVariable("TXT_MESSAGE",str_replace("\\n","<br>",$message));
00350 $tpl->setVariable("TXT_ENTER_USERNAME_AND_NEW_PASSWORD", $lng->txt("pwassist_enter_username_and_new_password"));
00351 $tpl->setVariable("TXT_USERNAME", $lng->txt("username"));
00352 $tpl->setVariable("TXT_PASSWORD1", $lng->txt("password"));
00353 $tpl->setVariable("TXT_PASSWORD2", $lng->txt("retype_password"));
00354 $tpl->setVariable("USERNAME", $username);
00355 $tpl->setVariable("PASSWORD1", $password1);
00356 $tpl->setVariable("PASSWORD2", $password2);
00357 $tpl->setVariable("TXT_SUBMIT", $lng->txt("submit"));
00358 $tpl->setVariable("KEY", $pwassist_id);
00359 $tpl->setVariable("BACK", $lng->txt("back"));
00360 $tpl->setVariable("LANG", $lng->getLangKey());
00361
00362 $tpl->show();
00363 }
00364 }
00365
00385 function submitAssignPasswordForm() {
00386 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00387
00388 require_once "include/inc.pwassist_session_handler.php";
00389
00390
00391 $pwassist_id = $_POST["key"];
00392 $username = $_POST["username"];
00393 $password1 = $_POST["password1"];
00394 $password2 = $_POST["password2"];
00395
00396
00397 $pwassist_session = db_pwassist_session_read($pwassist_id);
00398
00399 if (count($pwassist_session) == 0 || $pwassist_session["expires"] < time())
00400 {
00401 showAssistanceForm($lng->txt("pwassist_session_expired"));
00402 }
00403 else
00404 {
00405 $is_successful = true;
00406 $message = "";
00407
00408 $userObj = new ilObjUser($pwassist_session["user_id"]);
00409
00410
00411
00412
00413 if ($userObj == null)
00414 {
00415 $message = $lng->txt("user_does_not_exist");
00416 $is_successful = false;
00417 }
00418
00419
00420
00421 if ($is_successful && strcasecmp($userObj->getLogin(), $username) != 0)
00422 {
00423 $message = $lng->txt("pwassist_login_not_match");
00424 $is_successful = false;
00425 }
00426
00427
00428
00429 if ($is_successful && $password1 != $password2)
00430 {
00431 $message = $lng->txt("passwd_not_match");
00432 $is_successful = false;
00433 }
00434
00435
00436 if ($is_successful && !ilUtil::isPassword($password1))
00437 {
00438 $message = $lng->txt("passwd_invalid");
00439 $is_successful = false;
00440 }
00441
00442
00443
00444
00445
00446 if ($is_successful)
00447 {
00448 $is_successful = $userObj->resetPassword($password1,$password2);
00449 if (! $is_successful)
00450 {
00451 $message = $lng->txt("passwd_invalid");
00452 }
00453 }
00454
00455
00456
00457 if ($is_successful)
00458 {
00459 $is_successfull = $userObj->update();
00460 if (! $is_successful)
00461 {
00462 $message = $lng->txt("update_error");
00463 }
00464 }
00465
00466
00467
00468
00469
00470 if ($is_successful)
00471 {
00472 db_pwassist_session_destroy($pwassist_id);
00473 showMessageForm
00474 (
00475 null,
00476 sprintf
00477 (
00478 $lng->txt("pwassist_password_assigned"),
00479 $username
00480 )
00481 );
00482 }
00483 else
00484 {
00485 showAssignPasswordForm
00486 (
00487 $message,
00488 $username,
00489 $password1,
00490 $password2,
00491 $pwassist_id
00492 );
00493 }
00494 }
00495 }
00496
00497
00498
00499
00500 function showMessageForm($message="", $text="")
00501 {
00502 global $tpl, $ilias, $lng;
00503
00504
00505 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_message.html");
00506 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00507 $tpl->setVariable("TXT_MESSAGE",str_replace("\\n","<br>",$message));
00508 $tpl->setVariable("TXT_TEXT",str_replace("\\n","<br>",$text));
00509 $tpl->setVariable("BACK", $lng->txt("back"));
00510 $tpl->setVariable("LANG", $lng->getLangKey());
00511
00512 $tpl->show();
00513 }
00514
00515 ?>