Advertisement
Guest User

Untitled

a guest
Mar 28th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.11 KB | None | 0 0
  1. <?php
  2.  
  3. //DB con file
  4. include 'dbcon.php';
  5.  
  6. //JSON Ecrypt
  7. function xor_string($string, $key) {
  8.     for($i = 0; $i < strlen($string); $i++)
  9.         $string[$i] = ($string[$i] ^ $key[$i % strlen($key)]);
  10.     return $string;
  11. }
  12.  
  13. //Check acc exist in DB
  14. function UserValidation ($conn, $user, $pass) {
  15.     $checkuserquery = $conn->query("SELECT * FROM userinfo WHERE `username` = '".$user."' AND `password` = '".$pass."'");
  16.     $checkuservalid = $checkuserquery->num_rows;
  17.     if ($checkuservalid == 1) {
  18.         return true;
  19.     }else{
  20.         return false;
  21.     }
  22. }
  23.  
  24. //Check active(not expire) acc in DB
  25. function UserExpiryCheck ($conn, $user, $pass) {
  26.     $currenttime = time();
  27.     $userexpiryquery = UserExpiryTime($conn, $user, $pass);
  28.     if ($userexpiryquery > $currenttime || $userexpiryquery == "Unlimited") {
  29.         return true;
  30.     } else {
  31.         return false;
  32.     }
  33. }
  34.  
  35. //Get user expiry date
  36. function UserExpiryTime ($conn, $user, $pass) {
  37.     $getuserquery = $conn->query("SELECT * FROM userinfo WHERE `username` = '".$user."' AND `password` = '".$pass."'");
  38.     $getuserarray= $getuserquery->fetch_array(MYSQLI_ASSOC);
  39.     $userexpiryquery = $getuserarray['exp_unix'];
  40.     return $userexpiryquery;
  41. }
  42.  
  43. //Get OpenVPN configuration file
  44. function OpenVPNConfigFileGet ($server, $protocol, $proxy) {
  45.     $directory = getcwd() . "\config\ovpn";
  46.     if ($proxy == "allow"){
  47.         $download = $directory . "\\" . $server . "-" . $protocol . "-Proxy.ovpn";
  48.     } else{
  49.         $download = $directory . "\\" . $server . "-" . $protocol . ".ovpn";
  50.     }
  51.     $client = base64_encode(file_get_contents("$download"));
  52. }
  53.  
  54. //Deployement section
  55. $action = isset($_GET['action']) != '' ? $_GET['action'] : '';
  56. switch($action) {
  57.   //case "authorize" authorizes the users
  58.     case "authorize":
  59.     $obj = new stdClass();
  60.         $user = $conn->real_escape_string($_GET['user']);
  61.         $pass = $conn->real_escape_string($_GET['pass']);
  62.         $obj->auth = 'deny';
  63.     $obj->expirytime = 'expired';
  64.     $obj->user = 'not_exist'; // if user not exists
  65.         if(UserValidation ($conn, $user, $pass))
  66.         {
  67.       $obj->user = 'exists';
  68.             $obj->expirytime = UserExpiryTime($conn, $user, $pass);
  69.             if (UserExpiryCheck ($conn, $user, $pass))
  70.                 $obj->auth = 'allow';
  71.             else {
  72.                 $obj->auth = 'deny';
  73.             }
  74.         }
  75.     $encrypted = xor_string(base64_encode(json_encode($obj)), 'Arnu87UHpzWhEcbakpAJZif43jlvOFrQFIByTSFg8djGCLMT4nCIq0xYGid2');
  76.     echo $encrypted;
  77.         break;
  78.   //case "connectopenvpn" get OpenVPN configuration file //not complete
  79.   case "connectopenvpn":
  80.     $user = $conn->real_escape_string($_GET['user']);
  81.     $pass = $conn->real_escape_string($_GET['pass']);
  82.     $server = ($_GET['server']);
  83.     $protocol = ($_GET['protocol']);
  84.     $proxy = (isset($_GET['proxy']) && $_GET['proxy'] == 'allow') ? "allow" : "";
  85.     if(UserExpiryCheck ($conn, $user, $pass))
  86.         {
  87.       OpenVPNConfigFileGet ($server, $protocol, $proxy);
  88.       $encrypted = xor_string(base64_encode($client), 'Arnu87UHpzWhEcbakpAJZif43jlvOFrQFIByTSFg8djGCLMT4nCIq0xYGid2');
  89.       echo $encrypted;
  90.     }
  91.     break;
  92.     default:
  93.         echo "Hello World!";
  94. }
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement