Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function isValidIp($ip)
- {
- if(!eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(/[0-9]{1,2}){0,1}$", $ip))
- $return = false;
- else
- $return = true;
- if($return == true)
- {
- $parts = explode("/", $cidr);
- $ip = $parts[0];
- $netmask = $parts[1];
- $octets = explode(".", $ip);
- foreach($octets AS $octet)
- if($octet > 255)
- $return = false;
- if(($netmask != "") && ($netmask > 32))
- $return = false;
- }
- return $return;
- }
- function isValidEmail($value)
- {
- $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
- return preg_match($pattern, $value);
- }
- class conndb
- {
- private $mysql;
- public function __construct($db_host="localhost", $db_port="3306", $db_user="root", $db_pass="fr6truspak", $db_name="blah")
- {
- $this->mysql = @mysql_connect($db_host.":".$db_port, $db_user, $db_pass, true) or die('Unable to connect to database');
- mysql_select_db($db_name,$this->mysql) or die(mysql_error());
- }
- public function __destruct()
- {
- @mysql_close($this->mysql) or die(mysql_error());
- }
- public function send($query)
- {
- @mysql_query($query,$this->mysql) or die(mysql_error());
- }
- public function retrieve($query)
- {
- $sql = @mysql_query($query,$this->mysql) or die(mysql_error());
- return $sql;
- }
- }
- class account
- {
- private $mysql;
- public function __construct($account_db_conn)
- {
- $this->mysql = $account_db_conn;
- }
- public function isLoggedIn($ip)
- {
- $ip = mysql_real_escape_string($ip);
- if(!isValidIp($ip))
- return false;
- $sql = $this->mysql->retrieve("SELECT `date` FROM `logins` WHERE `ip` = INET_ATON('".$ip."') LIMIT 1");
- $row = mysql_fetch_array($sql);
- $one_min_ago = time() - 300;
- if(($row['date']) && ($row['date'] > $one_min_ago) && ($row['date'] < time()))
- return true;
- else
- return false;
- }
- public function validate($ip)
- {
- $ip = mysql_real_escape_string($ip);
- if(!isValidIp($ip))
- return false;
- $this->mysql->send("INSERT INTO `logins` (ip, date) VALUES (INET_ATON('".$ip."'),'".time()."')");
- }
- public function devalidate($ip)
- {
- $ip = mysql_real_escape_string($ip);
- if(!isValidIp($ip))
- return false;
- $this->mysql->send("DELETE FROM `logins` WHERE ip=INET_ATON('".$ip."') LIMIT 1");
- }
- public function register($username, $password, $user_email)
- {
- define('IN_PHPBB', true);
- $phpbb_root_path = '../';
- $phpEx = substr(strrchr(__FILE__, '.'), 1);
- include($phpbb_root_path . 'includes/functions_user.php');
- include($phpbb_root_path . 'includes/ucp/ucp_register.php');
- $username_clean=strtolower($username);
- $sql_ary = array(
- 'username' => $username,
- 'username_clean' => $username_clean,
- 'user_password' => phpbb_hash($password),
- 'user_pass_convert' => 0,
- 'user_email' => $user_email,
- 'user_email_hash' => crc32(strtolower($user_email)) . strlen($user_email),
- 'group_id' => 2,
- 'user_type' => 0,
- );
- return user_add($sql_ary);
- }
- }
- class regcode
- {
- private $mysql;
- public function __construct($db_conn)
- {
- $this->mysql = $db_conn;
- }
- public function isValidRegCode($reg_code)
- {
- $sql = $this->mysql->retrieve("SELECT * FROM `regcodes` WHERE `regcode` = '".$reg_code."' LIMIT 1");
- $row = mysql_fetch_array($sql);
- if(empty($row['regcode']))
- return false;
- if($this->is_banned($row['creator']))
- return false;
- if(is_numeric($row['owner']))
- return false;
- return true;
- }
- public function is_banned($account_id)
- {
- $sql = $this->mysql->retrieve("SELECT * FROM `phpbb_banlist` WHERE `ban_userid` = '".$account_id."'");
- while($row = mysql_fetch_array($sql))
- {
- if(($row['ban_start'] < time() && $row['ban_end'] > time()) || $row['ban_end']==0)
- return true;
- }
- return false;
- }
- public function generateRegCode($account_id)
- {
- $code = md5(uniqid());
- $this->mysql->send("INSERT INTO `regcodes` (regcode, creator, date_created) VALUES ('".$code."','".$account_id."','".time()."')");
- return $code;
- }
- public function calculateK($account_id)
- {
- $k = 0;
- $sql = $this->mysql->retrieve("SELECT * FROM `regcodes` WHERE `creator` = '".$account_id."' AND `owner`='0'");
- while($row = mysql_fetch_array($sql))
- {
- $k++;
- }
- return k;
- }
- public function viewRegCodes($account_id)
- {
- $sql = $this->mysql->retrieve("SELECT * FROM `regcodes` WHERE `creator` = '".$account_id."'");
- $i = 1; // IDENTIFIER
- $j = 0; // COUNTER: how many codes generated this function, updated
- $k = 0; // COUNTER: how many unused codes account has when calculated, not updated
- $g = 0; // COUNTER: how many codes POSSIBLY left to generate, updated
- while($row = mysql_fetch_array($sql))
- {
- $reg_codes[$i]['reg_code'] = $this->getRegCodeAsArray($row['regcode']);
- $reg_codes[$i]['status'] = $this->getRegCodeStatus($row['regcode']);
- $reg_codes[$i]['date_created'] = $row['date_created'];
- $reg_codes[$i]['owner'] = $row['owner'];
- $reg_codes[$i]['date_owned'] = $row['date_owned'];
- $i++;
- }
- $k = $this->calculateK($account_id);
- if($k > 1) // Reg codes must be used before you get more
- return $reg_codes;
- if(!is_array($reg_codes)) // New user: set up new reg codes
- {
- while($j < 2)
- {
- $this->generateRegCode($account_id);
- $j++;
- }
- }
- while($i > 1)
- {
- $diff = time() - $reg_codes[$i]['date_created'];
- $g = $k - $j;
- if(($diff > 1209600 || $diff < 0) && $g > 0)
- {
- $this->generateRegCode($account_id);
- $j++;
- }
- $i--;
- }
- if($j > 0)
- return $this->viewRegCodes($account_id);
- else
- return $reg_codes;
- }
- public function getRegCodeStatus($reg_code)
- {
- $sql = $this->mysql->retrieve("SELECT * FROM `regcodes` WHERE `regcode` = '".$reg_code."' LIMIT 1");
- $row = mysql_fetch_array($sql);
- if($row['owner'] > 0)
- return 0;
- if($row['owner'] > 0 && $this->is_banned($row['owner']))
- return 3;
- if(is_numeric($row['creator']) && !is_numeric($this->getRegCodeOwner($reg_code)))
- if($this->is_banned($row['creator']))
- return 2;
- return 1;
- }
- public function getRegCodeCreator($reg_code)
- {
- $sql = $this->mysql->retrieve("SELECT creator FROM `regcodes` WHERE `regcode` = '".$reg_code."' LIMIT 1");
- $row = mysql_fetch_array($sql);
- return $row['creator'];
- }
- public function getRegCodeOwner($reg_code)
- {
- $sql = $this->mysql->retrieve("SELECT owner FROM `regcodes` WHERE `regcode` = '".$reg_code."' LIMIT 1");
- $row = mysql_fetch_array($sql);
- return $row['owner'];
- }
- public function setRegCodeOwner($reg_code, $owner)
- {
- $this->mysql->send("UPDATE `regcodes` SET owner='".$owner."' WHERE regcode='".$reg_code."' LIMIT 1");
- }
- public function getRegCodeAsArray($reg_code)
- {
- $code[1] = substr($reg_code, 0, 4);
- $code[2] = substr($reg_code, 4, 3);
- $code[3] = substr($reg_code, 7, 5);
- $code[4] = substr($reg_code, 12, 20);
- return $code;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement