Merge branch 'develop' of https://github.com/phpservermon/phpservermon into develop

pull/421/head
shuhai 2017-03-10 16:30:23 +08:00
commit 2c5fe21cbb
29 changed files with 277 additions and 37 deletions

View File

@ -1 +1,20 @@
Options -Indexes Options -Indexes
<IfModule mod_expires.c>
<FilesMatch "\.(js|jpg|jpeg|gif|png|css)$">
ExpiresActive on
ExpiresDefault "access plus 1 month"
</FilesMatch>
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

View File

@ -21,7 +21,7 @@ v3.2.0 not yet released
* #181: Added blank index files to prevent directory listing. * #181: Added blank index files to prevent directory listing.
* #237: Adding CSRF protection. * #237: Adding CSRF protection.
* #287: Default language - English * #287: Default language - English
* #286: Add popular ports drop dowwn * #286: Add popular ports drop down
* #269: Added Slovenian language * #269: Added Slovenian language
* #96: Authentication for website checks * #96: Authentication for website checks

View File

@ -75,6 +75,7 @@ Requirements
* PHP 5.3.7+ * PHP 5.3.7+
* PHP cURL package * PHP cURL package
* PHP PDO mysql driver * PHP PDO mysql driver
* PHP-XML
Install Install
@ -116,3 +117,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License 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/. along with PHP Server Monitor. If not, see http://www.gnu.org/licenses/.
Docker
-------
PHPServerMonitor is now available on Docker : https://github.com/phpservermon/docker-phpservermonitor

View File

