PageRenderTime 29ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/contents/login.inc.php

https://github.com/awriel/s3st15_matoa
PHP | 199 lines | 138 code | 16 blank | 45 comment | 31 complexity | 35c844d420db6c3dcc7b7a9d6e5dafbf MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * Librarian login page
  5. * Copyright (C) 2007,2008 Arie Nugraha (dicarve@yahoo.com), Hendro Wicaksono (hendrowicaksono@yahoo.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. */
  22. // be sure that this file not accessed directly
  23. if (!defined('INDEX_AUTH')) {
  24. die("can not access this file directly");
  25. } elseif (INDEX_AUTH != 1) {
  26. die("can not access this file directly");
  27. }
  28. if (defined('LIGHTWEIGHT_MODE')) {
  29. header('Location: index.php');
  30. }
  31. // required file
  32. require LIB_DIR.'admin_logon.inc.php';
  33. // https connection (if enabled)
  34. if ($sysconf['https_enable']) {
  35. simbio_security::doCheckHttps($sysconf['https_port']);
  36. }
  37. // check if session browser cookie already exists
  38. if (isset($_COOKIE['admin_logged_in'])) {
  39. header('location: admin/index.php');
  40. }
  41. // start the output buffering for main content
  42. ob_start();
  43. // if there is login action
  44. if (isset($_POST['logMeIn'])) {
  45. $username = strip_tags($_POST['userName']);
  46. $password = strip_tags($_POST['passWord']);
  47. if (!$username OR !$password) {
  48. echo '<script type="text/javascript">alert(\''.__('Please supply valid username and password').'\');</script>';
  49. } else {
  50. // destroy previous session set in OPAC
  51. simbio_security::destroySessionCookie(null, SENAYAN_MEMBER_SESSION_COOKIES_NAME, SENAYAN_WEB_ROOT_DIR, false);
  52. require SENAYAN_BASE_DIR.'admin/default/session.inc.php';
  53. // regenerate session ID to prevent session hijacking
  54. session_regenerate_id(true);
  55. // create logon class instance
  56. $logon = new admin_logon($username, $password, $sysconf['auth']['user']['method']);
  57. if ($sysconf['auth']['user']['method'] == 'ldap') {
  58. $ldap_configs = $sysconf['auth']['user'];
  59. }
  60. if ($logon->adminValid($dbs)) {
  61. # <!-- Captcha form processing - start -->
  62. if ($sysconf['captcha']['smc']['enable']) {
  63. if ($sysconf['captcha']['smc']['type'] == 'recaptcha') {
  64. require_once LIB_DIR.$sysconf['captcha']['smc']['folder'].'/'.$sysconf['captcha']['smc']['incfile'];
  65. $privatekey = $sysconf['captcha']['smc']['privatekey'];
  66. $resp = recaptcha_check_answer ($privatekey,
  67. $_SERVER["REMOTE_ADDR"],
  68. $_POST["recaptcha_challenge_field"],
  69. $_POST["recaptcha_response_field"]);
  70. if (!$resp->is_valid) {
  71. // What happens when the CAPTCHA was entered incorrectly
  72. session_unset();
  73. header("location:index.php?p=login");
  74. die();
  75. }
  76. } elseif ($sysconf['captcha']['smc']['type'] == 'others') {
  77. # other captchas here
  78. }
  79. }
  80. # <!-- Captcha form processing - end -->
  81. // set cookie admin flag
  82. setcookie('admin_logged_in', true, time()+14400, SENAYAN_WEB_ROOT_DIR);
  83. // write log
  84. utility::writeLogs($dbs, 'staff', $username, 'Login', 'Login success for user '.$username.' from address '.$_SERVER['REMOTE_ADDR']);
  85. echo '<script type="text/javascript">';
  86. if ($sysconf['login_message']) {
  87. echo 'alert(\''.__('Welcome to Library Automation, ').$logon->real_name.'\');';
  88. }
  89. #echo 'location.href = \'admin/index.php\';';
  90. echo 'location.href = \''.SENAYAN_WEB_ROOT_DIR.'admin/index.php\';';
  91. echo '</script>';
  92. exit();
  93. } else {
  94. // write log
  95. utility::writeLogs($dbs, 'staff', $username, 'Login', 'Login FAILED for user '.$username.' from address '.$_SERVER['REMOTE_ADDR']);
  96. // message
  97. $msg = '<script type="text/javascript">';
  98. $msg .= 'alert(\''.__('Wrong Username or Password. ACCESS DENIED').'\');';
  99. $msg .= 'history.back();';
  100. $msg .= '</script>';
  101. simbio_security::destroySessionCookie($msg, SENAYAN_SESSION_COOKIES_NAME, SENAYAN_WEB_ROOT_DIR.'admin', false);
  102. exit();
  103. }
  104. }
  105. }
  106. ?>
  107. <div id="loginForm">
  108. <noscript>
  109. <div style="font-weight: bold; color: #FF0000;"><?php echo __('Your browser does not support Javascript or Javascript is disabled. Application won\'t run without Javascript!'); ?><div>
  110. </noscript>
  111. <!-- Captcha preloaded javascript - start -->
  112. <?php if ($sysconf['captcha']['smc']['enable']) { ?>
  113. <?php if ($sysconf['captcha']['smc']['type'] == "recaptcha") { ?>
  114. <script type="text/javascript">
  115. var RecaptchaOptions = {
  116. theme : '<?php echo$sysconf['captcha']['smc']['recaptcha']['theme']; ?>',
  117. lang : '<?php echo$sysconf['captcha']['smc']['recaptcha']['lang']; ?>',
  118. <?php if($sysconf['captcha']['smc']['recaptcha']['customlang']['enable']) { ?>
  119. custom_translations : {
  120. instructions_visual : "<?php echo $sysconf['captcha']['smc']['recaptcha']['customlang']['instructions_visual']; ?>",
  121. instructions_audio : "<?php echo $sysconf['captcha']['smc']['recaptcha']['customlang']['instructions_audio']; ?>",
  122. play_again : "<?php echo $sysconf['captcha']['smc']['recaptcha']['customlang']['play_again']; ?>",
  123. cant_hear_this : "<?php echo $sysconf['captcha']['smc']['recaptcha']['customlang']['cant_hear_this']; ?>",
  124. visual_challenge : "<?php echo $sysconf['captcha']['smc']['recaptcha']['customlang']['visual_challenge']; ?>",
  125. audio_challenge : "<?php echo $sysconf['captcha']['smc']['recaptcha']['customlang']['audio_challenge']; ?>",
  126. refresh_btn : "<?php echo $sysconf['captcha']['smc']['recaptcha']['customlang']['refresh_btn']; ?>",
  127. help_btn : "<?php echo $sysconf['captcha']['smc']['recaptcha']['customlang']['help_btn']; ?>",
  128. incorrect_try_again : "<?php echo $sysconf['captcha']['smc']['recaptcha']['customlang']['incorrect_try_again']; ?>",
  129. },
  130. <?php } ?>
  131. };
  132. </script>
  133. <?php } ?>
  134. <?php } ?>
  135. <!-- Captcha preloaded javascript - end -->
  136. <form action="index.php?p=login" method="post">
  137. <div class="heading1">Username</div>
  138. <div><input type="text" name="userName" id="userName" style="width: 80%;" /></div>
  139. <div class="heading1 marginTop">Password</div>
  140. <div><input type="password" name="passWord" style="width: 80%;" /></div>
  141. <!-- Captcha in form - start -->
  142. <?php if ($sysconf['captcha']['smc']['enable']) { ?>
  143. <?php if ($sysconf['captcha']['smc']['type'] == "recaptcha") { ?>
  144. <div style="margin-left:40px; margin-right:auto; margin-top:10px;">
  145. <?php
  146. require_once LIB_DIR.$sysconf['captcha']['smc']['folder'].'/'.$sysconf['captcha']['smc']['incfile'];
  147. $publickey = $sysconf['captcha']['smc']['publickey'];
  148. echo recaptcha_get_html($publickey);
  149. ?>
  150. </div>
  151. <!-- <div><input type="text" name="captcha_code" id="captcha-form" style="width: 80%;" /></div> -->
  152. <?php
  153. } elseif ($sysconf['captcha']['smc']['type'] == "others") {
  154. }
  155. #debugging
  156. #echo SENAYAN_WEB_ROOT_DIR.'lib/'.$sysconf['captcha']['folder'].'/'.$sysconf['captcha']['webfile'];
  157. } ?>
  158. <!-- Captcha in form - end -->
  159. <div class="marginTop"><input type="submit" name="logMeIn" value="Logon" id="loginButton" />
  160. <input type="button" value="Home" id="homeButton" class="button" onclick="javascript: location.href = 'index.php';" />
  161. </div>
  162. </form>
  163. </div>
  164. <script type="text/javascript">jQuery('#userName').focus();</script>
  165. <?php
  166. // main content
  167. $main_content = ob_get_clean();
  168. // page title
  169. $page_title = $sysconf['library_name'].' :: Library Automation LOGIN';
  170. if ($sysconf['template']['base'] == 'html') {
  171. // create the template object
  172. $template = new simbio_template_parser($sysconf['template']['dir'].'/'.$sysconf['template']['theme'].'/login_template.html');
  173. // assign content to markers
  174. $template->assign('<!--PAGE_TITLE-->', $page_title);
  175. $template->assign('<!--CSS-->', $sysconf['template']['css']);
  176. $template->assign('<!--MAIN_CONTENT-->', $main_content);
  177. // print out the template
  178. $template->printOut();
  179. } else if ($sysconf['template']['base'] == 'php') {
  180. require_once $sysconf['template']['dir'].'/'.$sysconf['template']['theme'].'/login_template.inc.php';
  181. }
  182. exit();
  183. ?>