/** * Create the HTML code for the module. * First the createHTMLLabels() will be called to add all labels to the template, * Then the tpl_id set in $this->getTemplateId() will be added to the main template automatically */ public function createHTML() { // add JS and CSS files $this->tpl->addJS('monitor.js'); $this->tpl->addCSS('monitor.css'); if (sm_get_conf('show_update')) { // user wants updates, lets see what we can do $this->createHTMLUpdateAvailable(); } $this->createHTMLLabels(); // add the module's custom template to the main template to get some content $this->tpl->addTemplatedata('main', array('content' => $this->tpl->getTemplate($this->getTemplateId()), 'message' => $this->message == '' ? ' ' : $this->message)); // display main template echo $this->tpl->display('main'); }
/** * If a post has been done, gather all the posted data * and save it to the database */ protected function executeSave() { // save new config $clean = array('language' => $_POST['language'], 'show_update' => isset($_POST['show_update']) ? '1' : '0', 'email_status' => isset($_POST['email_status']) ? '1' : '0', 'email_from_name' => $_POST['email_from_name'], 'email_from_email' => $_POST['email_from_email'], 'sms_status' => isset($_POST['sms_status']) ? '1' : '0', 'sms_gateway' => $_POST['sms_gateway'], 'sms_gateway_username' => $_POST['sms_gateway_username'], 'sms_gateway_password' => $_POST['sms_gateway_password'], 'sms_from' => $_POST['sms_from'], 'alert_type' => $_POST['alert_type'], 'log_status' => isset($_POST['log_status']) ? '1' : '0', 'log_email' => isset($_POST['log_email']) ? '1' : '0', 'log_sms' => isset($_POST['log_sms']) ? '1' : '0', 'auto_refresh_servers' => isset($_POST['auto_refresh_servers']) ? intval($_POST['auto_refresh_servers']) : '0'); // save all values to the database foreach ($clean as $key => $value) { // check if key already exists, otherwise add it if (sm_get_conf($key) === null) { // not yet set, add it $this->db->save(SM_DB_PREFIX . 'config', array('key' => $key, 'value' => $value)); } else { // update $this->db->save(SM_DB_PREFIX . 'config', array('value' => $value), array('key' => $key)); } } $this->message = sm_get_lang('config', 'updated'); }
/** * Check if an update is available for PHP Server Monitor * * @global object $db * @return boolean */ function sm_check_updates() { global $db; $last_update = sm_get_conf('last_update_check'); if (time() - 7 * 24 * 60 * 60 > $last_update) { // been more than a week since update, lets go // update "update-date" $db->save(SM_DB_PREFIX . 'config', array('value' => time()), array('key' => 'last_update_check')); $latest = sm_curl_get('http://phpservermon.neanderthal-technology.com/version'); $current = sm_get_conf('version'); if ((int) $current < (int) $latest) { // new update available return true; } } return false; }
/** * This functions performs the text message notifications * * @return unknown */ protected function notifyByTxtMsg() { // send sms to all users for this server using defined gateway $users = $this->db->select(SM_DB_PREFIX . 'users', 'FIND_IN_SET(\'' . $this->server['server_id'] . '\', `server_id`) AND `mobile` != \'\'', array('user_id', 'name', 'mobile')); if (empty($users)) { return false; } // we have to build an userlist for the log table.. $userlist = array(); // open the right class // not making this any more dynamic, because perhaps some gateways need custom settings (like Mollie) switch (strtolower(sm_get_conf('sms_gateway'))) { case 'inetworx': $sms = new txtmsgInetworx(); break; case 'mollie': $sms = new txtmsgMollie(); $sms->setGateway(1); break; case 'spryng': $sms = new txtmsgSpryng(); break; case 'clickatell': $sms = new txtmsgClickatell(); break; } // copy login information from the config file $sms->setLogin(sm_get_conf('sms_gateway_username'), sm_get_conf('sms_gateway_password')); $sms->setOriginator(sm_get_conf('sms_from')); // add all users to the recipients list foreach ($users as $user) { $userlist[] = $user['user_id']; $sms->addRecipients($user['mobile']); } $message = sm_parse_msg($this->status_new, 'sms', $this->server); // Send sms $result = $sms->sendSMS($message); if (sm_get_conf('log_sms')) { // save to log sm_add_log($this->server['server_id'], 'sms', $message, implode(',', $userlist)); } return $result; }
/** * Prepare the template to show a list of all servers */ protected function createHTMLList() { $this->setTemplateId('servers_list', 'servers.tpl.html'); // get servers from database $servers = $this->db->query('SELECT ' . '`server_id`, ' . '`ip`, ' . '`port`, ' . '`type`, ' . '`label`, ' . '`status`, ' . '`error`, ' . '`rtime`, ' . 'IF(' . '`last_check`=\'0000-00-00 00:00:00\', ' . '\'never\', ' . 'DATE_FORMAT(`last_check`, \'%d-%m-%y %H:%i\') ' . ') AS `last_check`, ' . 'IF(' . '`last_online`=\'0000-00-00 00:00:00\', ' . '\'never\', ' . 'DATE_FORMAT(`last_online`, \'%d-%m-%y %H:%i\') ' . ') AS `last_online`, ' . '`active`, ' . '`email`, ' . '`sms` ' . 'FROM `' . SM_DB_PREFIX . 'servers` ' . 'ORDER BY `active` ASC, `status` DESC, `type` ASC, `label` ASC'); $server_count = count($servers); for ($x = 0; $x < $server_count; $x++) { $servers[$x]['class'] = $x & 1 ? 'odd' : 'even'; $servers[$x]['rtime'] = round((double) $servers[$x]['rtime'], 4); if ($servers[$x]['type'] == 'website') { // add link to label $servers[$x]['ip'] = '<a href="' . $servers[$x]['ip'] . '" target="_blank">' . $servers[$x]['ip'] . '</a>'; } } // add servers to template $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers', $servers); // check if we need to add the auto refresh $auto_refresh = sm_get_conf('auto_refresh_servers'); if (intval($auto_refresh) > 0) { // add it $this->tpl->newTemplate('main_auto_refresh', 'main.tpl.html'); $this->tpl->addTemplateData('main_auto_refresh', array('seconds' => $auto_refresh)); $this->tpl->addTemplateData('main', array('auto_refresh' => $this->tpl->getTemplate('main_auto_refresh'))); } }