PageRenderTime 34ms CodeModel.GetById 24ms app.highlight 6ms RepoModel.GetById 1ms 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
  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/**
 20 * Provides several different debugging facilities.
 21 *
 22 * @author     Mark E. Haase <mhaase@endeavorsystems.com>
 23 * @copyright  (c) Endeavor Systems, Inc. 2009 {@link http://www.endeavorsystems.com}
 24 * @license    http://www.openfisma.org/content/license GPLv3
 25 * @package    Controller
 26 */
 27class DebugController extends Zend_Controller_Action
 28{
 29    /**
 30     * Display phpinfo()
 31     *
 32     * @GETAllowed
 33     * @return void
 34     */
 35    public function phpinfoAction()
 36    {
 37        $this->view->requiredExtensions = array(
 38            'apc',
 39            'bcmath',
 40            'ctype', 'curl',
 41            'dom',
 42            'fileinfo',
 43            'hash',
 44            'iconv', 'imagick',
 45            'json',
 46            'ldap',
 47            'mbstring', 'mysql',
 48            'openssl',
 49            'PDO',
 50            'SQLite',
 51            'tokenizer',
 52            'xmlreader', 'xmlwriter',
 53            'zip', 'zlib'
 54        );
 55        $this->view->installedExtensions = get_loaded_extensions();
 56    }
 57
 58    /**
 59     * Display error log
 60     *
 61     * @GETAllowed
 62     * @return void
 63     */
 64    public function errorlogAction()
 65    {
 66        $this->_helper->layout()->enableLayout();
 67        $this->_helper->viewRenderer->setNoRender(false);
 68        $this->view->errorLog = ($errorLog = @file_get_contents(APPLICATION_PATH . '/../data/logs/error.log'))
 69            ? $errorLog : 'There are no recent errors.';
 70    }
 71
 72    /**
 73     * Display php log
 74     *
 75     * @GETAllowed
 76     * @return void
 77     */
 78    public function phplogAction()
 79    {
 80        $this->view->log = ($log = @file_get_contents(APPLICATION_PATH . '/../data/logs/php.log'))
 81            ? $log : 'The php log does not exist';
 82    }
 83
 84    /**
 85     * Display APC system cache info
 86     *
 87     * @GETAllowed
 88     */
 89    public function apcCacheAction()
 90    {
 91        if (!Fisma_Menu::isApc()) {
 92            throw new Fisma_Zend_Exception_User('The application is not using APC.');
 93        }
 94
 95        // Cache type can be 'system' or 'user'. Defaults to 'system'.
 96        $cacheType = $this->getRequest()->getParam('type', 'system');
 97
 98        switch ($cacheType) {
 99            case 'system':
100                $cacheInfo = apc_cache_info();
101                break;
102            case 'user':
103                $cacheInfo = apc_cache_info('user');
104                break;
105            default:
106                throw new Fisma_Zend_Exception("Invalid cache type: '$cacheType'");
107                break;
108        }
109
110        // Cache info contains summary data and line item data. Separate these into two view variables for clarity.
111        $cacheItems = $cacheInfo['cache_list'];
112        unset($cacheInfo['cache_list']);
113
114        $this->view->cacheType = ucfirst(htmlspecialchars($cacheType));
115        $this->view->cacheSummary = $cacheInfo;
116
117        $invalidateCacheButton = new Fisma_Yui_Form_Button_Link(
118            'invalidateCache',
119            array(
120                'value' => "Invalidate {$this->view->cacheType} Cache",
121                'href' => "/debug/invalidate-apc-cache/type/$cacheType",
122                'imageSrc' => '/images/reload.png'
123            )
124        );
125        $this->view->invalidateCacheButton = $invalidateCacheButton;
126
127        if (count($cacheItems) > 0) {
128            $this->view->cacheItemHeaders = array_keys($cacheItems[0]);
129            $this->view->cacheItems = $cacheItems;
130        }
131    }
132
133    /**
134     * Invalidate APC cache
135     *
136     * @GETAllowed
137     */
138    public function invalidateApcCacheAction()
139    {
140        if (!Fisma_Menu::isApc()) {
141            throw new Fisma_Zend_Exception_User('The application is not using APC.');
142        }
143
144        // Cache type can be 'system' or 'user'
145        $cacheType = $this->getRequest()->getParam('type', 'system');
146
147        switch ($cacheType) {
148            case 'system':
149                apc_clear_cache();
150                break;
151            case 'user':
152                apc_clear_cache('user');
153                break;
154            default:
155                throw new Fisma_Zend_Exception("Invalid cache type: '$cacheType'");
156                break;
157        }
158
159        $this->_redirect("/debug/apc-cache/type/$cacheType");
160    }
161}