public function createDefaultGroup() { $defaultgroups = json_decode(MONITIS_ADMIN_CONTACT_GROUPS, true); $existedGroups = MonitisApi::getContactGroupList(); // existed monitis groups foreach ($defaultgroups as $mType => $groupName) { $group = MonitisHelper::in_array($existedGroups, 'id', MonitisConf::$settings['groups'][$mType]['groupId']); $alerts = json_decode(MONITIS_NOTIFICATION_RULE, true); if ($mType == 'internal') { $alerts['minFailedLocationCount'] = null; } $groupId = $group['id'] ? $group['id'] : 0; $notifByTypeGroup = MonitisApiHelper::getNotificationRuleByType($mType, $groupId); $alertRulesDefault = $notifByTypeGroup ? $notifByTypeGroup : $alerts; if ($group) { MonitisConf::$settings['groups'][$mType]['groupId'] = $group['id']; MonitisConf::$settings['groups'][$mType]['groupName'] = $group['name']; MonitisConf::$settings['groups'][$mType]['alert'] = $alertRulesDefault; } else { $newGroupName = $groupName; $resp = MonitisApi::addContactGroup(1, $newGroupName); if ($resp['status'] == 'ok') { MonitisConf::$settings['groups'][$mType]['groupId'] = $resp['data']; MonitisConf::$settings['groups'][$mType]['groupName'] = $newGroupName; MonitisConf::$settings['groups'][$mType]['alert'] = $alertRulesDefault; } else { // error return array('status' => 'error', 'msg' => 'Add contact group error ' . $resp['error']); } } // $r = $this->addContacts(ucfirst($mType), MonitisConf::$settings['groups'][$mType]['groupId']); } MonitisConf::update_settings(json_encode(MonitisConf::$settings)); return array('status' => 'ok', 'msg' => 'External, internal groups sets success'); }
function monitis_addon_activate() { //$result = mysql_query("DROP TABLE `mod_monitis_product_monitor`"); $query = "CREATE TABLE `" . MONITIS_SETTING_TABLE . "` (\n\t\t\t\t`client_id` INT,\n\t\t\t\t`apiKey` VARCHAR(255) NOT NULL,\n\t\t\t\t`secretKey` VARCHAR(255) NOT NULL,\n\t\t\t\t`authToken` VARCHAR(255) NOT NULL,\n\t\t\t\t`authToken_update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t`settings` TEXT NOT NULL,\n\t\t\t\t`locations` TEXT NOT NULL,\n\t\t\t\t`locations_update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t`admin_name` VARCHAR(255) DEFAULT '',\n\t\t\t\tPRIMARY KEY ( `client_id` )\n\t\t\t\t);"; mysql_query($query); $query = "CREATE TABLE `mod_monitis_product_monitor` (\n\t\t\t\t`server_id` INT NOT NULL,\n\t\t\t\t`product_id` INT NOT NULL,\n\t\t\t\t`service_id` INT NOT NULL,\n\t\t\t\t`type` varchar(50),\n\t\t\t\t`option_id` INT NOT NULL,\n\t\t\t\t`monitor_id` INT NOT NULL,\n\t\t\t\t`monitor_type` varchar(50),\n\t\t\t\t`user_id` INT NOT NULL,\n\t\t\t\t`order_id` INT NOT NULL,\n\t\t\t\t`publickey` varchar(255),\n\t\t\t\tPRIMARY KEY ( `monitor_id` )\n\t\t\t\t);"; mysql_query($query); $query = "CREATE TABLE `mod_monitis_ext_monitors` (\n\t\t\t\t`client_id` INT NOT NULL,\n\t\t\t\t`server_id` INT NOT NULL,\n\t\t\t\t`monitor_id` INT NOT NULL,\n\t\t\t\t`monitor_type` varchar(100),\n\t\t\t\t`available` INT default 1,\n\t\t\t\t`publickey` varchar(255),\n\t\t\t\tPRIMARY KEY ( `monitor_id` )\n\t\t\t\t);"; mysql_query($query); $query = "CREATE TABLE `mod_monitis_int_monitors` (\n\t\t\t\t`client_id` INT NOT NULL,\n\t\t\t\t`server_id` INT NOT NULL,\n\t\t\t\t`agent_id` INT NOT NULL,\n\t\t\t\t`monitor_id` INT NOT NULL,\n\t\t\t\t`monitor_type` varchar(100),\n\t\t\t\t`available` INT default 1,\n\t\t\t\t`publickey` varchar(255),\n\t\t\t\tPRIMARY KEY ( `monitor_id` )\n\t\t\t\t);"; mysql_query($query); $query = "CREATE TABLE `mod_monitis_product` (\n\t\t\t\t`product_id` INT NOT NULL,\n\t\t\t\t`settings` TEXT,\n\t\t\t\t`status` varchar(50) default 'active',\n\t\t\t\tPRIMARY KEY ( `product_id` )\n\t\t\t\t);"; mysql_query($query); $query = "CREATE TABLE `mod_monitis_addon` (\n\t\t\t\t`addon_id` INT NOT NULL,\n\t\t\t\t`type` varchar(50),\n\t\t\t\t`settings` TEXT,\n\t\t\t\t`status` varchar(50) default 'active',\n\t\t\t\tPRIMARY KEY ( `addon_id` )\n\t\t\t\t);"; mysql_query($query); $query = 'CREATE TABLE `mod_monitis_options`( `option_id` INT NOT NULL, `type` VARCHAR(50), `settings` TEXT, `is_active` TINYINT(1) DEFAULT 0, PRIMARY KEY (`option_id`) )'; mysql_query($query); // mod_monitis_report $query = "CREATE TABLE `" . MONITIS_HOOK_REPORT_TABLE . "` (\n\t\t\t`id` int NOT NULL AUTO_INCREMENT,\n\t\t\t`vars` TEXT,\n\t\t\t`json` TEXT,\n\t\t\t`date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\tPRIMARY KEY (`id`)\n\t)"; mysql_query($query); // mod_monitis_log $query = "CREATE TABLE `" . MONITIS_LOG_TABLE . "` (\n\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t`type` VARCHAR( 20 ) DEFAULT 'json',\n\t\t\t`title` VARCHAR( 255 ) DEFAULT '',\n\t\t\t`description` TEXT,\n\t\t\t`date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\tPRIMARY KEY (`id`)\n\t)"; mysql_query($query); // `auth_token` VARCHAR(255) NOT NULL, $query = "CREATE TABLE `" . MONITIS_USER_TABLE . "` (\n\t\t\t`user_id` INT NOT NULL,\n\t\t\t`api_key` VARCHAR(255) NOT NULL,\n\t\t\t`secret_key` VARCHAR(255) NOT NULL,\n\t\t\tPRIMARY KEY (`user_id`)\n\t)"; mysql_query($query); MonitisConf::setupDB(); return array('status' => 'success', 'description' => 'Monitis addon activation successful'); }
static function setupDB() { $row = monitisSqlHelper::objQuery('SELECT * FROM ' . MONITIS_SETTING_TABLE . ' WHERE client_id=' . MONITIS_CLIENT_ID); if (!$row) { $default_settings = json_decode(self::$default_settings, true); $default_settings["order_behavior"] = self::setupBehavior(MONITIS_ORDER_BEHAVIOR); $default_settings["user_behavior"] = self::setupBehavior(MONITIS_USER_STATUS_BEHAVIOR); $values = array('client_id' => MONITIS_CLIENT_ID, 'apiKey' => self::$apiKey, 'secretKey' => self::$secretKey, 'settings' => json_encode($default_settings)); self::$settings = $default_settings; insert_query(MONITIS_SETTING_TABLE, $values); } else { } //return true; }
define('MONITIS_APP_PATH', dirname(realpath(__FILE__))); require_once 'config.php'; // Includes lib require_once 'lib/common.php'; require_once 'lib/whmcs.class.php'; require_once 'lib/notifications.class.php'; require_once 'lib/internal.class.php'; require_once 'lib/monitisconf.php'; require_once 'lib/monitisrouter.php'; require_once 'lib/monitisapi.php'; require_once 'lib/monitisapihelper.php'; require_once 'lib/clientapi.class.php'; require_once 'lib/clientservices.php'; require_once 'lib/servermonitors.php'; MonitisConf::load(); class MonitisApp { private static $errors = array(); private static $warnings = array(); private static $messages = array(); static function addError($msg) { if (!empty($msg)) { self::$errors[] = $msg; } } static function addMessage($msg) { if (!empty($msg)) { self::$messages[] = $msg;
static function requestPost($action, $params) { // TODO: error handling when JSON is not returned //$authToken = self::authToken(); $authToken = MonitisConf::$authToken; if ($authToken) { $params['authToken'] = $authToken; $params['validation'] = 'token'; $params['version'] = MONITIS_API_VERSION; $params['action'] = $action; $params['apikey'] = MonitisConf::$apiKey; $query = http_build_query($params); $ch = curl_init(self::$endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query); if (MONITIS_SSL_NOVERIFY) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); } $result = curl_exec($ch); curl_close($ch); monitisLog("POST requestPost **** action = <b>{$action}</b><p>{$query}</p><p>{$result}</p>"); //$json = json_decode($result, true); $json = self::jsonDecode($result); if ($json && isset($json['errorCode']) && $json['errorCode'] == 4) { if (MonitisConf::update_token()) { return self::requestPost($action, $params); } else { return array('status' => 'error', 'msg' => 'Monitis server not response'); } } return $json; } else { if (MonitisConf::update_token()) { return self::requestPost($action, $params); } else { return array('status' => 'error', 'msg' => 'Monitis server not response'); } } }
static function requestPost($action, $params, $user) { //$authToken = $user['auth_token']; $authToken = MonitisConf::$authToken; if ($authToken) { $params['validation'] = 'token'; $params['version'] = MONITIS_API_VERSION; $params['action'] = $action; $params['timestamp'] = date("Y-m-d H:i:s", time()); $params['apikey'] = $user['api_key']; $params['authToken'] = $authToken; $query = http_build_query($params); $ch = curl_init(self::$endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query); if (MONITIS_SSL_NOVERIFY) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); } $result = curl_exec($ch); monitisLog("client requestPost **** action = <b>{$action}</b><p>{$query}</p><p>{$result}</p>"); //$resp = json_decode($result, true); $resp = self::jsonDecode($result); if (@$resp['error'] && @$resp['errorCode'] && $resp['errorCode'] == 4) { if (MonitisConf::update_token()) { return self::requestPost($action, $params); } else { return array('status' => 'error', 'msg' => 'Monitis server not response'); } } //else return $resp; } else { if (MonitisConf::update_token()) { return self::requestPost($action, $params); } else { return array('status' => 'error', 'msg' => 'Monitis server not response'); } } }
<?php $isNewAcc = empty(MonitisConf::$apiKey); if (monitisPostInt('monitisFormSubmitted')) { $apiKey = trim(monitisPost('apiKey')); $secretKey = trim(monitisPost('secretKey')); $timezone = monitisPostInt('monitisTimeZone'); if (empty($apiKey)) { MonitisApp::addError('Please provide valid API Key'); } elseif (empty($secretKey)) { MonitisApp::addError('Please provide valid Secret Key'); } elseif (!MonitisApi::checkKeysValid($apiKey, $secretKey)) { MonitisApp::addError('Wrong API and/or Secret keys provided.'); } else { MonitisConf::update_config(array('apiKey' => $apiKey, 'secretKey' => $secretKey, 'timezone' => $timezone)); if ($isNewAcc) { //header('location: ' . MONITIS_APP_URL . '&monitis_page=configure&isNewAcc=1'); header('location: ' . MONITIS_APP_URL . '&monitis_page=tabadmin&sub=settings&isNewAcc=1'); } } } else { if ($isNewAcc) { MonitisApp::addMessage('Please enter your Monitis account information below.'); } } MonitisApp::printNotifications(); ?> <script type="text/javascript"> $(document).ready(function() { var d = new Date(); var minutes = d.getTimezoneOffset(); // minutes
$order_title = json_decode(MONITIS_ORDER_BEHAVIOR_TITLE, true); //_dump( MonitisConf::$settings["order_behavior"] ); define('MONITIS_CLIENTSTATUS_BEHAVIOR_TITLE', '{ "noaction":"No action", "delete":"Delete" }'); $defaultStatusBehavior = json_decode(MONITIS_USER_STATUS_BEHAVIOR, true); $clientStatusTitle = json_decode(MONITIS_CLIENTSTATUS_BEHAVIOR_TITLE, true); if (isset($_POST["save_service"])) { MonitisConf::$settings["order_behavior"] = array('active' => $_POST['active'], 'pending' => $_POST['pending'], 'suspended' => $_POST['suspended'], 'terminated' => $_POST['terminated'], 'deleted' => $_POST['deleted'], 'cancelled' => $_POST['cancelled'], 'fraud' => $_POST['fraud']); $newsets_json = json_encode(MonitisConf::$settings); MonitisConf::update_settings($newsets_json); } elseif (isset($_POST["save_client"])) { MonitisConf::$settings["user_behavior"] = array('closed' => $_POST['closed'], 'deleted' => $_POST['deleted']); $newsets_json = json_encode(MonitisConf::$settings); MonitisConf::update_settings($newsets_json); } ?> <style type="text/css"> .monitis-setting { text-align: left; margin: 15px 0px; } .monitis-setting .title{ color: #555555; font-size: 12px; font-weight: bold; padding: 10px 0px; } .monitis-setting table.form { width: 100%;