Files
FOSSBilling/src/modules/System/Api/Admin.php
T
YağızhanandAdam Daley 0392fa8c44 Central Alerts System (#1143)
* +Central Alerts System

* Added a link to the pull request

* Bugfix

* Refactored to use symfony/cache

* Reverted the database patch

* Update foss-update.php

* Reverted the table structure

* Restore src/install/sql/structure.sql

* Fixed the HTTP client

* Restore src/foss-update.php

---------

Co-authored-by: Adam Daley <admdly@users.noreply.github.com>
2023-04-29 13:07:51 -07:00

217 lines
5.3 KiB
PHP

<?php
/**
* FOSSBilling.
*
* @copyright FOSSBilling (https://www.fossbilling.org)
* @license Apache-2.0
*
* Copyright FOSSBilling 2022
* This software may contain code previously used in the BoxBilling project.
* Copyright BoxBilling, Inc 2011-2021
*
* This source file is subject to the Apache-2.0 License that is bundled
* with this source code in the file LICENSE
*/
/**
* System management methods.
*/
namespace Box\Mod\System\Api;
class Admin extends \Api_Abstract
{
/**
* Get all defined system params.
*
* @return array
*/
public function get_params($data)
{
return $this->getService()->getParams($data);
}
/**
* Updated parameters array with new values. Creates new setting if it was
* not defined earlier. You can create new parameters using this method.
* This method accepts any number of parameters you pass.
*
* @param string $key - name of the parameter to be changed/created
*
* @return bool
*/
public function update_params($data)
{
return $this->getService()->updateParams($data);
}
/**
* System messages about working environment.
*
* @param string $type - messages type to be returned: info
*
* @return array
*/
public function messages($data)
{
$type = $data['type'] ?? 'info';
return $this->getService()->getMessages($type);
}
/**
* Get Central Alerts System messages sent for this installation.
*
* @return array - array of messages
*/
public function cas_messages()
{
return $this->getService()->getCasMessages();
}
/**
* Check if passed file name template exists for admin area.
*
* @param string $file - template file name, example: mod_index_dashboard.html.twig
*
* @return bool
*/
public function template_exists($data)
{
if (!isset($data['file'])) {
return false;
}
return $this->getService()->templateExists($data['file'], $this->getIdentity());
}
/**
* Parse string like FOSSBilling template.
*
* @param string $_tpl - Template text to be parsed
*
* @optional bool $_try - if true, will not throw error if template is not valid, returns _tpl string
* @optional int $_client_id - if passed client id, then client API will also be available
*
* @return string
*/
public function string_render($data)
{
if (!isset($data['_tpl'])) {
error_log('_tpl parameter not passed');
return '';
}
$tpl = $data['_tpl'];
$try_render = $data['_try'] ?? false;
$vars = $data;
unset($vars['_tpl'], $vars['_try']);
return $this->getService()->renderString($tpl, $try_render, $vars);
}
/**
* Returns system environment information.
*
* @return array
*/
public function env($data)
{
$ip = $data['ip'] ?? null;
return $this->getService()->getEnv($ip);
}
/**
* Method to check if staff member has permission to access module.
*
* @param string $mod - module name
*
* @optional string $f - module method name
*
* @return bool
*
* @throws \Box_Exception
*/
public function is_allowed($data)
{
$required = [
'mod' => 'mod key is missing',
];
$this->di['validator']->checkRequiredParamsForArray($required, $data);
$f = $data['f'] ?? null;
$service = $this->di['mod_service']('Staff');
return $service->hasPermission($this->getIdentity(), $data['mod'], $f);
}
/**
* Clear system cache.
*
* @return bool
*/
public function clear_cache()
{
return $this->getService()->clearCache();
}
/**
* Gets the latest release notes.
*
* @return string
*/
public function release_notes()
{
$updater = $this->di['updater'];
return $updater->getLatestReleaseNotes();
}
/**
* Update FOSSBilling core.
*
* @return bool
*
* @throws \Box_Exception
*/
public function update_core($data)
{
$updater = $this->di['updater'];
if ('preview' !== $updater->getUpdateBranch() && !$updater->getCanUpdate()) {
throw new \Box_Exception('You have latest version of FOSSBilling. You do not need to update.', null, 930);
}
$new_version = $updater->getLatestVersion();
$this->di['events_manager']->fire(['event' => 'onBeforeAdminUpdateCore']);
$updater->performUpdate();
$this->di['events_manager']->fire(['event' => 'onAfterAdminUpdateCore']);
$this->di['logger']->info('Updated FOSSBilling from %s to %s', \FOSSBilling_Version::VERSION, $new_version);
return true;
}
/**
* Update FOSSBilling config.
*
* @return bool
*
* @throws \Box_Exception
*/
public function update_config()
{
$updater = $this->di['updater'];
$this->di['events_manager']->fire(['event' => 'onBeforeAdminUpdateConfig']);
$updater->performConfigUpdate();
$this->di['events_manager']->fire(['event' => 'onAfterAdminUpdateConfig']);
$this->di['logger']->info('Updated FOSSBilling config');
return true;
}
}