update to support PHP 8.1.0

This commit is contained in:
Edoardo Gusmaroli 2023-12-11 15:39:38 +01:00
parent fccc264107
commit f380c5bc15
27 changed files with 745 additions and 235 deletions

View File

@ -4,20 +4,20 @@
"license": "GPL-3.0-or-later",
"homepage": "https://www.phpservermonitor.org",
"require": {
"php": "^5.5.9|>=7.0.8",
"php": ">=8.1.0",
"ext-curl": "*",
"ext-json": "*",
"ext-pdo": "*",
"ext-xml": "*",
"phpmailer/phpmailer": ">=6.5.0 ~6.0",
"symfony/config": "~3.4",
"symfony/dependency-injection": "~3.4",
"symfony/event-dispatcher": "~3.4",
"symfony/http-foundation": ">=3.4.35 ~3.4",
"symfony/filesystem": "~3.4",
"php-pushover/php-pushover": "dev-master",
"paragonie/random_compat": "^2.0",
"twig/twig": "~1.35",
"phpmailer/phpmailer": "^6.9",
"symfony/config": "^4.4",
"symfony/dependency-injection": "^4.4",
"symfony/event-dispatcher": "^5.4",
"symfony/http-foundation": "^6.4",
"symfony/filesystem": "^5.4",
"php-pushover/php-pushover": "^1.0",
"paragonie/random_compat": "^9.99",
"twig/twig": "^3.8",
"jaxl/jaxl": "^3.1",
"viharm/psm-ldap-auth": "^1.1"
},
@ -29,5 +29,10 @@
"psr-4": {
"psm\\": "src/psm/"
}
},
"config": {
"allow-plugins": {
"mnsami/composer-custom-directory-installer": true
}
}
}