@ -3,10 +3,7 @@
"description": "PHP Server Monitor", "description": "PHP Server Monitor",
"homepage": "http://www.phpservermonitor.org", "homepage": "http://www.phpservermonitor.org",
"repositories": [ "repositories": [
{
"type": "vcs",
"url": "https://github.com/phpservermon/php-pushover"
}
], ],
"require": { "require": {
"php": ">=5.3.7", "php": ">=5.3.7",

View File

@ -4,4 +4,5 @@ define('PSM_DB_USER', 'db_user');
define('PSM_DB_PASS', 'db_pass'); define('PSM_DB_PASS', 'db_pass');
define('PSM_DB_NAME', 'db_name'); define('PSM_DB_NAME', 'db_name');
define('PSM_DB_HOST', 'localhost'); define('PSM_DB_HOST', 'localhost');
define('PSM_DB_PORT', '3306');
define('PSM_BASE_URL', '');

View File

@ -29,7 +29,12 @@
require_once __DIR__ . '/../src/bootstrap.php'; require_once __DIR__ . '/../src/bootstrap.php';
if(!psm_is_cli()) { if(!psm_is_cli()) {
die('This script can only be run from the command line.'); // check if it's an allowed host
$allow = PSM_CRON_ALLOW;
if(!in_array($_SERVER['REMOTE_ADDR'], $allow) && !in_array($_SERVER["HTTP_X_FORWARDED_FOR"], $allow)) {
header('HTTP/1.0 404 Not Found');
die('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL /cron/status.cron.php was not found on this server.</p></body></html>');
}
} }
$cron_timeout = PSM_CRON_TIMEOUT; $cron_timeout = PSM_CRON_TIMEOUT;

View File

@ -27,6 +27,7 @@ To change these values correctly, only update the second parameter of the functi
define('PSM_DB_NAME', 'db_name'); define('PSM_DB_NAME', 'db_name');
define('PSM_DB_USER', 'db_user'); define('PSM_DB_USER', 'db_user');
define('PSM_DB_PASS', 'db_user_password'); define('PSM_DB_PASS', 'db_user_password');
define('PSM_DB_PORT', '3306');
For example: to change your username you should ONLY change the 'db\_user' part. For example: to change your username you should ONLY change the 'db\_user' part.
Do NOT remove the quotes around your username as that will result in an error. Do NOT remove the quotes around your username as that will result in an error.

View File

@ -6,8 +6,9 @@ define('PSM_DB_USER', 'psm'); \
define('PSM_DB_PASS', 'psm'); \ define('PSM_DB_PASS', 'psm'); \
define('PSM_DB_NAME', 'psm'); \ define('PSM_DB_NAME', 'psm'); \
define('PSM_DB_HOST', 'localhost'); \ define('PSM_DB_HOST', 'localhost'); \
define('PSM_DB_PORT', '3306'); \
?>" > /var/www/default/psm/config.php ?>" > /var/www/default/psm/config.php
echo "<?php \ echo "<?php \
header('Location: /psm/index.php'); \ header('Location: /psm/index.php'); \
?>" > /var/www/default/index.php ?>" > /var/www/default/index.php

View File

@ -18,6 +18,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/sc
<parameter key="path.templates">%path.src%templates</parameter> <parameter key="path.templates">%path.src%templates</parameter>
<parameter key="db.host" type="constant">PSM_DB_HOST</parameter> <parameter key="db.host" type="constant">PSM_DB_HOST</parameter>
<parameter key="db.port" type="constant">PSM_DB_PORT</parameter>
<parameter key="db.user" type="constant">PSM_DB_USER</parameter> <parameter key="db.user" type="constant">PSM_DB_USER</parameter>
<parameter key="db.pass" type="constant">PSM_DB_PASS</parameter> <parameter key="db.pass" type="constant">PSM_DB_PASS</parameter>
<parameter key="db.name" type="constant">PSM_DB_NAME</parameter> <parameter key="db.name" type="constant">PSM_DB_NAME</parameter>
@ -38,6 +39,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/sc
<argument>%db.user%</argument> <argument>%db.user%</argument>
<argument>%db.pass%</argument> <argument>%db.pass%</argument>
<argument>%db.name%</argument> <argument>%db.name%</argument>
<argument>%db.port%</argument>
</service> </service>
<service id="event" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher"> <service id="event" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">

View File

@ -335,6 +335,16 @@ function psm_curl_get($href, $header = false, $body = true, $timeout = null, $ad
curl_setopt($ch, CURLOPT_URL, $href); curl_setopt($ch, CURLOPT_URL, $href);
$proxy_url = psm_get_conf('proxy_url','');
if (psm_get_conf('proxy','0') === '1') {
curl_setopt($ch, CURLOPT_PROXY, $proxy_url);
$proxy_user = psm_get_conf('proxy_user','');
$proxy_password = psm_get_conf('proxy_password','');
if (!empty($proxy_user) && !empty($proxy_password)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_user . ':' . $proxy_password);
}
}
if($add_agent) { if($add_agent) {
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; phpservermon/'.PSM_VERSION.'; +http://www.phpservermonitor.org)'); curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; phpservermon/'.PSM_VERSION.'; +http://www.phpservermonitor.org)');
} }
@ -531,7 +541,11 @@ function psm_build_sms() {
break; break;
case 'octopush': case 'octopush':
$sms = new \psm\Txtmsg\Octopush(); $sms = new \psm\Txtmsg\Octopush();
break; } break;
case 'smsgw':
$sms = new \psm\Txtmsg\Smsgw();
break;
}
// copy login information from the config file // copy login information from the config file
if($sms) { if($sms) {

View File

@ -125,6 +125,7 @@ $sm_lang = array(
'type' => 'Typ', 'type' => 'Typ',
'type_website' => 'Webseite', 'type_website' => 'Webseite',
'type_service' => 'Service', 'type_service' => 'Service',
'type_ping' => 'Ping',
'pattern' => 'Suchstring/-muster', 'pattern' => 'Suchstring/-muster',
'pattern_description' => 'Wenn das gesuchte Muster nicht in der Webseite ist, wird die Seite als offline markiert. Reguläre Ausdrücke sind erlaubt.', 'pattern_description' => 'Wenn das gesuchte Muster nicht in der Webseite ist, wird die Seite als offline markiert. Reguläre Ausdrücke sind erlaubt.',
'last_check' => 'Letzter Check', 'last_check' => 'Letzter Check',

View File

@ -135,6 +135,7 @@ $sm_lang = array(
'type' => 'Type', 'type' => 'Type',
'type_website' => 'Website', 'type_website' => 'Website',
'type_service' => 'Service', 'type_service' => 'Service',
'type_ping' => 'Ping',
'pattern' => 'Search string/pattern', 'pattern' => 'Search string/pattern',
'pattern_description' => 'If this pattern is not found on the website, the server will be marked offline. Regular expressions are allowed.', 'pattern_description' => 'If this pattern is not found on the website, the server will be marked offline. Regular expressions are allowed.',
'last_check' => 'Last check', 'last_check' => 'Last check',
@ -188,6 +189,10 @@ $sm_lang = array(
'show_update' => 'Check for updates?', 'show_update' => 'Check for updates?',
'password_encrypt_key' => 'The encryption key password', 'password_encrypt_key' => 'The encryption key password',
'password_encrypt_key_note' => 'This key is used to encrypt passwords that are stored on servers for access to websites. If the key will change the stored password is invalid!', 'password_encrypt_key_note' => 'This key is used to encrypt passwords that are stored on servers for access to websites. If the key will change the stored password is invalid!',
'proxy' => 'Enable proxy',
'proxy_url' => 'Proxy URL',
'proxy_user' => 'Proxy username',
'proxy_password' => 'Proxy password',
'email_status' => 'Allow sending email', 'email_status' => 'Allow sending email',
'email_from_email' => 'Email from address', 'email_from_email' => 'Email from address',
'email_from_name' => 'Email from name', 'email_from_name' => 'Email from name',
@ -214,6 +219,7 @@ $sm_lang = array(
'sms_gateway_freemobilesms' => 'FreeMobileSMS', 'sms_gateway_freemobilesms' => 'FreeMobileSMS',
'sms_gateway_clicksend' => 'ClickSend', 'sms_gateway_clicksend' => 'ClickSend',
'sms_gateway_nexmo' => 'Nexmo', 'sms_gateway_nexmo' => 'Nexmo',
'sms_gateway_smsgw' => 'SMSgw',
'sms_gateway_username' => 'Gateway username', 'sms_gateway_username' => 'Gateway username',
'sms_gateway_password' => 'Gateway password', 'sms_gateway_password' => 'Gateway password',
'sms_from' => 'Sender\'s phone number', 'sms_from' => 'Sender\'s phone number',
@ -234,6 +240,8 @@ $sm_lang = array(
'alert_type_status' => 'Status change', 'alert_type_status' => 'Status change',
'alert_type_offline' => 'Offline', 'alert_type_offline' => 'Offline',
'alert_type_always' => 'Always', 'alert_type_always' => 'Always',
'alert_proxy' => 'Even if enabled, proxy is never used for services',
'alert_proxy_url' => '<b>Format:</b> Host:Port',
'log_status' => 'Log status', 'log_status' => 'Log status',
'log_status_description' => 'If log status is set to TRUE, the monitor will log the event whenever the Notification settings are passed.', 'log_status_description' => 'If log status is set to TRUE, the monitor will log the event whenever the Notification settings are passed.',
'log_email' => 'Log emails sent by the script', 'log_email' => 'Log emails sent by the script',
@ -248,6 +256,7 @@ $sm_lang = array(
'settings_pushover' => 'Pushover settings', 'settings_pushover' => 'Pushover settings',
'settings_notification' => 'Notification settings', 'settings_notification' => 'Notification settings',
'settings_log' => 'Log settings', 'settings_log' => 'Log settings',
'settings_proxy' => 'Proxy settings',
'auto_refresh' => 'Auto-refresh', 'auto_refresh' => 'Auto-refresh',
'auto_refresh_servers' => 'auto_refresh_servers' =>
'Auto-refresh servers page.<br/>'. 'Auto-refresh servers page.<br/>'.

View File

@ -282,7 +282,7 @@ $sm_lang = array(
'title_forgot' => 'Mot de passe oublié ?', 'title_forgot' => 'Mot de passe oublié ?',
'title_reset' => 'Réinitialisation du mot de passe', 'title_reset' => 'Réinitialisation du mot de passe',
'submit' => 'Envoyer', 'submit' => 'Envoyer',
'remember_me' => 'Se vouvenir de moi', 'remember_me' => 'Se souvenir de moi',
'login' => 'Connexion', 'login' => 'Connexion',
'logout' => 'Déconnexion', 'logout' => 'Déconnexion',
'username' => 'Nom', 'username' => 'Nom',

View File

@ -36,6 +36,7 @@ class ConfigController extends AbstractController {
* @var array $checkboxes * @var array $checkboxes
*/ */
protected $checkboxes = array( protected $checkboxes = array(
'proxy',
'email_status', 'email_status',
'email_smtp', 'email_smtp',
'sms_status', 'sms_status',
@ -52,6 +53,9 @@ class ConfigController extends AbstractController {
* @var array $fields * @var array $fields
*/ */
protected $fields = array( protected $fields = array(
'proxy_url',
'proxy_user',
'proxy_password',
'email_from_name', 'email_from_name',
'email_from_email', 'email_from_email',
'email_smtp_host', 'email_smtp_host',
@ -293,11 +297,16 @@ class ConfigController extends AbstractController {
'label_settings_pushover' => psm_get_lang('config', 'settings_pushover'), 'label_settings_pushover' => psm_get_lang('config', 'settings_pushover'),
'label_settings_notification' => psm_get_lang('config', 'settings_notification'), 'label_settings_notification' => psm_get_lang('config', 'settings_notification'),
'label_settings_log' => psm_get_lang('config', 'settings_log'), 'label_settings_log' => psm_get_lang('config', 'settings_log'),
'label_settings_proxy' => psm_get_lang('config', 'settings_proxy'),
'label_general' => psm_get_lang('config', 'general'), 'label_general' => psm_get_lang('config', 'general'),
'label_language' => psm_get_lang('config', 'language'), 'label_language' => psm_get_lang('config', 'language'),
'label_show_update' => psm_get_lang('config', 'show_update'), 'label_show_update' => psm_get_lang('config', 'show_update'),
'label_password_encrypt_key' => psm_get_lang('config', 'password_encrypt_key'), 'label_password_encrypt_key' => psm_get_lang('config', 'password_encrypt_key'),
'label_password_encrypt_key_note' => psm_get_lang('config', 'password_encrypt_key_note'), 'label_password_encrypt_key_note' => psm_get_lang('config', 'password_encrypt_key_note'),
'label_proxy' => psm_get_lang('config', 'proxy'),
'label_proxy_url' => psm_get_lang('config', 'proxy_url'),
'label_proxy_user' => psm_get_lang('config', 'proxy_user'),
'label_proxy_password' => psm_get_lang('config', 'proxy_password'),
'label_email_status' => psm_get_lang('config', 'email_status'), 'label_email_status' => psm_get_lang('config', 'email_status'),
'label_email_from_email' => psm_get_lang('config', 'email_from_email'), 'label_email_from_email' => psm_get_lang('config', 'email_from_email'),
'label_email_from_name' => psm_get_lang('config', 'email_from_name'), 'label_email_from_name' => psm_get_lang('config', 'email_from_name'),
@ -321,6 +330,7 @@ class ConfigController extends AbstractController {
'label_sms_gateway_freevoipdeal' => psm_get_lang('config', 'sms_gateway_freevoipdeal'), 'label_sms_gateway_freevoipdeal' => psm_get_lang('config', 'sms_gateway_freevoipdeal'),
'label_sms_gateway_smsglobal' => psm_get_lang('config', 'sms_gateway_smsglobal'), 'label_sms_gateway_smsglobal' => psm_get_lang('config', 'sms_gateway_smsglobal'),
'label_sms_gateway_nexmo' => psm_get_lang('config', 'sms_gateway_nexmo'), 'label_sms_gateway_nexmo' => psm_get_lang('config', 'sms_gateway_nexmo'),
'label_sms_gateway_smsgw' => psm_get_lang('config', 'sms_gateway_smsgw'),
'label_sms_gateway_octopush' => psm_get_lang('config', 'sms_gateway_octopush'), 'label_sms_gateway_octopush' => psm_get_lang('config', 'sms_gateway_octopush'),
'label_sms_gateway_freemobilesms' => psm_get_lang('config', 'sms_gateway_freemobilesms'), 'label_sms_gateway_freemobilesms' => psm_get_lang('config', 'sms_gateway_freemobilesms'),
'label_sms_gateway_clicksend' => psm_get_lang('config', 'sms_gateway_clicksend'), 'label_sms_gateway_clicksend' => psm_get_lang('config', 'sms_gateway_clicksend'),
@ -346,6 +356,8 @@ class ConfigController extends AbstractController {
'label_log_email' => psm_get_lang('config', 'log_email'), 'label_log_email' => psm_get_lang('config', 'log_email'),
'label_log_sms' => psm_get_lang('config', 'log_sms'), 'label_log_sms' => psm_get_lang('config', 'log_sms'),
'label_log_pushover' => psm_get_lang('config', 'log_pushover'), 'label_log_pushover' => psm_get_lang('config', 'log_pushover'),
'label_alert_proxy' => psm_get_lang('config', 'alert_proxy'),
'label_alert_proxy_url' => psm_get_lang('config', 'alert_proxy_url'),
'label_auto_refresh' => psm_get_lang('config', 'auto_refresh'), 'label_auto_refresh' => psm_get_lang('config', 'auto_refresh'),
'label_auto_refresh_servers' => psm_get_lang('config', 'auto_refresh_servers'), 'label_auto_refresh_servers' => psm_get_lang('config', 'auto_refresh_servers'),
'label_seconds' => psm_get_lang('config', 'seconds'), 'label_seconds' => psm_get_lang('config', 'seconds'),
@ -356,4 +368,4 @@ class ConfigController extends AbstractController {
'label_log_retention_days' => psm_get_lang('config', 'log_retention_days'), 'label_log_retention_days' => psm_get_lang('config', 'log_retention_days'),
); );
} }
} }

View File

@ -120,11 +120,13 @@ class InstallController extends AbstractController {
} }
$config = array( $config = array(
'host' => 'localhost', 'db_host' => 'localhost',
'name' => '', 'db_port' => '3306',
'user' => '', 'db_name' => '',
'pass' => '', 'db_user' => '',
'prefix' => 'psm_', 'db_pass' => '',
'db_prefix' => 'psm_',
'base_url' => '',
); );
$changed = false; $changed = false;
@ -140,10 +142,11 @@ class InstallController extends AbstractController {
if($changed) { if($changed) {
// test db connection // test db connection
$this->db = new \psm\Service\Database( $this->db = new \psm\Service\Database(
$config['host'], $config['db_host'],
$config['user'], $config['db_port'],
$config['pass'], $config['db_user'],
$config['name'] $config['db_pass'],
$config['db_name']
); );
if($this->db->status()) { if($this->db->status()) {
@ -275,11 +278,11 @@ class InstallController extends AbstractController {
* @param array $db_vars prefix,user,pass,name,host * @param array $db_vars prefix,user,pass,name,host
* @return boolean|string TRUE on success, string with config otherwise * @return boolean|string TRUE on success, string with config otherwise
*/ */
protected function writeConfigFile($db_vars) { protected function writeConfigFile($array_config) {
$config = "<?php".PHP_EOL; $config = "<?php".PHP_EOL;
foreach($db_vars as $key => $value) { foreach($array_config as $key => $value) {
$line = "define('PSM_DB_{key}', '{value}');".PHP_EOL; $line = "define('PSM_{key}', '{value}');".PHP_EOL;
$line = str_replace( $line = str_replace(
array('{key}', '{value}'), array('{key}', '{value}'),
array(strtoupper($key), $value), array(strtoupper($key), $value),
@ -307,8 +310,9 @@ class InstallController extends AbstractController {
'pass' => '', 'pass' => '',
'name' => '', 'name' => '',
'host' => '', 'host' => '',
'port' => '3306'
); );
$pattern = "/define\('SM_DB_{key}', '(.*?)'/u"; $pattern = "/define\('SM_{key}', '(.*?)'/u";
foreach($vars as $key => $value) { foreach($vars as $key => $value) {
$pattern_key = str_replace('{key}', strtoupper($key), $pattern); $pattern_key = str_replace('{key}', strtoupper($key), $pattern);

View File

@ -286,6 +286,8 @@ class ServerController extends AbstractServerController {
$clean["port"] = 443; $clean["port"] = 443;
} elseif ($tmp["scheme"] === "http") { } elseif ($tmp["scheme"] === "http") {
$clean["port"] = 80; $clean["port"] = 80;
} elseif ($tmp["scheme"] === "rdp") {
$clean["port"] = 3389;
} }
} }
@ -458,6 +460,7 @@ class ServerController extends AbstractServerController {
'label_type' => psm_get_lang('servers', 'type'), 'label_type' => psm_get_lang('servers', 'type'),
'label_website' => psm_get_lang('servers', 'type_website'), 'label_website' => psm_get_lang('servers', 'type_website'),
'label_service' => psm_get_lang('servers', 'type_service'), 'label_service' => psm_get_lang('servers', 'type_service'),
'label_ping' => psm_get_lang('servers', 'type_ping'),
'label_pattern' => psm_get_lang('servers', 'pattern'), 'label_pattern' => psm_get_lang('servers', 'pattern'),
'label_pattern_description' => psm_get_lang('servers', 'pattern_description'), 'label_pattern_description' => psm_get_lang('servers', 'pattern_description'),
'label_last_check' => psm_get_lang('servers', 'last_check'), 'label_last_check' => psm_get_lang('servers', 'last_check'),

View File

@ -37,6 +37,7 @@ class StatusController extends AbstractServerController {
function __construct(Database $db, \Twig_Environment $twig) { function __construct(Database $db, \Twig_Environment $twig) {
parent::__construct($db, $twig); parent::__construct($db, $twig);
$this->setCSRFKey('status');
$this->setActions(array('index', 'saveLayout'), 'index'); $this->setActions(array('index', 'saveLayout'), 'index');
} }

View File

@ -35,6 +35,12 @@ class Database {
*/ */
protected $db_host; protected $db_host;
/**
* DB port
* @var string $db_port
*/
protected $db_port = 3306;
/** /**
* DB name * DB name
* @var string $db_name * @var string $db_name
@ -81,9 +87,10 @@ class Database {
* @param string $pass * @param string $pass
* @param string $db * @param string $db
*/ */
function __construct($host = null, $user = null, $pass = null, $db = null) { function __construct($host = null, $user = null, $pass = null, $db = null, $port = null) {
if($host != null && $user != null && $pass !== null && $db != null) { if($host != null && $user != null && $pass !== null && $db != null) {
$this->db_host = $host; $this->db_host = $host;
$this->db_port = (!empty($port)) ? $port : 3306;
$this->db_name = $db; $this->db_name = $db;
$this->db_user = $user; $this->db_user = $user;
$this->db_pass = $pass; $this->db_pass = $pass;
@ -498,7 +505,7 @@ class Database {
// Initizale connection // Initizale connection
try { try {
$this->pdo = new \PDO( $this->pdo = new \PDO(
'mysql:host='.$this->db_host.';dbname='.$this->db_name.';charset=utf8', 'mysql:host='.$this->db_host.';port='.$this->db_port.';dbname='.$this->db_name.';charset=utf8',
$this->db_user, $this->db_user,
$this->db_pass $this->db_pass
); );

View File

@ -61,7 +61,7 @@ class Mollie extends Core {
public function sendSMS($message) { public function sendSMS($message) {
$recipients = implode(',', $this->recipients); $recipients = implode(',', $this->recipients);
$result = $this->_auth_https_post('www.mollie.nl', '/xml/sms/', $result = $this->_auth_https_post('api.messagebird.com', '/xml/sms/',
'gateway='.urlencode($this->gateway). 'gateway='.urlencode($this->gateway).
'&username='.urlencode($this->username). '&username='.urlencode($this->username).
'&password='.urlencode($this->password). '&password='.urlencode($this->password).
@ -97,4 +97,4 @@ class Mollie extends Core {
} }
return $buf; return $buf;
} }
} }

61
src/psm/Txtmsg/Smsgw.php Normal file
View File

@ -0,0 +1,61 @@
<?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 Daif Alotaibi <daif@daif.net>
* @copyright Copyright (c) 2008-2015 Pepijn Over <pep@peplab.net>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
**/
namespace psm\Txtmsg;
class Smsgw extends Core {
/**
* Send a text message to one or more recipients
*
* @param string $message
* @return boolean
*/
public function sendSMS($message) {
$url = 'http://api.smsgw.net/SendBulkSMS';
$post = array(
'strUserName' => $this->username,
'strPassword' => $this->password,
'strTagName' => $this->originator,
'strRecepientNumbers' => implode(';', $this->recipients),
'strMessage' => $message,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$data = curl_exec($ch);
if($data == '1') {
$this->success = true;
}
return $this->success;
}
}

View File

@ -130,6 +130,10 @@ class Installer {
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "users_servers` (`user_id`,`server_id`) VALUES (1, 1), (1, 2);"; $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "users_servers` (`user_id`,`server_id`) VALUES (1, 1), (1, 2);";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE
('language', 'en_US'), ('language', 'en_US'),
('proxy', '0'),
('proxy_url', ''),
('proxy_user', ''),
('proxy_password', ''),
('email_status', '1'), ('email_status', '1'),
('email_from_email', 'monitor@example.org'), ('email_from_email', 'monitor@example.org'),
('email_from_name', 'Server Monitor'), ('email_from_name', 'Server Monitor'),
@ -218,7 +222,7 @@ class Installer {
`ip` varchar(500) NOT NULL, `ip` varchar(500) NOT NULL,
`port` int(5) unsigned NOT NULL, `port` int(5) unsigned NOT NULL,
`label` varchar(255) NOT NULL, `label` varchar(255) NOT NULL,
`type` enum('service','website') NOT NULL default 'service', `type` enum('ping','service','website') NOT NULL default 'service',
`pattern` varchar(255) NOT NULL, `pattern` varchar(255) NOT NULL,
`status` enum('on','off') NOT NULL default 'on', `status` enum('on','off') NOT NULL default 'on',
`error` varchar(255) NULL, `error` varchar(255) NULL,
@ -442,6 +446,11 @@ class Installer {
psm_update_conf('password_encrypt_key', sha1(microtime())); psm_update_conf('password_encrypt_key', sha1(microtime()));
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `ip` `ip` VARCHAR(500) NOT NULL;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `ip` `ip` VARCHAR(500) NOT NULL;";
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `website_username` varchar(255) NULL, ADD `website_password` varchar(255) NULL AFTER `website_username`;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `website_username` varchar(255) NULL, ADD `website_password` varchar(255) NULL AFTER `website_username`;";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE
('proxy', '0'),
('proxy_url', ''),
('proxy_user', ''),
('proxy_password', '');";
$this->execSQL($queries); $this->execSQL($queries);

View File

@ -101,6 +101,11 @@ class ServerValidator {
throw new \InvalidArgumentException('server_ip_bad_service'); throw new \InvalidArgumentException('server_ip_bad_service');
} }
break; break;
case 'ping':
if(!filter_var($value, FILTER_VALIDATE_IP)) {
throw new \InvalidArgumentException('server_ip_bad_service');
}
break;
} }
return true; return true;
@ -113,7 +118,7 @@ class ServerValidator {
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function type($type) { public function type($type) {
if(!in_array($type, array('service', 'website'))) { if(!in_array($type, array('ping', 'service', 'website'))) {
throw new \InvalidArgumentException('server_type_invalid'); throw new \InvalidArgumentException('server_type_invalid');
} }
return true; return true;

View File

@ -90,6 +90,9 @@ class StatusUpdater {
} }
switch($this->server['type']) { switch($this->server['type']) {
case 'ping':
$this->status_new = $this->updatePing($max_runs);
break;
case 'service': case 'service':
$this->status_new = $this->updateService($max_runs); $this->status_new = $this->updateService($max_runs);
break; break;
@ -134,6 +137,41 @@ class StatusUpdater {
} }
/**
* Check the current servers ping status - Code from http://stackoverflow.com/a/20467492
* @param int $max_runs
* @param int $run
* @return boolean
*/
protected function updatePing($max_runs, $run = 1) {
$errno = 0;
// save response time
$starttime = microtime(true);
// set ping payload
$package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
$fp = @fsockopen ($this->server['ip'], $this->server['port'], $errno, $this->error, 10);
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 10, 'usec' => 0));
socket_connect($socket, $this->server['ip'], null);
socket_send($socket, $package, strLen($package), 0);
if (socket_read($socket, 255)) {
$this->rtime = microtime(true) - $starttime;
$status = true;
} else {
$status = false;
}
socket_close($socket);
// check if server is available and rerun if asked.
if(!$status && $run < $max_runs) {
return $this->updatePing($max_runs, $run + 1);
}
return $status;
}
/** /**
* Check the current server as a service * Check the current server as a service
* @param int $max_runs * @param int $max_runs

View File

@ -6,7 +6,7 @@
<title>{{ title }}</title> <title>{{ title }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, minimum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, minimum-scale=1">
<meta name="description" content=""> <meta name="description" content="">
<meta name="author" content=""> <meta name="robots" content="noindex" />
<meta name="theme-color" content="#424242"> <meta name="theme-color" content="#424242">
<link rel="icon" type="image/x-icon" href="favicon.ico" /> <link rel="icon" type="image/x-icon" href="favicon.ico" />
<link rel="icon" type="image/png" href="favicon.png" /> <link rel="icon" type="image/png" href="favicon.png" />

View File

@ -69,6 +69,32 @@
<input type="text" class="input-mini" id="log_retention_period" name="log_retention_period" value="{{ log_retention_period }}" data-toggle="tooltip" title="{{ label_log_retention_period_description }}" />&nbsp;{{ label_log_retention_days }} <input type="text" class="input-mini" id="log_retention_period" name="log_retention_period" value="{{ log_retention_period }}" data-toggle="tooltip" title="{{ label_log_retention_period_description }}" />&nbsp;{{ label_log_retention_days }}
</div> </div>
</div> </div>
<legend>{{ label_settings_proxy }}</legend>
<div class="control-group">
<div class="controls">
<label class="checkbox" for="proxy"><input type="checkbox" id="proxy" name="proxy[]" {{ proxy_checked|raw }} />{{ label_proxy }}</label>
<p class="help-block">{{ label_alert_proxy|raw }}</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="proxy_url">{{ label_proxy_url }}</label>
<div class="controls">
<input type="text" id="proxy_url" name="proxy_url" value="{{ proxy_url }}" maxlength="100" placeholder="{{ label_proxy_url }}" />
<p class="help-block">{{ label_alert_proxy_url|raw }}</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="proxy_user">{{ label_proxy_user }}</label>
<div class="controls">
<input type="text" id="proxy_user" name="proxy_user" value="{{ proxy_user }}" maxlength="100" placeholder="{{ label_proxy_user }}" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="proxy_password">{{ label_proxy_password }}</label>
<div class="controls">
<input type="password" id="proxy_password" name="proxy_password" value="{{ proxy_password }}" maxlength="100" placeholder="{{ label_proxy_password }}" />
</div>
</div>
<div class="form-actions"> <div class="form-actions">
<button class="btn btn-success" type="submit" name="general_submit">{{ label_save }}</button> <button class="btn btn-success" type="submit" name="general_submit">{{ label_save }}</button>
</div> </div>
@ -173,6 +199,7 @@
<option value="octopush" {{ sms_selected_octopush|raw }}>{{ label_sms_gateway_octopush }}</option> <option value="octopush" {{ sms_selected_octopush|raw }}>{{ label_sms_gateway_octopush }}</option>
<option value="freemobilesms" {{ sms_selected_freemobilesms|raw }}>{{ label_sms_gateway_freemobilesms }}</option> <option value="freemobilesms" {{ sms_selected_freemobilesms|raw }}>{{ label_sms_gateway_freemobilesms }}</option>
<option value="clicksend" {{ sms_selected_clicksend|raw }}>{{ label_sms_gateway_clicksend }}</option> <option value="clicksend" {{ sms_selected_clicksend|raw }}>{{ label_sms_gateway_clicksend }}</option>
<option value="smsgw" {{ sms_selected_smsgw|raw }}>{{ label_sms_gateway_smsgw }}</option>
</select> </select>
</div> </div>
</div> </div>

View File

@ -10,35 +10,48 @@
<div class="span6"> <div class="span6">
<form id="psm_config" class="form-horizontal" action="install.php?action=config" method="post"> <form id="psm_config" class="form-horizontal" action="install.php?action=config" method="post">
{{ macro.csrf_input() }} {{ macro.csrf_input() }}
<p>Please enter the application url:</p>
<div class="control-group">
<label class="control-label" for="base_url">Application base url</label>
<div class="controls">
<input type="text" id="base_url" name="base_url" value="{{ base_url }}" />
</div>
</div>
<p>Please enter your database info:</p> <p>Please enter your database info:</p>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="host">Database host</label> <label class="control-label" for="host">Database host</label>
<div class="controls"> <div class="controls">
<input type="text" id="host" name="host" value="{{ host }}" /> <input type="text" id="host" name="db_host" value="{{ db_host }}" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="host">Database port</label>
<div class="controls">
<input type="text" id="port" name="port" value="{{ port }}" />
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="name">Database name</label> <label class="control-label" for="name">Database name</label>
<div class="controls"> <div class="controls">
<input type="text" id="name" name="name" value="{{ name }}" placeholder="db name" /> <input type="text" id="name" name="db_name" value="{{ db_name }}" placeholder="db name" />
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="user">Database user</label> <label class="control-label" for="user">Database user</label>
<div class="controls"> <div class="controls">
<input type="text" id="user" name="user" value="{{ user }}" placeholder="db user" /> <input type="text" id="user" name="db_user" value="{{ db_user }}" placeholder="db user" />
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="pass">Database password</label> <label class="control-label" for="pass">Database password</label>
<div class="controls"> <div class="controls">
<input type="password" id="pass" name="pass" value="{{ pass }}" placeholder="db password" /> <input type="password" id="pass" name="db_pass" value="{{ db_pass }}" placeholder="db password" />
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="prefix">Table prefix</label> <label class="control-label" for="prefix">Table prefix</label>
<div class="controls"> <div class="controls">
<input type="text" id="prefix" name="prefix" value="{{ prefix }}" /> <input type="text" id="prefix" name="db_prefix" value="{{ db_prefix }}" />
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
@ -60,4 +73,4 @@
</div> </div>
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -20,6 +20,7 @@
<div class="controls"> <div class="controls">
<select id="type" name="type"> <select id="type" name="type">
<option value="">{{ label_please_select }}</option> <option value="">{{ label_please_select }}</option>
<option value="ping" {{ edit_type_selected_ping|raw }}>{{ label_ping }}</option>
<option value="service" {{ edit_type_selected_service|raw }}>{{ label_service }}</option> <option value="service" {{ edit_type_selected_service|raw }}>{{ label_service }}</option>
<option value="website" {{ edit_type_selected_website|raw }}>{{ label_website }}</option> <option value="website" {{ edit_type_selected_website|raw }}>{{ label_website }}</option>
</select> </select>
@ -47,6 +48,7 @@
<option value="115">SFTP (115)</option> <option value="115">SFTP (115)</option>
<option value="43">WHOIS (43)</option> <option value="43">WHOIS (43)</option>
<option value="53">BIND (53)</option> <option value="53">BIND (53)</option>
<option value="3389">RDP (3389)</option>
</optgroup> </optgroup>
</select> </select>
</div> </div>

View File

@ -1,4 +1,5 @@
<div class="tab-content"> <div class="tab-content">
<input type="hidden" name="saveLayout_csrf" value="{{ csrf_token(csrf_key|default('')) }}" />
<div id="flow-layout" class="tab-pane {{ block_layout_active }}"> <div id="flow-layout" class="tab-pane {{ block_layout_active }}">
<div class="entity-container"> <div class="entity-container">
{% for server in servers_offline %} {% for server in servers_offline %}

View File

@ -135,6 +135,7 @@ function psm_xhr(mod, params, method, on_complete, options) {
function psm_saveLayout(layout) { function psm_saveLayout(layout) {
var params = { var params = {
action: 'saveLayout', action: 'saveLayout',
csrf: $("input[name=saveLayout_csrf]").val(),
layout: layout layout: layout
}; };
psm_xhr('server_status', params, 'POST'); psm_xhr('server_status', params, 'POST');