2014-03-16 02:04:49 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHP Server Monitor
|
|
|
|
* Monitor your servers and websites.
|
|
|
|
*
|
|
|
|
* This file is part of PHP Server Monitor.
|
|
|
|
* PHP Server Monitor is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PHP Server Monitor is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @package phpservermon
|
2017-04-15 21:34:49 +02:00
|
|
|
* @author Pepijn Over <pep@mailbox.org>
|
|
|
|
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
|
2014-03-16 02:04:49 +01:00
|
|
|
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
|
|
|
|
* @version Release: @package_version@
|
|
|
|
* @link http://www.phpservermonitor.org/
|
2014-04-05 09:31:41 +02:00
|
|
|
* @since phpservermon 3.0.0
|
2014-03-16 02:04:49 +01:00
|
|
|
**/
|
|
|
|
|
2014-08-06 13:14:41 +02:00
|
|
|
namespace psm\Util\Server;
|
2018-04-09 19:12:10 +02:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
2015-02-27 15:05:46 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
2014-03-16 02:04:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run an update on all servers.
|
|
|
|
*/
|
2018-04-09 19:12:10 +02:00
|
|
|
class UpdateManager implements ContainerAwareInterface {
|
|
|
|
|
|
|
|
use ContainerAwareTrait;
|
2014-03-16 02:04:49 +01:00
|
|
|
|
2015-02-27 15:05:46 +01:00
|
|
|
function __construct(ContainerInterface $container) {
|
|
|
|
$this->container = $container;
|
2014-03-16 02:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go :-)
|
2015-02-27 15:05:46 +01:00
|
|
|
*
|
|
|
|
* @param boolean $skip_perms if TRUE, no user permissions will be taken in account and all servers will be updated
|
2014-03-16 02:04:49 +01:00
|
|
|
*/
|
2015-02-27 15:05:46 +01:00
|
|
|
public function run($skip_perms = false) {
|
2014-03-16 02:04:49 +01:00
|
|
|
// check if we need to restrict the servers to a certain user
|
|
|
|
$sql_join = '';
|
|
|
|
|
2015-02-27 15:05:46 +01:00
|
|
|
if(!$skip_perms && $this->container->get('user')->getUserLevel() > PSM_USER_ADMIN) {
|
2014-03-16 02:04:49 +01:00
|
|
|
// restrict by user_id
|
|
|
|
$sql_join = "JOIN `".PSM_DB_PREFIX."users_servers` AS `us` ON (
|
2015-02-27 15:05:46 +01:00
|
|
|
`us`.`user_id`={$this->container->get('user')->getUserId()}
|
2014-03-16 02:04:49 +01:00
|
|
|
AND `us`.`server_id`=`s`.`server_id`
|
|
|
|
)";
|
|
|
|
}
|
|
|
|
|
2018-02-26 23:23:50 +01:00
|
|
|
$sql = "SELECT `s`.`server_id`,`s`.`ip`,`s`.`port`,`s`.`label`,`s`.`type`,`s`.`pattern`,`s`.`header_name`,`s`.`header_value`,`s`.`status`,`s`.`active`,`s`.`email`,`s`.`sms`,`s`.`pushover`,`s`.`telegram`
|
2014-03-16 02:04:49 +01:00
|
|
|
FROM `".PSM_DB_PREFIX."servers` AS `s`
|
|
|
|
{$sql_join}
|
|
|
|
WHERE `active`='yes' ";
|
|
|
|
|
2015-02-27 15:05:46 +01:00
|
|
|
$servers = $this->container->get('db')->query($sql);
|
2018-02-26 23:23:50 +01:00
|
|
|
|
2015-02-27 15:05:46 +01:00
|
|
|
$updater = new Updater\StatusUpdater($this->container->get('db'));
|
|
|
|
$notifier = new Updater\StatusNotifier($this->container->get('db'));
|
2014-03-16 02:04:49 +01:00
|
|
|
|
|
|
|
foreach($servers as $server) {
|
2014-03-21 16:38:48 +01:00
|
|
|
$status_old = ($server['status'] == 'on') ? true : false;
|
|
|
|
$status_new = $updater->update($server['server_id']);
|
2014-03-16 02:04:49 +01:00
|
|
|
// notify the nerds if applicable
|
2014-03-21 16:38:48 +01:00
|
|
|
$notifier->notify($server['server_id'], $status_old, $status_new);
|
2018-03-01 00:54:29 +01:00
|
|
|
// clean-up time!! archive all records
|
|
|
|
$archive = new ArchiveManager($this->container->get('db'));
|
|
|
|
$archive->archive($server['server_id']);
|
|
|
|
$archive->cleanup($server['server_id']);
|
2018-02-28 22:49:45 +01:00
|
|
|
}
|
2014-03-16 02:04:49 +01:00
|
|
|
}
|
2018-02-26 23:23:50 +01:00
|
|
|
}
|