signup.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require_once "includes/require.php";
  23. require_once "includes/checkauth.php";
  24. if (if_group("admin") || if_group("superadmin")) {
  25. //access allowed
  26. }
  27. else {
  28. echo "access denied";
  29. return;
  30. }
  31. $username = check_str($_POST["username"]);
  32. $password = check_str($_POST["password"]);
  33. $confirmpassword = check_str($_POST["confirmpassword"]);
  34. $contact_organization = check_str($_POST["contact_organization"]);
  35. $contact_name_given = check_str($_POST["contact_name_given"]);
  36. $contact_name_family = check_str($_POST["contact_name_family"]);
  37. $user_email = check_str($_POST["user_email"]);
  38. if (count($_POST)>0 && check_str($_POST["persistform"]) != "1") {
  39. $msgerror = '';
  40. //--- begin captcha verification ---------------------
  41. //session_start(); //make sure sessions are started
  42. if (strtolower($_SESSION["captcha"]) != strtolower($_REQUEST["captcha"]) || strlen($_SESSION["captcha"]) == 0) {
  43. //$msgerror .= "Captcha Verification Failed<br>\n";
  44. }
  45. else {
  46. //echo "verified";
  47. }
  48. //--- end captcha verification -----------------------
  49. //username is already used.
  50. if (strlen($username) == 0) {
  51. $msgerror .= "Please provide a Username.<br>\n";
  52. }
  53. else {
  54. $sql = "SELECT * FROM v_users ";
  55. $sql .= "where domain_uuid = '$domain_uuid' ";
  56. $sql .= "and username = '$username' ";
  57. $prep_statement = $db->prepare(check_sql($sql));
  58. $prep_statement->execute();
  59. if (count($prep_statement->fetchAll(PDO::FETCH_NAMED)) > 0) {
  60. $msgerror .= "Please choose a different Username.<br>\n";
  61. }
  62. }
  63. if (strlen($password) == 0) { $msgerror .= "Password cannot be blank.<br>\n"; }
  64. if ($password != $confirmpassword) { $msgerror .= "Passwords did not match.<br>\n"; }
  65. //if (strlen($contact_organization) == 0) { $msgerror .= "Please provide a organization name.<br>\n"; }
  66. //if (strlen($contact_name_given) == 0) { $msgerror .= "Please provide a first name.<br>\n"; }
  67. //if (strlen($contact_name_family) == 0) { $msgerror .= "Please provide a last name $user_last_name.<br>\n"; }
  68. if (strlen($user_email) == 0) { $msgerror .= "Please provide an email.<br>\n"; }
  69. if (strlen($msgerror) > 0) {
  70. require_once "includes/header.php";
  71. echo "<div align='center'>";
  72. echo "<table><tr><td>";
  73. echo $msgerror;
  74. echo "</td></tr></table>";
  75. require_once "includes/persistform.php";
  76. echo persistform($_POST);
  77. echo "</div>";
  78. require_once "includes/footer.php";
  79. return;
  80. }
  81. //salt used with the password to create a one way hash
  82. $salt = generate_password('20', '4');
  83. //prepare the uuids
  84. $user_uuid = uuid();
  85. $contact_uuid = uuid();
  86. //add the user
  87. $sql = "insert into v_users ";
  88. $sql .= "(";
  89. $sql .= "domain_uuid, ";
  90. $sql .= "user_uuid, ";
  91. $sql .= "contact_uuid, ";
  92. $sql .= "username, ";
  93. $sql .= "password, ";
  94. $sql .= "salt, ";
  95. $sql .= "user_add_date, ";
  96. $sql .= "user_add_user ";
  97. $sql .= ") ";
  98. $sql .= "values ";
  99. $sql .= "(";
  100. $sql .= "'$domain_uuid', ";
  101. $sql .= "'$user_uuid', ";
  102. $sql .= "'$contact_uuid', ";
  103. $sql .= "'$username', ";
  104. $sql .= "'".md5($salt.$password)."', ";
  105. $sql .= "'".$salt."', ";
  106. $sql .= "now(), ";
  107. $sql .= "'".$_SESSION["username"]."' ";
  108. $sql .= ")";
  109. $db->exec(check_sql($sql));
  110. unset($sql);
  111. //add to contacts
  112. $sql = "insert into v_contacts ";
  113. $sql .= "(";
  114. $sql .= "domain_uuid, ";
  115. $sql .= "contact_uuid, ";
  116. $sql .= "contact_type, ";
  117. $sql .= "contact_organization, ";
  118. $sql .= "contact_name_given, ";
  119. $sql .= "contact_name_family, ";
  120. $sql .= "contact_nickname, ";
  121. $sql .= "contact_email ";
  122. $sql .= ") ";
  123. $sql .= "values ";
  124. $sql .= "(";
  125. $sql .= "'$domain_uuid', ";
  126. $sql .= "'$contact_uuid', ";
  127. $sql .= "'user', ";
  128. $sql .= "'$contact_organization', ";
  129. $sql .= "'$contact_name_given', ";
  130. $sql .= "'$contact_name_family', ";
  131. $sql .= "'$username', ";
  132. $sql .= "'$user_email' ";
  133. $sql .= ")";
  134. $db->exec(check_sql($sql));
  135. unset($sql);
  136. //log the success
  137. //$log_type = 'user'; $log_status='add'; $log_add_user=$_SESSION["username"]; $log_desc= "username: ".$username." user added.";
  138. //log_add($db, $log_type, $log_status, $log_desc, $log_add_user, $_SERVER["REMOTE_ADDR"]);
  139. $group_name = 'user';
  140. $sql = "insert into v_group_users ";
  141. $sql .= "(";
  142. $sql .= "group_user_uuid, ";
  143. $sql .= "domain_uuid, ";
  144. $sql .= "group_name, ";
  145. $sql .= "user_uuid ";
  146. $sql .= ")";
  147. $sql .= "values ";
  148. $sql .= "(";
  149. $sql .= "'".uuid()."', ";
  150. $sql .= "'$domain_uuid', ";
  151. $sql .= "'$group_name', ";
  152. $sql .= "'$user_uuid' ";
  153. $sql .= ")";
  154. $db->exec(check_sql($sql));
  155. unset($sql);
  156. require_once "includes/header.php";
  157. echo "<meta http-equiv=\"refresh\" content=\"3;url=index.php\">\n";
  158. echo "<div align='center'>Add Complete</div>";
  159. require_once "includes/footer.php";
  160. return;
  161. }
  162. //show the header
  163. require_once "includes/header.php";
  164. //show the content
  165. echo "<div align='center'>";
  166. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  167. echo "<tr>\n";
  168. echo " <td align=\"left\">\n";
  169. echo " <br>";
  170. $tablewidth ='width="100%"';
  171. echo "<form method='post' action=''>";
  172. echo "<div class='borderlight' style='padding:10px;'>\n";
  173. echo "<table border='0' $tablewidth cellpadding='6' cellspacing='0'>";
  174. echo " <tr>\n";
  175. echo " <td width='80%'>\n";
  176. echo " <b>To add a user, please fill out this form completely. All fields are required. </b><br>";
  177. echo " </td>\n";
  178. echo " <td width='20%' align='right'>\n";
  179. echo " <input type='button' class='btn' name='back' alt='back' onclick=\"window.history.back()\" value='Back'>\n";
  180. echo " </td>\n";
  181. echo " </tr>\n";
  182. echo "</table>\n";
  183. echo "<table border='0' $tablewidth cellpadding='6' cellspacing='0'>";
  184. echo " <tr>";
  185. echo " <td class='vncellreq' width='40%'>Username:</td>";
  186. echo " <td class='vtable' width='60%'><input type='text' class='formfld' autocomplete='off' name='username' value='$username'></td>";
  187. echo " </tr>";
  188. echo " <tr>";
  189. echo " <td class='vncellreq'>Password:</td>";
  190. echo " <td class='vtable'><input type='password' class='formfld' autocomplete='off' name='password' value='$password'></td>";
  191. echo " </tr>";
  192. echo " <tr>";
  193. echo " <td class='vncellreq'>Confirm Password:</td>";
  194. echo " <td class='vtable'><input type='password' class='formfld' autocomplete='off' name='confirmpassword' value='$confirmpassword'></td>";
  195. echo " </tr>";
  196. echo " <tr>";
  197. echo " <td class='vncellreq'>Email:</td>";
  198. echo " <td class='vtable'><input type='text' class='formfld' name='user_email' value='$user_email'></td>";
  199. echo " </tr>";
  200. echo " <tr>";
  201. echo " <td class='vncell'>First Name:</td>";
  202. echo " <td class='vtable'><input type='text' class='formfld' name='contact_name_given' value='$contact_name_given'></td>";
  203. echo " </tr>";
  204. echo " <tr>";
  205. echo " <td class='vncell'>Last Name:</td>";
  206. echo " <td class='vtable'><input type='text' class='formfld' name='contact_name_family' value='$contact_name_family'></td>";
  207. echo " </tr>";
  208. echo " <tr>";
  209. echo " <td class='vncell'>Company Name:</td>";
  210. echo " <td class='vtable'><input type='text' class='formfld' name='contact_organization' value='$contact_organization'></td>";
  211. echo " </tr>";
  212. echo "</table>";
  213. echo "</div>";
  214. echo "<div class='' style='padding:10px;'>\n";
  215. echo "<table $tablewidth>";
  216. echo " <tr>";
  217. echo " <td colspan='2' align='right'>";
  218. echo " <input type='submit' name='submit' class='btn' value='Create Account'>";
  219. echo " </td>";
  220. echo " </tr>";
  221. echo "</table>";
  222. echo "</form>";
  223. echo " </td>";
  224. echo " </tr>";
  225. echo "</table>";
  226. echo "</div>";
  227. //show the footer
  228. require_once "includes/footer.php";
  229. ?>