testing new folder structure, implementing namespaces, changing function prefix to match namespace.
This commit is contained in:
parent
ac60bf7de6
commit
e5567bb465
|
@ -1,74 +0,0 @@
|
||||||
<?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 Pepijn Over <pep@neanderthal-technology.com>
|
|
||||||
* @copyright Copyright (c) 2008-2014 Pepijn Over <pep@neanderthal-technology.com>
|
|
||||||
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
|
|
||||||
* @version Release: @package_version@
|
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
|
||||||
**/
|
|
||||||
|
|
||||||
########################################
|
|
||||||
#
|
|
||||||
# START SERVER MONITOR CONFIGURATION
|
|
||||||
#
|
|
||||||
########################################
|
|
||||||
|
|
||||||
// Database information
|
|
||||||
// Prefix used for tables
|
|
||||||
define('SM_DB_PREFIX', 'monitor_');
|
|
||||||
// Database username
|
|
||||||
define('SM_DB_USER', 'db_user');
|
|
||||||
// Database password
|
|
||||||
define('SM_DB_PASS', 'db_pass');
|
|
||||||
// Database name
|
|
||||||
define('SM_DB_NAME', 'db_name');
|
|
||||||
// Database host
|
|
||||||
define('SM_DB_HOST', 'localhost');
|
|
||||||
|
|
||||||
########################################
|
|
||||||
#
|
|
||||||
# END SERVER MONITOR CONFIGURATION
|
|
||||||
#
|
|
||||||
########################################
|
|
||||||
|
|
||||||
// Include paths
|
|
||||||
// Tell the script where to find the templates, css files and javascript files.
|
|
||||||
// If you haven't changed anything to the structure you should leave these unchanged
|
|
||||||
define('SM_PATH_TPL', 'tpl/');
|
|
||||||
define('SM_PATH_CSS', 'inc/');
|
|
||||||
define('SM_PATH_JS', 'inc/');
|
|
||||||
|
|
||||||
error_reporting(0);
|
|
||||||
ini_set('display_errors', 'Off');
|
|
||||||
|
|
||||||
require 'functions.inc.php';
|
|
||||||
$db = new smDatabase();
|
|
||||||
|
|
||||||
sm_load_conf();
|
|
||||||
|
|
||||||
$lang = sm_get_conf('language');
|
|
||||||
|
|
||||||
if(!$lang) {
|
|
||||||
$lang = 'en';
|
|
||||||
}
|
|
||||||
sm_load_lang($lang);
|
|
||||||
|
|
||||||
?>
|
|
|
@ -26,16 +26,16 @@
|
||||||
**/
|
**/
|
||||||
|
|
||||||
// include main configuration and functionality
|
// include main configuration and functionality
|
||||||
require_once dirname(__FILE__) . '/../config.inc.php';
|
require_once dirname(__FILE__) . '/../src/bootstrap.php';
|
||||||
|
|
||||||
// get the active servers from database
|
// get the active servers from database
|
||||||
$servers = $db->select(
|
$servers = $db->select(
|
||||||
SM_DB_PREFIX.'servers',
|
PSM_DB_PREFIX.'servers',
|
||||||
array('active' => 'yes'),
|
array('active' => 'yes'),
|
||||||
array('server_id', 'ip', 'port', 'label', 'type', 'status', 'active', 'email', 'sms')
|
array('server_id', 'ip', 'port', 'label', 'type', 'status', 'active', 'email', 'sms')
|
||||||
);
|
);
|
||||||
|
|
||||||
$updater = new smUpdaterStatus();
|
$updater = new \psm\UpdaterStatus();
|
||||||
|
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
$status_org = $server['status'];
|
$status_org = $server['status'];
|
||||||
|
@ -64,7 +64,7 @@ foreach ($servers as $server) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->save(
|
$db->save(
|
||||||
SM_DB_PREFIX . 'servers',
|
PSM_DB_PREFIX . 'servers',
|
||||||
$save,
|
$save,
|
||||||
array('server_id' => $server['server_id'])
|
array('server_id' => $server['server_id'])
|
||||||
);
|
);
|
||||||
|
|
|
@ -25,12 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
if(!file_exists('config.inc.php')) {
|
require 'src/bootstrap.php';
|
||||||
die('Failed to locate config file. Please read README.md for more information on how to setup PHP Server Monitor.');
|
|
||||||
}
|
|
||||||
require_once 'config.inc.php';
|
|
||||||
|
|
||||||
sm_no_cache();
|
psm_no_cache();
|
||||||
|
|
||||||
if(isset($_GET['action']) && $_GET['action'] == 'check') {
|
if(isset($_GET['action']) && $_GET['action'] == 'check') {
|
||||||
require 'cron/status.cron.php';
|
require 'cron/status.cron.php';
|
||||||
|
@ -45,7 +42,7 @@ if(!in_array($type, $allowed_types)) {
|
||||||
$type = $allowed_types[0];
|
$type = $allowed_types[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
eval('$mod = new mod'.ucfirst($type).'();');
|
eval('$mod = new psm\Module\\'.ucfirst($type).'();');
|
||||||
// let the module prepare it's HTML code
|
// let the module prepare it's HTML code
|
||||||
$mod->createHTML();
|
$mod->createHTML();
|
||||||
|
|
||||||
|
|
23
install.php
23
install.php
|
@ -28,14 +28,13 @@
|
||||||
// this script creates all the database tables required for server monitor
|
// this script creates all the database tables required for server monitor
|
||||||
error_reporting(0x0ffffff);
|
error_reporting(0x0ffffff);
|
||||||
|
|
||||||
require 'config.inc.php';
|
require 'src/bootstrap.php';
|
||||||
|
|
||||||
if(!function_exists('curl_init')) {
|
if(!function_exists('curl_init')) {
|
||||||
die('PHP is installed without the cURL module. Please install cURL first.');
|
die('PHP is installed without the cURL module. Please install cURL first.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl = new smTemplate();
|
$tpl = new psm\Template();
|
||||||
$tpl->addCSS('monitor.css', 'install');
|
|
||||||
|
|
||||||
$tpl->newTemplate('install', 'install.tpl.html');
|
$tpl->newTemplate('install', 'install.tpl.html');
|
||||||
|
|
||||||
|
@ -53,7 +52,7 @@ if(!is_resource($db->getLink())) {
|
||||||
$tables = array(
|
$tables = array(
|
||||||
'users' =>
|
'users' =>
|
||||||
array(
|
array(
|
||||||
0 => "CREATE TABLE `" . SM_DB_PREFIX . "users` (
|
0 => "CREATE TABLE `" . PSM_DB_PREFIX . "users` (
|
||||||
`user_id` int(11) NOT NULL auto_increment,
|
`user_id` int(11) NOT NULL auto_increment,
|
||||||
`server_id` varchar(255) NOT NULL,
|
`server_id` varchar(255) NOT NULL,
|
||||||
`name` varchar(255) NOT NULL,
|
`name` varchar(255) NOT NULL,
|
||||||
|
@ -61,11 +60,11 @@ $tables = array(
|
||||||
`email` varchar(255) NOT NULL,
|
`email` varchar(255) NOT NULL,
|
||||||
PRIMARY KEY (`user_id`)
|
PRIMARY KEY (`user_id`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
|
||||||
1 => "INSERT INTO `" . SM_DB_PREFIX . "users` (`server_id`, `name`, `mobile`, `email`) VALUES ('1,2', 'example_user', '0123456789', 'user@example.com')"
|
1 => "INSERT INTO `" . PSM_DB_PREFIX . "users` (`server_id`, `name`, `mobile`, `email`) VALUES ('1,2', 'example_user', '0123456789', 'user@example.com')"
|
||||||
),
|
),
|
||||||
'log' =>
|
'log' =>
|
||||||
array(
|
array(
|
||||||
0 => "CREATE TABLE `" . SM_DB_PREFIX . "log` (
|
0 => "CREATE TABLE `" . PSM_DB_PREFIX . "log` (
|
||||||
`log_id` int(11) NOT NULL auto_increment,
|
`log_id` int(11) NOT NULL auto_increment,
|
||||||
`server_id` int(11) NOT NULL,
|
`server_id` int(11) NOT NULL,
|
||||||
`type` enum('status','email','sms') NOT NULL,
|
`type` enum('status','email','sms') NOT NULL,
|
||||||
|
@ -77,7 +76,7 @@ $tables = array(
|
||||||
),
|
),
|
||||||
'servers' =>
|
'servers' =>
|
||||||
array(
|
array(
|
||||||
0 => "CREATE TABLE `" . SM_DB_PREFIX . "servers` (
|
0 => "CREATE TABLE `" . PSM_DB_PREFIX . "servers` (
|
||||||
`server_id` int(11) NOT NULL auto_increment,
|
`server_id` int(11) NOT NULL auto_increment,
|
||||||
`ip` varchar(100) NOT NULL,
|
`ip` varchar(100) NOT NULL,
|
||||||
`port` int(5) NOT NULL,
|
`port` int(5) NOT NULL,
|
||||||
|
@ -93,18 +92,18 @@ $tables = array(
|
||||||
`sms` enum('yes','no') NOT NULL default 'no',
|
`sms` enum('yes','no') NOT NULL default 'no',
|
||||||
PRIMARY KEY (`server_id`)
|
PRIMARY KEY (`server_id`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
|
||||||
1 => "INSERT INTO `" . SM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `status`, `error`, `rtime`, `last_online`, `last_check`, `active`, `email`, `sms`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes')",
|
1 => "INSERT INTO `" . PSM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `status`, `error`, `rtime`, `last_online`, `last_check`, `active`, `email`, `sms`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes')",
|
||||||
),
|
),
|
||||||
'config' =>
|
'config' =>
|
||||||
array(
|
array(
|
||||||
0 => "CREATE TABLE `" . SM_DB_PREFIX . "config` (
|
0 => "CREATE TABLE `" . PSM_DB_PREFIX . "config` (
|
||||||
`config_id` int(11) NOT NULL AUTO_INCREMENT,
|
`config_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`key` varchar(255) NOT NULL,
|
`key` varchar(255) NOT NULL,
|
||||||
`value` varchar(255) NOT NULL,
|
`value` varchar(255) NOT NULL,
|
||||||
PRIMARY KEY (`config_id`),
|
PRIMARY KEY (`config_id`),
|
||||||
KEY `key` (`key`(50))
|
KEY `key` (`key`(50))
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
|
||||||
1 => "INSERT INTO `" . SM_DB_PREFIX . "config` (`config_id`, `key`, `value`) VALUES
|
1 => "INSERT INTO `" . PSM_DB_PREFIX . "config` (`config_id`, `key`, `value`) VALUES
|
||||||
(null, 'language', 'en'),
|
(null, 'language', 'en'),
|
||||||
(null, 'email_status', '1'),
|
(null, 'email_status', '1'),
|
||||||
(null, 'email_from_email', 'monitor@example.org'),
|
(null, 'email_from_email', 'monitor@example.org'),
|
||||||
|
@ -128,10 +127,10 @@ $tables = array(
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
foreach($tables as $name => $queries) {
|
foreach($tables as $name => $queries) {
|
||||||
$if_table_exists = $db->query('SHOW TABLES LIKE \'' . SM_DB_PREFIX . $name.'\'');
|
$if_table_exists = $db->query('SHOW TABLES LIKE \'' . PSM_DB_PREFIX . $name.'\'');
|
||||||
|
|
||||||
if(!empty($if_table_exists)) {
|
if(!empty($if_table_exists)) {
|
||||||
$message = 'Table ' . SM_DB_PREFIX . $name . ' already exists in your database!';
|
$message = 'Table ' . PSM_DB_PREFIX . $name . ' already exists in your database!';
|
||||||
} else {
|
} else {
|
||||||
$message = '';
|
$message = '';
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Include paths
|
||||||
|
define('PSM_PATH_SRC', dirname(__FILE__) . DIRECTORY_SEPARATOR);
|
||||||
|
define('PSM_PATH_VENDOR', PSM_PATH_SRC . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR);
|
||||||
|
define('PSM_PATH_INC', PSM_PATH_SRC . 'includes' . DIRECTORY_SEPARATOR);
|
||||||
|
define('PSM_PATH_TPL', PSM_PATH_SRC . 'templates' . DIRECTORY_SEPARATOR);
|
||||||
|
define('PSM_PATH_LANG', PSM_PATH_SRC . 'lang' . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
// set autoloader, make sure to set $prepend = true so that our autoloader is called first
|
||||||
|
function __autoload($class) {
|
||||||
|
// remove leading \
|
||||||
|
$class = ltrim($class, '\\');
|
||||||
|
$path_parts = explode('\\', $class);
|
||||||
|
|
||||||
|
$filename = array_pop($path_parts);
|
||||||
|
$path = implode(DIRECTORY_SEPARATOR, $path_parts) .
|
||||||
|
DIRECTORY_SEPARATOR .
|
||||||
|
$filename . '.class.php'
|
||||||
|
;
|
||||||
|
// search in these dirs:
|
||||||
|
$basedirs = array(
|
||||||
|
PSM_PATH_SRC,
|
||||||
|
PSM_PATH_VENDOR
|
||||||
|
);
|
||||||
|
foreach($basedirs as $dir) {
|
||||||
|
if(file_exists($dir . $path)) {
|
||||||
|
require_once $dir . $path;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// auto-find all include files
|
||||||
|
$includes = glob(PSM_PATH_INC . '*.inc.php');
|
||||||
|
foreach($includes as $file) {
|
||||||
|
include_once $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!defined('PSM_CONFIG')) {
|
||||||
|
// redirect to install.php
|
||||||
|
die('Failed to locate config file. Please read README.md for more information on how to setup PHP Server Monitor.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// init db connection
|
||||||
|
$db = new psm\Database();
|
||||||
|
|
||||||
|
psm_load_conf();
|
||||||
|
|
||||||
|
$lang = psm_get_conf('language');
|
||||||
|
|
||||||
|
if(!$lang) {
|
||||||
|
$lang = 'en';
|
||||||
|
}
|
||||||
|
psm_load_lang($lang);
|
||||||
|
|
||||||
|
?>
|
|
@ -25,13 +25,16 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
abstract class smCore {
|
define('SM_CONFIG', true);
|
||||||
public $db;
|
// Prefix used for tables
|
||||||
|
define('SM_DB_PREFIX', 'monitor_');
|
||||||
function __construct() {
|
// Database username
|
||||||
// add database handler
|
define('SM_DB_USER', 'db_user');
|
||||||
$this->db = $GLOBALS['db'];
|
// Database password
|
||||||
}
|
define('SM_DB_PASS', 'db_pass');
|
||||||
}
|
// Database name
|
||||||
|
define('SM_DB_NAME', 'db_name');
|
||||||
|
// Database host
|
||||||
|
define('SM_DB_HOST', 'localhost');
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -25,38 +25,6 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Autoload
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function __autoload($class) {
|
|
||||||
// first check if a subdir exists for the class
|
|
||||||
// it splits using uppercase chars
|
|
||||||
preg_match_all("/(\P{Lu}+)|(\p{Lu}+\P{Lu}*)/", $class, $subdir_matches);
|
|
||||||
|
|
||||||
if(!empty($subdir_matches) && count($subdir_matches[0]) > 1) {
|
|
||||||
// okay we have some upper case, lets see if a dir exists
|
|
||||||
$dir = dirname(__FILE__) . '/classes/' . trim($subdir_matches[0][0]);
|
|
||||||
$file = $dir . '/' . trim($class) . '.class.php';
|
|
||||||
|
|
||||||
if(is_dir($dir) && file_exists($file)) {
|
|
||||||
require $file;
|
|
||||||
return $file;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$file = dirname(__FILE__).'/classes/'.trim(strtolower($class)).'.class.php';
|
|
||||||
|
|
||||||
if(file_exists($file)){
|
|
||||||
require $file;
|
|
||||||
return $file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trigger_error("KERNEL_ERR : Unable to find file:\n\t\t[$file]\n\t associated with class:\n\t\t$class", E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
###############################################
|
###############################################
|
||||||
#
|
#
|
||||||
# Language functions
|
# Language functions
|
||||||
|
@ -67,9 +35,9 @@ function __autoload($class) {
|
||||||
* Retrieve language settings from the selected language file
|
* Retrieve language settings from the selected language file
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @see sm_load_lang()
|
* @see psm_load_lang()
|
||||||
*/
|
*/
|
||||||
function sm_get_lang() {
|
function psm_get_lang() {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
if(empty($args)) return $GLOBALS['sm_lang'];
|
if(empty($args)) return $GLOBALS['sm_lang'];
|
||||||
|
@ -89,10 +57,10 @@ function sm_get_lang() {
|
||||||
* Load language from the language file to the $GLOBALS['sm_lang'] variable
|
* Load language from the language file to the $GLOBALS['sm_lang'] variable
|
||||||
*
|
*
|
||||||
* @param string $lang language
|
* @param string $lang language
|
||||||
* @see sm_get_lang()
|
* @see psm_get_lang()
|
||||||
*/
|
*/
|
||||||
function sm_load_lang($lang) {
|
function psm_load_lang($lang) {
|
||||||
$lang_file = dirname(__FILE__) . '/lang/' . $lang . '.lang.php';
|
$lang_file = PSM_PATH_LANG . $lang . '.lang.php';
|
||||||
|
|
||||||
if(!file_exists($lang_file)) {
|
if(!file_exists($lang_file)) {
|
||||||
die('unable to load language file: ' . $lang_file);
|
die('unable to load language file: ' . $lang_file);
|
||||||
|
@ -107,11 +75,11 @@ function sm_load_lang($lang) {
|
||||||
* Retrieve a list with keys of the available languages
|
* Retrieve a list with keys of the available languages
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @see sm_load_lang()
|
* @see psm_load_lang()
|
||||||
*/
|
*/
|
||||||
function sm_get_langs() {
|
function psm_get_langs() {
|
||||||
$fn_ext = '.lang.php';
|
$fn_ext = '.lang.php';
|
||||||
$lang_files = glob(dirname(__FILE__) . '/lang/*' . $fn_ext);
|
$lang_files = glob(PSM_PATH_LANG . '*' . $fn_ext);
|
||||||
$langs = array();
|
$langs = array();
|
||||||
|
|
||||||
foreach($lang_files as $file) {
|
foreach($lang_files as $file) {
|
||||||
|
@ -122,13 +90,13 @@ function sm_get_langs() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a setting from the config.
|
* Get a setting from the config.
|
||||||
* The config must have been loaded first using sm_load_conf()
|
* The config must have been loaded first using psm_load_conf()
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return string
|
* @return string
|
||||||
* @see sm_load_conf()
|
* @see psm_load_conf()
|
||||||
*/
|
*/
|
||||||
function sm_get_conf($key) {
|
function psm_get_conf($key) {
|
||||||
$result = (isset($GLOBALS['sm_config'][$key])) ? $GLOBALS['sm_config'][$key] : null;
|
$result = (isset($GLOBALS['sm_config'][$key])) ? $GLOBALS['sm_config'][$key] : null;
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -138,14 +106,14 @@ function sm_get_conf($key) {
|
||||||
* Load config from the database to the $GLOBALS['sm_config'] variable
|
* Load config from the database to the $GLOBALS['sm_config'] variable
|
||||||
*
|
*
|
||||||
* @global object $db
|
* @global object $db
|
||||||
* @see sm_get_conf()
|
* @see psm_get_conf()
|
||||||
*/
|
*/
|
||||||
function sm_load_conf() {
|
function psm_load_conf() {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
// load config from database into global scope
|
// load config from database into global scope
|
||||||
$GLOBALS['sm_config'] = array();
|
$GLOBALS['sm_config'] = array();
|
||||||
$config_db = $db->select(SM_DB_PREFIX . 'config', null, array('key', 'value'));
|
$config_db = $db->select(PSM_DB_PREFIX . 'config', null, array('key', 'value'));
|
||||||
foreach($config_db as $setting) {
|
foreach($config_db as $setting) {
|
||||||
$GLOBALS['sm_config'][$setting['key']] = $setting['value'];
|
$GLOBALS['sm_config'][$setting['key']] = $setting['value'];
|
||||||
}
|
}
|
||||||
|
@ -170,11 +138,11 @@ function sm_load_conf() {
|
||||||
* @param string $server_id
|
* @param string $server_id
|
||||||
* @param string $message
|
* @param string $message
|
||||||
*/
|
*/
|
||||||
function sm_add_log($server_id, $type, $message, $user_id = null) {
|
function psm_add_log($server_id, $type, $message, $user_id = null) {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
$db->save(
|
$db->save(
|
||||||
SM_DB_PREFIX.'log',
|
PSM_DB_PREFIX.'log',
|
||||||
array(
|
array(
|
||||||
'server_id' => $server_id,
|
'server_id' => $server_id,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
|
@ -192,10 +160,10 @@ function sm_add_log($server_id, $type, $message, $user_id = null) {
|
||||||
* @param array $server information about the server which may be placed in a message: %KEY% will be replaced by your value
|
* @param array $server information about the server which may be placed in a message: %KEY% will be replaced by your value
|
||||||
* @return string parsed message
|
* @return string parsed message
|
||||||
*/
|
*/
|
||||||
function sm_parse_msg($status, $type, $vars) {
|
function psm_parse_msg($status, $type, $vars) {
|
||||||
$message = '';
|
$message = '';
|
||||||
|
|
||||||
$message = sm_get_lang('notifications', $status . '_' . $type);
|
$message = psm_get_lang('notifications', $status . '_' . $type);
|
||||||
|
|
||||||
if(!$message) {
|
if(!$message) {
|
||||||
return $message;
|
return $message;
|
||||||
|
@ -215,7 +183,7 @@ function sm_parse_msg($status, $type, $vars) {
|
||||||
* @param string $href
|
* @param string $href
|
||||||
* @return string cURL result
|
* @return string cURL result
|
||||||
*/
|
*/
|
||||||
function sm_curl_get($href) {
|
function psm_curl_get($href) {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||||
|
@ -236,7 +204,7 @@ function sm_curl_get($href) {
|
||||||
* @return string
|
* @return string
|
||||||
* @todo add translation to timespan messages
|
* @todo add translation to timespan messages
|
||||||
*/
|
*/
|
||||||
function sm_timespan($time) {
|
function psm_timespan($time) {
|
||||||
if ($time !== intval($time)) { $time = strtotime($time); }
|
if ($time !== intval($time)) { $time = strtotime($time); }
|
||||||
$d = time() - $time;
|
$d = time() - $time;
|
||||||
if ($time < strtotime(date('Y-m-d 00:00:00')) - 60*60*24*3) {
|
if ($time < strtotime(date('Y-m-d 00:00:00')) - 60*60*24*3) {
|
||||||
|
@ -266,17 +234,17 @@ function sm_timespan($time) {
|
||||||
* @global object $db
|
* @global object $db
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function sm_check_updates() {
|
function psm_check_updates() {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
$last_update = sm_get_conf('last_update_check');
|
$last_update = psm_get_conf('last_update_check');
|
||||||
|
|
||||||
if((time() - (7 * 24 * 60 * 60)) > $last_update) {
|
if((time() - (7 * 24 * 60 * 60)) > $last_update) {
|
||||||
// been more than a week since update, lets go
|
// been more than a week since update, lets go
|
||||||
// update "update-date"
|
// update "update-date"
|
||||||
$db->save(SM_DB_PREFIX . 'config', array('value' => time()), array('key' => 'last_update_check'));
|
$db->save(PSM_DB_PREFIX . 'config', array('value' => time()), array('key' => 'last_update_check'));
|
||||||
$latest = sm_curl_get('http://phpservermon.neanderthal-technology.com/version');
|
$latest = psm_curl_get('http://phpservermon.neanderthal-technology.com/version');
|
||||||
$current = sm_get_conf('version');
|
$current = psm_get_conf('version');
|
||||||
|
|
||||||
if((int) $current < (int) $latest) {
|
if((int) $current < (int) $latest) {
|
||||||
// new update available
|
// new update available
|
||||||
|
@ -307,7 +275,7 @@ function pre($arr = null) {
|
||||||
/**
|
/**
|
||||||
* Send headers to the browser to avoid caching
|
* Send headers to the browser to avoid caching
|
||||||
*/
|
*/
|
||||||
function sm_no_cache() {
|
function psm_no_cache() {
|
||||||
header("Expires: Mon, 20 Dec 1998 01:00:00 GMT");
|
header("Expires: Mon, 20 Dec 1998 01:00:00 GMT");
|
||||||
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
||||||
header("Cache-Control: no-cache, must-revalidate");
|
header("Cache-Control: no-cache, must-revalidate");
|
|
@ -25,7 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class smDatabase {
|
namespace psm;
|
||||||
|
|
||||||
|
class Database {
|
||||||
|
|
||||||
protected $debug = array();
|
protected $debug = array();
|
||||||
protected $last_inserted_id;
|
protected $last_inserted_id;
|
||||||
|
@ -35,9 +37,9 @@ class smDatabase {
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
// Initizale connection
|
// Initizale connection
|
||||||
$this->link = mysql_connect(SM_DB_HOST, SM_DB_USER, SM_DB_PASS);
|
$this->link = mysql_connect(PSM_DB_HOST, PSM_DB_USER, PSM_DB_PASS);
|
||||||
|
|
||||||
if (!mysql_select_db(SM_DB_NAME, $this->link)) {
|
if (!mysql_select_db(PSM_DB_NAME, $this->link)) {
|
||||||
trigger_error(mysql_errno() . ": " . mysql_error());
|
trigger_error(mysql_errno() . ": " . mysql_error());
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class modConfig extends modCore {
|
namespace psm\Module;
|
||||||
|
|
||||||
|
class Config extends Core {
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
@ -49,7 +51,7 @@ class modConfig extends modCore {
|
||||||
*/
|
*/
|
||||||
public function populateFields() {
|
public function populateFields() {
|
||||||
$config_db = $this->db->select(
|
$config_db = $this->db->select(
|
||||||
SM_DB_PREFIX . 'config',
|
PSM_DB_PREFIX . 'config',
|
||||||
null,
|
null,
|
||||||
array('key', 'value')
|
array('key', 'value')
|
||||||
);
|
);
|
||||||
|
@ -60,10 +62,10 @@ class modConfig extends modCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate language array
|
// generate language array
|
||||||
$lang_keys = sm_get_langs();
|
$lang_keys = psm_get_langs();
|
||||||
$languages = array();
|
$languages = array();
|
||||||
foreach($lang_keys as $key) {
|
foreach($lang_keys as $key) {
|
||||||
$label = sm_get_lang('config', 'language_' . $key);
|
$label = psm_get_lang('config', 'language_' . $key);
|
||||||
// if we don't have a proper label, just show the key..
|
// if we don't have a proper label, just show the key..
|
||||||
// better something than nothing huh
|
// better something than nothing huh
|
||||||
if($label == null) {
|
if($label == null) {
|
||||||
|
@ -125,10 +127,10 @@ class modConfig extends modCore {
|
||||||
// save all values to the database
|
// save all values to the database
|
||||||
foreach($clean as $key => $value) {
|
foreach($clean as $key => $value) {
|
||||||
// check if key already exists, otherwise add it
|
// check if key already exists, otherwise add it
|
||||||
if(sm_get_conf($key) === null) {
|
if(psm_get_conf($key) === null) {
|
||||||
// not yet set, add it
|
// not yet set, add it
|
||||||
$this->db->save(
|
$this->db->save(
|
||||||
SM_DB_PREFIX . 'config',
|
PSM_DB_PREFIX . 'config',
|
||||||
array(
|
array(
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
|
@ -137,16 +139,16 @@ class modConfig extends modCore {
|
||||||
} else {
|
} else {
|
||||||
// update
|
// update
|
||||||
$this->db->save(
|
$this->db->save(
|
||||||
SM_DB_PREFIX . 'config',
|
PSM_DB_PREFIX . 'config',
|
||||||
array('value' => $value),
|
array('value' => $value),
|
||||||
array('key' => $key)
|
array('key' => $key)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->message = sm_get_lang('config', 'updated');
|
$this->message = psm_get_lang('config', 'updated');
|
||||||
|
|
||||||
if($clean['language'] != sm_get_conf('language')) {
|
if($clean['language'] != psm_get_conf('language')) {
|
||||||
header('Location: ' . $_SERVER['REQUEST_URI']);
|
header('Location: ' . $_SERVER['REQUEST_URI']);
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@ -157,35 +159,35 @@ class modConfig extends modCore {
|
||||||
$this->tpl->addTemplateData(
|
$this->tpl->addTemplateData(
|
||||||
$this->getTemplateId(),
|
$this->getTemplateId(),
|
||||||
array(
|
array(
|
||||||
'label_settings_email' => sm_get_lang('config', 'settings_email'),
|
'label_settings_email' => psm_get_lang('config', 'settings_email'),
|
||||||
'label_settings_sms' => sm_get_lang('config', 'settings_sms'),
|
'label_settings_sms' => psm_get_lang('config', 'settings_sms'),
|
||||||
'label_settings_notification' => sm_get_lang('config', 'settings_notification'),
|
'label_settings_notification' => psm_get_lang('config', 'settings_notification'),
|
||||||
'label_settings_log' => sm_get_lang('config', 'settings_log'),
|
'label_settings_log' => psm_get_lang('config', 'settings_log'),
|
||||||
'label_general' => sm_get_lang('config', 'general'),
|
'label_general' => psm_get_lang('config', 'general'),
|
||||||
'label_language' => sm_get_lang('config', 'language'),
|
'label_language' => psm_get_lang('config', 'language'),
|
||||||
'label_show_update' => sm_get_lang('config', 'show_update'),
|
'label_show_update' => psm_get_lang('config', 'show_update'),
|
||||||
'label_email_status' => sm_get_lang('config', 'email_status'),
|
'label_email_status' => psm_get_lang('config', 'email_status'),
|
||||||
'label_email_from_email' => sm_get_lang('config', 'email_from_email'),
|
'label_email_from_email' => psm_get_lang('config', 'email_from_email'),
|
||||||
'label_email_from_name' => sm_get_lang('config', 'email_from_name'),
|
'label_email_from_name' => psm_get_lang('config', 'email_from_name'),
|
||||||
'label_sms_status' => sm_get_lang('config', 'sms_status'),
|
'label_sms_status' => psm_get_lang('config', 'sms_status'),
|
||||||
'label_sms_gateway' => sm_get_lang('config', 'sms_gateway'),
|
'label_sms_gateway' => psm_get_lang('config', 'sms_gateway'),
|
||||||
'label_sms_gateway_mosms' => sm_get_lang('config', 'sms_gateway_mosms'),
|
'label_sms_gateway_mosms' => psm_get_lang('config', 'sms_gateway_mosms'),
|
||||||
'label_sms_gateway_mollie' => sm_get_lang('config', 'sms_gateway_mollie'),
|
'label_sms_gateway_mollie' => psm_get_lang('config', 'sms_gateway_mollie'),
|
||||||
'label_sms_gateway_spryng' => sm_get_lang('config', 'sms_gateway_spryng'),
|
'label_sms_gateway_spryng' => psm_get_lang('config', 'sms_gateway_spryng'),
|
||||||
'label_sms_gateway_inetworx' => sm_get_lang('config', 'sms_gateway_inetworx'),
|
'label_sms_gateway_inetworx' => psm_get_lang('config', 'sms_gateway_inetworx'),
|
||||||
'label_sms_gateway_clickatell' => sm_get_lang('config', 'sms_gateway_clickatell'),
|
'label_sms_gateway_clickatell' => psm_get_lang('config', 'sms_gateway_clickatell'),
|
||||||
'label_sms_gateway_username' => sm_get_lang('config', 'sms_gateway_username'),
|
'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'),
|
||||||
'label_sms_gateway_password' => sm_get_lang('config', 'sms_gateway_password'),
|
'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'),
|
||||||
'label_sms_from' => sm_get_lang('config', 'sms_from'),
|
'label_sms_from' => psm_get_lang('config', 'sms_from'),
|
||||||
'label_alert_type' => sm_get_lang('config', 'alert_type'),
|
'label_alert_type' => psm_get_lang('config', 'alert_type'),
|
||||||
'label_alert_type_description' => sm_get_lang('config', 'alert_type_description'),
|
'label_alert_type_description' => psm_get_lang('config', 'alert_type_description'),
|
||||||
'label_alert_type_status' => sm_get_lang('config', 'alert_type_status'),
|
'label_alert_type_status' => psm_get_lang('config', 'alert_type_status'),
|
||||||
'label_alert_type_offline' => sm_get_lang('config', 'alert_type_offline'),
|
'label_alert_type_offline' => psm_get_lang('config', 'alert_type_offline'),
|
||||||
'label_alert_type_always' => sm_get_lang('config', 'alert_type_always'),
|
'label_alert_type_always' => psm_get_lang('config', 'alert_type_always'),
|
||||||
'label_log_status' => sm_get_lang('config', 'log_status'),
|
'label_log_status' => psm_get_lang('config', 'log_status'),
|
||||||
'label_log_email' => sm_get_lang('config', 'log_email'),
|
'label_log_email' => psm_get_lang('config', 'log_email'),
|
||||||
'label_log_sms' => sm_get_lang('config', 'log_sms'),
|
'label_log_sms' => psm_get_lang('config', 'log_sms'),
|
||||||
'label_auto_refresh_servers' => sm_get_lang('config', 'auto_refresh_servers'),
|
'label_auto_refresh_servers' => psm_get_lang('config', 'auto_refresh_servers'),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -25,17 +25,19 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
abstract class modCore {
|
namespace psm\Module;
|
||||||
|
|
||||||
|
abstract class Core {
|
||||||
/**
|
/**
|
||||||
* Custom message
|
* Custom message
|
||||||
* @var string
|
* @var string $message
|
||||||
*/
|
*/
|
||||||
public $message;
|
public $message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current mode. Can be used by modules to determine
|
* Current mode. Can be used by modules to determine
|
||||||
* what to do
|
* what to do
|
||||||
* @var string
|
* @var string $mode
|
||||||
*/
|
*/
|
||||||
public $mode;
|
public $mode;
|
||||||
|
|
||||||
|
@ -47,13 +49,13 @@ abstract class modCore {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* smDatabase object
|
* smDatabase object
|
||||||
* @var object
|
* @var object $db
|
||||||
*/
|
*/
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* smTemplate object
|
* \psm\Template object
|
||||||
* @var object
|
* @var object $tpl
|
||||||
*/
|
*/
|
||||||
protected $tpl;
|
protected $tpl;
|
||||||
|
|
||||||
|
@ -67,8 +69,8 @@ abstract class modCore {
|
||||||
function __construct() {
|
function __construct() {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
$this->db = ($db) ? $db : new smDatabase();
|
$this->db = ($db) ? $db : new \psm\Database();
|
||||||
$this->tpl = new smTemplate();
|
$this->tpl = new \psm\Template();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -87,7 +89,7 @@ abstract class modCore {
|
||||||
$html_footer = '';
|
$html_footer = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sm_get_conf('show_update')) {
|
if(psm_get_conf('show_update')) {
|
||||||
// user wants updates, lets see what we can do
|
// user wants updates, lets see what we can do
|
||||||
$this->createHTMLUpdateAvailable();
|
$this->createHTMLUpdateAvailable();
|
||||||
}
|
}
|
||||||
|
@ -101,7 +103,7 @@ abstract class modCore {
|
||||||
'content' => $this->tpl->getTemplate($this->getTemplateId()),
|
'content' => $this->tpl->getTemplate($this->getTemplateId()),
|
||||||
'message' => ($this->message == '') ? ' ' : $this->message,
|
'message' => ($this->message == '') ? ' ' : $this->message,
|
||||||
'html_footer' => $html_footer,
|
'html_footer' => $html_footer,
|
||||||
'label_back_to_top' => sm_get_lang('system', 'back_to_top'),
|
'label_back_to_top' => psm_get_lang('system', 'back_to_top'),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -116,12 +118,12 @@ abstract class modCore {
|
||||||
protected function createHTMLUpdateAvailable() {
|
protected function createHTMLUpdateAvailable() {
|
||||||
// check for updates?
|
// check for updates?
|
||||||
|
|
||||||
if(sm_check_updates()) {
|
if(psm_check_updates()) {
|
||||||
// yay, new update available =D
|
// yay, new update available =D
|
||||||
$this->tpl->addTemplateData(
|
$this->tpl->addTemplateData(
|
||||||
'main',
|
'main',
|
||||||
array(
|
array(
|
||||||
'update_available' => '<div id="update">'.sm_get_lang('system', 'update_available').'</div>',
|
'update_available' => '<div id="update">'.psm_get_lang('system', 'update_available').'</div>',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -138,15 +140,15 @@ abstract class modCore {
|
||||||
$this->tpl->addTemplateData(
|
$this->tpl->addTemplateData(
|
||||||
'main',
|
'main',
|
||||||
array(
|
array(
|
||||||
'title' => strtoupper(sm_get_lang('system', 'title')),
|
'title' => strtoupper(psm_get_lang('system', 'title')),
|
||||||
'subtitle' => sm_get_lang('system', $type),
|
'subtitle' => psm_get_lang('system', $type),
|
||||||
'active_' . $type => 'active',
|
'active_' . $type => 'active',
|
||||||
'label_servers' => sm_get_lang('system', 'servers'),
|
'label_servers' => psm_get_lang('system', 'servers'),
|
||||||
'label_users' => sm_get_lang('system', 'users'),
|
'label_users' => psm_get_lang('system', 'users'),
|
||||||
'label_log' => sm_get_lang('system', 'log'),
|
'label_log' => psm_get_lang('system', 'log'),
|
||||||
'label_config' => sm_get_lang('system', 'config'),
|
'label_config' => psm_get_lang('system', 'config'),
|
||||||
'label_update' => sm_get_lang('system', 'update'),
|
'label_update' => psm_get_lang('system', 'update'),
|
||||||
'label_help' => sm_get_lang('system', 'help'),
|
'label_help' => psm_get_lang('system', 'help'),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -25,10 +25,12 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
namespace psm\Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log module. Create the page to view previous log messages
|
* Log module. Create the page to view previous log messages
|
||||||
*/
|
*/
|
||||||
class modLog extends modCore {
|
class Log extends Core {
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
@ -36,8 +38,6 @@ class modLog extends modCore {
|
||||||
|
|
||||||
// override parent::createHTML()
|
// override parent::createHTML()
|
||||||
public function createHTML() {
|
public function createHTML() {
|
||||||
$this->tpl->addCSS('tabs.css', 'main');
|
|
||||||
|
|
||||||
$this->createHTMLList();
|
$this->createHTMLList();
|
||||||
|
|
||||||
return parent::createHTML();
|
return parent::createHTML();
|
||||||
|
@ -55,7 +55,7 @@ class modLog extends modCore {
|
||||||
$entries['sms'] = $this->getEntries('sms');
|
$entries['sms'] = $this->getEntries('sms');
|
||||||
|
|
||||||
// get users
|
// get users
|
||||||
$users = $this->db->select(SM_DB_PREFIX.'users', null, array('user_id','name'));
|
$users = $this->db->select(PSM_DB_PREFIX.'users', null, array('user_id','name'));
|
||||||
|
|
||||||
$users_labels = array();
|
$users_labels = array();
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
|
@ -122,8 +122,8 @@ class modLog extends modCore {
|
||||||
'\'%H:%i:%s %d-%m-%y\''.
|
'\'%H:%i:%s %d-%m-%y\''.
|
||||||
') AS `datetime_format`, '.
|
') AS `datetime_format`, '.
|
||||||
'`user_id` '.
|
'`user_id` '.
|
||||||
'FROM `'.SM_DB_PREFIX.'log` AS `log` '.
|
'FROM `'.PSM_DB_PREFIX.'log` AS `log` '.
|
||||||
'JOIN `'.SM_DB_PREFIX.'servers` AS `servers` ON (`servers`.`server_id`=`log`.`server_id`) '.
|
'JOIN `'.PSM_DB_PREFIX.'servers` AS `servers` ON (`servers`.`server_id`=`log`.`server_id`) '.
|
||||||
'WHERE `log`.`type`=\''.$type.'\' '.
|
'WHERE `log`.`type`=\''.$type.'\' '.
|
||||||
'ORDER BY `datetime` DESC '.
|
'ORDER BY `datetime` DESC '.
|
||||||
'LIMIT 0,20'
|
'LIMIT 0,20'
|
||||||
|
@ -136,15 +136,15 @@ class modLog extends modCore {
|
||||||
$this->tpl->addTemplateData(
|
$this->tpl->addTemplateData(
|
||||||
$this->getTemplateId(),
|
$this->getTemplateId(),
|
||||||
array(
|
array(
|
||||||
'label_status' => sm_get_lang('log', 'status'),
|
'label_status' => psm_get_lang('log', 'status'),
|
||||||
'label_email' => sm_get_lang('log', 'email'),
|
'label_email' => psm_get_lang('log', 'email'),
|
||||||
'label_sms' => sm_get_lang('log', 'sms'),
|
'label_sms' => psm_get_lang('log', 'sms'),
|
||||||
'label_title' => sm_get_lang('log', 'title'),
|
'label_title' => psm_get_lang('log', 'title'),
|
||||||
'label_server' => sm_get_lang('servers', 'server'),
|
'label_server' => psm_get_lang('servers', 'server'),
|
||||||
'label_type' => sm_get_lang('log', 'type'),
|
'label_type' => psm_get_lang('log', 'type'),
|
||||||
'label_message' => sm_get_lang('system', 'message'),
|
'label_message' => psm_get_lang('system', 'message'),
|
||||||
'label_date' => sm_get_lang('system', 'date'),
|
'label_date' => psm_get_lang('system', 'date'),
|
||||||
'label_users' => ucfirst(sm_get_lang('system', 'users')),
|
'label_users' => ucfirst(psm_get_lang('system', 'users')),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -25,10 +25,12 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
namespace psm\Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server module. Add/edit/delete servers, show a list of all servers etc.
|
* Server module. Add/edit/delete servers, show a list of all servers etc.
|
||||||
*/
|
*/
|
||||||
class modServers extends modCore {
|
class Servers extends Core {
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
@ -76,7 +78,7 @@ class modServers extends modCore {
|
||||||
switch(intval($server_id)) {
|
switch(intval($server_id)) {
|
||||||
case 0:
|
case 0:
|
||||||
// insert mode
|
// insert mode
|
||||||
$tpl_data['titlemode'] = sm_get_lang('system', 'insert');
|
$tpl_data['titlemode'] = psm_get_lang('system', 'insert');
|
||||||
$tpl_data['edit_server_id'] = '0';
|
$tpl_data['edit_server_id'] = '0';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -84,7 +86,7 @@ class modServers extends modCore {
|
||||||
|
|
||||||
// get server entry
|
// get server entry
|
||||||
$edit_server = $this->db->selectRow(
|
$edit_server = $this->db->selectRow(
|
||||||
SM_DB_PREFIX.'servers',
|
PSM_DB_PREFIX.'servers',
|
||||||
array('server_id' => $server_id)
|
array('server_id' => $server_id)
|
||||||
);
|
);
|
||||||
if (empty($edit_server)) {
|
if (empty($edit_server)) {
|
||||||
|
@ -93,7 +95,7 @@ class modServers extends modCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl_data = array_merge($tpl_data, array(
|
$tpl_data = array_merge($tpl_data, array(
|
||||||
'titlemode' => sm_get_lang('system', 'edit') . ' ' . $edit_server['label'],
|
'titlemode' => psm_get_lang('system', 'edit') . ' ' . $edit_server['label'],
|
||||||
'edit_server_id' => $edit_server['server_id'],
|
'edit_server_id' => $edit_server['server_id'],
|
||||||
'edit_value_label' => $edit_server['label'],
|
'edit_value_label' => $edit_server['label'],
|
||||||
'edit_value_ip' => $edit_server['ip'],
|
'edit_value_ip' => $edit_server['ip'],
|
||||||
|
@ -143,7 +145,7 @@ class modServers extends modCore {
|
||||||
'`active`, '.
|
'`active`, '.
|
||||||
'`email`, '.
|
'`email`, '.
|
||||||
'`sms` '.
|
'`sms` '.
|
||||||
'FROM `'.SM_DB_PREFIX.'servers` '.
|
'FROM `'.PSM_DB_PREFIX.'servers` '.
|
||||||
'ORDER BY `active` ASC, `status` DESC, `type` ASC, `label` ASC'
|
'ORDER BY `active` ASC, `status` DESC, `type` ASC, `label` ASC'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -162,7 +164,7 @@ class modServers extends modCore {
|
||||||
$this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers', $servers);
|
$this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers', $servers);
|
||||||
|
|
||||||
// check if we need to add the auto refresh
|
// check if we need to add the auto refresh
|
||||||
$auto_refresh = sm_get_conf('auto_refresh_servers');
|
$auto_refresh = psm_get_conf('auto_refresh_servers');
|
||||||
if(intval($auto_refresh) > 0) {
|
if(intval($auto_refresh) > 0) {
|
||||||
// add it
|
// add it
|
||||||
$this->tpl->newTemplate('main_auto_refresh', 'main.tpl.html');
|
$this->tpl->newTemplate('main_auto_refresh', 'main.tpl.html');
|
||||||
|
@ -192,16 +194,16 @@ class modServers extends modCore {
|
||||||
if ((int) $_POST['server_id'] > 0) {
|
if ((int) $_POST['server_id'] > 0) {
|
||||||
// edit
|
// edit
|
||||||
$this->db->save(
|
$this->db->save(
|
||||||
SM_DB_PREFIX.'servers',
|
PSM_DB_PREFIX.'servers',
|
||||||
$clean,
|
$clean,
|
||||||
array('server_id' => $_POST['server_id'])
|
array('server_id' => $_POST['server_id'])
|
||||||
);
|
);
|
||||||
$this->message = sm_get_lang('servers', 'updated');
|
$this->message = psm_get_lang('servers', 'updated');
|
||||||
} else {
|
} else {
|
||||||
// add
|
// add
|
||||||
$clean['status'] = 'on';
|
$clean['status'] = 'on';
|
||||||
$this->db->save(SM_DB_PREFIX.'servers', $clean);
|
$this->db->save(PSM_DB_PREFIX.'servers', $clean);
|
||||||
$this->message = sm_get_lang('servers', 'inserted');
|
$this->message = psm_get_lang('servers', 'inserted');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,12 +214,12 @@ class modServers extends modCore {
|
||||||
protected function executeDelete() {
|
protected function executeDelete() {
|
||||||
// do delete
|
// do delete
|
||||||
$this->db->delete(
|
$this->db->delete(
|
||||||
SM_DB_PREFIX . 'servers',
|
PSM_DB_PREFIX . 'servers',
|
||||||
array(
|
array(
|
||||||
'server_id' => $_GET['delete']
|
'server_id' => $_GET['delete']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->message = sm_get_lang('system', 'deleted');
|
$this->message = psm_get_lang('system', 'deleted');
|
||||||
}
|
}
|
||||||
|
|
||||||
// override parent::createHTMLLabels()
|
// override parent::createHTMLLabels()
|
||||||
|
@ -225,23 +227,23 @@ class modServers extends modCore {
|
||||||
$this->tpl->addTemplateData(
|
$this->tpl->addTemplateData(
|
||||||
$this->getTemplateId(),
|
$this->getTemplateId(),
|
||||||
array(
|
array(
|
||||||
'label_label' => sm_get_lang('servers', 'label'),
|
'label_label' => psm_get_lang('servers', 'label'),
|
||||||
'label_domain' => sm_get_lang('servers', 'domain'),
|
'label_domain' => psm_get_lang('servers', 'domain'),
|
||||||
'label_port' => sm_get_lang('servers', 'port'),
|
'label_port' => psm_get_lang('servers', 'port'),
|
||||||
'label_type' => sm_get_lang('servers', 'type'),
|
'label_type' => psm_get_lang('servers', 'type'),
|
||||||
'label_last_check' => sm_get_lang('servers', 'last_check'),
|
'label_last_check' => psm_get_lang('servers', 'last_check'),
|
||||||
'label_rtime' => sm_get_lang('servers', 'rtime'),
|
'label_rtime' => psm_get_lang('servers', 'rtime'),
|
||||||
'label_last_online' => sm_get_lang('servers', 'last_online'),
|
'label_last_online' => psm_get_lang('servers', 'last_online'),
|
||||||
'label_monitoring' => sm_get_lang('servers', 'monitoring'),
|
'label_monitoring' => psm_get_lang('servers', 'monitoring'),
|
||||||
'label_send_email' => sm_get_lang('servers', 'send_email'),
|
'label_send_email' => psm_get_lang('servers', 'send_email'),
|
||||||
'label_send_sms' => sm_get_lang('servers', 'send_sms'),
|
'label_send_sms' => psm_get_lang('servers', 'send_sms'),
|
||||||
'label_action' => sm_get_lang('system', 'action'),
|
'label_action' => psm_get_lang('system', 'action'),
|
||||||
'label_save' => sm_get_lang('system', 'save'),
|
'label_save' => psm_get_lang('system', 'save'),
|
||||||
'label_edit' => sm_get_lang('system', 'edit') . ' ' . sm_get_lang('servers', 'server'),
|
'label_edit' => psm_get_lang('system', 'edit') . ' ' . psm_get_lang('servers', 'server'),
|
||||||
'label_delete' => sm_get_lang('system', 'delete') . ' ' . sm_get_lang('servers', 'server'),
|
'label_delete' => psm_get_lang('system', 'delete') . ' ' . psm_get_lang('servers', 'server'),
|
||||||
'label_yes' => sm_get_lang('system', 'yes'),
|
'label_yes' => psm_get_lang('system', 'yes'),
|
||||||
'label_no' => sm_get_lang('system', 'no'),
|
'label_no' => psm_get_lang('system', 'no'),
|
||||||
'label_add_new' => sm_get_lang('system', 'add_new'),
|
'label_add_new' => psm_get_lang('system', 'add_new'),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -26,10 +26,12 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
namespace psm\Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status module
|
* Status module
|
||||||
*/
|
*/
|
||||||
class modStatus extends modCore {
|
class Status extends Core {
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
@ -52,7 +54,7 @@ class modStatus extends modCore {
|
||||||
|
|
||||||
// get the active servers from database
|
// get the active servers from database
|
||||||
$servers = $this->db->select(
|
$servers = $this->db->select(
|
||||||
SM_DB_PREFIX.'servers',
|
PSM_DB_PREFIX.'servers',
|
||||||
array('active' => 'yes'),
|
array('active' => 'yes'),
|
||||||
array('server_id', 'label', 'status', 'last_online', 'last_check', 'rtime')
|
array('server_id', 'label', 'status', 'last_online', 'last_check', 'rtime')
|
||||||
);
|
);
|
||||||
|
@ -70,8 +72,8 @@ class modStatus extends modCore {
|
||||||
$this->tpl->addTemplateData($this->getTemplateId(), $tpl_data);
|
$this->tpl->addTemplateData($this->getTemplateId(), $tpl_data);
|
||||||
|
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
$server['last_checked_nice'] = sm_timespan($server['last_check']);
|
$server['last_checked_nice'] = psm_timespan($server['last_check']);
|
||||||
$server['last_online_nice'] = sm_timespan($server['last_online']);
|
$server['last_online_nice'] = psm_timespan($server['last_online']);
|
||||||
|
|
||||||
if ($server['status'] == "off") {
|
if ($server['status'] == "off") {
|
||||||
$offline[$server['server_id']] = $server;
|
$offline[$server['server_id']] = $server;
|
|
@ -25,11 +25,13 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
namespace psm\Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User module. Add, edit and delete users, or assign
|
* User module. Add, edit and delete users, or assign
|
||||||
* servers to users.
|
* servers to users.
|
||||||
*/
|
*/
|
||||||
class modUsers extends modCore {
|
class Users extends Core {
|
||||||
public $servers;
|
public $servers;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
@ -50,7 +52,7 @@ class modUsers extends modCore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->servers = $this->db->select(SM_DB_PREFIX.'servers', null, array('server_id', 'label'));
|
$this->servers = $this->db->select(PSM_DB_PREFIX.'servers', null, array('server_id', 'label'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// override parent::createHTML()
|
// override parent::createHTML()
|
||||||
|
@ -81,7 +83,7 @@ class modUsers extends modCore {
|
||||||
switch((int) $user_id) {
|
switch((int) $user_id) {
|
||||||
case 0:
|
case 0:
|
||||||
// insert mode
|
// insert mode
|
||||||
$tpl_data['titlemode'] = sm_get_lang('system', 'insert');
|
$tpl_data['titlemode'] = psm_get_lang('system', 'insert');
|
||||||
$tpl_data['edit_user_id'] = '0';
|
$tpl_data['edit_user_id'] = '0';
|
||||||
|
|
||||||
// add inactive class to all servers
|
// add inactive class to all servers
|
||||||
|
@ -95,7 +97,7 @@ class modUsers extends modCore {
|
||||||
|
|
||||||
// get user entry
|
// get user entry
|
||||||
$edit_user = $this->db->selectRow(
|
$edit_user = $this->db->selectRow(
|
||||||
SM_DB_PREFIX.'users',
|
PSM_DB_PREFIX.'users',
|
||||||
array('user_id' => $user_id)
|
array('user_id' => $user_id)
|
||||||
);
|
);
|
||||||
if (empty($edit_user)) {
|
if (empty($edit_user)) {
|
||||||
|
@ -104,7 +106,7 @@ class modUsers extends modCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl_data = array_merge($tpl_data, array(
|
$tpl_data = array_merge($tpl_data, array(
|
||||||
'titlemode' => sm_get_lang('system', 'edit') . ' ' . $edit_user['name'],
|
'titlemode' => psm_get_lang('system', 'edit') . ' ' . $edit_user['name'],
|
||||||
'edit_user_id' => $edit_user['user_id'],
|
'edit_user_id' => $edit_user['user_id'],
|
||||||
'edit_value_name' => $edit_user['name'],
|
'edit_value_name' => $edit_user['name'],
|
||||||
'edit_value_mobile' => $edit_user['mobile'],
|
'edit_value_mobile' => $edit_user['mobile'],
|
||||||
|
@ -146,7 +148,7 @@ class modUsers extends modCore {
|
||||||
|
|
||||||
// get users from database
|
// get users from database
|
||||||
$users = $this->db->select(
|
$users = $this->db->select(
|
||||||
SM_DB_PREFIX.'users',
|
PSM_DB_PREFIX.'users',
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
@ -193,15 +195,15 @@ class modUsers extends modCore {
|
||||||
if ((int) $_POST['user_id'] > 0) {
|
if ((int) $_POST['user_id'] > 0) {
|
||||||
// edit
|
// edit
|
||||||
$this->db->save(
|
$this->db->save(
|
||||||
SM_DB_PREFIX.'users',
|
PSM_DB_PREFIX.'users',
|
||||||
$clean,
|
$clean,
|
||||||
array('user_id' => $_POST['user_id'])
|
array('user_id' => $_POST['user_id'])
|
||||||
);
|
);
|
||||||
$this->message = sm_get_lang('users', 'updated');
|
$this->message = psm_get_lang('users', 'updated');
|
||||||
} else {
|
} else {
|
||||||
// add
|
// add
|
||||||
$this->db->save(SM_DB_PREFIX.'users', $clean);
|
$this->db->save(PSM_DB_PREFIX.'users', $clean);
|
||||||
$this->message = sm_get_lang('users', 'inserted');
|
$this->message = psm_get_lang('users', 'inserted');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,12 +214,12 @@ class modUsers extends modCore {
|
||||||
protected function executeDelete() {
|
protected function executeDelete() {
|
||||||
// do delete
|
// do delete
|
||||||
$this->db->delete(
|
$this->db->delete(
|
||||||
SM_DB_PREFIX . 'users',
|
PSM_DB_PREFIX . 'users',
|
||||||
array(
|
array(
|
||||||
'user_id' => $_GET['delete']
|
'user_id' => $_GET['delete']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->message = sm_get_lang('system', 'deleted');
|
$this->message = psm_get_lang('system', 'deleted');
|
||||||
}
|
}
|
||||||
|
|
||||||
// override parent::createHTMLLabels()
|
// override parent::createHTMLLabels()
|
||||||
|
@ -225,16 +227,16 @@ class modUsers extends modCore {
|
||||||
$this->tpl->addTemplateData(
|
$this->tpl->addTemplateData(
|
||||||
$this->getTemplateId(),
|
$this->getTemplateId(),
|
||||||
array(
|
array(
|
||||||
'label_users' => sm_get_lang('system', 'users'),
|
'label_users' => psm_get_lang('system', 'users'),
|
||||||
'label_name' => sm_get_lang('users', 'name'),
|
'label_name' => psm_get_lang('users', 'name'),
|
||||||
'label_mobile' => sm_get_lang('users', 'mobile'),
|
'label_mobile' => psm_get_lang('users', 'mobile'),
|
||||||
'label_email' => sm_get_lang('users', 'email'),
|
'label_email' => psm_get_lang('users', 'email'),
|
||||||
'label_servers' => sm_get_lang('system', 'servers'),
|
'label_servers' => psm_get_lang('system', 'servers'),
|
||||||
'label_action' => sm_get_lang('system', 'action'),
|
'label_action' => psm_get_lang('system', 'action'),
|
||||||
'label_save' => sm_get_lang('system', 'save'),
|
'label_save' => psm_get_lang('system', 'save'),
|
||||||
'label_edit' => sm_get_lang('system', 'edit') . ' ' . sm_get_lang('users', 'user'),
|
'label_edit' => psm_get_lang('system', 'edit') . ' ' . psm_get_lang('users', 'user'),
|
||||||
'label_delete' => sm_get_lang('system', 'delete') . ' ' . sm_get_lang('users', 'user'),
|
'label_delete' => psm_get_lang('system', 'delete') . ' ' . psm_get_lang('users', 'user'),
|
||||||
'label_add_new' => sm_get_lang('system', 'add_new'),
|
'label_add_new' => psm_get_lang('system', 'add_new'),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class smTemplate {
|
namespace psm;
|
||||||
protected $css_files = array();
|
|
||||||
protected $js_files = array();
|
class Template {
|
||||||
protected $output;
|
protected $output;
|
||||||
protected $templates = array();
|
protected $templates = array();
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ class smTemplate {
|
||||||
public function newTemplate($id, $filename) {
|
public function newTemplate($id, $filename) {
|
||||||
if (file_exists($filename)) {
|
if (file_exists($filename)) {
|
||||||
$this->templates[$id] = $this->parseFile($filename);
|
$this->templates[$id] = $this->parseFile($filename);
|
||||||
} elseif (file_exists(SM_PATH_TPL.$filename)) {
|
} elseif (file_exists(PSM_PATH_TPL.$filename)) {
|
||||||
$this->templates[$id] = $this->parseFile(SM_PATH_TPL.$filename);
|
$this->templates[$id] = $this->parseFile(PSM_PATH_TPL.$filename);
|
||||||
} else {
|
} else {
|
||||||
// file does not exist
|
// file does not exist
|
||||||
trigger_error('Template not found with id: '.$id.' and filename: '.$filename);
|
trigger_error('Template not found with id: '.$id.' and filename: '.$filename);
|
||||||
|
@ -159,9 +159,6 @@ class smTemplate {
|
||||||
// check for tpl variables that have not been replaced. ie: {name}. ignore literal stuff, though. ie: {{name}} is {name} and should not be removed
|
// check for tpl variables that have not been replaced. ie: {name}. ignore literal stuff, though. ie: {{name}} is {name} and should not be removed
|
||||||
preg_match_all('~{?{(.+?)}}?~', $result, $matches);
|
preg_match_all('~{?{(.+?)}}?~', $result, $matches);
|
||||||
|
|
||||||
// add css and javascript files to header
|
|
||||||
$result = $this->addHeaderFiles($id, $result);
|
|
||||||
|
|
||||||
foreach($matches[0] as $match) {
|
foreach($matches[0] as $match) {
|
||||||
if (substr($match, 0, 2) == '{{') {
|
if (substr($match, 0, 2) == '{{') {
|
||||||
// literal! remove only first and last bracket!
|
// literal! remove only first and last bracket!
|
||||||
|
@ -174,48 +171,6 @@ class smTemplate {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a css file to the list which will be added to the template when display() is called
|
|
||||||
*
|
|
||||||
* @param string $template_id
|
|
||||||
* @param string $filename
|
|
||||||
* @param string $path uses default set in config if non specified
|
|
||||||
*/
|
|
||||||
public function addCSS($filename, $template_id = 'main', $path = SM_PATH_CSS) {
|
|
||||||
if (!isset($this->css_files[$template_id])) {
|
|
||||||
$this->css_files[$template_id] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
// if file doesn't exist we assume it's inline
|
|
||||||
$type = (file_exists($path.$filename)) ? 'file' : 'inline';
|
|
||||||
|
|
||||||
$this->css_files[$template_id][$filename] = array(
|
|
||||||
'file' => ($type == 'file') ? $path.$filename : $filename,
|
|
||||||
'type' => $type
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a javascript file to the list which will be added to the template when display() is called
|
|
||||||
*
|
|
||||||
* @param string $template_id
|
|
||||||
* @param string $filename path to file or CSS code to be added inline
|
|
||||||
* @param string $path uses default set in config if non specified
|
|
||||||
*/
|
|
||||||
public function addJS($filename, $template_id = 'main', $path = SM_PATH_JS) {
|
|
||||||
if (!isset($this->js_files[$template_id])) {
|
|
||||||
$this->js_files[$template_id] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
// if file doesn't exist we assume it's inline
|
|
||||||
$type = (file_exists($path.$filename)) ? 'file' : 'inline';
|
|
||||||
|
|
||||||
$this->js_files[$template_id][$filename] = array(
|
|
||||||
'file' => ($type == 'file') ? $path.$filename : $filename,
|
|
||||||
'type' => $type
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get html code for a template, or if no template id given get all templates
|
* Get html code for a template, or if no template id given get all templates
|
||||||
*
|
*
|
||||||
|
@ -232,62 +187,6 @@ class smTemplate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the CSS and JavaScript files to the header html.
|
|
||||||
*
|
|
||||||
* @param string $template_id
|
|
||||||
* @param string $html
|
|
||||||
* @return string new html code
|
|
||||||
*/
|
|
||||||
protected function addHeaderFiles($template_id, $html) {
|
|
||||||
// get code between <head> tags
|
|
||||||
preg_match_all("{<head>(.*?)<\/head>}is", $html, $matches);
|
|
||||||
|
|
||||||
if (isset($matches[1][0]) && $matches[1][0] != '') {
|
|
||||||
$header = $matches[1][0];
|
|
||||||
|
|
||||||
if (isset($this->css_files[$template_id]) && !empty($this->css_files[$template_id])) {
|
|
||||||
$header .= "\t<!--CSS Files-->\n";
|
|
||||||
|
|
||||||
foreach($this->css_files[$template_id] as $filename => $info) {
|
|
||||||
switch($info['type']) {
|
|
||||||
case 'file':
|
|
||||||
$header .= "\t<link type=\"text/css\" href=\"{$info['file']}\" rel=\"stylesheet\" />\n";
|
|
||||||
break;
|
|
||||||
case 'inline':
|
|
||||||
$header .=
|
|
||||||
"\t<style type=\"text/css\">\n".
|
|
||||||
$info['file'].
|
|
||||||
"\t</style>\n";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->js_files[$template_id]) && !empty($this->js_files[$template_id])) {
|
|
||||||
$header .= "\t<!--JavaScript Files-->\n";
|
|
||||||
|
|
||||||
foreach($this->js_files[$template_id] as $filename => $info) {
|
|
||||||
switch($info['type']) {
|
|
||||||
case 'file':
|
|
||||||
$header .= "\t<script src=\"".$info['file']."\" type=\"text/javascript\" ></script>\n";
|
|
||||||
break;
|
|
||||||
case 'inline':
|
|
||||||
$header .=
|
|
||||||
"\t<script type=\"text/javascript\">\n".
|
|
||||||
$info['file'].
|
|
||||||
"\t</script>\n";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// add new header to html
|
|
||||||
$html = preg_replace('{'.$matches[1][0].'}is', $header, $html);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Get file content
|
* Get file content
|
|
@ -25,7 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class txtmsgClickatell extends txtmsgCore {
|
namespace psm\Txtmsg;
|
||||||
|
|
||||||
|
class Clickatell extends Core {
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
// [ Fields ]
|
// [ Fields ]
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
@ -59,7 +61,7 @@ class txtmsgClickatell extends txtmsgCore {
|
||||||
|
|
||||||
protected function _auth_https_post($host, $path, $data) {
|
protected function _auth_https_post($host, $path, $data) {
|
||||||
$url = $host . $path . $data;
|
$url = $host . $path . $data;
|
||||||
return sm_curl_get($url);
|
return psm_curl_get($url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
abstract class txtmsgCore implements txtmsgInterface {
|
namespace psm\Txtmsg;
|
||||||
|
|
||||||
|
abstract class Core implements TxtmsgInterface {
|
||||||
protected $originator;
|
protected $originator;
|
||||||
protected $password;
|
protected $password;
|
||||||
protected $recipients = array();
|
protected $recipients = array();
|
|
@ -25,7 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class txtmsgInetworx extends txtmsgCore {
|
namespace psm\Txtmsg;
|
||||||
|
|
||||||
|
class Inetworx extends Core {
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
// [ Fields ]
|
// [ Fields ]
|
||||||
// =========================================================================
|
// =========================================================================
|
|
@ -25,7 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class txtmsgMollie extends txtmsgCore {
|
namespace psm\Txtmsg;
|
||||||
|
|
||||||
|
class Mollie extends Core {
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
// [ Fields ]
|
// [ Fields ]
|
||||||
// =========================================================================
|
// =========================================================================
|
|
@ -26,7 +26,9 @@
|
||||||
* @since phpservermon 2.1
|
* @since phpservermon 2.1
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class txtmsgMosms extends txtmsgCore {
|
namespace psm\Txtmsg;
|
||||||
|
|
||||||
|
class Mosms extends Core {
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
// [ Fields ]
|
// [ Fields ]
|
||||||
// =========================================================================
|
// =========================================================================
|
|
@ -25,7 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class txtmsgSpryng extends txtmsgCore {
|
namespace psm\Txtmsg;
|
||||||
|
|
||||||
|
class Spryng extends Core {
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
// [ Fields ]
|
// [ Fields ]
|
||||||
// =========================================================================
|
// =========================================================================
|
|
@ -25,7 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
interface txtmsgInterface {
|
namespace psm\Txtmsg;
|
||||||
|
|
||||||
|
interface TxtmsgInterface {
|
||||||
|
|
||||||
public function setLogin($username, $password);
|
public function setLogin($username, $password);
|
||||||
public function setOriginator($originator);
|
public function setOriginator($originator);
|
|
@ -25,7 +25,9 @@
|
||||||
* @link http://phpservermon.neanderthal-technology.com/
|
* @link http://phpservermon.neanderthal-technology.com/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class smUpdaterStatus extends smCore {
|
namespace psm;
|
||||||
|
|
||||||
|
class UpdaterStatus {
|
||||||
public $error;
|
public $error;
|
||||||
public $notify;
|
public $notify;
|
||||||
public $rtime = 0;
|
public $rtime = 0;
|
||||||
|
@ -33,6 +35,13 @@ class smUpdaterStatus extends smCore {
|
||||||
public $status_org = false;
|
public $status_org = false;
|
||||||
public $status_new = false;
|
public $status_new = false;
|
||||||
|
|
||||||
|
public $db;
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
// add database handler
|
||||||
|
$this->db = $GLOBALS['db'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a new server
|
* Set a new server
|
||||||
*
|
*
|
||||||
|
@ -168,14 +177,14 @@ class smUpdaterStatus extends smCore {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function notify() {
|
public function notify() {
|
||||||
if(sm_get_conf('email_status') == false && sm_get_conf('sms_status') == false && sm_get_conf('log_status') == false) {
|
if(psm_get_conf('email_status') == false && psm_get_conf('sms_status') == false && psm_get_conf('log_status') == false) {
|
||||||
// seems like we have nothing to do. skip the rest
|
// seems like we have nothing to do. skip the rest
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$notify = false;
|
$notify = false;
|
||||||
|
|
||||||
// check which type of alert the user wants
|
// check which type of alert the user wants
|
||||||
switch(sm_get_conf('alert_type')) {
|
switch(psm_get_conf('alert_type')) {
|
||||||
case 'always':
|
case 'always':
|
||||||
if($this->status_new == 'off') {
|
if($this->status_new == 'off') {
|
||||||
// server is offline. we are in error state.
|
// server is offline. we are in error state.
|
||||||
|
@ -201,22 +210,22 @@ class smUpdaterStatus extends smCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
// first add to log (we use the same text as the SMS message because its short..)
|
// first add to log (we use the same text as the SMS message because its short..)
|
||||||
if(sm_get_conf('log_status')) {
|
if(psm_get_conf('log_status')) {
|
||||||
sm_add_log(
|
psm_add_log(
|
||||||
$this->server['server_id'],
|
$this->server['server_id'],
|
||||||
'status',
|
'status',
|
||||||
sm_parse_msg($this->status_new, 'sms', $this->server)
|
psm_parse_msg($this->status_new, 'sms', $this->server)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if email is enabled for this server
|
// check if email is enabled for this server
|
||||||
if(sm_get_conf('email_status') && $this->server['email'] == 'yes') {
|
if(psm_get_conf('email_status') && $this->server['email'] == 'yes') {
|
||||||
// send email
|
// send email
|
||||||
$this->notifyByEmail();
|
$this->notifyByEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if sms is enabled for this server
|
// check if sms is enabled for this server
|
||||||
if(sm_get_conf('sms_status') && $this->server['sms'] == 'yes') {
|
if(psm_get_conf('sms_status') && $this->server['sms'] == 'yes') {
|
||||||
// yay lets wake those nerds up!
|
// yay lets wake those nerds up!
|
||||||
$this->notifyByTxtMsg();
|
$this->notifyByTxtMsg();
|
||||||
}
|
}
|
||||||
|
@ -233,7 +242,7 @@ class smUpdaterStatus extends smCore {
|
||||||
|
|
||||||
// find all the users with this server listed
|
// find all the users with this server listed
|
||||||
$users = $this->db->select(
|
$users = $this->db->select(
|
||||||
SM_DB_PREFIX . 'users',
|
PSM_DB_PREFIX . 'users',
|
||||||
'FIND_IN_SET(\''.$this->server['server_id'].'\', `server_id`) AND `email` != \'\'',
|
'FIND_IN_SET(\''.$this->server['server_id'].'\', `server_id`) AND `email` != \'\'',
|
||||||
array('user_id', 'name', 'email')
|
array('user_id', 'name', 'email')
|
||||||
);
|
);
|
||||||
|
@ -243,14 +252,14 @@ class smUpdaterStatus extends smCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
// build mail object with some default values
|
// build mail object with some default values
|
||||||
$mail = new phpmailer();
|
$mail = new \phpmailer();
|
||||||
|
|
||||||
$mail->From = sm_get_conf('email_from_email');
|
$mail->From = psm_get_conf('email_from_email');
|
||||||
$mail->FromName = sm_get_conf('email_from_name');
|
$mail->FromName = psm_get_conf('email_from_name');
|
||||||
$mail->Subject = sm_parse_msg($this->status_new, 'email_subject', $this->server);
|
$mail->Subject = psm_parse_msg($this->status_new, 'email_subject', $this->server);
|
||||||
$mail->Priority = 1;
|
$mail->Priority = 1;
|
||||||
|
|
||||||
$body = sm_parse_msg($this->status_new, 'email_body', $this->server);
|
$body = psm_parse_msg($this->status_new, 'email_body', $this->server);
|
||||||
$mail->Body = $body;
|
$mail->Body = $body;
|
||||||
$mail->AltBody = str_replace('<br/>', "\n", $body);
|
$mail->AltBody = str_replace('<br/>', "\n", $body);
|
||||||
|
|
||||||
|
@ -263,9 +272,9 @@ class smUpdaterStatus extends smCore {
|
||||||
$mail->ClearAddresses();
|
$mail->ClearAddresses();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sm_get_conf('log_email')) {
|
if(psm_get_conf('log_email')) {
|
||||||
// save to log
|
// save to log
|
||||||
sm_add_log($this->server['server_id'], 'email', $body, implode(',', $userlist));
|
psm_add_log($this->server['server_id'], 'email', $body, implode(',', $userlist));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +286,7 @@ class smUpdaterStatus extends smCore {
|
||||||
protected function notifyByTxtMsg() {
|
protected function notifyByTxtMsg() {
|
||||||
// send sms to all users for this server using defined gateway
|
// send sms to all users for this server using defined gateway
|
||||||
$users = $this->db->select(
|
$users = $this->db->select(
|
||||||
SM_DB_PREFIX . 'users',
|
PSM_DB_PREFIX . 'users',
|
||||||
'FIND_IN_SET(\''.$this->server['server_id'].'\', `server_id`) AND `mobile` != \'\'',
|
'FIND_IN_SET(\''.$this->server['server_id'].'\', `server_id`) AND `mobile` != \'\'',
|
||||||
array('user_id', 'name', 'mobile')
|
array('user_id', 'name', 'mobile')
|
||||||
);
|
);
|
||||||
|
@ -291,28 +300,28 @@ class smUpdaterStatus extends smCore {
|
||||||
|
|
||||||
// open the right class
|
// open the right class
|
||||||
// not making this any more dynamic, because perhaps some gateways need custom settings (like Mollie)
|
// not making this any more dynamic, because perhaps some gateways need custom settings (like Mollie)
|
||||||
switch(strtolower(sm_get_conf('sms_gateway'))) {
|
switch(strtolower(psm_get_conf('sms_gateway'))) {
|
||||||
case 'mosms':
|
case 'mosms':
|
||||||
$sms = new txtmsgMosms();
|
$sms = new \psm\Txtmsg\Mosms();
|
||||||
break;
|
break;
|
||||||
case 'inetworx':
|
case 'inetworx':
|
||||||
$sms = new txtmsgInetworx();
|
$sms = new \psm\Txtmsg\Inetworx();
|
||||||
break;
|
break;
|
||||||
case 'mollie':
|
case 'mollie':
|
||||||
$sms = new txtmsgMollie();
|
$sms = new \psm\Txtmsg\Mollie();
|
||||||
$sms->setGateway(1);
|
$sms->setGateway(1);
|
||||||
break;
|
break;
|
||||||
case 'spryng':
|
case 'spryng':
|
||||||
$sms = new txtmsgSpryng();
|
$sms = new \psm\Txtmsg\Spryng();
|
||||||
break;
|
break;
|
||||||
case 'clickatell':
|
case 'clickatell':
|
||||||
$sms = new txtmsgClickatell();
|
$sms = new \psm\Txtmsg\Clickatell();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy login information from the config file
|
// copy login information from the config file
|
||||||
$sms->setLogin(sm_get_conf('sms_gateway_username'), sm_get_conf('sms_gateway_password'));
|
$sms->setLogin(psm_get_conf('sms_gateway_username'), psm_get_conf('sms_gateway_password'));
|
||||||
$sms->setOriginator(sm_get_conf('sms_from'));
|
$sms->setOriginator(psm_get_conf('sms_from'));
|
||||||
|
|
||||||
// add all users to the recipients list
|
// add all users to the recipients list
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
|
@ -320,14 +329,14 @@ class smUpdaterStatus extends smCore {
|
||||||
$sms->addRecipients($user['mobile']);
|
$sms->addRecipients($user['mobile']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = sm_parse_msg($this->status_new, 'sms', $this->server);
|
$message = psm_parse_msg($this->status_new, 'sms', $this->server);
|
||||||
|
|
||||||
// Send sms
|
// Send sms
|
||||||
$result = $sms->sendSMS($message);
|
$result = $sms->sendSMS($message);
|
||||||
|
|
||||||
if(sm_get_conf('log_sms')) {
|
if(psm_get_conf('log_sms')) {
|
||||||
// save to log
|
// save to log
|
||||||
sm_add_log($this->server['server_id'], 'sms', $message, implode(',', $userlist));
|
psm_add_log($this->server['server_id'], 'sms', $message, implode(',', $userlist));
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
Loading…
Reference in New Issue