"http://rsrcs.exyks.org/dtds/myks.dtd", ); if(!function_exists('json_encode')) { function json_encode($hash){if(!is_array($hash)) return "\"".trim($hash)."\""; $str = "{"; $vals = array(); foreach($hash as $k=>$v) $vals[] = "'$k':".json_encode($v);$str .= join(',', $vals)."}"; return $str; }} $del=DIRECTORY_SEPARATOR; $sep="\n"; $rsrcs="http://ksplorer.cloudyks.org"; $valid_msg=""; $notepad=0; $fold=$_GET['fold']; $action=$_POST['action']; list($mode)=each($_GET); $fold=realpath($fold?$fold:'.'); $backup_fold="$root_fold{$del}backup$fold"; $pcl_file="$root_fold{$del}pclzip.php"; $file_get_contents = "file_get_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); define('FIND_SURFACE',1); define('FIND_FOLLOWLINK',2); define('FIND_DEFAULT',0); function find_file($dir,$pattern='.',$opts=FIND_DEFAULT){ $files=array(); foreach(array_slice(glob("$dir/{.?,}*",GLOB_BRACE),1) as $item){ $base_file=substr(strrchr($item,'/'),1); if(is_dir($item) && !($opts&FIND_SURFACE) && (is_link($item)?($opts&FIND_FOLLOWLINK):true) ) $files=array_merge($files, find_file($item,$pattern,$opts)); if(preg_match("#$pattern#",$base_file))$files[]=$item; }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_encode($GLOBALS['rbx']));} function rbx_msg($dest,$msg){ $GLOBALS['rbx'][$dest].="$msg\n";return 0; } $conf="ks_pref.conf"; if(is_file($conf)) include $conf; define("KSP_XML",''); define("KSP_TYPE_XML","Content-type: text/xml; charset=$encoding"); define("KSP_TYPE_TEXT","Content-type: text/plain; charset=$encoding"); $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); if(!is_file($pcl_file) ){ copy("$rsrcs/pclzip.txt",$pcl_file); rbx_msg('ok',"Pclzip successfully installated ($pcl_file)"); } chdir($fold); if(!$handle = opendir('.'))die("Unable to open directory"); 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" && extension_loaded('apc')){ header(KSP_TYPE_TEXT); $data=apc_fetch("upload_{$_GET['upload_flag']}"); die(json_encode($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'){ $view = isset($_GET['file'])?'file':'folds'; header(KSP_TYPE_XML); header("Last-Modified: Thu, 15 Feb 1986 00:02:11 GMT"); $url = "$rsrcs/xsls/$view.xsl"; $xsl = $file_get_contents($url); $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","Unable to write : file modified"); $size=strlen($text); $backup_file="$backup_fold$del$file-".date("d-m-Y-H-i-s"); $bytes=file_put_contents($file,$text); if($bytes!==$size) break rbx_msg("error","Unable to write : access denied"); create_dir($backup_fold);copy($file,$backup_file); rbx_msg("ok",$valid_msg);rbx_msg('size',$size); }while(false); }if($rbx) jsx_end(); $vers="";$tmp=glob("$backup_fold$del$file-*"); $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,2000); 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; /* Temporary replace & validate declared public dtds_uri */ $dtds_restore=array(); foreach((array)$dtds_uri as $dtd_name=>$dtd_uri){ $search = '#<\!DOCTYPE\s+([a-z_0-9]+)\s+PUBLIC\s+"'.$dtd_name.'"[^>]*>#'; $replace = ''; if(!preg_match($search, $text, $out)) continue; $text = preg_replace( $search, $replace, $text); $dtds_restore[str_replace('$1',$out[1],$replace)] = $out[0]; } $load = $dom->loadXML($text); $valid = (bool)$dom->validate(); $text = $load ? $dom->saveXML():$text; //indentation if($dtds_restore) $text = strtr($text, $dtds_restore); $errs = libxml_get_errors(); libxml_clear_errors(); if($errs ) error_log(print_r($errs,1)); } $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',"Error while copying $from to $tmp"); else rbx_msg('ok',"Copy $from to $tmp : ok"); } } if($action=='rename'){ foreach($files_list as $from){ $tmp=$files?$to.$from:$to; if(!rename($from,$tmp)) rbx_msg('error',"Error while renaming $from to $tmp"); else rbx_msg('ok',"Moving $from to $tmp : ok"); } } 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',"$file deleted"); else rbx_msg('error',"Unable to delete $file"); if($action=='new' ||$action=="fold") do{ $tmp=$_POST['todo'];$do=$_POST['do']; if( is_dir($tmp) || is_file($tmp) || is_link($tmp) ) break rbx_msg('error',"Error $tmp already exists"); if( ($do['fold']||$action=="fold") && !mkdir($tmp) && !chmod($tmp,0775) || ($do['file']&&$action=="new") && !file_put_contents($tmp,'') && !chmod($tmp,0664) ) rbx_msg('error',"Unable to create $tmp"); }while(false); if($action=='link') if(symlink ($to,$link=$file)) rbx_msg('ok',"New link : $file to $to"); else rbx_msg('error',"Unable to create symbolic link $file to $to"); if($action=='zip'){ include $pcl_file; 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)." files added)"); } if($action=="unzip"){ include $pcl_file; $archive = new PclZip($file); if(is_file($file) && ($num=$archive->extract())) rbx_msg('ok',"Unzipping $file : ".count($num)." file(s) extracted"); else rbx_msg('error',"Unable to extract files from $file"); } $folds=$files=array();$cumul_size=0; if($action=="find"){ $q=$_POST['q']; $list=find_file(".",$search_mask);$res=array(); foreach($list as $file) if(preg_match("#$q#s",file_get_contents($file))) $files[]=$file; } else { while (false !== ($tmp = readdir($handle))) { if(is_dir($tmp) && $tmp!='.' && $tmp!='..'){ $tmp=htmlspecialchars($tmp); $folds[$tmp]="$tmp"; } elseif(is_file($tmp)||is_link($tmp))$files[]=$tmp; } closedir($handle); } natsort($files); ksort($folds);$xml_folds="\n".join($sep,$folds)."\n\n"; $xml_files=""; foreach($files as $file){ $true=basename(realpath($file),'.php'); $link=is_link($file)?' link="1" file="'.$true.'"':''; $ext=strtolower(strrchr($file,".")); $cumul_size =($size=filesize($file)); $date=date('d/m/y H:i:s',filemtime($file)); $file=addslashes(htmlspecialchars($file,ENT_QUOTES,'utf-8')); $xml_files.="\n$file"; } $xml_files.="\n\n"; $readme = ""; $readme_file = "README"; if(file_exists($readme_file)) $readme = "".htmlspecialchars(file_get_contents($readme_file)).""; ?> '?>
".nl2br($rbx['ok'])."
".nl2br($rbx['error'])."
":''?> \n"; }?>