PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/application/modules/default/controllers/DebugController.php

https://bitbucket.org/openfisma-ondemand/openfisma
PHP | 161 lines | 92 code | 14 blank | 55 comment | 5 complexity | 9f9a5661948395925eb1ebd1040603f0 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, GPL-3.0, Apache-2.0, EPL-1.0
  1. <?php
  2. /**
  3. * Copyright (c) 2008 Endeavor Systems, Inc.
  4. *
  5. * This file is part of OpenFISMA.
  6. *
  7. * OpenFISMA is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
  8. * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  9. * version.
  10. *
  11. * OpenFISMA is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  12. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with OpenFISMA. If not, see
  16. * {@link http://www.gnu.org/licenses/}.
  17. */
  18. /**
  19. * Provides several different debugging facilities.
  20. *
  21. * @author Mark E. Haase <mhaase@endeavorsystems.com>
  22. * @copyright (c) Endeavor Systems, Inc. 2009 {@link http://www.endeavorsystems.com}
  23. * @license http://www.openfisma.org/content/license GPLv3
  24. * @package Controller
  25. */
  26. class DebugController extends Zend_Controller_Action
  27. {
  28. /**
  29. * Display phpinfo()
  30. *
  31. * @GETAllowed
  32. * @return void
  33. */
  34. public function phpinfoAction()
  35. {
  36. $this->view->requiredExtensions = array(
  37. 'apc',
  38. 'bcmath',
  39. 'ctype', 'curl',
  40. 'dom',
  41. 'fileinfo',
  42. 'hash',
  43. 'iconv', 'imagick',
  44. 'json',
  45. 'ldap',
  46. 'mbstring', 'mysql',
  47. 'openssl',
  48. 'PDO',
  49. 'SQLite',
  50. 'tokenizer',
  51. 'xmlreader', 'xmlwriter',
  52. 'zip', 'zlib'
  53. );
  54. $this->view->installedExtensions = get_loaded_extensions();
  55. }
  56. /**
  57. * Display error log
  58. *
  59. * @GETAllowed
  60. * @return void
  61. */
  62. public function errorlogAction()
  63. {
  64. $this->_helper->layout()->enableLayout();
  65. $this->_helper->viewRenderer->setNoRender(false);
  66. $this->view->errorLog = ($errorLog = @file_get_contents(APPLICATION_PATH . '/../data/logs/error.log'))
  67. ? $errorLog : 'There are no recent errors.';
  68. }
  69. /**
  70. * Display php log
  71. *
  72. * @GETAllowed
  73. * @return void
  74. */
  75. public function phplogAction()
  76. {
  77. $this->view->log = ($log = @file_get_contents(APPLICATION_PATH . '/../data/logs/php.log'))
  78. ? $log : 'The php log does not exist';
  79. }
  80. /**
  81. * Display APC system cache info
  82. *
  83. * @GETAllowed
  84. */
  85. public function apcCacheAction()
  86. {
  87. if (!Fisma_Menu::isApc()) {
  88. throw new Fisma_Zend_Exception_User('The application is not using APC.');
  89. }
  90. // Cache type can be 'system' or 'user'. Defaults to 'system'.
  91. $cacheType = $this->getRequest()->getParam('type', 'system');
  92. switch ($cacheType) {
  93. case 'system':
  94. $cacheInfo = apc_cache_info();
  95. break;
  96. case 'user':
  97. $cacheInfo = apc_cache_info('user');
  98. break;
  99. default:
  100. throw new Fisma_Zend_Exception("Invalid cache type: '$cacheType'");
  101. break;
  102. }
  103. // Cache info contains summary data and line item data. Separate these into two view variables for clarity.
  104. $cacheItems = $cacheInfo['cache_list'];
  105. unset($cacheInfo['cache_list']);
  106. $this->view->cacheType = ucfirst(htmlspecialchars($cacheType));
  107. $this->view->cacheSummary = $cacheInfo;
  108. $invalidateCacheButton = new Fisma_Yui_Form_Button_Link(
  109. 'invalidateCache',
  110. array(
  111. 'value' => "Invalidate {$this->view->cacheType} Cache",
  112. 'href' => "/debug/invalidate-apc-cache/type/$cacheType",
  113. 'imageSrc' => '/images/reload.png'
  114. )
  115. );
  116. $this->view->invalidateCacheButton = $invalidateCacheButton;
  117. if (count($cacheItems) > 0) {
  118. $this->view->cacheItemHeaders = array_keys($cacheItems[0]);
  119. $this->view->cacheItems = $cacheItems;
  120. }
  121. }
  122. /**
  123. * Invalidate APC cache
  124. *
  125. * @GETAllowed
  126. */
  127. public function invalidateApcCacheAction()
  128. {
  129. if (!Fisma_Menu::isApc()) {
  130. throw new Fisma_Zend_Exception_User('The application is not using APC.');
  131. }
  132. // Cache type can be 'system' or 'user'
  133. $cacheType = $this->getRequest()->getParam('type', 'system');
  134. switch ($cacheType) {
  135. case 'system':
  136. apc_clear_cache();
  137. break;
  138. case 'user':
  139. apc_clear_cache('user');
  140. break;
  141. default:
  142. throw new Fisma_Zend_Exception("Invalid cache type: '$cacheType'");
  143. break;
  144. }
  145. $this->_redirect("/debug/apc-cache/type/$cacheType");
  146. }
  147. }