Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
169 lines (129 sloc) 4.07 KB
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
class sQanner
{
private $build = 6;
private $key;
private $endpoint;
private $config;
public function __construct($key, $endpoint, $config)
{
$this->key = $key;
$this->endpoint = $endpoint;
$this->config = json_decode($config, true);
}
private function strposa($haystack, $needle)
{
if (!is_array($needle))
$needle = array($needle);
foreach ($needle as $query) {
if (trim($query) == '')
continue;
if (strpos($haystack, $query) !== false)
return true;
}
return false;
}
private function file_post_contents($url, $data)
{
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($data)
)
);
$context = stream_context_create($opts);
return file_get_contents($url, false, $context);
}
public function run()
{
$config = $this->config;
$structure = array();
$directory = $config['root_dir'] . $config['path'];
$directory = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($iterator as $object) {
try {
$name = $object->getFilename();
$ext = $object->getExtension();
$path = $object->getPathname();
// Пропускаем дирку
if (!empty($config['skipdir']) && $this->strposa($path, $config['skipdir']))
continue;
// Расширение разрешено
if (!empty($config['ext_incl']) && !in_array($ext, $config['ext_incl']))
continue;
// Расширение запрещено
if (!empty($config['ext_excl']) && in_array($ext, $config['ext_excl']))
continue;
// Файл запрещённый
if (!empty($config['skipfile']) && $this->strposa($path, $config['skipfile']))
continue;
$date_time = $object->getMTime();
$size = $object->getSize();
$hash = md5($path . $name . $size . $date_time);
$structure[$hash]['path'] = $path;
$structure[$hash]['date'] = $date_time;
} catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }
}
return $base_json = serialize($structure);
}
public function send($db)
{
/*if (function_exists('bzcompress')) {
$db = bzcompress($db, 9);
$compress = 'bzcompress';
}elseif (function_exists('gzcompress')) {
$db = gzcompress($db, 9);
$compress = 'gzcompress';
}*/
$data = array(
'key' => $this->key,
'db' => $db,
'compress' => (isset($compress) ? $compress : 'nope')
);
$this->file_post_contents($this->endpoint, $data);
}
public function update()
{
$update = file_get_contents('https://raw.githubusercontent.com/OnArs/sQanner.php/master/sQanner.php?'.date('His'));
preg_match('/build = (\d+);/', $update, $v);
$v = $v[1];
// если эта версия новее (больше) той что у нас то
if ($v > $this->build) {
file_put_contents(__FILE__, $update);
// отправляем пуш в сервис о том что обновились на таком то сервере до такой то версии
$data = array(
'key' => $this->key,
'build' => $v
);
$this->file_post_contents($this->endpoint, $data);
}
}
}
if ($_GET['whereisit'])
die(__DIR__);
if (!$_POST['config'] && !$_POST['key'])
die('This site is under sQanner security');
if (!$_POST['key'] || trim($_POST['key'])=='')
die('WTF! Where is the key?');
$key = $_POST['key'];
if ($_POST['mode']=='update'){
$cw = new sQanner($key, null, null);
$cw->update();
}
if (!$_POST['config'] || trim($_POST['config'])=='')
die('WTF! Where is the configuration?');
else
$config = $_POST['config'];
if (!$_POST['endpoint'] || trim($_POST['endpoint'])=='')
die('WTF! Where is the configuration?');
else
$endpoint = $_POST['endpoint'];
if ($_POST['mode']=='run'){
$cw = new sQanner($key, $endpoint, $config);
$db = $cw->run();
$cw->send($db);
}
You can’t perform that action at this time.