1
0

checkSFV.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /* $Id: checkSFV.php 2900 2007-04-14 19:55:03Z warion $ */
  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_sfvcheck"] != 1) {
  28. AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: ".$cfg["user"]." tried to use checkSFV");
  29. @error("checkSFV is disabled", "index.php?iid=index", "");
  30. }
  31. // check the needed bins
  32. // cksfv
  33. if (@file_exists($cfg['bin_cksfv']) !== true) {
  34. @error("Required binary could not be found", "", "",
  35. (
  36. ($cfg['isAdmin'])
  37. ? array(
  38. 'cksfv is required for sfv-checking',
  39. 'Specified cksfv-binary does not exist: '.$cfg['bin_cksfv'],
  40. 'Check Settings on Admin-Server-Settings Page')
  41. : array('Please contact an Admin')
  42. )
  43. );
  44. }
  45. // target
  46. $dir = tfb_getRequestVar('dir');
  47. $file = tfb_getRequestVar('file');
  48. // validate dir + file
  49. if (!empty($dir)) {
  50. $dirS = str_replace($cfg["path"], '', $dir);
  51. if (!((tfb_isValidPath($dir)) &&
  52. (hasPermission($dirS, $cfg["user"], 'r')))) {
  53. AuditAction($cfg["constants"]["error"], "ILLEGAL SFV-ACCESS: ".$cfg["user"]." tried to check ".$dirS);
  54. @error("Illegal access. Action has been logged.", "", "");
  55. }
  56. }
  57. if (!empty($file)) {
  58. $fileS = str_replace($cfg["path"], '', $file);
  59. if (!((tfb_isValidPath($file)) &&
  60. (isValidEntry(basename($file))) &&
  61. (hasPermission($fileS, $cfg["user"], 'r')))) {
  62. AuditAction($cfg["constants"]["error"], "ILLEGAL SFV-ACCESS: ".$cfg["user"]." tried to check ".$fileS);
  63. @error("Illegal access. Action has been logged.", "", "");
  64. }
  65. }
  66. // init template-instance
  67. tmplInitializeInstance($cfg["theme"], "page.checkSFV.tmpl");
  68. // process
  69. $cmd = $cfg['bin_cksfv'] . ' -C ' . tfb_shellencode($dir) . ' -f ' . tfb_shellencode($file);
  70. $handle = popen($cmd . ' 2>&1', 'r' );
  71. $buff = (isset($cfg["debuglevel"]) && $cfg["debuglevel"] == 2)
  72. ? "<strong>Debug:</strong> Evaluating command:<br/><br/><pre>".tfb_htmlencode($cmd)."</pre><br/>Output follows below:<br/>"
  73. : "";
  74. $buff .= "<pre>";
  75. while (!feof($handle))
  76. $buff .= tfb_htmlencode(@fgets($handle, 30));
  77. $tmpl->setvar('buff', $buff);
  78. pclose($handle);
  79. $buff.= "</pre>";
  80. // set vars
  81. tmplSetTitleBar($cfg["pagetitle"].' - checkSFV', false);
  82. tmplSetIidVars();
  83. // parse template
  84. $tmpl->pparse();
  85. ?>