PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/frontend/php/account/register.php

#
PHP | 369 lines | 239 code | 57 blank | 73 comment | 55 complexity | 34e4d98f4903191bbbc9b91399d11be7 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. # Register an account, part 1 (part 2 is e-mail confirmation)
  3. #
  4. # Copyright 1999-2000 (c) The SourceForge Crew
  5. # Copyright 2003-2006 (c) Mathieu Roy <yeupou--gna.org>
  6. # Copyright (C) 2007 Sylvain Beucler
  7. #
  8. # This file is part of Savane.
  9. #
  10. # Savane is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU Affero General Public License as
  12. # published by the Free Software Foundation, either version 3 of the
  13. # License, or (at your option) any later version.
  14. #
  15. # Savane is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU Affero General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Affero General Public License
  21. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. require_once('../include/init.php');
  23. require_once('../include/sane.php');
  24. require_once('../include/account.php');
  25. require_once('../include/dnsbl.php');
  26. require_once('../include/spam.php');
  27. require_once('../include/form.php');
  28. require_once('../include/utils.php');
  29. require_once('../include/html.php');
  30. require_once('../include/sendmail.php');
  31. register_globals_off();
  32. extract(sane_import('post',
  33. array('update', 'form_id',
  34. 'form_loginname', 'form_pw', 'form_pw2', 'form_realname', 'form_email',
  35. 'form_year',
  36. 'form_usepam')));
  37. if (isset($GLOBALS['sys_https_host']) && !session_issecure())
  38. {
  39. # Force use of TLS for login
  40. header('Location: '.$GLOBALS['sys_https_url'].$_SERVER['REQUEST_URI']);
  41. }
  42. # Logged users have no business here
  43. if (user_isloggedin())
  44. {
  45. session_redirect($GLOBALS['sys_home'] . 'my/');
  46. }
  47. # Block here potential robots
  48. dnsbl_check();
  49. # Block banned IP
  50. spam_bancheck();
  51. $login_is_valid = false;
  52. $pw_is_valid = false;
  53. $email_is_valid = false;
  54. $realname_is_valid = false;
  55. $antispam_is_valid = false;
  56. if (!empty($update) and form_check($form_id))
  57. // Form is submitted
  58. {
  59. // feedback included by the check function
  60. // Temporary spam block
  61. if ($GLOBALS['sys_registration_text_spam_test'])
  62. {
  63. if ($form_year != 1983)
  64. {
  65. fb(_("Please answer the antispam test!"),1);
  66. }
  67. else
  68. {
  69. $antispam_is_valid = true;
  70. }
  71. }
  72. if ($GLOBALS['sys_registration_captcha'])
  73. {
  74. include_once $GLOBALS['sys_securimagedir'] . '/securimage.php';
  75. $securimage = new Securimage();
  76. if ($securimage->check($_POST['captcha_code']) == false)
  77. {
  78. fb(_("Please correctly answer the antispam captcha!"),1);
  79. }
  80. else
  81. {
  82. $antispam_is_valid = true;
  83. }
  84. }
  85. if (!$GLOBALS['sys_registration_captcha'] &&
  86. !$GLOBALS['sys_registration_text_spam_test'])
  87. {
  88. $antispam_is_valid = true;
  89. }
  90. // Login
  91. if ($form_loginname == '')
  92. {
  93. fb(_("You must supply a username."),1);
  94. }
  95. else if (!account_namevalid($form_loginname))
  96. {
  97. // feedback included by the check function
  98. }
  99. // Avoid duplicates
  100. else if (db_numrows(db_execute("SELECT user_id FROM user WHERE user_name = ?",
  101. array($form_loginname))) > 0)
  102. {
  103. fb(_("That username already exists."),1);
  104. }
  105. else if (db_numrows(db_execute("SELECT group_list_id FROM mail_group_list WHERE "
  106. . "list_name = ?", array($form_loginname))) > 0)
  107. {
  108. fb(_("That username is blocked to avoid conflict with mailing-list addresses."),1);
  109. }
  110. else
  111. {
  112. $login_is_valid = true;
  113. }
  114. // Password
  115. if ($form_pw == '')
  116. {
  117. fb(_("You must supply a password."),1);
  118. }
  119. // Password sanity checks - unless PAM is used
  120. else if ($GLOBALS['sys_use_pamauth'] != "yes" and $form_usepam != 1 and $form_pw != $form_pw2)
  121. {
  122. fb(_("Passwords do not match."),1);
  123. }
  124. else if ($GLOBALS['sys_use_pamauth'] != "yes" and $form_usepam != 1 and !account_pwvalid($form_pw))
  125. {
  126. // feedback included by the check function
  127. }
  128. else
  129. {
  130. $pw_is_valid = true;
  131. }
  132. // E-mail
  133. if (!$form_email)
  134. {
  135. fb(_("You must supply a valid email address."),1);
  136. }
  137. else if (!account_emailvalid($form_email))
  138. {
  139. // feedback included by the check function
  140. }
  141. else
  142. {
  143. $email_is_valid = true;
  144. }
  145. // Real name
  146. if ($form_realname == '')
  147. {
  148. fb(_("You must supply a real name."),1);
  149. }
  150. else
  151. {
  152. $realname_is_valid = true;
  153. }
  154. # Remove quotes from the realname, we do not want to allow that but
  155. # it is not a blocker issue.
  156. # Beuc 2007-02-24: enable quotes in realname, it's a perfect test for unsecure MySQL queries
  157. # $GLOBALS['form_realname'] = strtr($_POST['form_realname'], "\'\"\,", " ");
  158. ####
  159. $krb5ret = '';
  160. if ($GLOBALS['sys_use_krb5'] == "yes")
  161. {
  162. $krb5ret = krb5_login($form_loginname, $form_pw);
  163. if($krb5ret == -1)
  164. { # KRB5_NOTOK
  165. fb(_("phpkrb5 module failure"),1);
  166. $pw_is_valid = false;
  167. }
  168. elseif($krb5ret == 1)
  169. { # KRB5_BAD_PASSWORD
  170. fb(sprintf(_("User is a kerberos principal but password do not match. Please use your kerberos password for the first login and then change your %s password. This is necessary to prevent someone from stealing your account name."),$GLOBALS['sys_name']),1);
  171. $pw_is_valid = false;
  172. }
  173. elseif ($krb5ret == "2")
  174. {
  175. # KRB5_BAD_USER
  176. /*
  177. FIXME : this is broken and seems to be due to the kerberos module.
  178. we did not changed anything about that and we get 2 as return
  179. for any name.
  180. if($_POST['form_loginname']."@".$GLOBALS['sys_mail_domain'])
  181. {
  182. $GLOBALS['register_error'] = sprintf(_("User %s is a known mail alias and cannot be used. If you own this alias (%s@%s) please create a another user (for instance xx%s) and ask %s@%s to rename it to %s."),
  183. $_POST['form_loginname'],
  184. $_POST['form_loginname'],
  185. $GLOBALS['sys_mail_domain'],
  186. $_POST['form_loginname'],
  187. $GLOBALS['sys_admin_list'],
  188. $GLOBALS['sys_mail_domain'],
  189. $_POST['form_loginname']);
  190. return 0;
  191. }
  192. */
  193. }
  194. }
  195. }
  196. # Don't forget parenthesis to avoid precendence issues with 'and'
  197. $form_is_valid = ($login_is_valid and $pw_is_valid
  198. and $email_is_valid and $realname_is_valid
  199. and $antispam_is_valid);
  200. if ($form_is_valid)
  201. {
  202. if ($GLOBALS['sys_use_pamauth'] == "yes" && $form_usepam == 1)
  203. {
  204. // if user chose PAM based authentication, set his encrypted
  205. // password to the specified string
  206. $passwd = 'PAM';
  207. }
  208. else
  209. {
  210. $passwd = account_encryptpw($form_pw);
  211. }
  212. $confirm_hash = substr(md5(rand(0, 32768) . $passwd . time()), 0, 16);
  213. $result=db_autoexecute(
  214. 'user',
  215. array(
  216. 'user_name' => strtolower($form_loginname),
  217. 'user_pw' => $passwd,
  218. 'realname' => $form_realname,
  219. 'email' => $form_email,
  220. 'add_date' => time(),
  221. 'status' => 'P',
  222. 'confirm_hash' => $confirm_hash),
  223. DB_AUTOQUERY_INSERT);
  224. if (!$result)
  225. {
  226. exit_error('error',db_error());
  227. }
  228. else
  229. {
  230. $newuserid = db_insertid($result);
  231. # clean id
  232. form_clean($form_id);
  233. # send mail
  234. $message = sprintf(_("Thank you for registering on the %s web site."),$GLOBALS['sys_name'])."\n"
  235. ."("._("Your login is not mentioned in this mail to prevent account creation by robots").")\n\n"
  236. # .sprintf(_("Your login is: %s"), addslashes(strtolower($_POST[form_loginname])))."\n\n"
  237. ._("In order to complete your registration, visit the following URL:\n\n")
  238. . $GLOBALS['sys_https_url']
  239. . $GLOBALS['sys_home']
  240. . "account/verify.php?confirm_hash=$confirm_hash\n\n"
  241. ._("Enjoy the site").".\n\n"
  242. . sprintf(_("-- the %s team.")."\n",$GLOBALS['sys_name']);
  243. if ($krb5ret == 0) #KRB5_OK
  244. {
  245. $message .= sprintf(_("P.S. Your kerberos password is now stored in encrypted form\nin the %s database."),$GLOBALS['sys_name']);
  246. $message .= sprintf(_("For better security we advise you\nto change your %s password as soon as possible.\n"),$GLOBALS['sys_name']);
  247. }
  248. sendmail_mail($GLOBALS['sys_mail_replyto']."@".$GLOBALS['sys_mail_domain'],
  249. $form_email,
  250. $GLOBALS['sys_name']." "._("Account Registration"),
  251. $message);
  252. $HTML->header(array('title'=>_("Register Confirmation")));
  253. print '<h3>'.$GLOBALS['sys_name'].' : '._("New Account Registration Confirmation").'</h3>'
  254. .sprintf(_("Congratulations. You have registered on %s "),$GLOBALS['sys_name'])
  255. .sprintf(_("Your login is: %s"), '<strong>'.user_getname($newuserid).'</strong>');
  256. print '<p>'._("You are now being sent a confirmation email to verify your email address. Visiting the link sent to you in this email will activate your account.").' <span class="warn">'._("Accounts not confirmed after two days are deleted from the database.").'</span></p>';
  257. }
  258. }
  259. # not valid registration, or first time to page
  260. else
  261. {
  262. site_header(array('title'=>_("User account registration"),'context'=>'account'));
  263. print form_header($_SERVER['PHP_SELF'], $form_id);
  264. print '<p><span class="preinput">'._("Login Name:").'</span><br />&nbsp;&nbsp;';
  265. print form_input("text", "form_loginname", $form_loginname);
  266. print '<p><span class="preinput">'._("Password / passphrase:")." ".account_password_help().'</span><br />&nbsp;&nbsp;';
  267. print form_input("password", "form_pw", $form_pw);
  268. print "</p>";
  269. print '<p><span class="preinput">'._("Re-type Password:").'</span><br />&nbsp;&nbsp;';
  270. print form_input("password", "form_pw2", $form_pw2);
  271. print "</p>";
  272. print '<p><span class="preinput">'._("Real Name:").'</span><br />&nbsp;&nbsp;';
  273. print '<input size="30" type="text" name="form_realname" value="'.$form_realname.'" /></p>';
  274. print '<p><span class="preinput">'._("Email Address:").'</span><br />&nbsp;&nbsp;';
  275. print '<input size="30" type="text" name="form_email" value="'.$form_email.'" />';
  276. print '<br /><span class="text">'._("This email address will be verified before account activation.").'</span></p>';
  277. if ($GLOBALS['sys_registration_text_spam_test'])
  278. {
  279. print '<p><span class="preinput">'._("Antispam test:").'</span><br />&nbsp;&nbsp;';
  280. print '<input size="30" type="text" name="form_year" value="'.$form_year.'" />';
  281. print '<br /><span class="text">'
  282. ._("In what year was the GNU project announced?"
  283. . " [<a href='http://www.gnu.org/gnu/gnu-history.html'>click for a hint</a>]")
  284. . '</span></p>';
  285. }
  286. if ($GLOBALS['sys_registration_captcha'])
  287. {
  288. print '<img id="captcha" src="' . $GLOBALS['sys_home'] . 'gencaptcha.php" alt="CAPTCHA" /><br />';
  289. print '[ <a href="#" onclick="document.getElementById(\'captcha\').src = \'' .
  290. $GLOBALS['sys_home'] . 'gencaptcha.php?\' + Math.random(); return false">' . _("Different Image") . '</a> ] ';
  291. print '[ <a href="' . $GLOBALS['sys_home'] . 'playcaptcha.php">' . _("Play Captcha") . '</a> ]<br />';
  292. print _("Antispam test:") . '<input type="text" name="captcha_code" size="10" maxlength="6" />';
  293. }
  294. # Extension for PAM authentication
  295. # FIXME: for now, only the PAM authentication that exists is for AFS.
  296. # but PAM is not limited to AFS, so we should consider a way to configure
  297. # this (to put it in site specific content probably).
  298. if ($sys_use_pamauth=="yes")
  299. {
  300. print "<p>Instead of providing a new password you
  301. may choose to authenticate via an <strong>AFS</strong> account you own
  302. at this site (this requires your new login name to be the
  303. same as the AFS account name):";
  304. print '<p>&nbsp;&nbsp;&nbsp;<INPUT type="checkbox"
  305. name="form_usepam" value="1" > use AFS based authentication';
  306. }
  307. print form_footer();
  308. }
  309. $HTML->footer(array());