813
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -63,7 +63,7 @@ namespace {
}
$cron_timeout = PSM_CRON_TIMEOUT;
// parse a couple of arguments
// parse a couple of arguments
if (!empty($_SERVER['argv'])) {
foreach ($_SERVER['argv'] as $argv) {
$argi = explode('=', ltrim($argv, '--'));
@ -83,10 +83,10 @@ namespace {
}
}
// prevent cron from running twice at the same time
// however if the cron has been running for X mins, we'll assume it died and run anyway
// if you want to change PSM_CRON_TIMEOUT, have a look in src/includes/psmconfig.inc.php.
// or you can provide the --timeout=x argument
// prevent cron from running twice at the same time
// however if the cron has been running for X mins, we'll assume it died and run anyway
// if you want to change PSM_CRON_TIMEOUT, have a look in src/includes/psmconfig.inc.php.
// or you can provide the --timeout=x argument
$status = null;
if (PHP_SAPI === 'cli') {

BIN
img/alert.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

BIN
img/alert.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -42,16 +42,16 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/sc
<argument>%db.port%</argument>
</service>
<service id="event" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
<service id="event" class="Symfony\Component\EventDispatcher\EventDispatcher">
<argument type="service" id="service_container" />
</service>
<service id="user" class="psm\Service\User">
<argument type="service" id="db" />
</service>
<service id="twig.loader" class="Twig_Loader_Filesystem">
<service id="twig.loader" class="Twig\Loader\FilesystemLoader">
<argument>%path.templates%/%config.theme%</argument>
</service>
<service id="twig" class="Twig_Environment">
<service id="twig" class="Twig\Environment">
<argument type="service" id="twig.loader" />
</service>
<!--SERVICES end-->

View File

@ -489,20 +489,19 @@ namespace {
$time = strtotime($time);
}
if ($time < strtotime(date('Y-m-d 00:00:00')) - 60 * 60 * 24 * 3) {
$format = psm_get_lang('system', (date('Y') !== date('Y', $time)) ?
'long_day_format' : 'short_day_format');
$format = psm_get_lang('system', (date('Y') !== date('Y', $time) ? 'long_day_format' : 'short_day_format'));
// Check for Windows to find and replace the %e
// modifier correctly
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format);
}
return strftime($format, $time);
return date(strftime_format_to_date_format($format), $time);
}
$d = time() - $time;
if ($d >= 60 * 60 * 24) {
$format = psm_get_lang('system', (date('l', time() - 60 * 60 * 24) == date('l', $time)) ?
'yesterday_format' : 'other_day_format');
return strftime($format, $time);
'yesterday_format' : 'other_day_format');
return date(strftime_format_to_date_format($format), $time);
}
if ($d >= 60 * 60 * 2) {
return sprintf(psm_get_lang('system', 'hours_ago'), intval($d / (60 * 60)));
@ -533,7 +532,7 @@ namespace {
if (empty($time) || $time == '0000-00-00 00:00:00') {
return psm_get_lang('system', 'never');
}
return strftime('%x %X', strtotime($time));
return date(strftime_format_to_date_format('%x %X'), strtotime($time));
}
/**
@ -1006,13 +1005,43 @@ namespace {
return $decrypted;
}
/**
* Send notification to Telegram
*
* @return string
* @author Tim Zandbergen <tim@xervion.nl>
* Convert strftime format to php date format
* @param $strftimeformat
* @return string|string[]
* @throws Exception
*/
function strftime_format_to_date_format($strftimeformat){
$unsupported = ['%U', '%V', '%C', '%g', '%G'];
$foundunsupported = [];
foreach($unsupported as $unsup){
if (strpos($strftimeformat, $unsup) !== false){
$foundunsupported[] = $unsup;
}
}
if (!empty($foundunsupported)){
throw new \Exception("Found these unsupported chars: ".implode(",", $foundunsupported).' in '.$strftimeformat);
}
// It is important to note that some do not translate accurately ie. lowercase L is supposed to convert to number with a preceding space if it is under 10, there is no accurate conversion so we just use 'g'
$phpdateformat = str_replace(
['%a','%A','%d','%e','%u','%w','%W','%b','%h','%B','%m','%y','%Y', '%D', '%F', '%x', '%n', '%t', '%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r' /* %I:%M:%S %p */, '%R' /* %H:%M */, '%S', '%T' /* %H:%M:%S */, '%X', '%z', '%Z',
'%c', '%s',
'%%'],
['D','l', 'd', 'j', 'N', 'w', 'W', 'M', 'M', 'F', 'm', 'y', 'Y', 'm/d/y', 'Y-m-d', 'm/d/y',"\n","\t", 'H', 'G', 'h', 'g', 'i', 'A', 'a', 'h:i:s A', 'H:i', 's', 'H:i:s', 'H:i:s', 'O', 'T',
'D M j H:i:s Y' /*Tue Feb 5 00:45:10 2009*/, 'U',
'%'],
$strftimeformat
);
return $phpdateformat;
}
/**
* Send notification to Telegram
*
* @return string
* @author Tim Zandbergen <tim@xervion.nl>
*/
class Telegram
{
private $token;

View File

@ -109,7 +109,7 @@ abstract class AbstractController implements ControllerInterface
/**
* Twig object
* @var \Twig_Environment $twig
* @var \Twig\Environment $twig
*/
protected $twig;
@ -146,7 +146,7 @@ abstract class AbstractController implements ControllerInterface
*/
protected $xhr = false;
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
$this->db = $db;
$this->twig = $twig;

View File

@ -114,7 +114,7 @@ class ConfigController extends AbstractController
private $default_tab = 'general';
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
parent::__construct($db, $twig);

View File

@ -35,7 +35,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
interface ControllerInterface extends ContainerAwareInterface
{
public function __construct(Database $db, \Twig_Environment $twig);
public function __construct(Database $db, \Twig\Environment $twig);
/**
* Run the controller

View File

@ -35,7 +35,7 @@ use psm\Service\Database;
class ErrorController extends AbstractController
{
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
parent::__construct($db, $twig);

View File

@ -47,7 +47,7 @@ class InstallController extends AbstractController
*/
protected $path_config_old;
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
parent::__construct($db, $twig);

View File

@ -81,7 +81,7 @@ abstract class AbstractServerController extends AbstractController
`s`.`active`,
`s`.`email`,
`s`.`sms`,
`s`.`discord`,
`s`.`discord`,
`s`.`webhook`,
`s`.`pushover`,
`s`.`telegram`,

View File

@ -36,7 +36,7 @@ use psm\Service\Database;
class LogController extends AbstractServerController
{
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
parent::__construct($db, $twig);

View File

@ -42,7 +42,7 @@ class ServerController extends AbstractServerController
*/
protected $server_id;
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
parent::__construct($db, $twig);
@ -518,14 +518,14 @@ class ServerController extends AbstractServerController
'label' => $server_available['label'],
);
}
$tpl_data['last_output_truncated'] = $tpl_data['last_output'];
$tpl_data['last_error_output_truncated'] = $tpl_data['last_error_output'];
if (strlen($tpl_data['last_output']) > 255) {
$tpl_data['last_output_truncated'] = substr($tpl_data['last_output'], 0, 255) . '...';
}
if (strlen($tpl_data['last_error_output']) > 255) {
$tpl_data['last_error_output_truncated'] = substr($tpl_data['last_error_output'], 0, 255) . '...';
}

View File

@ -37,7 +37,7 @@ use psm\Service\Database;
class StatusController extends AbstractServerController
{
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
parent::__construct($db, $twig);
@ -70,6 +70,13 @@ class StatusController extends AbstractServerController
'layout' => $layout,
'url_save' => psm_build_url(array('mod' => 'server', 'action' => 'edit')),
);
$auto_refresh_seconds = psm_get_conf('auto_refresh_servers');
if (intval($auto_refresh_seconds) > 0) {
$this->twig->addGlobal('auto_refresh', true);
$this->twig->addGlobal('auto_refresh_seconds', $auto_refresh_seconds);
}
$this->setHeaderAccessories($this->twig->render('module/server/status/header.tpl.html', $layout_data));
$this->addFooter(false);
@ -107,12 +114,6 @@ class StatusController extends AbstractServerController
}
}
$auto_refresh_seconds = psm_get_conf('auto_refresh_servers');
if (intval($auto_refresh_seconds) > 0) {
$this->twig->addGlobal('auto_refresh', true);
$this->twig->addGlobal('auto_refresh_seconds', $auto_refresh_seconds);
}
if ($this->isXHR() || isset($_SERVER["HTTP_X_REQUESTED_WITH"])) {
$this->xhr = true;
//disable auto refresh in ajax return html

View File

@ -36,7 +36,7 @@ use psm\Service\Database;
class UpdateController extends AbstractController
{
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
parent::__construct($db, $twig);

View File

@ -35,7 +35,7 @@ use psm\Service\Database;
class LoginController extends AbstractController
{
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
parent::__construct($db, $twig);

View File

@ -41,7 +41,7 @@ class ProfileController extends AbstractController
protected $profile_fields =
array('name', 'user_name', 'email', 'mobile', 'pushover_key', 'pushover_device', 'discord', 'webhook_url', 'webhook_json', 'telegram_id', 'jabber');
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
parent::__construct($db, $twig);

View File

@ -39,7 +39,7 @@ class UserController extends AbstractController
{
public $servers = array();
public function __construct(Database $db, \Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
parent::__construct($db, $twig);

View File

@ -231,7 +231,7 @@ class Router
}
$twig->addFunction(
new \Twig_SimpleFunction(
new \Twig\TwigFunction(
'csrf_token',
function ($lock_to = null) use ($session) {
if (empty($lock_to)) {

View File

@ -67,11 +67,11 @@ class Modal implements ModalInterface
/**
* Twig environment
* @var \Twig_Environment $twig
* @var \Twig\Environment $twig
*/
protected $twig;
public function __construct(\Twig_Environment $twig, $modal_id = 'main', $type = self::MODAL_TYPE_OK)
public function __construct(\Twig\Environment $twig, $modal_id = 'main', $type = self::MODAL_TYPE_OK)
{
$this->modal_id = $modal_id;
$this->twig = $twig;
@ -142,7 +142,7 @@ class Modal implements ModalInterface
}
}
$tpl = $this->twig->loadTemplate('util/module/modal.tpl.html');
$tpl = $this->twig->load('util/module/modal.tpl.html');
$html = $tpl->render(array(
'modal_id' => $this->modal_id,
'modal_title' => !empty($this->title) ? $this->title : psm_get_conf('site_title', psm_get_lang('system', 'title')),

View File

@ -32,7 +32,7 @@ namespace psm\Util\Module;
interface ModalInterface
{
public function __construct(\Twig_Environment $twig);
public function __construct(\Twig\Environment $twig);
public function getModalID();
public function createHTML();

View File

@ -57,7 +57,7 @@ class Sidebar implements SidebarInterface
*/
protected $twig;
public function __construct(\Twig_Environment $twig)
public function __construct(\Twig\Environment $twig)
{
$this->twig = $twig;
}
@ -182,7 +182,7 @@ class Sidebar implements SidebarInterface
}
}
$tpl = $this->twig->loadTemplate('util/module/sidebar.tpl.html');
$tpl = $this->twig->load('util/module/sidebar.tpl.html');
$html = $tpl->render($tpl_data);
return $html;

View File

@ -31,7 +31,7 @@ namespace psm\Util\Module;
interface SidebarInterface
{
public function __construct(\Twig_Environment $twig);
public function __construct(\Twig\Environment $twig);
public function createHTML();
}

View File

@ -32,7 +32,7 @@ namespace psm\Util\Server;
use DateTime;
use psm\Service\Database;
use Twig\Error\Error;
use Twig_Environment;
use Twig\Environment;
/**
* History util, create HTML for server graphs
@ -52,7 +52,7 @@ class HistoryGraph
*/
protected $twig;
public function __construct(Database $db, Twig_Environment $twig)
public function __construct(Database $db, \Twig\Environment $twig)
{
$this->db = $db;
$this->twig = $twig;
@ -294,7 +294,7 @@ class HistoryGraph
// Previous datapoint was offline
: ['x' => $time_ms, 'y' => null];
// new outage start
$lines['offline'][] = ['x' => $time_ms, 'y' => $highest_latency];
$lines['offline'][] = ['x' => $time_ms, 'y' => 0];
if ($prev_downtime === 0) {
$prev_downtime = $time;
@ -306,7 +306,7 @@ class HistoryGraph
// Previous datapoint was online
? ['x' => $time_ms, 'y' => null]
// Previous datapoint was offline
: ['x' => $time_ms, 'y' => $highest_latency];
: ['x' => $time_ms, 'y' => 0];
$lines['online'][] = ['x' => $time_ms, 'y' => round($record['latency'] * 1000, 3)];
if ($prev_downtime !== 0) {

View File

@ -237,7 +237,7 @@
<li class="list-group-item">
<dl class="row">
<dt class="col-md-3">{{ label_last_output }}:</dt>
<dd class="col-md-9">{{ last_output_truncated|nl2br }}</dd>
<dd class="col-md-9">{{ last_output_truncated|raw|nl2br }}</dd>
{% if last_output_truncated != last_output %}
<dt class="col-md-3"></dt>
<dd class="col-md-9">
@ -420,7 +420,7 @@
</button>
</div>
<div class="modal-body" style="word-wrap: break-word;">
{{ last_output|nl2br }}
{{ last_output|raw|nl2br }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>