Advertisement
klyx99

Trinity-Mangos Registration PHP Script - Rel: 160226.0704

Feb 24th, 2016
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.00 KB | None | 0 0
  1. <?php
  2.     /*
  3.         A simple mangos/trinity registration engine
  4.         This is the engine only. Use it as a snippet or
  5.         include it as an iframe.
  6.        
  7.         If you don't know what to edit
  8.         or change, don't ask or use - it get more complicated
  9.         from here - especially if you are running a server
  10.        
  11.         DEFINITIONS:
  12.             - TM    : trinity and mangos
  13.        
  14.         FEATURES:
  15.             - simple php (or as easy as I could make it)
  16.             - self-contained file
  17.             - checks existing (ofc)
  18.             - checks for banned
  19.             - auto inserts ip (not perfect but works) TM do this automatically later.
  20.             - creates join date
  21.             - fills both emails
  22.            
  23.         ADMIN:
  24.             You will have to adjust the INSERT if you are using MANGOS as this script is
  25.             written with TRINITY in use.
  26.        
  27.         Coded by: FrostByte (send thank you to klyxmaster[]gmail if you find this useful!)      
  28.         Rel:  160226.0704
  29.  
  30.         UPDATES:
  31.             - 160226
  32.                 o Added captcha
  33.                 o Missing "set realmlist..." Fixed
  34.             - 160225
  35.                 o released script
  36.     */
  37.    
  38.    
  39.    
  40.     /*
  41.         change these
  42.     */
  43.     date_default_timezone_set('America/Chicago');
  44.     $server     = array (
  45.         'host'          => 'localhost',
  46.         'user'          => 'root',
  47.         'pass'          => 'root',
  48.         'realmd'        => 'auth',                  // usually Trinity: auth, Mangos: realmd
  49.         'xpac'          => '2',                     // 0:vanilla, 1:TBC, 2:WotLK, 3:Cata, 4:MoP etc...
  50.         'servername'    => 'FrostByte',
  51.         'email'         => 'optional@thismail.com',
  52.         'realmlist'     => 'mycoolwow.domain.net' // this is what user's will be told to set the realmlist.wtf to
  53.     );
  54.    
  55.     /*
  56.         If everything above is correct, this should go through smoothly
  57.     */
  58.     @mysql_connect($server['host'], $server['user'], $server['pass']) or
  59.         die('Unable to connect to SQL server');
  60.     @mysql_select_db($server['realmd']) or
  61.         die('Unable to connect to '.$server["realmd"].' database!');
  62.    
  63.     $errorTxt = '';
  64.    
  65.     /*
  66.         various functions
  67.         -----^-----^-----^-----^-----^-----^-----^-----^-----^-----^-----^-----
  68.     */
  69.     /** clean up some strings nothing fancy **/
  70.     function clean($text)
  71.     {
  72.         return mysql_real_escape_string($text);
  73.     }
  74.    
  75.     /** decent ip finder **/
  76.     function userIP()
  77.     {
  78.         if (!empty($_SERVER['HTTP_CLIENT_IP'])) :      
  79.             $ip = $_SERVER['HTTP_CLIENT_IP'];
  80.         elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) :    
  81.             $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  82.         else :
  83.             $ip = $_SERVER['REMOTE_ADDR'];
  84.         endif;
  85.        
  86.         return $ip;
  87.     }
  88.    
  89.     /** simple query routine **/
  90.     function query($sql)
  91.     {
  92.         $query = @mysql_query($sql) or die("Bad query string: <br/>$sql<br/>".mysql_error());
  93.         return $query;
  94.     }
  95.    
  96.     function wowPW($username, $password)
  97.     {
  98.         return SHA1($username.':'.$password);
  99.     }
  100.    
  101.     /*
  102.         process the form
  103.         -----^-----^-----^-----^-----^-----^-----^-----^-----^-----^-----^-----
  104.     */
  105.     if( isset($_POST['username']) ):
  106.        
  107.         /** get and clean up some form vars **/
  108.         $username       = strtoupper( clean($_POST['username']) );
  109.         $password       = strtoupper( clean($_POST['password']) );
  110.         $pw2            = strtoupper( clean($_POST['password2']) );
  111.         $email          = clean($_POST['email']);
  112.         $ip             = $_POST['ip'];
  113.         $time           = $_POST['time'];
  114.         $captchaAnswer  = $_POST['captchaAnswer'];
  115.         $captcha        = $_POST['captcha'];
  116.        
  117.         /** see if any part of the account exist **/
  118.         $result = query("SELECT * FROM `account` WHERE `username` = '$username' LIMIT 1");
  119.         if( mysql_num_rows($result) > 0 ): $errorTxt .= 'This name is in use!<br/>'; endif;
  120.        
  121.         $result = query("SELECT * FROM `account` WHERE `email` = '$email' LIMIT 1");
  122.         if( mysql_num_rows($result) > 0 ): $errorTxt .= 'That email is already registered!<br/>'; endif;
  123.        
  124.         $result = query("SELECT * FROM `account` WHERE `last_ip` = '$ip' LIMIT 1");
  125.         if( mysql_num_rows($result) > 0 ): $errorTxt .= 'That IP is in use!<br/>'; endif;
  126.        
  127.         /** matching pw? **/
  128.         if ( $password != $pw2 ): $errorTxt .= 'Confirmation password does not match.'; endif;
  129.        
  130.         /** correct captcha **/
  131.         if ( $captcha != $captchaAnswer ): $errorTxt .= 'Captcha answer incorrect.'; endif;
  132.        
  133.         /** if all is good errorTxt will still be NULL  **/
  134.         if( empty($errorTxt) ):
  135.             $time = date("Y-m-d H:i:s", $time);
  136.             $password = wowPW($username, $password);
  137.            
  138.             $insert = "INSERT INTO `account`
  139.            (
  140.                username,
  141.                sha_hash_pass,
  142.                email,
  143.                reg_email,
  144.                joindate,
  145.                last_ip,
  146.                last_attempt_ip,
  147.                expansion
  148.              
  149.            ) VALUES (
  150.                '$username',
  151.                '$password',
  152.                '$email',
  153.                '$email',
  154.                '$time',
  155.                '$ip',
  156.                '$ip',
  157.                ".$server['xpac']."
  158.            )";
  159.            
  160.             /**
  161.                 I check every applicant before haphazardly letting the system add them. Adjust / comment out
  162.                 the following as needed
  163.             **/
  164.             /*
  165.             file_put_contents($username.'.sql',$insert);        // comment out this line to use below
  166.             echo 'Your account was created successfully. A staff member will review it shortly and update it to play. <br/>
  167.                 You will be notified by email (one you provided) when updated. If you are unable to access it after <br/>6hrs (rare),
  168.                 please email <a href="mailto:'.$server['email'].'">'.$server['email'].'</a> to expidite it.<br/><br/>Thank you!';
  169.            
  170.            */
  171.             file_put_contents('new_users/'.$username.'.sql',$insert);        // save it in case something goes wrong
  172.             query($insert);                                                 // uncomment this line to add instantly
  173.            
  174.             echo 'Your account here has been created successfully!<br/>
  175.                    You will need to edit your c:/[wowfolder]/data/enUS/realmlist.wtf file. <br/>
  176.                    replace its contents with the following:
  177.                    <center><h2>set realmlist '.$server['realmlist'].'</h2></center>
  178.                    To play: use the WOW.EXE, <font color="red">NEVER USE THE LAUNCHER</font><br/><br/>
  179.                    If you have any questions, post in the forums
  180.            ';
  181.            
  182.             die;
  183.            
  184.         endif; // errorTxt = NULL
  185.     endif; // form check
  186.        
  187. ?>
  188. <center>
  189.    
  190.     <form method="post" action="register.php">
  191.         <?='<h2><font color="white">'.$server['servername'].' Registration</font></h2>';?>
  192.         <?php
  193.            
  194.             if( !empty($errorTxt) ):
  195.                 echo "<p><font color='red'><b>$errorTxt</b></font></p>";
  196.             endif;
  197.            
  198.             // captcha basic -
  199.             $v1 = rand(1,10);
  200.             $v2 = rand(1,10);
  201.             $an = $v1 + $v2;
  202.            
  203.         ?>
  204.         <input required type="text" placeholder="Desired Login ID" name="username" /><br/>
  205.         <input required type="password" placeholder="Password" name="password" /><br/>
  206.         <input required type="password" placeholder="Verify PW" name="password2" /><br/>
  207.         <input required type="email" placeholder="Valid Email" name="email" /><br/>
  208.         <font color="white"><?="$v1 + $v2";?> = </font><input required type="text" name="captchaAnswer" placeholder="answer" size="5"/><br/>
  209.        
  210.         <input type="hidden" name="captcha" value="<?=$an;?>" />
  211.         <input type="hidden" name="ip" value="<?=userIp();?>" />
  212.         <input type="hidden" name="time" value="<?=time();?>" /><br/>
  213.         <input type="submit" value="Signup" />
  214.     </form>
  215.  
  216. </center>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement