/** generate report */ public function generate() { /** @var ErrorlogModel $errorLogModel */ $errorLogModel = MidasLoader::loadModel('Errorlog'); /** @var AssetstoreModel $assetStoreModel */ $assetStoreModel = MidasLoader::loadModel('Assetstore'); $reportContent = ''; $reportContent .= '<b>Midas Report: ' . Zend_Registry::get('configGlobal')->application->name . '</b>'; $reportContent .= '<br/>http://' . $_SERVER['SERVER_NAME']; $reportContent .= '<br/><br/><b>Status</b>'; $errors = $errorLogModel->getLog(date('Y-m-d H:i:s', strtotime('-1 day' . date('Y-m-j G:i:s'))), date('Y-m-d H:i:s'), 'all', 2); $reportContent .= '<br/>Yesterday Errors: ' . count($errors); $assetStores = $assetStoreModel->getAll(); foreach ($assetStores as $assetStore) { $totalSpace = UtilityComponent::diskTotalSpace($assetStore->getPath()); $freeSpace = UtilityComponent::diskFreeSpace($assetStore->getPath()); $reportContent .= '<br/>Assetstore ' . $assetStore->getName(); if ($totalSpace > 0) { $reportContent .= ', Free space: ' . round($freeSpace / $totalSpace * 100, 2) . '%'; } } $reportContent .= '<br/><br/><b>Dashboard</b><br/>'; $dashboard = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_DASHBOARD'); ksort($dashboard); foreach ($dashboard as $module => $dasboard) { $reportContent .= '-' . ucfirst($module); $reportContent .= '<table>'; foreach ($dasboard as $name => $status) { $reportContent .= '<tr>'; $reportContent .= ' <td>' . $name . '</td>'; if ($status) { $reportContent .= ' <td>ok</td>'; } else { $reportContent .= ' <td>Error</td>'; } if (isset($status[1])) { $reportContent .= ' <td>' . $status[1] . '</td>'; } $reportContent .= '</tr>'; } $reportContent .= '</table>'; } /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $piwikUrl = $settingModel->getValueByName(STATISTICS_PIWIK_URL_KEY, $this->moduleName); $piwikId = $settingModel->getValueByName(STATISTICS_PIWIK_SITE_ID_KEY, $this->moduleName); $piwikApiKey = $settingModel->getValueByName(STATISTICS_PIWIK_API_KEY_KEY, $this->moduleName); $content = file_get_contents($piwikUrl . '/?module=API&format=json&method=VisitsSummary.get&period=day&date=yesterday&idSite=' . $piwikId . '&token_auth=' . $piwikApiKey); $piwik = json_decode($content); $reportContent .= '<br/><b>Statistics (yesterday)</b>'; $reportContent .= '<br/>Number of visit: ' . $piwik->nb_uniq_visitors; $reportContent .= '<br/>Number of actions: ' . $piwik->nb_actions; $reportContent .= '<br/>Average time on the website: ' . $piwik->avg_time_on_site; $this->report = $reportContent; return $reportContent; }
/** index action */ public function indexAction() { $this->requireAdminPrivileges(); $assetstores = $this->Assetstore->getAll(); foreach ($assetstores as $key => $assetstore) { // Check if we can access the path if (file_exists($assetstore->getPath())) { $assetstores[$key]->totalSpace = UtilityComponent::diskTotalSpace($assetstore->getPath()); $assetstores[$key]->freeSpace = UtilityComponent::diskFreeSpace($assetstore->getPath()); $assetstores[$key]->usedSpace = $assetstores[$key]->totalSpace - $assetstores[$key]->freeSpace; if ($assetstores[$key]->totalSpace > 0) { $assetstores[$key]->usedSpaceText = round($assetstores[$key]->usedSpace / $assetstores[$key]->totalSpace * 100, 2); $assetstores[$key]->freeSpaceText = round($assetstores[$key]->freeSpace / $assetstores[$key]->totalSpace * 100, 2); } else { $assetstores[$key]->usedSpaceText = 0; $assetstores[$key]->freeSpaceText = 0; } } else { $assetstores[$key]->totalSpaceText = false; } } $jqplotAssetstoreArray = array(); foreach ($assetstores as $assetstore) { $jqplotAssetstoreArray[] = array($assetstore->getName() . ', ' . $assetstore->getPath(), array(array('Free Space: ' . $this->Component->Utility->formatSize($assetstore->freeSpace), $assetstore->freeSpaceText), array('Used Space: ' . $this->Component->Utility->formatSize($assetstore->usedSpace), $assetstore->usedSpaceText))); } $errors = $this->Errorlog->getLog(date('Y-m-d H:i:s', strtotime('-20 day' . date('Y-m-d H:i:s'))), date('Y-m-d H:i:s'), 'all', 2); $errors = $errors['logs']; $arrayErrors = array(); $format = 'Y-m-d'; for ($i = 0; $i < 21; ++$i) { $key = date($format, strtotime(date('Y-m-d H:i:s', strtotime('-' . $i . ' day' . date('Y-m-d H:i:s'))))); $arrayErrors[$key] = 0; } foreach ($errors as $error) { $key = date($format, strtotime($error->getDatetime())); ++$arrayErrors[$key]; } $jqplotArray = array(); foreach ($arrayErrors as $key => $value) { $jqplotArray[] = array($key . ' 8:00AM', $value); } $this->view->json['stats']['errors'] = $jqplotArray; $this->view->json['stats']['assetstores'] = $jqplotAssetstoreArray; $this->view->piwikUrl = $this->Setting->getValueByName(STATISTICS_PIWIK_URL_KEY, $this->moduleName); $this->view->piwikId = $this->Setting->getValueByName(STATISTICS_PIWIK_SITE_ID_KEY, $this->moduleName); $this->view->piwikKey = $this->Setting->getValueByName(STATISTICS_PIWIK_API_KEY_KEY, $this->moduleName); }
/** index */ public function indexAction() { $this->requireAdminPrivileges(); $this->view->header = 'Administration'; $options = array('allowModifications' => true); $config = new Zend_Config_Ini(APPLICATION_CONFIG, null, $options); $configForm = $this->Form->Admin->createConfigForm(); $formArray = $this->getFormAsArray($configForm); $formArray['description']->setValue($config->global->application->description); $formArray['lang']->setValue($config->global->application->lang); $formArray['name']->setValue($config->global->application->name); $formArray['timezone']->setValue($config->global->default->timezone); if (isset($config->global->allow_password_reset)) { $formArray['allow_password_reset']->setValue($config->global->allow_password_reset); } if (isset($config->global->closeregistration)) { $formArray['closeregistration']->setValue($config->global->closeregistration); } if (isset($config->global->dynamichelp)) { $formArray['dynamichelp']->setValue($config->global->dynamichelp); } if (isset($config->global->gravatar)) { $formArray['gravatar']->setValue($config->global->gravatar); } if (isset($config->global->httpproxy)) { $formArray['httpProxy']->setValue($config->global->httpproxy); } $this->view->configForm = $formArray; $this->view->selectedLicense = $config->global->defaultlicense; try { $this->view->allLicenses = $this->License->getAll(); } catch (Exception $e) { $this->view->allLicenses = array(); } $allModules = $this->Component->Utility->getAllModules(); $this->view->extraTabs = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_ADMIN_TABS'); if ($this->_request->isPost()) { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $submitConfig = $this->getParam('submitConfig'); $submitModule = $this->getParam('submitModule'); if (isset($submitConfig)) { $config->global->application->name = $this->getParam('name'); $config->global->application->description = $this->getParam('description'); $config->global->application->lang = $this->getParam('lang'); $config->global->default->timezone = $this->getParam('timezone'); $config->global->defaultlicense = $this->getParam('licenseSelect'); $config->global->allow_password_reset = $this->getParam('allow_password_reset'); $config->global->closeregistration = $this->getParam('closeregistration'); $config->global->dynamichelp = $this->getParam('dynamichelp'); $config->global->gravatar = $this->getParam('gravatar'); $config->global->httpproxy = $this->getParam('httpProxy'); $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($config); $writer->setFilename(APPLICATION_CONFIG); $writer->write(); echo JsonComponent::encode(array(true, 'Changes saved')); } if (isset($submitModule)) { $moduleName = $this->getParam('modulename'); $modulevalue = $this->getParam('modulevalue'); $moduleConfigLocalFile = LOCAL_CONFIGS_PATH . '/' . $moduleName . '.local.ini'; $moduleConfigFile = BASE_PATH . '/modules/' . $moduleName . '/configs/module.ini'; $moduleConfigPrivateFile = BASE_PATH . '/privateModules/' . $moduleName . '/configs/module.ini'; if (!file_exists($moduleConfigLocalFile) && file_exists($moduleConfigFile)) { copy($moduleConfigFile, $moduleConfigLocalFile); $this->Component->Utility->installModule($moduleName); } elseif (!file_exists($moduleConfigLocalFile) && file_exists($moduleConfigPrivateFile)) { copy($moduleConfigPrivateFile, $moduleConfigLocalFile); $this->Component->Utility->installModule($moduleName); } elseif (!file_exists($moduleConfigLocalFile)) { throw new Zend_Exception('Unable to find config file'); } $config->module->{$moduleName} = $modulevalue; $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($config); $writer->setFilename(APPLICATION_CONFIG); $writer->write(); echo JsonComponent::encode(array(true, 'Changes saved')); } } $defaultAssetStoreId = $this->Assetstore->getDefault()->getKey(); // get assetstore data $assetstores = $this->Assetstore->getAll(); $defaultSet = false; foreach ($assetstores as $key => $assetstore) { if ($assetstore->getKey() == $defaultAssetStoreId) { $assetstores[$key]->default = true; $defaultSet = true; } else { $assetstores[$key]->default = false; } // Check if we can access the path if (file_exists($assetstore->getPath())) { $assetstores[$key]->totalSpace = UtilityComponent::diskTotalSpace($assetstore->getPath()); $assetstores[$key]->totalSpaceText = $this->Component->Utility->formatSize($assetstores[$key]->totalSpace); $assetstores[$key]->freeSpace = UtilityComponent::diskFreeSpace($assetstore->getPath()); $assetstores[$key]->freeSpaceText = $this->Component->Utility->formatSize($assetstores[$key]->freeSpace); } else { $assetstores[$key]->totalSpaceText = false; } } if (!$defaultSet) { foreach ($assetstores as $key => $assetstore) { $assetstores[$key]->default = true; $this->Setting->setConfig('default_assetstore', $assetstores[$key]->getKey()); $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($config); $writer->setFilename(APPLICATION_CONFIG); $writer->write(); break; } } $this->view->assetstores = $assetstores; $this->view->assetstoreForm = $this->Form->Assetstore->createAssetstoreForm(); // get modules $enabledModules = Zend_Registry::get('modulesEnable'); $adapter = Zend_Registry::get('configDatabase')->database->adapter; foreach ($allModules as $key => $module) { if (file_exists(BASE_PATH . '/modules/' . $key . '/controllers/ConfigController.php')) { $allModules[$key]->configPage = 'config'; } elseif (file_exists(BASE_PATH . '/privateModules/' . $key . '/controllers/ConfigController.php')) { $allModules[$key]->configPage = 'config'; } elseif (file_exists(BASE_PATH . '/modules/' . $key . '/controllers/AdminController.php')) { $allModules[$key]->configPage = 'admin'; } elseif (file_exists(BASE_PATH . '/privateModules/' . $key . '/controllers/AdminController.php')) { $allModules[$key]->configPage = 'admin'; } else { $allModules[$key]->configPage = false; } if (isset($module->db->{$adapter})) { $allModules[$key]->dbOk = true; } else { $allModules[$key]->dbOk = false; } $allModules[$key]->dependenciesArray = array(); $allModules[$key]->dependenciesExist = true; // check if dependencies exit if (isset($allModules[$key]->dependencies) && !empty($allModules[$key]->dependencies)) { $allModules[$key]->dependenciesArray = explode(',', trim($allModules[$key]->dependencies)); foreach ($allModules[$key]->dependenciesArray as $dependency) { if (!isset($allModules[$dependency])) { $allModules[$key]->dependenciesExist = false; } } } } $modulesList = array(); $countModules = array(); foreach ($allModules as $k => $module) { if (!isset($module->category) || empty($module->category)) { $category = 'Misc'; } else { $category = ucfirst($module->category); } if (!isset($modulesList[$category])) { $modulesList[$category] = array(); $countModules[$category] = array('visible' => 0, 'hidden' => 0); } $modulesList[$category][$k] = $module; if ($module->dbOk && $module->dependenciesExist) { ++$countModules[$category]['visible']; } else { ++$countModules[$category]['hidden']; } } foreach ($modulesList as $k => $l) { ksort($modulesList[$k]); } ksort($modulesList); $this->view->countModules = $countModules; $this->view->modulesList = $modulesList; $this->view->modulesEnable = $enabledModules; $this->view->databaseType = Zend_Registry::get('configDatabase')->database->adapter; }
/** * called from ajax. */ public function addAction() { $this->requireAdminPrivileges(); $this->disableLayout(); $this->disableView(); $form = $this->Form->Assetstore->createAssetstoreForm(); if ($this->getRequest()->isPost() && !$form->isValid($_POST)) { echo json_encode(array('error' => 'Missing or invalid form values.')); return false; } if ($this->getRequest()->isPost() && $form->isValid($_POST)) { // Save the assetstore in the database $assetstoreDao = new AssetstoreDao(); $assetstoreDao->setName($form->name->getValue()); $assetstoreDao->setPath($form->basedirectory->getValue()); $assetstoreDao->setType($form->assetstoretype->getValue()); if (!is_dir($assetstoreDao->getPath())) { echo JsonComponent::encode(array('error' => 'The path provided is not a valid directory')); return false; } if (!is_writable($assetstoreDao->getPath())) { echo JsonComponent::encode(array('error' => 'The specified directory is not writable')); return false; } try { $this->Assetstore->save($assetstoreDao); } catch (Zend_Exception $ze) { echo JsonComponent::encode(array('error' => $ze->getMessage())); return false; } $totalSpace = UtilityComponent::diskTotalSpace($assetstoreDao->getPath()); $freeSpace = UtilityComponent::diskFreeSpace($assetstoreDao->getPath()); echo JsonComponent::encode(array('msg' => 'The assetstore has been added.', 'assetstore_id' => $assetstoreDao->getAssetstoreId(), 'assetstore_name' => $assetstoreDao->getName(), 'assetstore_type' => $assetstoreDao->getType(), 'totalSpace' => $totalSpace, 'totalSpaceText' => $this->Component->Utility->formatSize($totalSpace), 'freeSpace' => $freeSpace, 'freeSpaceText' => $this->Component->Utility->formatSize($freeSpace))); return true; } echo json_encode(array('error' => 'Bad request.')); return false; }
/** * Add free space information to the DOM on the revision uploader page. * * @param array $args parameters, including "item", the item DAO that you are uploading a new revision into * @return string * @throws Zend_Exception */ public function getExtraHtmlRevision($args) { /** @var FolderModel $folderModel */ $folderModel = MidasLoader::loadModel('Folder'); /** @var Sizequota_FolderQuotaModel $folderQuotaModel */ $folderQuotaModel = MidasLoader::loadModel('FolderQuota', $this->moduleName); $item = $args['item']; if (!$item) { return '<div id="sizequotaFreeSpace" style="display:none;">0</div>' . '<div id="sizequotaHFreeSpace" style="display:none;">--</div>'; } $folders = $item->getFolders(); if (count($folders) == 0) { // don't allow any more uploading into an orphaned item return '<div id="sizequotaFreeSpace" style="display:none;">0</div>' . '<div id="sizequotaHFreeSpace" style="display:none;">--</div>'; } else { $rootFolder = $folderModel->getRoot($folders[0]); $quota = $folderQuotaModel->getFolderQuota($rootFolder); $assetstoreFree = UtilityComponent::diskFreeSpace($this->Assetstore->getDefault()->getPath()); if ($quota == '') { $free = $assetstoreFree; } else { $used = $folderModel->getSize($rootFolder); $free = min($assetstoreFree, $quota - $used); } $free = number_format($free, 0, '.', ''); $hFree = UtilityComponent::formatSize($free); return '<div id="sizequotaFreeSpace" style="display:none;">' . htmlspecialchars($free, ENT_QUOTES, 'UTF-8') . '</div>' . '<div id="sizequotaHFreeSpace" style="display:none;">' . htmlspecialchars($hFree, ENT_QUOTES, 'UTF-8') . '</div>'; } }