uncomp.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /* $Id: uncomp.php 3082 2007-06-09 13:51:43Z danez $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. // prevent direct invocation
  16. if ((!isset($cfg['user'])) || (isset($_REQUEST['cfg']))) {
  17. @ob_end_clean();
  18. @header("location: ../../index.php");
  19. exit();
  20. }
  21. /******************************************************************************/
  22. // common functions
  23. require_once('inc/functions/functions.common.php');
  24. // dir functions
  25. require_once('inc/functions/functions.dir.php');
  26. // is enabled ?
  27. if ($cfg["enable_rar"] != 1) {
  28. AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: ".$cfg["user"]." tried to use uncompress");
  29. @error("uncompress is disabled. Action has been logged.", "", "");
  30. }
  31. // check the needed bins
  32. // php
  33. if (@file_exists($cfg['bin_php']) !== true) {
  34. @error("Required binary could not be found", "", "",
  35. (
  36. ($cfg['isAdmin'])
  37. ? array(
  38. 'PHP-cli is required for uncompress',
  39. 'Specified PHP-cli-binary does not exist: '.$cfg['bin_php'],
  40. 'Check Settings on Admin-Server-Settings Page')
  41. : array('Please contact an Admin')
  42. )
  43. );
  44. }
  45. // unrar / unzip
  46. $uncompbin = "";
  47. $uncomplabel = "";
  48. if (isset($_REQUEST['type'])) {
  49. if (strcasecmp('rar', $_REQUEST['type']) == 0) {
  50. $uncompbin = $cfg['bin_unrar'];
  51. $uncomplabel = "unrar";
  52. } else if (strcasecmp('zip', $_REQUEST['type']) == 0) {
  53. $uncompbin = $cfg['bin_unzip'];
  54. $uncomplabel = "unzip";
  55. }
  56. }
  57. if (($uncompbin != "") && (@file_exists($uncompbin) !== true)) {
  58. @error("Required binary could not be found", "", "",
  59. (
  60. ($cfg['isAdmin'])
  61. ? array(
  62. $uncomplabel.' is required',
  63. 'Specified '.$uncomplabel.' does not exist: '.$uncompbin,
  64. 'Check Settings on Admin-Server-Settings Page')
  65. : array('Please contact an Admin')
  66. )
  67. );
  68. }
  69. // init template-instance
  70. tmplInitializeInstance($cfg["theme"], "page.uncomp.tmpl");
  71. // process
  72. if ((isset($_POST['exec'])) && ($_POST['exec'] == true)) {
  73. $file = tfb_getRequestVar('file');
  74. $dir = tfb_getRequestVar('dir');
  75. // only valid dirs + entries with permission
  76. $fileS = str_replace($cfg["path"], '', $file);
  77. $dirS = str_replace($cfg["path"], '', $dir);
  78. if (!((tfb_isValidPath($file)) &&
  79. (isValidEntry(basename($file))) &&
  80. (hasPermission($fileS, $cfg["user"], 'r')) &&
  81. (hasPermission($dirS, $cfg["user"], 'w')))) {
  82. AuditAction($cfg["constants"]["error"], "ILLEGAL UNCOMPRESS-ACCESS: ".$cfg["user"]." tried to uncompress ".$fileS." in ".$dirS);
  83. @error("Illegal access. Action has been logged.", "", "");
  84. }
  85. //
  86. $passwd = isset($_POST['passwd']) ? $_POST['passwd'] : "";
  87. if ($passwd == "")
  88. $passwd = "-";
  89. $cmd = $cfg['bin_php']." bin/uncompress.php";
  90. $cmd .= " ".tfb_shellencode($file);
  91. $cmd .= " ".tfb_shellencode($dir);
  92. $cmd .= " ".tfb_shellencode(tfb_getRequestVar('type'));
  93. if (strcasecmp('rar', $_REQUEST['type']) == 0)
  94. $cmd .= " ".tfb_shellencode($cfg['bin_unrar']);
  95. else if (strcasecmp('zip', $_REQUEST['type']) == 0)
  96. $cmd .= " ".tfb_shellencode($cfg['bin_unzip']);
  97. $cmd .= " ".tfb_shellencode($passwd);
  98. // os-switch
  99. switch ($cfg["_OS"]) {
  100. case 1: // linux
  101. $cmd .= ' 2>&1';
  102. break;
  103. case 2: // bsd (snip from khr0n0s)
  104. $cmd .= ' 2>&1 &';
  105. break;
  106. }
  107. @session_write_close();
  108. $handle = popen($cmd, 'r' );
  109. $buff= "";
  110. while (!feof($handle))
  111. $buff .= fgets($handle,30);
  112. $tmpl->setvar('buff', nl2br($buff));
  113. pclose($handle);
  114. }
  115. // set vars
  116. if ((isset($_REQUEST['file'])) && ($_REQUEST['file'] != "")) {
  117. $file = tfb_getRequestVar('file');
  118. $dir = tfb_getRequestVar('dir');
  119. $file = str_replace($cfg["path"], '', $file);
  120. $dir = str_replace($cfg["path"], '', $dir);
  121. $targetFile = $cfg["path"].$file;
  122. // only valid dirs + entries with permission
  123. if (!((tfb_isValidPath($targetFile)) &&
  124. (isValidEntry(basename($targetFile))) &&
  125. (hasPermission($file, $cfg["user"], 'r')) &&
  126. (hasPermission($dir, $cfg["user"], 'w')))) {
  127. AuditAction($cfg["constants"]["error"], "ILLEGAL UNCOMPRESS-ACCESS: ".$cfg["user"]." tried to uncompress ".$file);
  128. @error("Illegal access. Action has been logged.", "", "");
  129. }
  130. //
  131. $tmpl->setvar('is_file', 1);
  132. $tmpl->setvar('url_file', str_replace('%2F', '/', urlencode($cfg["path"].$file)));
  133. $tmpl->setvar('url_dir', str_replace('%2F', '/', urlencode($cfg["path"].$dir)));
  134. $tmpl->setvar('type', tfb_getRequestVar('type'));
  135. } else {
  136. $tmpl->setvar('is_file', 0);
  137. }
  138. //
  139. tmplSetTitleBar('Uncompress File', false);
  140. tmplSetIidVars();
  141. // parse template
  142. $tmpl->pparse();
  143. ?>