Merge branch 'develop' into feature/custom-user-agent

This commit is contained in:
Tim 2020-05-18 19:53:38 +02:00 committed by GitHub
commit 15ff967f06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 251 additions and 3 deletions

View File

@ -60,6 +60,7 @@ The following SMS gateways are currently available:
* SolutionsInfini - <https://solutionsinfini.com/>
* Plivo - <https://www.plivo.com/>
* Callr - <https://www.callr.com/>
* SMSAPI - <https://www.smsapi.com/en>

View File

@ -85,6 +85,10 @@ The following people have contributed to the development of PHP Server Monitor:
* Nexmo SMS gateway
* Mateusz Małek - https://github.com/mateuszmalek
* SMSAPI gateway
Translators
+++++++++++

View File

@ -779,6 +779,9 @@ namespace {
case 'solutionsinfini':
$sms = new \psm\Txtmsg\SolutionsInfini();
break;
case 'smsapi':
$sms = new \psm\Txtmsg\SMSAPI();
break;
}
// copy login information from the config file

View File

@ -281,6 +281,7 @@ $sm_lang = array(
),
'config' => array(
'general' => 'General',
'site_title' => 'Site title',
'language' => 'Language',
'show_update' => 'Check for updates?',
'password_encrypt_key' => 'The encryption key password',

View File

@ -244,6 +244,7 @@ $sm_lang = array(
),
'config' => array(
'general' => 'Algemeen',
'site_title' => 'Website titel',
'language' => 'Taal',
'show_update' => 'Controleer wekelijks voor updates?',
'email_status' => 'Sta email berichten toe?',

View File

@ -191,6 +191,7 @@ $sm_lang = array(
),
'config' => array(
'general' => 'Ogólne',
'site_title' => 'Tytuł strony',
'language' => 'Język',
'show_update' => 'Sprawdzić aktualizacje?',
'email_status' => 'Pozwól na wysyłkę email',

View File

@ -217,7 +217,7 @@ abstract class AbstractController implements ControllerInterface
if (!$this->xhr) {
// in XHR mode, we will not add the main template
$tpl_data = array(
'title' => strtoupper(psm_get_lang('system', 'title')),
'title' => psm_get_conf('site_title', strtoupper(psm_get_lang('system', 'title'))),
'label_back_to_top' => psm_get_lang('system', 'back_to_top'),
'add_footer' => $this->add_footer,
'version' => 'v' . PSM_VERSION,

View File

@ -79,6 +79,7 @@ class ConfigController extends AbstractController
'jabber_username',
'jabber_domain',
'user_agent',
'site_title'
);
/**
@ -197,6 +198,9 @@ class ConfigController extends AbstractController
'Mozilla/5.0 (compatible; phpservermon/' .
PSM_VERSION . '; +https://github.com/phpservermon/phpservermon)' : $tpl_data['user_agent'];
$tpl_data['site_title'] = empty($tpl_data['site_title']) ?
strtoupper(psm_get_lang('system', 'title')) : $tpl_data['site_title'];
// encrypted fields
foreach ($this->encryptedFields as $encryptedField) {
$tpl_data[$encryptedField] = '';
@ -230,6 +234,7 @@ class ConfigController extends AbstractController
// save new config
$clean = array(
'language' => $_POST['language'],
'site_title' => $_POST['site_title'],
'sms_gateway' => $_POST['sms_gateway'],
'alert_type' => $_POST['alert_type'],
'email_smtp_security' =>
@ -524,6 +529,7 @@ class ConfigController extends AbstractController
'label_leave_blank' => psm_get_lang('users', 'password_leave_blank'),
'label_user_agent' => psm_get_lang('config', 'user_agent'),
'label_user_agent_key_note' => psm_get_lang('config', 'user_agent_key_note'),
'label_site_title' => psm_get_lang('config', 'site_title'),
);
}
}

View File

@ -518,6 +518,15 @@ class ServerController extends AbstractServerController
if (strlen($tpl_data['last_error_output']) > 255) {
$tpl_data['last_error_output_truncated'] = substr($tpl_data['last_error_output'], 0, 255) . '...';
}
// fetch server status logs
$log_entries = $this->getServerLogs($this->server_id);
for ($x = 0; $x < count($log_entries); $x++) {
$record = &$log_entries[$x];
$record['datetime_format'] = psm_date($record['datetime']);
}
$tpl_data['log_entries'] = $log_entries;
return $this->twig->render('module/server/server/view.tpl.html', $tpl_data);
}
@ -606,6 +615,10 @@ class ServerController extends AbstractServerController
'label_settings' => psm_get_lang('system', 'settings'),
'label_output' => psm_get_lang('servers', 'output'),
'label_search' => psm_get_lang('system', 'search'),
'label_log_title' => psm_get_lang('log', 'title'),
'label_log_no_logs' => psm_get_lang('log', 'no_logs'),
'label_date' => psm_get_lang('system', 'date'),
'label_message' => psm_get_lang('system', 'message'),
);
}
@ -627,4 +640,42 @@ class ServerController extends AbstractServerController
}
return $result;
}
/**
* Get logs for a server
* @param int $server_id
* @param string $type status/email/sms
* @return \PDOStatement array
*/
protected function getServerLogs($server_id, $type = 'status')
{
$sql_join = '';
if ($this->getUser()->getUserLevel() > PSM_USER_ADMIN) {
// restrict by user_id
$sql_join = "JOIN `" . PSM_DB_PREFIX . "users_servers` AS `us` ON (
`us`.`user_id`={$this->getUser()->getUserId()}
AND `us`.`server_id`=`servers`.`server_id`
)";
}
$entries = $this->db->query(
'SELECT ' .
'`servers`.`label`, ' .
'`servers`.`ip`, ' .
'`servers`.`port`, ' .
'`servers`.`type` AS server_type, ' .
'`log`.`log_id`, ' .
'`log`.`type`, ' .
'`log`.`message`, ' .
'`log`.`datetime` ' .
'FROM `' . PSM_DB_PREFIX . 'log` AS `log` ' .
'JOIN `' . PSM_DB_PREFIX . 'servers` AS `servers` ON (`servers`.`server_id`=`log`.`server_id`) ' .
$sql_join .
'WHERE `log`.`type`=\'' . $type . '\' ' .
'AND `log`.`server_id`=' . $server_id . ' ' .
'ORDER BY `datetime` DESC ' .
'LIMIT 0,20'
);
return $entries;
}
}

149
src/psm/Txtmsg/SMSAPI.php Executable file
View File

@ -0,0 +1,149 @@
<?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
* @author Mateusz Małek <tajgeer@gmail.com>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.5
**/
namespace psm\Txtmsg;
class SMSAPI extends Core
{
const VARIANT_INTERNATIONAL = 1;
const VARIANT_POLISH = 2;
/**
* SMSAPI comes with two variants - designed for polish or international customers.
*
* @var int
*/
private $variant = self::VARIANT_INTERNATIONAL;
/**
* Name of the sender. As a default the sender name is set to "Test".
* Only verified names are being accepted.
* Sender name may be set after logging into Customer Portal on Sendernames.
* @see https://www.smsapi.com/docs/#2-single-sms
*
* @var string
*/
protected $originator;
/**
* Token used to authenticate in SMSAPI system.
* @see https://www.smsapi.com/docs/#authentication
*
* @var string
*/
protected $password;
/**
* Send sms using the SMSAPI
*
* @var string $message
* @var array $this->recipients
* @var array $this->originator
* @var string $this->password
* @var array $recipients_chunk
* @var string $host
*
* @var mixed $result
* @var array $headers
*
* @var int $success
* @var string $error
*
* @return bool|string
*/
public function sendSMS($message)
{
$tld = ($this->variant === static::VARIANT_INTERNATIONAL) ? "com" : "pl";
$host = "api.smsapi.{$tld}";
$backupHost = "api2.smsapi.{$tld}";
// One user at a time.
$recipients_chunk = array_chunk($this->recipients, 1);
foreach ($recipients_chunk as $recipient) {
try {
$response = $this->processSendOperation($host, $recipient, $message);
} catch (\RuntimeException $e) {
try {
$response = $this->processSendOperation($backupHost, $recipient, $message);
} catch (\RuntimeException $e) {
return "({$recipient}) " . $e->getMessage();
}
}
if (isset($response->error)) {
return $response->message;
}
return 1;
}
}
/**
* Perform actual SMS sending operation
*
* @param $host
* @param $recipient
* @param $message
* @return object
* @throws RuntimeException
*/
private function processSendOperation($host, $recipient, $message)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://{$host}/sms.do");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
"access_token" => $this->password,
"from" => $this->originator,
"to" => $recipient,
"message" => $message,
"encoding" => "utf-8",
"normalize" => "1",
"format" => "json"
)));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$result = curl_exec($ch);
$error = false;
if (curl_errno($ch)) {
$error = curl_error($ch);
}
curl_close($ch);
if ($error !== false) {
throw new \RuntimeException($error);
}
return json_decode($result);
}
}

