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_DEFAULT != 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 case "submitusernameassign":
00085 break;
00086
00087 case "submitusernameassist":
00088 submitUsernameAssistanceForm();
00089 break;
00090
00091 case "forgot_username":
00092 showUsernameAssistanceForm();
00093 break;
00094
00095 default :
00096 if (!empty($_GET["key"])) {
00097 showAssignPasswordForm();
00098 } else {
00099 showAssistanceForm();
00100 }
00101 break;
00102 }
00103
00104
00105 $ilias->auth->logout();
00106 session_destroy();
00107
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 function showAssistanceForm($message="", $username="", $email="")
00126 {
00127 global $tpl, $ilias, $lng;
00128
00129
00130 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_assistance.html");
00131 $tpl->setVariable("FORMACTION","pwassist.php?cmd=submitassist&lang=".$lng->getLangKey());
00132 $tpl->setVariable("TARGET","target=\"_parent\"");
00133 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00134 $tpl->setVariable("TXT_MESSAGE", str_replace("\\n","<br>",$message));
00135
00136 $contact_address = $ilias->getSetting("admin_email");
00137 $tpl->setVariable
00138 (
00139 "TXT_ENTER_USERNAME_AND_EMAIL",
00140 str_replace
00141 (
00142 "\\n","<br>",
00143 sprintf
00144 (
00145 $lng->txt("pwassist_enter_username_and_email"),
00146 "<a href=\"mailto:".$contact_address."\">".$contact_address."</a>"
00147 )
00148 )
00149 );
00150 $tpl->setVariable("TXT_USERNAME", $lng->txt("username"));
00151 $tpl->setVariable("TXT_EMAIL", $lng->txt("email"));
00152 $tpl->setVariable("USERNAME", $username);
00153 $tpl->setVariable("EMAIL", $email);
00154 $tpl->setVariable("TXT_SUBMIT", $lng->txt("submit"));
00155 $tpl->setVariable("BACK", $lng->txt("back"));
00156 $tpl->setVariable("LANG", $lng->getLangKey());
00157
00158 $tpl->show();
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 function showUsernameAssistanceForm($message="", $username="", $email="")
00177 {
00178 global $tpl, $ilias, $lng;
00179
00180
00181 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_username_assistance.html");
00182 $tpl->setVariable("FORMACTION","pwassist.php?cmd=submitusernameassist&lang=".$lng->getLangKey());
00183 $tpl->setVariable("TARGET","target=\"_parent\"");
00184 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00185 $tpl->setVariable("TXT_MESSAGE", str_replace("\\n","<br>",$message));
00186
00187 $contact_address = $ilias->getSetting("admin_email");
00188 $tpl->setVariable
00189 (
00190 "TXT_ENTER_USERNAME_AND_EMAIL",
00191 str_replace
00192 (
00193 "\\n","<br>",
00194 sprintf
00195 (
00196 $lng->txt("pwassist_enter_email"),
00197 "<a href=\"mailto:".$contact_address."\">".$contact_address."</a>"
00198 )
00199 )
00200 );
00201 $tpl->setVariable("TXT_USERNAME", $lng->txt("username"));
00202 $tpl->setVariable("TXT_EMAIL", $lng->txt("email"));
00203 $tpl->setVariable("USERNAME", $username);
00204 $tpl->setVariable("EMAIL", $email);
00205 $tpl->setVariable("TXT_SUBMIT", $lng->txt("submit"));
00206 $tpl->setVariable("BACK", $lng->txt("back"));
00207 $tpl->setVariable("LANG", $lng->getLangKey());
00208
00209 $tpl->show();
00210 }
00211
00224 function submitAssistanceForm()
00225 {
00226 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00227
00228 require_once "classes/class.ilObjUser.php";
00229 require_once "classes/class.ilUtil.php";
00230
00231
00232 $username = $_POST["username"];
00233 $email = $_POST["email"];
00234
00235
00236 $userObj = null;
00237 $userid = ilObjUser::getUserIdByLogin($username);
00238 if ($userid != 0)
00239 {
00240 $userObj = new ilObjUser($userid);
00241 if (strcasecmp($userObj->getEmail(), $email) != 0)
00242 {
00243 $userObj = null;
00244 }
00245 }
00246
00247
00248
00249 if ($userObj == null)
00250 {
00251 showAssistanceForm
00252 (
00253 $lng->txt("pwassist_invalid_username_or_email"),
00254 $username,
00255 $email
00256 );
00257 }
00258
00259
00260
00261
00262 else
00263 {
00264
00265
00266
00267
00268 if ($rbacreview->isAssigned($userObj->getID, ANONYMOUS_ROLE_ID)
00269 || $rbacreview->isAssigned($userObj->getID, SYSTEM_ROLE_ID)
00270 )
00271 {
00272 showAssistanceForm
00273 (
00274 $lng->txt("pwassist_not_permitted"),
00275 $username,
00276 $email
00277 );
00278 }
00279 else
00280 {
00281 sendPasswordAssistanceMail($userObj);
00282 showMessageForm
00283 (
00284 null,
00285 sprintf
00286 (
00287 $lng->txt("pwassist_mail_sent"),
00288 $email
00289 )
00290 );
00291 }
00292 }
00293 }
00294
00307 function submitUsernameAssistanceForm()
00308 {
00309 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00310
00311 require_once "classes/class.ilObjUser.php";
00312 require_once "classes/class.ilUtil.php";
00313
00314
00315 $email = $_POST["email"];
00316
00317
00318 $logins = ilObjUser::_getUserIdsByEmail($email);
00319
00320
00321
00322 if (count($logins)< 1)
00323 {
00324 showUsernameAssistanceForm
00325 (
00326 $lng->txt("pwassist_invalid_email"),
00327 "",
00328 $email
00329 );
00330 }
00331
00332
00333
00334
00335 else
00336 {
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 {
00354 sendUsernameAssistanceMail($email, $logins);
00355 showMessageForm
00356 (
00357 null,
00358 sprintf
00359 (
00360 $lng->txt("pwassist_mail_sent"),
00361 $email
00362 )
00363 );
00364 }
00365 }
00366 }
00367
00381 function sendPasswordAssistanceMail($userObj)
00382 {
00383 global $lng, $ilias;
00384
00385 include_once "classes/class.ilMailbox.php";
00386 include_once "classes/class.ilMimeMail.php";
00387 require_once "include/inc.pwassist_session_handler.php";
00388
00389
00390
00391 $pwassist_session = db_pwassist_session_find($userObj->getId());
00392 if (count($pwassist_session) == 0 || $pwassist_session["expires"] < time())
00393 {
00394
00395 $pwassist_session["pwassist_id"] = db_pwassist_create_id();
00396
00397 db_pwassist_session_write(
00398 $pwassist_session["pwassist_id"],
00399 3600,
00400 $userObj->getId()
00401 );
00402 }
00403
00404
00405 $server_url='http://'.$_SERVER['HTTP_HOST'].
00406 substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],'/')).
00407 '/';
00408 $pwassist_url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']
00409 ."?client_id=".$ilias->getClientId()
00410 ."&lang=".$lng->getLangKey()
00411 ."&key=".$pwassist_session["pwassist_id"];
00412 $contact_address=$ilias->getSetting("admin_email");
00413
00414 $mm = new ilMimeMail();
00415 $mm->Subject($lng->txt("pwassist_mail_subject"));
00416 $mm->From($contact_address);
00417 $mm->To($userObj->getEmail());
00418
00419 $mm->Body
00420 (
00421 str_replace
00422 (
00423 array("\\n","\\t"),
00424 array("\n","\t"),
00425 sprintf
00426 (
00427 $lng->txt("pwassist_mail_body"),
00428 $pwassist_url,
00429 $server_url,
00430 $_SERVER['REMOTE_ADDR'],
00431 $userObj->getLogin(),
00432 'mailto:'.$contact_address
00433 )
00434 )
00435 );
00436
00437 $mm->Send();
00438 }
00439
00440
00454 function sendUsernameAssistanceMail($email, $logins)
00455 {
00456 global $lng, $ilias;
00457
00458 include_once "classes/class.ilMailbox.php";
00459 include_once "classes/class.ilMimeMail.php";
00460 require_once "include/inc.pwassist_session_handler.php";
00461
00462
00463
00464 $server_url='http://'.$_SERVER['HTTP_HOST'].
00465 substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],'/')).
00466 '/';
00467 $login_url=$server_url."pwassist.php"
00468 ."?client_id=".$ilias->getClientId()
00469 ."&lang=".$lng->getLangKey();
00470
00471 $contact_address=$ilias->getSetting("admin_email");
00472
00473 $mm = new ilMimeMail();
00474 $mm->Subject($lng->txt("pwassist_mail_subject"));
00475 $mm->From($contact_address);
00476 $mm->To($email);
00477
00478 $mm->Body
00479 (
00480 str_replace
00481 (
00482 array("\\n","\\t"),
00483 array("\n","\t"),
00484 sprintf
00485 (
00486 $lng->txt("pwassist_username_mail_body"),
00487 join ($logins,",\n"),
00488 $server_url,
00489 $_SERVER['REMOTE_ADDR'],
00490 $email,
00491 'mailto:'.$contact_address,
00492 $login_url
00493 )
00494 )
00495 );
00496
00497 $mm->Send();
00498 }
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 function showAssignPasswordForm($message="", $username="", $password1="", $password2="", $pwassist_id="")
00520 {
00521 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00522
00523 require_once "include/inc.pwassist_session_handler.php";
00524 require_once "classes/class.ilLanguage.php";
00525
00526
00527 if ($pwassist_id == "")
00528 {
00529 $pwassist_id = $_GET["key"];
00530 }
00531
00532
00533 $pwassist_session = db_pwassist_session_read($pwassist_id);
00534 if (count($pwassist_session) == 0 || $pwassist_session["expires"] < time())
00535 {
00536 showAssistanceForm($lng->txt("pwassist_session_expired"));
00537 }
00538 else
00539 {
00540 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_assignpassword.html");
00541 $tpl->setVariable("FORMACTION","pwassist.php?cmd=submitassign&lang=".$lng->getLangKey());
00542 $tpl->setVariable("TARGET","target=\"_parent\"");
00543 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00544 $tpl->setVariable("TXT_MESSAGE",str_replace("\\n","<br>",$message));
00545 $tpl->setVariable("TXT_ENTER_USERNAME_AND_NEW_PASSWORD", $lng->txt("pwassist_enter_username_and_new_password"));
00546 $tpl->setVariable("TXT_USERNAME", $lng->txt("username"));
00547 $tpl->setVariable("TXT_PASSWORD1", $lng->txt("password"));
00548 $tpl->setVariable("TXT_PASSWORD2", $lng->txt("retype_password"));
00549 $tpl->setVariable("USERNAME", $username);
00550 $tpl->setVariable("PASSWORD1", $password1);
00551 $tpl->setVariable("PASSWORD2", $password2);
00552 $tpl->setVariable("TXT_SUBMIT", $lng->txt("submit"));
00553 $tpl->setVariable("KEY", $pwassist_id);
00554 $tpl->setVariable("BACK", $lng->txt("back"));
00555 $tpl->setVariable("LANG", $lng->getLangKey());
00556
00557 $tpl->show();
00558 }
00559 }
00560
00580 function submitAssignPasswordForm() {
00581 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00582
00583 require_once "include/inc.pwassist_session_handler.php";
00584
00585
00586 $pwassist_id = $_POST["key"];
00587 $username = $_POST["username"];
00588 $password1 = $_POST["password1"];
00589 $password2 = $_POST["password2"];
00590
00591
00592 $pwassist_session = db_pwassist_session_read($pwassist_id);
00593
00594 if (count($pwassist_session) == 0 || $pwassist_session["expires"] < time())
00595 {
00596 showAssistanceForm($lng->txt("pwassist_session_expired"));
00597 }
00598 else
00599 {
00600 $is_successful = true;
00601 $message = "";
00602
00603 $userObj = new ilObjUser($pwassist_session["user_id"]);
00604
00605
00606
00607
00608 if ($userObj == null)
00609 {
00610 $message = $lng->txt("user_does_not_exist");
00611 $is_successful = false;
00612 }
00613
00614
00615
00616 if ($is_successful && strcasecmp($userObj->getLogin(), $username) != 0)
00617 {
00618 $message = $lng->txt("pwassist_login_not_match");
00619 $is_successful = false;
00620 }
00621
00622
00623
00624 if ($is_successful && $password1 != $password2)
00625 {
00626 $message = $lng->txt("passwd_not_match");
00627 $is_successful = false;
00628 }
00629
00630
00631 if ($is_successful && !ilUtil::isPassword($password1))
00632 {
00633 $message = $lng->txt("passwd_invalid");
00634 $is_successful = false;
00635 }
00636
00637
00638
00639
00640
00641 if ($is_successful)
00642 {
00643 $is_successful = $userObj->resetPassword($password1,$password2);
00644 if (! $is_successful)
00645 {
00646 $message = $lng->txt("passwd_invalid");
00647 }
00648 }
00649
00650
00651
00652 if ($is_successful)
00653 {
00654 $is_successfull = $userObj->update();
00655 if (! $is_successful)
00656 {
00657 $message = $lng->txt("update_error");
00658 }
00659 }
00660
00661
00662
00663
00664
00665 if ($is_successful)
00666 {
00667 db_pwassist_session_destroy($pwassist_id);
00668 showMessageForm
00669 (
00670 null,
00671 sprintf
00672 (
00673 $lng->txt("pwassist_password_assigned"),
00674 $username
00675 )
00676 );
00677 }
00678 else
00679 {
00680 showAssignPasswordForm
00681 (
00682 $message,
00683 $username,
00684 $password1,
00685 $password2,
00686 $pwassist_id
00687 );
00688 }
00689 }
00690 }
00691
00692
00693
00694
00695 function showMessageForm($message="", $text="")
00696 {
00697 global $tpl, $ilias, $lng;
00698
00699
00700 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_message.html");
00701 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00702 $tpl->setVariable("TXT_MESSAGE",str_replace("\\n","<br>",$message));
00703 $tpl->setVariable("TXT_TEXT",str_replace("\\n","<br>",$text));
00704 $tpl->setVariable("BACK", $lng->txt("back"));
00705 $tpl->setVariable("LANG", $lng->getLangKey());
00706
00707 $tpl->show();
00708 }
00709
00710 ?>