PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/assets/snippets/weblogin/weblogin.inc.php

https://github.com/modxcms/evolution
PHP | 187 lines | 157 code | 12 blank | 18 comment | 38 complexity | dcd6a5129be12942bc143c24e8cb72c9 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MIT, BSD-2-Clause, Apache-2.0, BSD-3-Clause
  1. <?php
  2. # WebLogin 1.0
  3. # Created By Raymond Irving 2004
  4. #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  5. defined('IN_PARSER_MODE') or die();
  6. # load tpl
  7. if(is_numeric($tpl)) $tpl = ($doc=$modx->getDocuments($tpl)) ? $doc['content']:"Document '$tpl' not found.";
  8. else if($tpl)
  9. $tpl = (((substr(strtolower($tpl), 0, 5) == "@file") && ($chunk=file_get_contents(MODX_BASE_PATH.trim(substr($tpl, 6))))) || ($chunk=$modx->getChunk($tpl))) ? $chunk:"Chunk '$tpl' not found.";
  10. if(!$tpl) $tpl = getWebLogintpl();
  11. // extract declarations
  12. $declare = webLoginExtractDeclarations($tpl);
  13. $tpls = explode((isset($declare["separator"]) ? $declare["separator"]:"<!--tpl_separator-->"),$tpl);
  14. if(!isset($_SESSION['webValidated'])){
  15. ob_start();
  16. // if(isset($_COOKIE[$cookieKey])) {
  17. // $cookieSet = 1;
  18. // $sitename = $_COOKIE[$cookieKey];
  19. // $thepasswd = substr($site_id,-5)."crypto"; // create a password based on site id
  20. // $rc4 = new rc4crypt;
  21. // $thestring = $rc4->endecrypt($thepasswd,$sitename,'de');
  22. // $uid = $thestring;
  23. // }else{
  24. $uid = isset($_POST['username'])? $modx->db->escape(htmlspecialchars(trim($_POST['username']), ENT_QUOTES)):'';
  25. // }
  26. ?>
  27. <script type="text/JavaScript">
  28. <!--//--><![CDATA[//><!--
  29. function getElementById(id){
  30. var o, d=document;
  31. if (d.layers) {o=d.layers[id];if(o) o.style=o};
  32. if (!o && d.getElementById) o=d.getElementById(id);
  33. if (!o && d.all) o = d.all[id];
  34. return o;
  35. }
  36. function webLoginShowForm(i){
  37. var a = getElementById('WebLoginLayer0');
  38. var b = getElementById('WebLoginLayer2');
  39. if(i==1 && a && b) {
  40. a.style.display="block";
  41. b.style.display="none";
  42. document.forms['loginreminder'].txtpwdrem.value = 0;
  43. }
  44. else if(i==2 && a && b) {
  45. a.style.display="none";
  46. b.style.display="block";
  47. document.forms['loginreminder'].txtpwdrem.value = 1;
  48. }
  49. };
  50. function webLoginCheckRemember () {
  51. if(document.loginfrm.rememberme.value==1) {
  52. document.loginfrm.rememberme.value=0;
  53. } else {
  54. document.loginfrm.rememberme.value=1;
  55. }
  56. }
  57. function webLoginEnter(nextfield,event) {
  58. if(event && event.keyCode == 13) {
  59. if(nextfield.name=='cmdweblogin') {
  60. document.loginfrm.submit();
  61. return false;
  62. }
  63. else {
  64. nextfield.focus();
  65. return false;
  66. }
  67. } else {
  68. return true;
  69. }
  70. }
  71. //--><!]]>
  72. </script>
  73. <?php
  74. // display login
  75. $ref = isset($_REQUEST["refurl"]) ? array("refurl" => urlencode($_REQUEST["refurl"])) : array();
  76. $tpl = "<div id='WebLoginLayer0' style='position:relative'>".$tpls[0]."</div>";
  77. $tpl.= "<div id='WebLoginLayer2' style='position:relative;display:none'>".$tpls[2]."</div>";
  78. $tpl = str_replace("[+action+]",preserveUrl($modx->documentIdentifier,"",$ref),$tpl);
  79. $tpl = str_replace("[+rememberme+]",($_POST['rememberme'] ? 1 : 0),$tpl);
  80. $tpl = str_replace("[+username+]",$uid,$tpl);
  81. $tpl = str_replace("[+checkbox+]",($_POST['rememberme'] ? "checked='checked'" : ""),$tpl);
  82. $tpl = str_replace("[+logintext+]",$loginText,$tpl);
  83. echo $tpl;
  84. ?>
  85. <script type="text/javascript">
  86. if (document.loginfrm) <?php echo !empty($uid) ? "document.loginfrm.password.focus()" : "document.loginfrm.username.focus()" ?>;
  87. </script>
  88. <?php
  89. $output .= ob_get_contents();
  90. ob_end_clean();
  91. } else {
  92. $output= '';
  93. if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
  94. else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
  95. else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
  96. else $ip = "UNKNOWN";$_SESSION['ip'] = $ip;
  97. $itemid = isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ? $_REQUEST['id'] : 'NULL' ;$lasthittime = time();$a = 998;
  98. if($a!=1) {
  99. $sql = "REPLACE INTO ".$modx->getFullTableName('active_users')." (internalKey, username, lasthit, action, id, ip) values(-{$_SESSION['webInternalKey']}, '{$_SESSION['webShortname']}', '{$lasthittime}', '{$a}', {$itemid}, '{$ip}')";
  100. $modx->db->query($sql);
  101. }
  102. // display logout
  103. $tpl = $tpls[1];
  104. $url = preserveUrl($modx->documentObject['id']);
  105. $url = $url.((strpos($url,"?")===false) ? "?":"&amp;")."webloginmode=lo";
  106. $tpl = str_replace("[+action+]",$url,$tpl);
  107. $tpl = str_replace("[+logouttext+]",$logoutText,$tpl);
  108. $output .= $tpl;
  109. }
  110. # Returns Default WebLogin tpl
  111. function getWebLogintpl(){
  112. ob_start();
  113. ?>
  114. <!-- #declare:separator <hr> -->
  115. <!-- login form section-->
  116. <form method="post" name="loginfrm" action="[+action+]" style="margin: 0px; padding: 0px;">
  117. <input type="hidden" value="[+rememberme+]" name="rememberme" />
  118. <table border="0" cellspacing="0" cellpadding="0">
  119. <tr>
  120. <td>
  121. <table border="0" cellspacing="0" cellpadding="0">
  122. <tr>
  123. <td><b>User:</b></td>
  124. <td><input type="text" name="username" tabindex="1" onkeypress="return webLoginEnter(document.loginfrm.password);" size="8" style="width: 150px;" value="[+username+]" /></td>
  125. </tr>
  126. <tr>
  127. <td><b>Password:</b></td>
  128. <td><input type="password" name="password" tabindex="2" onkeypress="return webLoginEnter(document.loginfrm.cmdweblogin);" style="width: 150px;" value="" /></td>
  129. </tr>
  130. <tr>
  131. <td><label for="chkbox" style="cursor:pointer">Remember me:&nbsp; </label></td>
  132. <td>
  133. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  134. <tr>
  135. <td valign="top"><input type="checkbox" id="chkbox" name="chkbox" tabindex="4" size="1" value="" [+checkbox+] onclick="webLoginCheckRemember()" /></td>
  136. <td align="right">
  137. <input type="submit" value="[+logintext+]" name="cmdweblogin" /></td>
  138. </tr>
  139. </table>
  140. </td>
  141. </tr>
  142. <tr>
  143. <td colspan="2"><a href="#" onclick="webLoginShowForm(2);return false;">Forget Password?</a></td>
  144. </tr>
  145. </table>
  146. </td>
  147. </tr>
  148. </table>
  149. </form>
  150. <hr>
  151. <!-- log out hyperlink section -->
  152. <a href='[+action+]'>[+logouttext+]</a>
  153. <hr>
  154. <!-- Password reminder form section -->
  155. <form name="loginreminder" method="post" action="[+action+]" style="margin: 0px; padding: 0px;">
  156. <input type="hidden" name="txtpwdrem" value="0" />
  157. <table border="0">
  158. <tr>
  159. <td>Enter the email address of your account <br />below to receive your password:</td>
  160. </tr>
  161. <tr>
  162. <td><input type="text" name="txtwebemail" size="24" /></td>
  163. </tr>
  164. <tr>
  165. <td align="right"><input type="submit" value="Submit" name="cmdweblogin" />
  166. <input type="reset" value="Cancel" name="cmdcancel" onclick="webLoginShowForm(1);" /></td>
  167. </tr>
  168. </table>
  169. </form>
  170. <?php
  171. $t = ob_get_contents();
  172. ob_end_clean();
  173. return $t;
  174. }
  175. ?>