View File

@ -145,7 +145,7 @@ class Modal implements ModalInterface
$tpl = $this->twig->loadTemplate('util/module/modal.tpl.html');
$html = $tpl->render(array(
'modal_id' => $this->modal_id,
'modal_title' => !empty($this->title) ? $this->title : psm_get_lang('system', 'title'),
'modal_title' => !empty($this->title) ? $this->title : psm_get_conf('site_title', psm_get_lang('system', 'title')),
'modal_body' => $message,
'has_cancel' => $has_cancel,
'label_cancel' => psm_get_lang('system', 'cancel'),

View File

@ -461,7 +461,7 @@ class StatusNotifier
$pushover->setTitle($title);
$pushover->setMessage(str_replace('<br/>', "\n", $message));
$pushover->setUrl(psm_build_url());
$pushover->setUrlTitle(psm_get_lang('system', 'title'));
$pushover->setUrlTitle(psm_get_conf('site_title', psm_get_lang('system', 'title')));
// Log
if (psm_get_conf('log_pushover')) {

View File

@ -41,6 +41,8 @@
<legend>{{ label_general }}</legend>
<!-- Update check -->
{{ macro.input_checkbox("show_update", "show_update[]", label_show_update, show_update_checked) }}
<!-- Site title -->
{{ macro.input_field("text", "site_title", null, "site_title", label_site_title, site_title, label_site_title, "255", null, null, null, null, true) }}
<!-- Language -->
{{ macro.input_select("language", "language", label_language, languages, language_current) }}
<!-- Auto refresh -->

View File

@ -354,6 +354,35 @@
<div class="row">
{{ html_history|raw }}
</div>
{% if log_entries %}
<div class="row mt-4">
<div class="card col-md-12 pl-0 pr-0">
<div class="card-header">
{{ label_log_title }}
</div>
<div class="card-body d-flex align-items-center justify-content-center">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col" style="width: 15%;">{{ label_date }}</th>
<th scope="col">{{ label_message }}</th>
</tr>
</thead>
<tbody>
{% for entry in log_entries %}
<tr>
<td><time>{{ entry.datetime_format }}</time></td>
<td class="full">{{ entry.message|raw }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endif %}
<div class="modal fade" id="modal_last_output" tabindex="-1" role="dialog" aria-labelledby="modal_last_output_label" aria-hidden="true">
<div class="modal-dialog" style="width:75%;max-width: 100%" role="document">