<?php
function cidr_match($ip, $ranges)
{
$ranges = (array)$ranges;
foreach($ranges as $range) {
list($subnet, $mask) = explode('/', $range);
if((ip2long($ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) {
return true;
}
}
return false;
}
$github_ips = array('207.97.227.253', '50.57.128.197', '108.171.174.178', '50.57.231.61');
$github_cidrs = array('204.232.175.64/27', '192.30.252.0/22');
$dir = dirname(__FILE__) . '/../../..';
if( in_array($_SERVER['REMOTE_ADDR'], ['77.220.134.85', '95.143.220.95']) ||
in_array($_SERVER['REMOTE_ADDR'], $github_ips) ||
cidr_match($_SERVER['REMOTE_ADDR'], $github_cidrs)) {
$hard = "git checkout -- .";
if(!empty($_GET['hard']))
{
$hard = "git reset --hard HEAD^";
}
echo "<pre>";
echo "Восстанавливаем все из репозитория\n";
$command = "cd $dir && $hard && git pull && git submodule update --init --recursive\n";
echo "$command\n";
$return = htmlentities(trim(shell_exec($command)));
if($return){
$time = time();
$status = htmlentities(trim(shell_exec("cd $dir && git status")));
file_put_contents("$dir/../$time.deploy", $return);
if(is_dir("$dir/app/runtime"))
{
echo $return . "\n" . $status . "\n";
echo "Очищаем папку $dir/app/runtime\n";
}
if(is_dir("$dir/app/runtime"))
{
shell_exec("cd $dir/app/runtime && rm -f ./*");
echo "Очищаем папку $dir/app/web/assets\n";
}
if(is_dir("$dir/app/web/assets"))
{
shell_exec("cd $dir/app/web/assets && rm -f ./*");
echo "Очищаем папку $dir/app/web/minify\n";
}
shell_exec("cd $dir/app/web/minify && rm -f ./*");
echo "</pre>";
}
}
else {
header('HTTP/1.1 404 Not Found');
echo "404 Not Found.\n";
echo 'Remote addr: ' . $_SERVER['REMOTE_ADDR'];
exit;
}