diff --git a/README.rst b/README.rst index 11837483..52c184f7 100644 --- a/README.rst +++ b/README.rst @@ -60,6 +60,7 @@ The following SMS gateways are currently available: * SolutionsInfini - * Plivo - * Callr - +* SMSAPI - diff --git a/docs/credits.rst b/docs/credits.rst index 6786fb1d..75a1aadc 100644 --- a/docs/credits.rst +++ b/docs/credits.rst @@ -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 +++++++++++ diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 64c0e96c..db077969 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -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 diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 4f3648d7..1542b63f 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -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', diff --git a/src/lang/nl_NL.lang.php b/src/lang/nl_NL.lang.php index f7bc5751..3c749338 100644 --- a/src/lang/nl_NL.lang.php +++ b/src/lang/nl_NL.lang.php @@ -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?', diff --git a/src/lang/pl_PL.lang.php b/src/lang/pl_PL.lang.php index b8ef6531..e7d1688c 100644 --- a/src/lang/pl_PL.lang.php +++ b/src/lang/pl_PL.lang.php @@ -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', diff --git a/src/psm/Module/AbstractController.php b/src/psm/Module/AbstractController.php index 260543e6..284a0fef 100644 --- a/src/psm/Module/AbstractController.php +++ b/src/psm/Module/AbstractController.php @@ -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, diff --git a/src/psm/Module/Config/Controller/ConfigController.php b/src/psm/Module/Config/Controller/ConfigController.php index e98fee6d..f26b1ff0 100644 --- a/src/psm/Module/Config/Controller/ConfigController.php +++ b/src/psm/Module/Config/Controller/ConfigController.php @@ -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'), ); } } diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index 1c2cb299..28c03f8d 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -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; + } } diff --git a/src/psm/Txtmsg/SMSAPI.php b/src/psm/Txtmsg/SMSAPI.php new file mode 100755 index 00000000..83601e05 --- /dev/null +++ b/src/psm/Txtmsg/SMSAPI.php @@ -0,0 +1,149 @@ +. + * + * @package phpservermon + * @author Mateusz Małek + * @copyright Copyright (c) 2008-2017 Pepijn Over + * @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); + } +} diff --git a/src/psm/Util/Module/Modal.php b/src/psm/Util/Module/Modal.php index fba72822..21176096 100644 --- a/src/psm/Util/Module/Modal.php +++ b/src/psm/Util/Module/Modal.php @@ -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'), diff --git a/src/psm/Util/Server/Updater/StatusNotifier.php b/src/psm/Util/Server/Updater/StatusNotifier.php index d1db8ae7..080f0fbc 100644 --- a/src/psm/Util/Server/Updater/StatusNotifier.php +++ b/src/psm/Util/Server/Updater/StatusNotifier.php @@ -461,7 +461,7 @@ class StatusNotifier $pushover->setTitle($title); $pushover->setMessage(str_replace('
', "\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')) { diff --git a/src/templates/default/module/config/config.tpl.html b/src/templates/default/module/config/config.tpl.html index 804c171c..1472bc61 100644 --- a/src/templates/default/module/config/config.tpl.html +++ b/src/templates/default/module/config/config.tpl.html @@ -41,6 +41,8 @@ {{ label_general }} {{ macro.input_checkbox("show_update", "show_update[]", label_show_update, show_update_checked) }} + + {{ macro.input_field("text", "site_title", null, "site_title", label_site_title, site_title, label_site_title, "255", null, null, null, null, true) }} {{ macro.input_select("language", "language", label_language, languages, language_current) }} diff --git a/src/templates/default/module/server/server/view.tpl.html b/src/templates/default/module/server/server/view.tpl.html index 20218480..7b22a0f0 100644 --- a/src/templates/default/module/server/server/view.tpl.html +++ b/src/templates/default/module/server/server/view.tpl.html @@ -354,6 +354,35 @@
{{ html_history|raw }}
+ {% if log_entries %} +
+
+
+ {{ label_log_title }} +
+
+
+ + + + + + + + + {% for entry in log_entries %} + + + + + {% endfor %} + +
{{ label_date }}{{ label_message }}
{{ entry.message|raw }}
+
+
+
+
+ {% endif %}