PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/WebCalendar-1.2.5/login.php

#
PHP | 306 lines | 236 code | 36 blank | 34 comment | 80 complexity | 284c8ca70aa7954965f008b298a4ea3e MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /* $Id: login.php,v 1.111.2.9 2011/04/27 00:27:35 rjones6061 Exp $ */
  3. @session_start ();
  4. foreach ( $_SESSION as $key=>$value ) {
  5. $dummy[$key]=$value; // copy to a dummy array
  6. }
  7. if ( ! empty ( $dummy ) )
  8. foreach ($dummy as $key=>$value) {
  9. if ( substr ( $key, 0, 6 ) == 'webcal' )
  10. unset ( $_SESSION[$key] );
  11. }
  12. //php 4.1.0 may have issues with the above code
  13. unset ( $_SESSION['webcal_login'] );
  14. unset ( $_SESSION['webcalendar_session'] );
  15. require_once 'includes/classes/WebCalendar.class';
  16. $WebCalendar = new WebCalendar ( __FILE__ );
  17. include 'includes/translate.php';
  18. include 'includes/config.php';
  19. include 'includes/dbi4php.php';
  20. include 'includes/formvars.php';
  21. include 'includes/functions.php';
  22. $WebCalendar->initializeFirstPhase ();
  23. include 'includes/' . $user_inc;
  24. include_once 'includes/access.php';
  25. include 'includes/gradient.php';
  26. $WebCalendar->initializeSecondPhase ();
  27. load_global_settings ();
  28. // Change this to true to show "no such user" or "invalid password" on
  29. // login failures.
  30. $showLoginFailureReason = true;
  31. if ( ! empty ( $last_login ) ) {
  32. $login = '';
  33. }
  34. if ( empty ( $webcalendar_login ) ) {
  35. $webcalendar_login = '';
  36. }
  37. if ( $REMEMBER_LAST_LOGIN == 'Y' && empty ( $login ) ) {
  38. $last_login = $login = $webcalendar_login;
  39. }
  40. load_user_preferences ( 'guest' );
  41. $WebCalendar->setLanguage ();
  42. $cookie_path = str_replace ( 'login.php', '', $PHP_SELF );
  43. //echo "Cookie path: $cookie_path\n";
  44. // Look for action=logout
  45. $logout = false;
  46. $action = getGetValue ( 'action' );
  47. if ( ! empty ( $action ) && $action == 'logout' ) {
  48. $logout = true;
  49. $return_path = '';
  50. SetCookie ( 'webcalendar_login', '', 0, $cookie_path );
  51. SetCookie ( 'webcalendar_last_view', '', 0, $cookie_path );
  52. } else if ( empty ( $return_path ) ) {
  53. // see if a return path was set
  54. $return_path = get_last_view ( false );
  55. }
  56. if ( ! empty ( $return_path ) ) {
  57. $return_path = clean_whitespace ( $return_path );
  58. $url = $return_path;
  59. } else {
  60. $url = 'index.php';
  61. }
  62. // If Application Name is set to Title then get translation
  63. // If not, use the Admin defined Application Name
  64. $appStr = generate_application_name ();
  65. $login = getPostValue ( 'login' );
  66. $password = getPostValue ( 'password' );
  67. $remember = getPostValue ( 'remember' );
  68. // calculate path for cookie
  69. if ( empty ( $PHP_SELF ) ) {
  70. $PHP_SELF = $_SERVER['PHP_SELF'];
  71. }
  72. if ( $single_user == 'Y' ) {
  73. // No login for single-user mode
  74. do_redirect ( 'index.php' );
  75. } else if ( $use_http_auth ) {
  76. // There is no login page when using HTTP authorization
  77. do_redirect ( 'index.php' );
  78. } else {
  79. if ( ! empty ( $login ) && ! empty ( $password ) && ! $logout ) {
  80. if ( get_magic_quotes_gpc () ) {
  81. $password = stripslashes ( $password );
  82. $login = stripslashes ( $login );
  83. }
  84. $login = trim ( $login );
  85. if ( $login != addslashes ( $login ) ) {
  86. die_miserable_death ( 'Illegal characters in login ' .
  87. '<tt>' . htmlentities ( $login ) . '</tt>' );
  88. }
  89. if ( user_valid_login ( $login, $password ) ) {
  90. user_load_variables ( $login, '' );
  91. $encoded_login = encode_string ( $login . '|' . crypt($password) );
  92. // set login to expire in 365 days
  93. if ( ! empty ( $remember ) && $remember == 'yes' ) {
  94. SetCookie ( 'webcalendar_session', $encoded_login,
  95. time () + ( 24 * 3600 * 365 ), $cookie_path );
  96. } else {
  97. SetCookie ( 'webcalendar_session', $encoded_login, 0, $cookie_path );
  98. }
  99. // The cookie "webcalendar_login" is provided as a convenience to
  100. // other apps that may wish to find out what the last calendar
  101. // login was, so they can use week_ssi.php as a server-side include.
  102. // As such, it's not a security risk to have it un-encoded since it
  103. // is not used to allow logins within this app. It is used to
  104. // load user preferences on the login page (before anyone has
  105. // logged in) if $REMEMBER_LAST_LOGIN is set to "Y" (in admin.php).
  106. if ( ! empty ( $remember ) && $remember == 'yes' ) {
  107. SetCookie ( 'webcalendar_login', $login,
  108. time () + ( 24 * 3600 * 365 ), $cookie_path );
  109. } else {
  110. SetCookie ( 'webcalendar_login', $login, 0, $cookie_path );
  111. }
  112. if ( ! empty ( $GLOBALS['newUserUrl'] ) ) $url = $GLOBALS['newUserUrl'];
  113. do_redirect ( $url );
  114. } else {
  115. // Invalid login
  116. if ( empty ( $error ) || ! $showLoginFailureReason ) {
  117. $error = translate ('Invalid login', true );
  118. }
  119. activity_log ( 0, 'system', '', LOG_LOGIN_FAILURE,
  120. translate ( 'Username' ) . ": " . $login .
  121. ", IP: " . $_SERVER['REMOTE_ADDR'] );
  122. }
  123. } else {
  124. // No login info... just present empty login page
  125. //$error = "Start";
  126. }
  127. // delete current user
  128. SetCookie ( 'webcalendar_session', '', 0, $cookie_path );
  129. // In older versions the cookie path had no trailing slash and NS 4.78
  130. // thinks "path/" and "path" are different, so the line above does not
  131. // delete the "old" cookie. This prohibits the login. So we delete the
  132. // cookie with the trailing slash removed
  133. if (substr ($cookie_path, -1) == '/') {
  134. SetCookie ( 'webcalendar_session', '', 0, substr ($cookie_path, 0, -1) );
  135. }
  136. }
  137. echo send_doctype ( $appStr );
  138. if ( ! $logout ) { ?>
  139. <script type="text/javascript">
  140. // error check login/password
  141. function valid_form ( form ) {
  142. if ( form.login.value.length == 0 || form.password.value.length == 0 ) {
  143. alert ( '<?php etranslate ( 'You must enter a login and password.', true)?>' );
  144. return false;
  145. }
  146. return true;
  147. }
  148. function myOnLoad () {
  149. document.login_form.login.focus ();
  150. <?php
  151. if ( ! empty ( $login ) ) echo "document.login_form.login.select();";
  152. if ( ! empty ( $error ) ) {
  153. echo " alert ( \"$error\" );\n";
  154. }
  155. ?>
  156. }
  157. </script>
  158. <?php
  159. }
  160. $csscache = ( isset ( $_COOKIE['webcalendar_csscache'] ) ?
  161. $_COOKIE['webcalendar_csscache'] : 1 );
  162. echo '<link rel="stylesheet" type="text/css" href="css_cacher.php?login=__public__'
  163. . $csscache . '" />';
  164. // Print custom header (since we do not call print_header function)
  165. if ( ! empty ( $CUSTOM_SCRIPT ) && $CUSTOM_SCRIPT == 'Y' ) {
  166. echo load_template ( $login, 'S' );
  167. }
  168. ?>
  169. </head>
  170. <body id="login" <?php if ( ! $logout ) { ?>onload="myOnLoad();"<?php } ?>>
  171. <?php
  172. // Print custom header (since we do not call print_header function)
  173. if ( ! empty ( $CUSTOM_HEADER ) && $CUSTOM_HEADER == 'Y' ) {
  174. echo load_template ( $login, 'H' );
  175. }
  176. ?>
  177. <h2><?php echo $appStr?></h2>
  178. <?php
  179. if ( ! empty ( $error ) ) {
  180. echo '<span style="color:#FF0000; font-weight:bold;">' .
  181. translate ( 'Error' ) . ": $error</span><br />\n";
  182. } else {
  183. echo "<br />\n";
  184. }
  185. if ( $logout ) {
  186. echo '<p>' . translate ( 'You have been logged out.' ) . ".</p>\n";
  187. echo "<br /><br />\n";
  188. echo '<a href="login.php' .
  189. ( ! empty ( $return_path ) ?
  190. '?return_path=' . htmlentities ( $return_path ) : '' ) .
  191. '" class="nav">' . translate ( 'Login' ) .
  192. "</a><br /><br /><br />\n";
  193. }
  194. if ( ! $logout ) {
  195. ?>
  196. <form name="login_form" id="login" action="login.php" method="post"
  197. onsubmit="return valid_form( this )">
  198. <?php
  199. if ( ! empty ( $return_path ) ) {
  200. echo '<input type="hidden" name="return_path" value="' .
  201. htmlentities ( $return_path ) . '" />' . "\n";
  202. }
  203. ?>
  204. <table align="center" cellspacing="10" cellpadding="10">
  205. <tr><td rowspan="2">
  206. <img src="images/login.gif" alt="Login" /></td><td align="right">
  207. <label for="user"><?php etranslate ( 'Username' )?>:</label></td><td>
  208. <input name="login" id="user" size="15" maxlength="25"
  209. value="<?php if ( ! empty ( $last_login ) ) echo $last_login;?>"
  210. tabindex="1" />
  211. </td></tr>
  212. <tr><td class="alignright">
  213. <label for="password"><?php etranslate ( 'Password' )?>:</label></td><td>
  214. <input name="password" id="password" type="password" size="15"
  215. maxlength="30" tabindex="2" />
  216. </td></tr>
  217. <tr><td colspan="3" style="font-size: 10px;">
  218. <input type="checkbox" name="remember" id="remember" tabindex="3"
  219. value="yes" <?php if ( ! empty ( $remember ) && $remember == 'yes' ) {
  220. echo 'checked="checked"'; }?> /><label for="remember">&nbsp;
  221. <?php etranslate ( 'Save login via cookies so I dont have to login next time.' )?></label>
  222. </td></tr>
  223. <tr><td colspan="4" class="aligncenter">
  224. <input type="submit" value="<?php etranslate ( 'Login' )?>" tabindex="4" />
  225. </td></tr>
  226. </table>
  227. </form>
  228. <?php }
  229. if ( ! empty ( $PUBLIC_ACCESS ) && $PUBLIC_ACCESS == 'Y' ) { ?>
  230. <br /><br />
  231. <a class="nav" href="index.php">
  232. <?php etranslate ( 'Access public calendar' )?></a><br />
  233. <?php }
  234. $nulist = get_nonuser_cals ();
  235. for ( $i = 0, $cnt = count ( $nulist ); $i < $cnt; $i++ ) {
  236. if ( $nulist[$i]['cal_is_public'] == 'Y' ) {
  237. ?><a class="nav" href="nulogin.php?login=<?php
  238. echo $nulist[$i]['cal_login'] . '">' .
  239. translate ( 'Access' ) . ' ' . $nulist[$i]['cal_fullname'] . ' ' .
  240. translate ( 'calendar' );
  241. ?></a><br /><?php
  242. }
  243. }
  244. if ( $DEMO_MODE == 'Y' ) {
  245. // This is used on the sourceforge demo page
  246. echo 'Demo login: user = "demo", password = "demo"<br />';
  247. } ?>
  248. <br /><br />
  249. <?php if ( ! empty ( $ALLOW_SELF_REGISTRATION ) &&
  250. $ALLOW_SELF_REGISTRATION == 'Y' ) {
  251. // We can limit what domain is allowed to self register
  252. // $self_registration_domain should have this format "192.168.220.0:255.255.240.0";
  253. $valid_ip = validate_domain ();
  254. if ( ! empty ( $valid_ip ) ) {
  255. echo '<b><a href="register.php">' . translate ( 'Not yet registered? Register here!' ) .
  256. '</a></b><br />';
  257. }
  258. }
  259. ?>
  260. <span class="cookies"><?php etranslate ( 'cookies-note' )?></span><br />
  261. <hr />
  262. <br />
  263. <a href="<?php echo $PROGRAM_URL ?>" id="programname"><?php echo $PROGRAM_NAME?></a>
  264. <?php // Print custom trailer (since we do not call print_trailer function)
  265. if ( ! empty ( $CUSTOM_TRAILER ) && $CUSTOM_TRAILER == 'Y' ) {
  266. echo load_template ( $login, 'T' );
  267. }
  268. ?>
  269. </body>
  270. </html>