oppose

t4545t45

Dec 1st, 2016
990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. <?php
  2. class initialiser {
  3.   /*
  4.   * @var array contains isp's
  5.   */
  6.   protected $vpn = array('opengw', 'midphase.com', 'ipvanish', 'ovh', 'pointtoserver', 'privateinternetaccess', 'blazingfast', 'cyberghost');
  7.   /*
  8.   * @var string url for redirection
  9.   */
  10.   protected $redir;
  11.   /*
  12.   * @var string remote client domain
  13.   */
  14.   protected $domain;
  15.   /*
  16.   * Constructor
  17.   * sets client variables and calls main
  18.   */
  19.   public function __construct()
  20.   {
  21.     if(isset($_SERVER['HTTP_CF_CONNECTING_IP']))
  22.     {
  23.       $this->domain = gethostbyaddr($_SERVER['HTTP_CF_CONNECTING_IP']); // Configured client address for cloudflare
  24.     } else {
  25.       $this->domain = gethostbyaddr($_SERVER['REMOTE_ADDR']); // Configured client address raw
  26.     }
  27.     $config = json_decode(file_get_contents('config.json'));
  28.     $this->redir = $config->{'redirurl'};
  29.     $this->main();
  30.   }
  31.   /*
  32.   * allows strpos to act within an array to detect vpn hostnames
  33.   * @param array haystack
  34.   * @param string needle
  35.   */
  36.   public function astrpos($haystack, $needle)
  37.   {
  38.     if(!is_array($needle)) $needle = array($needle);
  39.     foreach($needle as $x)
  40.     {
  41.       if(strpos($haystack, $x) !== false) return true;
  42.     }
  43.     return false;
  44.   }
  45.   /*
  46.   * Check if the hostname corresponds with the protected array
  47.   * @returns boolean
  48.   */
  49.   public function isVPN()
  50.   {
  51.     if($this->astrpos($this->domain, $this->vpn) === false)
  52.     {
  53.       return false;
  54.     } else {
  55.       return true;
  56.     }
  57.   }
  58.   /*
  59.   * Main function that calls all returning objects
  60.   */
  61.   public function main()
  62.   {
  63.     if($this->isVPN() === true)
  64.     {
  65.       header("Location: " . $this->redir);
  66.     }
  67.   }
  68. }
  69. new initialiser();
  70.  ?>
Advertisement
Add Comment
Please, Sign In to add comment