Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PGPShare
- {
- public $mysqli;
- public $errormsg;
- function __construct()
- {
- include("config.php");
- $this->mysqli = new mysqli($db['host'], $db['user'], $db['pass'], $db['name']);
- }
- function AddUser1Key($key)
- {
- $id = substr(hash("SHA512", microtime()), 10, 10);
- $ip = $_SERVER['REMOTE_ADDR'];
- if(strlen($key) == 0) { $this->errormsg = 1; return false; }
- elseif(strlen($key) < 10) { $this->errormsg = 2; return false; }
- elseif(strlen($key) > 4294967295) { $this->errormsg = 3; return false; }
- else
- {
- $user2key = "None";
- $query = $this->mysqli->prepare("INSERT INTO `keys` (`id`, `user1key`, `user2key`, `user1ip`) VALUES (?, ?, ?, ?)");
- $query->bind_param("ssss", $id, $key, $user2key, $ip);
- $query->execute();
- $query->close();
- return $id;
- }
- }
- function AddUser2Key($key, $id)
- {
- if(strlen($id) == 0) { $this->errormsg = 1; return false; }
- elseif(strlen($id) > 10) { $this->errormsg = 2; return false; }
- elseif(strlen($id) < 10) { $this->errormsg = 3; return false; }
- elseif(strlen($key) == 0) { $this->errormsg = 4; return false; }
- elseif(strlen($key) < 10) { $this->errormsg = 5; return false; }
- elseif(strlen($key) > 4294967295) { $this->errormsg = 6; return false; }
- else
- {
- $query = $this->mysqli->prepare("SELECT `user2key` FROM `keys` WHERE `id`=?");
- $query->bind_param("s", $id);
- $query->bind_result($user2key);
- $query->execute();
- $query->store_result();
- $count = $query->num_rows;
- $query->fetch();
- $query->close();
- if($count == 0)
- {
- $this->errormsg = 7;
- return false;
- }
- else
- {
- if($user2key !== "None")
- {
- $this->errormsg = 8;
- return false;
- }
- else
- {
- $query = $this->mysqli->prepare("UPDATE `keys` SET `user2key`=? WHERE `id`=?");
- $query->bind_param("ss", $key, $id);
- $query->execute();
- $query->close();
- return true;
- }
- }
- }
- }
- function VerifyId($id)
- {
- if(strlen($id) == 0) { $this->errormsg = 1; return false; }
- elseif(strlen($id) > 10) { $this->errormsg = 2; return false; }
- elseif(strlen($id) < 10) { $this->errormsg = 3; return false; }
- else
- {
- if(!$query = $this->mysqli->prepare("SELECT `user2ip` FROM `keys` WHERE `id`=?"))
- {
- $this->errormsg = $query->mysqli->error;
- }
- $query->bind_param("s", $id);
- $query->bind_result($user2ip);
- $query->execute();
- $query->store_result();
- $count = $query->num_rows;
- $query->fetch();
- if($count == 0)
- {
- $this->errormsg = 4;
- return false;
- }
- else
- {
- if($user2ip !== "0.0.0.0")
- {
- $this->errormsg = 5;
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- }
- function VerifyIp($id)
- {
- if(strlen($id) == 0) { $this->errormsg = 1; return false; }
- elseif(strlen($id) > 10) { $this->errormsg = 2; return false; }
- elseif(strlen($id) < 10) { $this->errormsg = 3; return false; }
- else
- {
- $ip = $_SERVER['REMOTE_ADDR'];
- $query = $this->mysqli->prepare("SELECT * FROM `keys` WHERE `id`=? AND `user1ip`=?");
- $query->bind_param("ss", $id, $ip);
- $query->execute();
- $query->store_result();
- $count = $query->num_rows;
- $query->close();
- if($count == 0)
- {
- $query = $this->mysqli->prepare("UPDATE `keys` SET `user2ip`=? WHERE `id`=?");
- $query->bind_param("ss", $ip, $id);
- $query->execute();
- $query->close();
- return true;
- }
- else
- {
- $this->errormsg = 4;
- return false;
- }
- }
- }
- function GetUser1Key($id)
- {
- if(strlen($id) == 0) { $this->errormsg = 1; return false; }
- elseif(strlen($id) > 10) { $this->errormsg = 2; return false; }
- elseif(strlen($id) < 10) { $this->errormsg = 3; return false; }
- else
- {
- $query = $this->mysqli->prepare("SELECT `user1key` FROM `keys` WHERE `id`=?");
- $query->bind_param("s", $id);
- $query->bind_result($user1key);
- $query->execute();
- $query->store_result();
- $count = $query->num_rows;
- $query->fetch();
- $query->close();
- if($count == 0)
- {
- $this->errormsg = 4;
- return false;
- }
- else
- {
- return $user1key;
- }
- }
- }
- function GetUser2Key($id)
- {
- if(strlen($id) == 0) { $this->errormsg = 1; return false; }
- elseif(strlen($id) > 10) { $this->errormsg = 2; return false; }
- elseif(strlen($id) < 10) { $this->errormsg = 3; return false; }
- else
- {
- $ip = $_SERVER['REMOTE_ADDR'];
- $query = $this->mysqli->prepare("SELECT `user1ip`,`user2key` FROM `keys` WHERE `id`=?");
- $query->bind_param("s", $id);
- $query->bind_result($user1ip, $user2key);
- $query->execute();
- $query->store_result();
- $count = $query->num_rows;
- $query->fetch();
- $query->close();
- if($count == 0)
- {
- $this->errormsg = 4;
- return false;
- }
- else
- {
- if($ip == $user1ip)
- {
- return $user2key;
- }
- else
- {
- $this->errormsg = 5;
- return false;
- }
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement