images.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. /* $Id: images.php 3010 2007-05-17 20:23:53Z msn_exploder $ */
  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. // default-type
  23. define('_DEFAULT_TYPE', 'server');
  24. // default-targets
  25. define('_DEFAULT_TARGET_SERVER', 'all');
  26. define('_DEFAULT_TARGET_MRTG', 'traffic');
  27. // input-dir mrtg
  28. define('_MRTG_DIR_INPUT', $cfg["path"].'.mrtg');
  29. // image-defines
  30. define('_IMAGE_URL', "image.php");
  31. define('_IMAGE_PREFIX_MRTG', "?i=mrtg&f=");
  32. // init template-instance
  33. tmplInitializeInstance($cfg["theme"], "page.images.tmpl");
  34. // request-vars
  35. $type = (isset($_REQUEST['type'])) ? tfb_getRequestVar('type') : _DEFAULT_TYPE;
  36. $target = tfb_getRequestVar('target');
  37. // types
  38. $type_list = array();
  39. array_push($type_list, array(
  40. 'name' => "server",
  41. 'selected' => ($type == "server") ? 1 : 0
  42. )
  43. );
  44. array_push($type_list, array(
  45. 'name' => "mrtg",
  46. 'selected' => ($type == "mrtg") ? 1 : 0
  47. )
  48. );
  49. $tmpl->setloop('type_list', $type_list);
  50. // type-switch
  51. switch ($type) {
  52. // server
  53. case "server":
  54. // target
  55. if ($target == "")
  56. $target = _DEFAULT_TARGET_SERVER;
  57. // targets
  58. $target_list = array();
  59. array_push($target_list, array(
  60. 'name' => "all",
  61. 'selected' => ($target == "all") ? 1 : 0
  62. )
  63. );
  64. array_push($target_list, array(
  65. 'name' => "bandwidth",
  66. 'selected' => ($target == "bandwidth") ? 1 : 0
  67. )
  68. );
  69. array_push($target_list, array(
  70. 'name' => "drivespace",
  71. 'selected' => ($target == "drivespace") ? 1 : 0
  72. )
  73. );
  74. $tmpl->setloop('target_list', $target_list);
  75. // target-content
  76. // create template-instance
  77. $_tmpl = tmplGetInstance($cfg["theme"], "component.images.server.tmpl");
  78. // set vars
  79. $image_list = array();
  80. if (($target == "bandwidth") || ($target == "all"))
  81. array_push($image_list, array(
  82. 'title' => "Bandwidth",
  83. 'src' => "image.php?i=pieServerBandwidth"
  84. )
  85. );
  86. if (($target == "drivespace") || ($target == "all"))
  87. array_push($image_list, array(
  88. 'title' => "Drivespace",
  89. 'src' => "image.php?i=pieServerDrivespace"
  90. )
  91. );
  92. if (!empty($image_list))
  93. $_tmpl->setloop('image_list', $image_list);
  94. $_tmpl->setvar('type', $type);
  95. $_tmpl->setvar('target', $target);
  96. // grab + set the content of template
  97. $tmpl->setvar('content', $_tmpl->grab());
  98. break;
  99. // mrtg
  100. case "mrtg":
  101. // target
  102. if ($target == "")
  103. $target = _DEFAULT_TARGET_MRTG;
  104. // targets
  105. $target_list = array();
  106. if ((@is_dir(_MRTG_DIR_INPUT)) && ($dirHandle = @opendir(_MRTG_DIR_INPUT))) {
  107. while (false !== ($file = @readdir($dirHandle))) {
  108. if ((strlen($file) > 4) && (substr($file, -4) == ".inc")) {
  109. $targetName = (substr($file, 0, -4));
  110. array_push($target_list, array(
  111. 'name' => $targetName,
  112. 'selected' => ($target == $targetName) ? 1 : 0
  113. )
  114. );
  115. }
  116. }
  117. @closedir($dirHandle);
  118. }
  119. // stop here if no targets found
  120. if (empty($target_list)) {
  121. $tmpl->setvar('content', "<br><p><strong>No Targets found.</strong></p>");
  122. break;
  123. }
  124. // set target-list
  125. $tmpl->setloop('target_list', $target_list);
  126. // target-content
  127. $targetFile = _MRTG_DIR_INPUT."/".$target.".inc";
  128. // check target
  129. if (!((tfb_isValidPath($targetFile) === true)
  130. && (preg_match('/^[0-9a-zA-Z_]+$/D', $target))
  131. && (@is_file($targetFile))
  132. )) {
  133. AuditAction($cfg["constants"]["error"], "ILLEGAL MRTG-TARGET: ".$cfg["user"]." tried to access ".$target);
  134. @error("Invalid Target", "", "", array($target));
  135. }
  136. $content = @file_get_contents($targetFile);
  137. // we are only interested in the "real" content
  138. $tempAry = explode("_CONTENT_BEGIN_", $content);
  139. if (is_array($tempAry)) {
  140. $tempVar = array_pop($tempAry);
  141. $tempAry = explode("_CONTENT_END_", $tempVar);
  142. if (is_array($tempAry)) {
  143. $content = array_shift($tempAry);
  144. // rewrite image-links
  145. $content = preg_replace('/(.*")(.*)(png".*)/i', '${1}'._IMAGE_URL._IMAGE_PREFIX_MRTG.'${2}${3}', $content);
  146. // set var
  147. $tmpl->setvar('content', $content);
  148. }
  149. }
  150. break;
  151. // default
  152. default:
  153. $tmpl->setvar('content', "Invalid Type");
  154. break;
  155. }
  156. // set vars
  157. $tmpl->setvar('type', $type);
  158. $tmpl->setvar('target', $target);
  159. // more vars
  160. tmplSetTitleBar($cfg["pagetitle"].' - '.$cfg['_ID_IMAGES']);
  161. tmplSetFoot();
  162. $tmpl->setvar('enable_multiupload', $cfg["enable_multiupload"]);
  163. $tmpl->setvar('_MULTIPLE_UPLOAD', $cfg['_MULTIPLE_UPLOAD']);
  164. $tmpl->setvar('_ID_IMAGES', $cfg['_ID_IMAGES']);
  165. tmplSetIidVars();
  166. // parse template
  167. $tmpl->pparse();
  168. ?>