/* by 131 - cloudyks.org */
/* St Exupery Style */
$encoding="iso-8859-15";
$conf="ks_pref.conf";
if(is_file($conf)) include $conf;
error_reporting(0);
$version=1179735798;
define("KSP_XML",'');
define("KSP_TYPE_XML","Content-type: text/xml; charset=$encoding");
define("KSP_TYPE_TEXT","Content-type: text/plain; charset=$encoding");
$del=DIRECTORY_SEPARATOR;
$sep="\n";
$rsrcs="http://ksplorer.cloudyks.org";
$valid_msg="";
$fold=$_GET['fold'];
$action=$_POST['action'];
list($mode)=each($_GET);
$fold=realpath($fold?$fold:'.');
$fold_name=strrchr($fold,$del);
$parent=substr($fold,0,strrpos($fold,$del));
$parent_name=strrchr($parent,$del);
if(!$parent)list($parent,$parent_name)=array($del,$del);
$root_fold=dirname($_SERVER['SCRIPT_FILENAME']);
$backup_fold="$root_fold{$del}backup$fold";
$pcl_file="$root_fold{$del}pclzip.php";
function json_enc($vals){
if(!is_array($vals))return strtr($vals,array('"'=>'\"',"\n"=>''));
$str="";;foreach($vals as $k=>$v)$str.=",$k:\"".json_enc($v).'"';
return '{'.substr($str,1).'}';
}
function file_put_content($file,$contents){ return fwrite(fopen($file,'w'),$contents);}
function stripslashes_deep($value) { return is_array($value)?array_map('stripslashes_deep', $value):stripslashes($value); }
if(get_magic_quotes_gpc()) $_POST=stripslashes_deep($_POST);
function find_file($dir,$pattern){
$files=array();
foreach(glob("$dir/*") as $file){
$base_file=substr(strrchr($file,'/'),1);
if(is_dir($file)) $files=array_merge($files, find_file($file,$pattern));
if(preg_match("#$pattern#",$base_file))$files[]=$file;
}return $files;
}
function create_dir($dir){
if($dir && !is_dir($dir)) {
create_dir(substr($dir,0,strrpos($dir,'/')));
mkdir($dir);
}
}
function jsx_end(){die(json_enc($GLOBALS['rbx']));}
function rbx_msg($dest,$msg){ $GLOBALS['rbx'][$dest].="$msg\n";return 0; }
if(!is_file($pcl_file)){
copy("$rsrcs/pclzip.txt",$pcl_file);
rbx_msg('ok',"Module pclzip installé ($pcl_file)");
}
chdir($fold);
if(!$handle = opendir('.'))die("Impossible d'ouvrir le dossier");
if($action){
$file=$_POST['sub0'];$to=$_POST['sub1'];
$files_list=array_filter(explode($sep,str_replace("\r","",$file)));
$files=count($files_list)>1;
}
if($mode=="upload" ){
header(KSP_TYPE_TEXT);
if(extension_loaded('apc'))$data=apc_fetch("upload_{$_GET['upload_flag']}");
else $data=array();
die(json_enc($data));
}
if($mode=='view'){
$file=$_GET['file'];
header("Content-disposition: name=\"filename\";filename=\"$file\"");
header("Content-type: image/png");
$file="$fold$del$file";
list($w,$h,$type)=getimagesize($file);
if((!$_GET['full']) && ($w>80 || $h>80) ){
$exts=array(1=>'gif', 2=>'jpeg',3=>'png');
$create="imagecreatefrom".$exts[$type];
$im=$create($file);
$rat=$w/80;$nh=$h/$rat;
$pic=imagecreatetruecolor(80,$nh);
imagecopyresampled ($pic,$im,0,0,0,0,80,$nh,$w,$h);
imagepng($pic);
}else echo file_get_contents($file);
exit;
}
if($action=='get'){
header("Content-length: ".filesize($file));
header("Content-disposition: form-data;name=\"filename\";filename=\"$file\"");
header("Content-type: application/octet-stream");
$file="$fold$del$file";
echo file_get_contents($file);
exit;
}
if($mode=='xsl'){
header(KSP_TYPE_XML);
header("Last-Modified: Thu, 15 Feb 1986 00:02:11 GMT");
$xsl=file_get_contents("$rsrcs/style.xsl");
$xsl=str_replace("ok");
}while(false);
if($mode=='edit'){
$file=$_GET['file']; $back=$_GET['loadb']; $size=filesize($file);
if($action=="write") {do {
header(KSP_TYPE_TEXT);
$text=$_POST['content']; $text=str_replace("\r","",$text);
if(substr($encoding,0,8)=="iso-8859") $text=utf8_decode($text);
if($_POST['size']!=$size) break rbx_msg("error","Modification intermédiaire");
$size=strlen($text); $backup_file="$backup_fold$del$file-".date("d-m-Y-H-i-s");
$bytes=file_put_content($file,$text);
if($bytes!==$size) break rbx_msg("error","Ecriture impossible");
create_dir($backup_fold);copy($file,$backup_file);
rbx_msg("ok",$valid_msg);rbx_msg('size',$size);
}while(false);jsx_end();
}
$vers="";$tmp=glob($dest="$backup_fold$del$file-*");if(!$tmp)$tmp=array();
$versions=array();$sz=strlen("$backup_fold/$file-");
foreach($tmp as $v){ list($d,$m,$y,$h,$i,$s)=explode('-',substr($v,-19));$versions["$y$m$d$h$i$s"]=substr($v,$sz); }
krsort($versions);$versions=array_slice($versions,0,20);
foreach($versions as $v) $vers.="$v\n";
$text=file_get_contents($back?"$backup_fold$del$file-$back":$file);
$is_xml=(int)(substr($text,0,5)=='formatOutput = true;
$dom->preserveWhiteSpace= false;
$dom->loadXML($text);
$text=$dom->validate()?$dom->saveXML():$text;
}
$text=str_replace(array('<','>'),array('<','>'),str_replace('&','&',$text));
header(KSP_TYPE_XML);
echo KSP_XML;
echo '';
echo "\n
$back$vers
$text\n".
"";
die;
}
if($action=="file"){
$tmp=$_FILES['userfile']['tmp_name'];
$file=$_FILES['userfile']['name'];
move_uploaded_file($tmp,$file);
rbx_msg('ok',"Upload $file");
}
if($action=='copy'){
foreach($files_list as $from){
$tmp=$files?$to.$from:$to;
if(!copy($from,$tmp)) rbx_msg('error',"Erreur lors de la copie de $from vers $tmp");
else rbx_msg('ok',"Copie $from vers $tmp reussie");
}
}
if($action=='rename'){
foreach($files_list as $from){
$tmp=$files?$to.$from:$to;
if(!rename($from,$tmp)) rbx_msg('error',"Erreur lors du changement de nom de $from vers $tmp");
else rbx_msg('ok',"Deplacement $from vers $tmp reussi");
}
}
if($action=='delete')
foreach($files_list as $file)
if(is_file($file)&&unlink($file) || is_link($file)&&unlink($file) || is_dir($file)&&rmdir($file))
rbx_msg('ok',"Suppression reussie $file");
else rbx_msg('error',"Impossible de supprimer le fichier $file");
if($action=='new') do{
$tmp=$_POST['todo'];$do=$_POST['do'];
if( is_dir($tmp) || is_file($tmp) || is_link($tmp) )
break rbx_msg('error',"Erreur $tmp deja présent");
if( $do['fold'] && !mkdir($tmp) || $do['file'] && !touch($tmp) )
rbx_msg('error',"Impossible de creer $tmp");
}while(false);
if($action=='link')
if(symlink ($to,$link=$file))
rbx_msg('ok',"Nouveau lien : $file vers $to");
else rbx_msg('error',"Erreur lors de la création du lien $file vers $to");
if($action=='zip'){
include 'pclzip.php';
if(is_file($to))unlink($to);
$archive = new PclZip($to);
foreach($files_list as $from)
$archive->add($from);
rbx_msg('ok',"Archive $to (".count($files_list)." fichiers ajoutés)");
}
if($action=="unzip"){
include 'pclzip.php';
$archive = new PclZip($file);
if(is_file($file) && ($num=$archive->extract()))
rbx_msg('ok',"Extraction reussie $file ".count($num)." fichier(s) extrait(s)");
else rbx_msg('error',"Impossible d'extraire l'archive $file");
}
$folds=$files=array();$cumul_size=0;
if($action=="find"){
$q=$_POST['q'];
$list=find_file(".",'.*(php|tpl|css|js|txt)$');$res=array();
foreach($list as $file){
if( !preg_match("#$q#",file_get_contents($file))) continue;
$ext=strtolower(strrchr($file,"."));
$size=filesize($file);$date=date('d/m/y H:i:s',filemtime($file));
$files[$file]="$file\n";
}
} else {
while (false !== ($tmp = readdir($handle))) {
if(is_dir($tmp) && $tmp!='.' && $tmp!='..'){
$folds[$tmp]="$tmp";
} elseif(is_file($tmp)||is_link($tmp)){
$true=basename(realpath($tmp),'.php');
$link=is_link($tmp)?' link="1" file="'.$true.'"':'';
$ext=strtolower(strrchr($tmp,"."));
$cumul_size =($size=filesize($tmp));
$date=date('d/m/y H:i:s',filemtime($tmp));
$files[$tmp]="$tmp\n";
}
} closedir($handle);
}
ksort($folds);$xml_folds="\n".join('',$folds)."\n";
ksort($files);$xml_files="\n".join('',$files)."\n";
?>
=KSP_XML?>
=''?>
=$rbx?"".nl2br($rbx['ok'])."
".nl2br($rbx['error'])."
":''?>
$tmp='';foreach(explode($del,$fold) as $fold){
$tmp.=$tmp==$del?$fold:$del.$fold;
echo "\n";
}?>
=$xml_folds?>
=$xml_files?>