Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
date_default_timezone_set('Europe/Moscow');
header('Content-Type: text/html; charset=utf-8');
set_time_limit(0);
function ccc($url, $proxy)
{
$url = trim($url);
$proxy = trim($proxy);
if ($ch = curl_init($url)) {
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$content = curl_exec($ch);
$header = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($header != 200)
{
echo "bad proxy\n";
return false;
}
return $content;
}
}
function my_shell_exec($cmd, &$stdout=null, &$stderr=null) {
$proc = proc_open($cmd,[
1 => ['pipe','w'],
2 => ['pipe','w'],
],$pipes);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
return proc_close($proc);
}
$files = file('files.txt');
$proxyList = file('proxy.txt');
$i = 0;
$url = 'http://zhopify.hackquest.phdays.com/'; // without /.git
foreach ($files as $k => $file)
{
$content = false;
if (
strpos($file, '.svg') !== false ||
strpos($file, '.gif') !== false ||
strpos($file, '.png') !== false ||
strpos($file, '.jpg') !== false ||
strpos($file, '.css') !== false ||
strpos($file, '.js') !== false ||
strpos($file, '.eot') !== false ||
strpos($file, '.ttf') !== false ||
strpos($file, '.woff') !== false
)
{
continue;
}
my_shell_exec("git checkout $file", $null, $e);
echo $e . "\n";
if (preg_match('#\(([^)]+)\)#', $e, $o))
{
$hash = $o[1];
$dir ='.git/objects/' . substr($hash, 0, 2) . '/';
$path = $dir . substr($hash, 2);
if (!is_dir($dir)) mkdir($dir, 0755);
do {
$proxy = $proxyList[$i];
echo "Proxy $proxy ::: GET [$k] $file\n";
$content = ccc($url . $path, $proxy);
if (!$content || strpos("Too Many requests", $content) !== false)
{
$content = false;
$i++;
if ($i > $proxyList)
{
$i = 0;
}
}
} while ($content == false);
file_put_contents($path, $content);
exec("git checkout $file");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.