Guest User

Untitled

a guest
Feb 14th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. <?php
  2. //single file registration script!
  3. session_start();
  4. //requires
  5. require("simple-php-captcha.php");
  6.  
  7. //uncomment to Disable registration.
  8. //die("<br><br><center>Registration is currently disabled due to closed beta testing. Please try again in a couple days! :D</center><br><center><p>Right now, beta testing is invite only.</p></center>");
  9.  
  10. //Config (You really only need to change domain, m, & p. But anything in the config array can be changed how you want :)
  11. $config = array(
  12. "domain" => "example.com",
  13. "m" => escapeshellcmd("me@example.com"),
  14. "p" => escapeshellcmd("password"),
  15. "captcha" => array( //Configure Captcha settings for registration.
  16. 'min_length' => 5,
  17. 'max_length' => 5,
  18. 'backgrounds' => array('backgrounds/45-degree-fabric.png','backgrounds/45-degree-fabric.png','backgrounds/45-degree-fabric.png','backgrounds/45-degree-fabric.png'),
  19. 'fonts' => array('fonts/times_new_yorker.ttf'),
  20. 'characters' => 'ABCDEFGHJKLMNPRSTUVWXYZabcdefghjkmnprstuvwxyz23456789',
  21. 'min_font_size' => 15,
  22. 'max_font_size' => 20,
  23. 'color' => '#666',
  24. 'angle_min' => 0,
  25. 'angle_max' => 20,
  26. 'shadow' => true,
  27. 'shadow_color' => '#fff',
  28. 'shadow_offset_x' => -1,
  29. 'shadow_offset_y' => 1
  30. )
  31. );
  32. //Check for POST
  33. head();
  34. if(isset($_SESSION['email']) && isset($_POST['username'])){
  35. //body();
  36. $_SESSION['message'] = '<p style="color:DarkRed">You already created an email. Get outta here!</p>';
  37.  
  38. }
  39. if(isset($_POST['username']) && isset($_POST['password']) && isset($_POST['captcha'])){
  40. //Process a registration.
  41. if($_POST['captcha'] == $_SESSION['captcha']['code']){
  42. if(!isset($_SESSION['email'])){
  43. $ret = register($_POST['username'], $_POST['password']);
  44. if($ret === true){
  45. $_SESSION['message'] = '<text><p style="color:green">E-mail '.$_POST['username'].'@'.$config['domain'].' successfully created! You may login to that email using the following settings:</p>
  46. <br>
  47. Server: <b>'.$config['domain'].'</b><br>
  48. Username: <b>'.$_POST['username'].'@'.$config['domain'].'</b><br>
  49. Password: Duh?<br>
  50. Type: <b>IMAP/SMTP</b><br>
  51. Ports: <b>993/587</b><br>
  52. SSL/TLS: <b>Yes</b><br>
  53. </text>';
  54. $_SESSION['email'] = $username."@".$config['domain'];
  55. } else {
  56. $_SESSION['message'] = '<text style="color:darkred">There was an error creating the email, please try again or contact the systems administrator!<br>'.$ret.'</text>';
  57. }
  58. }
  59.  
  60. } else {
  61. $_SESSION['message'] = '<text style="color:darkred">The captcha was invalid, please try again!</text>';
  62. }
  63.  
  64. }
  65. bodyLogin();
  66. function head(){
  67. echo '';
  68. ?>
  69. <html>
  70. <head>
  71. <title><?php echo $config['domain']; ?> Registration</title>
  72. <meta charset="utf-8">
  73. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  74. <meta name="viewport" content="width=device-width, initial-scale=1">
  75. <meta name="description" content="">
  76. <meta name="author" content="">
  77. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  78. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
  79. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  80. <style>
  81. .frame {
  82. display: block;
  83. width: 100vw;
  84. height: 80vh;
  85. max-width: 100%;
  86. margin: 0;
  87. padding: 0;
  88. border: 0 none;
  89. box-sizing: border-box;
  90. }
  91. </style>
  92. </head>
  93.  
  94. <?php
  95. }
  96.  
  97. function bodyLogin(){
  98. global $config;
  99. $_SESSION['captcha'] = simple_php_captcha($config['captcha']);
  100. echo '';
  101. ?>
  102. <body>
  103. <div class="container">
  104. <div class="page-header">
  105. <h1><?php echo $config['domain']; ?> Registration Form</h1>
  106. </div>
  107. <div class="row">
  108. <div class="col-md-6">
  109. <iframe src="eula.html" class="frame"></iframe><br />
  110. </div>
  111. <div class="col-md-6">
  112. <form action="" method="POST">
  113. <div class="form-group">
  114. <label for="user">Username:</label>
  115. <div class="row">
  116. <div class="col-md-6">
  117. <input type="username" class="form-control" id="username" name="username">
  118. </div>
  119. <div class="col-md-6">
  120. <p>@<?php echo $config['domain']; ?></p>
  121. </div>
  122. </div>
  123. </div>
  124. <div class="form-group">
  125. <label for="pass">Password:</label>
  126. <input type="password" class="form-control" id="password" name="password">
  127. </div>
  128. <div class="form-group">
  129. <label for="cap">Captcha Request:</label><br />
  130. <img src="<?php echo $_SESSION['captcha']['image_src']; ?>">&nbsp;&nbsp;<input type="text" name="captcha" id="captcha" rows="12">
  131. </div>
  132. <small>By clicking "Submit" you are agreeing to the Terms and Conditions found to the left of this form.</small><button type="submit" class="btn btn-primary pull-right">Submit</button>
  133. </form><br>
  134. <?php
  135. if(isset($_SESSION['message']) && $_SESSION['message'] !== ""){
  136. echo $_SESSION['message'];
  137. $_SESSION['message'] = "";
  138. }
  139. ?>
  140. </div>
  141. </div>
  142. </div>
  143. </body>
  144. <?php
  145. }
  146. function register($username, $password){
  147. global $config;
  148. //first make sure this shit is safe.
  149. $username = clean($username);
  150. $password = escapeshellcmd($password);
  151. $return = shell_exec('curl -X POST -k --insecure --user '.$config['m'].':'.$config['p'].' -d "email='.$username.'@'.$config['domain'].'" -d "password='.$password.'" https://localhost/admin/mail/users/add');
  152. $bool = false;
  153. if(strpos($return, 'mail user added') !== false){
  154. $bool = true;
  155. } else if(strpos($return, 'User already exists.') !== false){
  156. $bool = "User account already exists, please use a different name.";
  157. } else {
  158. $bool = false;
  159. }
  160. return $bool;
  161. }
  162. function clean($string) {
  163. $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
  164. $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
  165.  
  166. return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
  167. }
  168. ?>
Add Comment
Please, Sign In to add comment