public function synchronizeClients() { $all = array(); $subUsers = MonitisApi::clients(true); $clntByUsr = monitisSqlHelper::query('SELECT user_id, firstname, lastname, email, LOWER(status) as status, api_key, secret_key FROM mod_monitis_user LEFT JOIN tblclients ON tblclients.id=mod_monitis_user.user_id'); for ($i = 0; $i < count($subUsers); $i++) { $apikey = $subUsers[$i]['apikey']; $whmcsUser = MonitisHelper::in_array($clntByUsr, 'api_key', $apikey); $userid = 0; // user linked if ($whmcsUser) { $userid = $whmcsUser['user_id']; } else { // link user $arr = explode('_', $subUsers[$i]['account']); if ($arr && $arr[0]) { $userid = intval(substr($arr[0], 5)); if ($userid > 0) { $resp = monitisClientApi::linkUserByApikey($apikey, $userid); if (@$resp['status'] == 'ok' && isset($resp['data'])) { //$secretkey = $resp['data']['secret_key']; $whmcsUser = $this->userById($userid); $whmcsUser['api_key'] = $apikey; $whmcsUser['secret_key'] = $resp['data']['secret_key']; } } } } $monitors = null; if ($userid > 0) { $monitors = $subUsers[$i]['monitors']; $monitors = $this->synchronizeMonitors($userid, $monitors); } $all[] = array('api_user' => $subUsers[$i], 'whmcs_user' => $whmcsUser, 'monitors' => $monitors); } return $all; }
public function clientProductMonitors($userid) { $monitors = monitisSqlHelper::query('SELECT * FROM mod_monitis_product_monitor WHERE user_id =' . $userid); $apiMons = monitisClientApi::externalMonitors($userid); if ($apiMons && isset($apiMons['testList'])) { $apiMons = $apiMons['testList']; } else { $apiMons = null; } $userProducts = MonitisSeviceHelper::userProducts($userid); $avMonitors = array(); $ids = array(); if ($userProducts) { for ($i = 0; $i < count($monitors); $i++) { $orderid = $monitors[$i]['order_id']; $serviceid = $monitors[$i]['service_id']; $isAvailble = false; if ($monitors[$i]['type'] == 'addon') { $addon = $this->_addonsByServiceId($serviceid, $monitors[$i]['product_id'], $userid); if ($addon) { $monitors[$i]['settings'] = $addon['settings']; $product = $this->productByField($userProducts, 'id', $serviceid); if ($product && $product['status'] == "Active") { $monitors[$i]['productname'] = $product['groupname'] . ' - ' . $product['name'] . ' <div class="addon">addon: ' . $addon['addonname'] . '</div>'; $isAvailble = true; } } } else { $result = select_query('tblhosting', 'domainstatus', array('id' => $serviceid, 'userid' => $userid), null, null, 1); $data = mysql_fetch_assoc($result); if ($data && $data['domainstatus'] == "Active") { $product = $this->productByField($userProducts, 'id', $serviceid); if ($product && $product['status'] == "Active") { if ($monitors[$i]['type'] == 'product') { $monproduct = $this->isMonitisProduct($product['pid']); $monitors[$i]['settings'] = $monproduct['settings']; } else { // hayk $option_id = $monitors[$i]['option_id']; $result = select_query('mod_monitis_options', 'settings', array('option_id' => $option_id), null, null, 1); $data = mysql_fetch_assoc($result); $monitors[$i]['settings'] = html_entity_decode($data['settings']); } $monitors[$i]['productname'] = $product['groupname'] . ' - ' . $product['name']; $isAvailble = true; } } } if ($isAvailble) { $monitor_id = intval($monitors[$i]['monitor_id']); $monitorIndex = $this->in_array($apiMons, 'id', $monitor_id); if ($monitorIndex > -1) { $monitors[$i]['info'] = $apiMons[$monitorIndex]; $avMonitors[] = $monitors[$i]; } else { // delete $monitor_id from mod_monitis_product //monitisSqlHelper::altQuery('DELETE FROM mod_monitis_product WHERE monitor_id='.$monitor_id ); } } } } else { return null; } return $avMonitors; }
if ($resp["status"] == 'ok') { monitisClientUi::successMessage('Contact timezone updated'); $hTimezone = $newTimezone; } else { monitisClientUi::errorMessage($resp['error']); } } break; } } if ($userid > 0) { $oService = new monitisClientUi(); $monitors = $oService->clientProductMonitors($userid); if ($monitors) { /* all user's notification rules */ $alerts = monitisClientApi::getNotificationRules(array('monitorType' => 'external'), $userid); /* default notification rule - type "All" */ $allAlert = MonitisHelper::in_array($alerts, 'monitorId', 'All'); $rule = ''; $allRuleid = 0; $allContactId = 0; if ($allAlert) { $rule = $allAlert['rule']; $allRuleid = $allAlert['id']; $allContactId = $allAlert['contactId']; } else { $rule = MONITIS_NOTIFICATION_RULE; } $alertAll = str_replace('"', "~", $rule); echo "<section>"; //$monitors = $monitors['monitors'];
private function toDo(&$data, $action, $hookType = '') { if (isset($data['products']) && count($data['products']) > 0) { $result = array('status' => 'ok', 'msg' => ''); $products = $data['products']; $arr = array(); for ($i = 0; $i < count($products); $i++) { $prdct = $products[$i]; $mon = $prdct['monitor']; $api = null; if ($mon) { $api = $mon['api']; } $rslt = null; switch ($action) { case 'active': case 'create': $status = ''; if ($prdct['producttype'] == 'addon') { $status = $this->addonStatus($prdct); } else { $status = $this->prdctStatus($data, $prdct); } if ($status) { if ($mon) { if ($api) { if ($api['isSuspended']) { $resp = monitisClientApi::activateExternal($mon); if (!$resp['error']) { $rslt = array('status' => 'ok', 'msg' => 'Monitor successfully activated'); } else { $rslt = array('status' => 'warning', 'msg' => $resp['error']); } } else { // edit $rslt = array('status' => 'warning', 'msg' => 'Monitor is exist and active'); } } else { // link $rslt = MonitisSeviceHelper::createMonitor($prdct); } } else { $rslt = MonitisSeviceHelper::createMonitor($prdct); } } else { $rslt = array('status' => 'error', 'msg' => 'Product status is inactive'); } break; case 'unlink': if ($mon) { $resp = monitisWhmcsServer::unlinkProductMonitorById($mon['monitor_id']); $rslt = array('status' => 'ok', 'msg' => 'Monitor unlinked successfully'); } else { $rslt = array('status' => 'warning', 'msg' => 'Monitor is not linked'); } break; case 'delete': if ($mon) { $resp = monitisClientApi::deleteExternalMonitor($mon); if ($resp['status'] == 'ok') { $rslt = array('status' => 'ok', 'msg' => 'Monitor deleted successfully'); } else { $rslt = array('status' => 'error', 'msg' => $resp['error']); } } else { $rslt = array('status' => 'warning', 'msg' => 'Monitor is not linked'); } break; case 'suspended': if ($mon) { $resp = monitisClientApi::suspendExternal($mon); if ($resp['status'] == 'ok') { if (@$resp['data']) { $rslt = array('status' => 'ok', 'msg' => $resp['data']); } else { $rslt = array('status' => 'ok', 'msg' => 'The monitor suspended successfully'); } } else { $rslt = array('status' => 'error', 'msg' => 'Error suspended'); } } else { $rslt = array('status' => 'warning', 'msg' => 'Monitor is not linked'); } break; } $arr[] = array('product' => $products[$i], 'response' => $rslt); } return $arr; } else { return null; } }
function monitisClientHookHandler(&$vars, $hook) { $resp = monitisClientApi::userHookHandler($vars, $hook); //monitisLog( $resp, 'userHookHandler'); }