PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/frontend/php/account/login.php

#
PHP | 256 lines | 159 code | 37 blank | 60 comment | 35 complexity | 7c8f547c9fa51bcb25d15502bd35ade9 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. # Front page - news, latests projects, etc.
  3. # Copyright 1999-2000 (c) The SourceForge Crew
  4. # Copyright 2003-2006 (c) Mathieu Roy <yeupou--gnu.org>
  5. # Copyright (C) 2006, 2007 Sylvain Beucler
  6. #
  7. # This file is part of Savane.
  8. #
  9. # Savane is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU Affero General Public License as
  11. # published by the Free Software Foundation, either version 3 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # Savane is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. require_once('../include/init.php');
  22. require_once('../include/account.php');
  23. require_once('../include/sane.php');
  24. Header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
  25. Header("Cache-Control: no-cache");
  26. Header("Cache-Control: must-revalidate");
  27. extract(sane_import('request', array('from_brother')));
  28. # Block here potential robots
  29. # 2006-12-04, yeupou: allows them to login, so they can post on trackers of
  30. # their projects. This is a compromise between the need to avoid spam by all
  31. # means and the fact that we still want to allow to work people in obvious
  32. # legit cases even if they are blacklisted.
  33. # They wont be able to use savane normally but only to post on the project
  34. # they are member of. The way to go for them is to ask their IP to be delisted,
  35. # not from us to maintain another list of exceptions. If they cant, it is sad
  36. # but we cannot encourage this because it would defeat the whole purpose of
  37. # DNSbl, while DNSbl seems to be the only truly effective way to get rid of
  38. # spams.
  39. #dnsbl_check();
  40. # Logged users have no business here
  41. if (user_isloggedin() && !$from_brother)
  42. { session_redirect($GLOBALS['sys_home']."my/"); }
  43. # Input checks
  44. extract(sane_import('request',
  45. array('form_loginname', 'form_pw', 'cookie_for_a_year',
  46. 'stay_in_ssl', 'brotherhood',
  47. 'uri', 'login', 'cookie_test')));
  48. #if (isset($GLOBALS['sys_https_host']) && !session_issecure())
  49. #{
  50. # # Force use of TLS for login
  51. # header('Location: '.$GLOBALS['sys_https_url'].$_SERVER['REQUEST_URI']);
  52. #}
  53. # Check cookie support
  54. if (!$from_brother and !isset($_COOKIE["cookie_probe"]))
  55. {
  56. if (!$cookie_test)
  57. {
  58. // Attempt to set a cookie to go to a new page to see if the client will indeed send that cookie.
  59. session_cookie('cookie_probe', 1);
  60. header('Location: login.php?uri='.$uri.'&cookie_test=1');
  61. }
  62. else #
  63. {
  64. fb(sprintf(_("Savane thinks your cookies are not activated for %s. To log-in, we need you to activate cookies in your web browser for this website. Please do so and click here:"), $sys_default_domain).' '.$GLOBALS['sys_https_url'].$GLOBALS['sys_home'].'account/login.php?uri='.$uri, 1);
  65. }
  66. }
  67. if (!empty($login))
  68. {
  69. if ($from_brother)
  70. {
  71. extract(sane_import('get', array('session_uid', 'session_hash')));
  72. if (!ctype_digit($session_uid))
  73. { exit("Invalid session_uid"); }
  74. if (!ctype_alnum($session_hash))
  75. { exit("Invalid session_hash"); }
  76. }
  77. if (isset($session_uid) and session_exists($session_uid, $session_hash))
  78. {
  79. $GLOBALS['session_hash'] = $session_hash;
  80. session_set_new_cookies($session_uid, $cookie_for_a_year, $stay_in_ssl);
  81. $success = 1;
  82. }
  83. else
  84. {
  85. $success = session_login_valid($form_loginname, $form_pw, 0, $cookie_for_a_year, 0, $stay_in_ssl);
  86. }
  87. if ($success)
  88. {
  89. # Set up the theme, if the user has selected any in the user
  90. # preferences -- but give priority to a cookie, if set.
  91. if (!isset($_COOKIE['SV_THEME']))
  92. {
  93. $theme_result = user_get_result_set(user_getid());
  94. $theme = db_result($theme_result, 0, 'theme');
  95. if (strlen($theme) > 0)
  96. {
  97. setcookie('SV_THEME', $theme, time() + 60*60*24,
  98. $GLOBALS['sys_home'], $GLOBALS['sys_default_domain']);
  99. }
  100. }
  101. # We return to our brother 'my', where we login originally,
  102. # unless we are request to go to an uri
  103. if (!$uri)
  104. {
  105. $uri = $GLOBALS['sys_home'] . 'my/';
  106. }
  107. # If a brother server exists, login there too, if we are not
  108. # already coming from there
  109. if (!empty($GLOBALS['sys_brother_domain']) && $brotherhood)
  110. {
  111. if (session_issecure())
  112. { $http = "https"; }
  113. else
  114. { $http = "http"; }
  115. if (!$from_brother)
  116. {
  117. # Go there saying hello to your brother
  118. header ("Location: ".$http."://".$GLOBALS['sys_brother_domain'].$GLOBALS['sys_home']."/account/login.php?session_uid=".user_getid()."&session_hash=".$GLOBALS['session_hash']."&cookie_for_a_year=$cookie_for_a_year&from_brother=1&login=1&stay_in_ssl=$stay_in_ssl&brotherhood=1&uri=".urlencode($uri));
  119. exit;
  120. }
  121. else
  122. {
  123. header("Location: ".$http."://".$GLOBALS['sys_brother_domain'].$uri);
  124. exit;
  125. }
  126. }
  127. else
  128. {
  129. # If No brother server exists, just go to 'my' page
  130. # unless we are request to go to an uri
  131. // Optionally stay in TLS mode
  132. if ($stay_in_ssl)
  133. {
  134. // switch to requested HTTPs mode
  135. header("Location: {$GLOBALS['sys_https_url']}$uri");
  136. }
  137. else
  138. {
  139. // Stay in current http mode (also avoids mentioning
  140. // hostname&port, which can be useful in test
  141. // environments with port forwarding)
  142. header("Location: $uri");
  143. }
  144. exit;
  145. }
  146. }
  147. }
  148. if (isset($session_hash))
  149. {
  150. # Nuke their old session securely.
  151. session_delete_cookie('session_hash');
  152. db_execute("DELETE FROM session WHERE session_hash=? AND user=?",
  153. array($session_hash, $user_id));
  154. }
  155. site_header(array('title'=>_("Login")));
  156. if (!empty($login) && !$success)
  157. {
  158. if ("Account Pending" == $feedback)
  159. {
  160. print '<h3>'._("Pending Account").'</h3>';
  161. print '<p>'._("Your account is currently pending your email confirmation. Visiting the link sent to you in this email will activate your account.").'</p>';
  162. print '<p>'._("If you need this email resent, please click below and a confirmation email will be sent to the email address you provided in registration.").'</p>';
  163. print '<p><a href="pending-resend.php?form_user='.htmlspecialchars($form_loginname, ENT_QUOTES).'">['._("Resend Confirmation Email").']</a></p>';
  164. }
  165. else
  166. {
  167. # print helpful error message
  168. print '<div class="splitright"><div class="boxitem">';
  169. print '<div class="warn">'._("Troubleshooting:").'</div></div><ul class="boxli">'.
  170. '<li class="boxitemalt">'._("Is the \"Caps Lock\" or \"A\" light on your keyboard on?").'<br />'._("If so, hit \"Caps Lock\" key before trying again.").'</li>'.
  171. '<li class="boxitem">'._("Did you forget or misspell your password?").'<br />'.utils_link('lostpw.php', _("You can recover your password using the lost password form.")).'</li>'.
  172. '<li class="boxitemalt">'._("Still having trouble?").'<br />'.utils_link($GLOBALS['sys_home'].'support/?group='.$GLOBALS['sys_unix_group_name'], _("Fill a support request.")).'</li>';
  173. print '</ul></div>';
  174. }
  175. }
  176. if (isset($GLOBALS['sys_https_host']))
  177. {
  178. utils_get_content("account/login");
  179. }
  180. print '<form action="'.$GLOBALS['sys_https_url'].$GLOBALS['sys_home'].'account/login.php" method="post">';
  181. print '<input type="hidden" name="uri" value="'.htmlspecialchars($uri, ENT_QUOTES).'" />';
  182. # Shortcuts to New Account and Lost Password have a tabindex superior to
  183. # the rest of form,
  184. # so they dont mess with the normal order when you press TAB on the keyboard
  185. # (login -> password -> post)
  186. print '<p><span class="preinput">'._("Login Name:").'</span><br />&nbsp;&nbsp;';
  187. print '<input type="text" name="form_loginname" value="'.htmlspecialchars($form_loginname, ENT_QUOTES).'" tabindex="1" /> <a class="smaller" href="register.php" tabindex="2">['._("No account yet?").']</a></p>';
  188. print '<p><span class="preinput">'._("Password:").'</span><br />&nbsp;&nbsp;';
  189. print '<input type="password" name="form_pw" tabindex="1" /> <a class="smaller" href="lostpw.php" tabindex="2">['._("Lost your password?").']</a></p>';
  190. if (isset($GLOBALS['sys_https_host']))
  191. {
  192. $checked = 'checked="checked" ';
  193. if ($login and !$stay_in_ssl)
  194. { $checked = ''; }
  195. print '<p><input type="checkbox" name="stay_in_ssl" value="1" tabindex="1" '.$checked.'/><span class="preinput">';
  196. print _("Stay in secure (https) mode after login")."</span><br />\n";
  197. print '<span class="text">'._("Lynx, Emacs w3 and Microsoft Internet Explorer users will have intermittent https problems, so they should leave https after login. Gecko-based browser (Mozilla, Galeon, Netscape...) and Konqueror users should stay in https mode permanently for maximum security.").'</span></p>';
  198. }
  199. else
  200. {
  201. print '<p class="warn"><input type="hidden" name="stay_in_ssl" value="0" />';
  202. print _("This server does not encrypt data (no https), so the password you sent may be viewed by other people. Do not use any important passwords.").'</p>';
  203. }
  204. $checked = '';
  205. if ($cookie_for_a_year)
  206. { $checked = 'checked="checked" '; }
  207. print '<p><input type="checkbox" name="cookie_for_a_year" tabindex="1" value="1" '.$checked.'/><span class="preinput">'._("Remember me").'</span><br />';
  208. print '<span class="text">'._("For a year, your login information will be stored in a cookie. Use this only if you are using your own computer.").'</span>';
  209. if (!empty($GLOBALS['sys_brother_domain']))
  210. {
  211. $checked = 'checked="checked" ';
  212. if ($login and !$brotherhood)
  213. $checked = '';
  214. print '<p><input type="checkbox" name="brotherhood" value="1" tabindex="1" '.$checked.'/><span class="preinput">';
  215. printf (_("Login also in %s").'</span><br />', $GLOBALS['sys_brother_domain']);
  216. }
  217. print '<div class="center"><input type="submit" name="login" value="'._("Login").'" tabindex="1" /></div>';
  218. print '</form>';
  219. $HTML->footer(array());