function discover_wifi_radio($device_id, $radio) { $params = array('radio_ap', 'radio_mib', 'radio_number', 'radio_type', 'radio_status', 'radio_clients', 'radio_txpower', 'radio_channel', 'radio_mac', 'radio_protection', 'radio_bsstype'); if (is_array($GLOBALS['cache']['wifi_radios'][$radio['radio_ap']][$radio['radio_number']])) { $radio_db = $GLOBALS['cache']['wifi_radios'][$radio['radio_ap']][$radio['radio_number']]; } if (!isset($radio_db['wifi_radio_id'])) { $insert = array(); $insert['device_id'] = $device_id; foreach ($params as $param) { $insert[$param] = $radio[$param]; if ($radio[$param] == NULL) { $insert[$param] = array('NULL'); } } $wifi_radio_id = dbInsert($insert, 'wifi_radios'); echo "+"; } else { $update = array(); foreach ($params as $param) { if ($radio[$param] != $radio_db[$param]) { $update[$param] = $radio[$param]; } } if (count($update)) { dbUpdate($update, 'wifi_radios', '`wifi_radio_id` = ?', array($radio_db['wifi_radio_id'])); echo 'U'; } else { echo '.'; } } $GLOBALS['valid']['wifi']['radio'][$radio['radio_mib']][$wifi_radio_id] = 1; // FIXME. What? How it passed there? }
/** * Add a new device group * @param $pattern * @param $name * @param $desc * @return int|string */ function AddDeviceGroup($name, $desc, $pattern) { $group_id = dbInsert(array('name' => $name, 'desc' => $desc, 'pattern' => $pattern), 'device_groups'); if ($group_id) { UpdateDeviceGroup($group_id); } return $group_id; }
function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd = '1', $description = "") { if (!user_exists($username)) { $encrypted = crypt($password, '$1$' . generateSalt(8) . '$'); return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description), 'users'); } else { return FALSE; } }
function adduser($username, $password, $level, $email = '', $realname = '', $can_modify_passwd = '1') { if (!user_exists($username)) { $hasher = new PasswordHash(8, false); $encrypted = $hasher->HashPassword($password); return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname), 'users'); } else { return false; } }
function add_service($device, $type, $desc, $ip = 'localhost', $param = "", $ignore = 0) { if (!is_array($device)) { $device = device_by_id_cache($device); } if (empty($ip)) { $ip = $device['hostname']; } $insert = array('device_id' => $device['device_id'], 'service_ip' => $ip, 'service_type' => $type, 'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $desc, 'service_param' => $param, 'service_ignore' => $ignore, 'service_status' => 3, 'service_message' => 'Service not yet checked'); return dbInsert($insert, 'services'); }
/** * Post notifications to users * @return null */ function post_notifications() { $notifs = get_notifications(); echo '[ ' . date('r') . ' ] Updating DB '; foreach ($notifs as $notif) { if (dbFetchCell('select 1 from notifications where checksum = ?', array($notif['checksum'])) != 1 && dbInsert('notifications', $notif) > 0) { echo '.'; } } echo ' Done'; echo PHP_EOL; }
function ecError($file, $error, $fatal = 0) { global $ecLocal, $ecUser; $fatalMessage = $fatal == 1 ? 'Fatal error' : 'Skript Error'; $message = $fatalMessage . ' in file ' . $file . ': ' . $error; array_push($ecLocal['errors'], $message); if ($ecLocal['errorLog'] == 1) { $insertData['errorsFatal'] = $fatal; $insertData['errorsMessage'] = $error; $insertData['errorsTimestamp'] = $ecLocal['timestamp']; $insertData['errorsUserId'] = $ecUser['userId']; $insertData['errorsUserIP'] = $ecLocal['userIP']; $insertData['errorsFile'] = $file; dbInsert(1, 'errors', $insertData); } }
function adduser($username, $level = 0, $email = '', $realname = '', $can_modify_passwd = 0, $description = '', $twofactor = 0) { // Check to see if user is already added in the database if (!user_exists_in_db($username)) { $userid = dbInsert(array('username' => $username, 'realname' => $realname, 'email' => $email, 'descr' => $description, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'twofactor' => $twofactor, 'user_id' => get_userid($username)), 'users'); if ($userid == false) { return false; } else { foreach (dbFetchRows('select notifications.* from notifications where not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.user_id = ?) order by notifications.notifications_id desc', array($userid)) as $notif) { dbInsert(array('notifications_id' => $notif['notifications_id'], 'user_id' => $userid, 'key' => 'read', 'value' => 1), 'notifications_attribs'); } } return $userid; } else { return false; } }
function adduser($username, $password, $level, $email = '', $realname = '', $can_modify_passwd = 1, $description = '', $twofactor = 0) { if (!user_exists($username)) { $hasher = new PasswordHash(8, false); $encrypted = $hasher->HashPassword($password); $userid = dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users'); if ($userid == false) { return false; } else { foreach (dbFetchRows('select notifications.* from notifications where not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.user_id = ?) order by notifications.notifications_id desc', array($userid)) as $notif) { dbInsert(array('notifications_id' => $notif['notifications_id'], 'user_id' => $userid, 'key' => 'read', 'value' => 1), 'notifications_attribs'); } } return $userid; } else { return false; } }
function process_port_adsl(&$this_port, $device, $port) { // Check to make sure Port data is cached. if (!isset($this_port['adslLineCoding'])) { return; } // Used below for StatsD only $adsl_oids = array('adslAtucCurrSnrMgn', 'adslAtucCurrAtn', 'adslAtucCurrOutputPwr', 'adslAtucCurrAttainableRate', 'adslAtucChanCurrTxRate', 'adslAturCurrSnrMgn', 'adslAturCurrAtn', 'adslAturCurrOutputPwr', 'adslAturCurrAttainableRate', 'adslAturChanCurrTxRate', 'adslAtucPerfLofs', 'adslAtucPerfLoss', 'adslAtucPerfLprs', 'adslAtucPerfESs', 'adslAtucPerfInits', 'adslAturPerfLofs', 'adslAturPerfLoss', 'adslAturPerfLprs', 'adslAturPerfESs', 'adslAtucChanCorrectedBlks', 'adslAtucChanUncorrectBlks', 'adslAturChanCorrectedBlks', 'adslAturChanUncorrectBlks'); $adsl_db_oids = array('adslLineCoding', 'adslLineType', 'adslAtucInvVendorID', 'adslAtucInvVersionNumber', 'adslAtucCurrSnrMgn', 'adslAtucCurrAtn', 'adslAtucCurrOutputPwr', 'adslAtucCurrAttainableRate', 'adslAturInvSerialNumber', 'adslAturInvVendorID', 'adslAturInvVersionNumber', 'adslAtucChanCurrTxRate', 'adslAturChanCurrTxRate', 'adslAturCurrSnrMgn', 'adslAturCurrAtn', 'adslAturCurrOutputPwr', 'adslAturCurrAttainableRate'); $adsl_tenth_oids = array('adslAtucCurrSnrMgn', 'adslAtucCurrAtn', 'adslAtucCurrOutputPwr', 'adslAturCurrSnrMgn', 'adslAturCurrAtn', 'adslAturCurrOutputPwr'); foreach ($adsl_tenth_oids as $oid) { if (isset($this_port[$oid])) { $this_port[$oid] = $this_port[$oid] / 10; } } if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = ?", array($port['port_id'])) == "0") { dbInsert(array('port_id' => $port['port_id']), 'ports_adsl'); } $adsl_update = array('port_adsl_updated' => array('NOW()')); foreach ($adsl_db_oids as $oid) { $adsl_update[$oid] = $this_port[$oid]; } dbUpdate($adsl_update, 'ports_adsl', '`port_id` = ?', array($port['port_id'])); if ($this_port['adslAtucCurrSnrMgn'] > "1280") { $this_port['adslAtucCurrSnrMgn'] = "U"; } if ($this_port['adslAturCurrSnrMgn'] > "1280") { $this_port['adslAturCurrSnrMgn'] = "U"; } rrdtool_update_ng($device, 'port-adsl', array('AtucCurrSnrMgn' => $this_port['adslAtucCurrSnrMgn'], 'AtucCurrAtn' => $this_port['adslAtucCurrAtn'], 'AtucCurrOutputPwr' => $this_port['adslAtucCurrOutputPwr'], 'AtucCurrAttainableR' => $this_port['adslAtucCurrAttainableR'], 'AtucChanCurrTxRate' => $this_port['adslAtucChanCurrTxRate'], 'AturCurrSnrMgn' => $this_port['adslAturCurrSnrMgn'], 'AturCurrAtn' => $this_port['adslAturCurrAtn'], 'AturCurrOutputPwr' => $this_port['adslAturCurrOutputPwr'], 'AturCurrAttainableR' => $this_port['adslAturCurrAttainableR'], 'AturChanCurrTxRate' => $this_port['adslAturChanCurrTxRate'], 'AtucPerfLofs' => $this_port['adslAtucPerfLofs'], 'AtucPerfLoss' => $this_port['adslAtucPerfLoss'], 'AtucPerfLprs' => $this_port['adslAtucPerfLprs'], 'AtucPerfESs' => $this_port['adslAtucPerfESs'], 'AtucPerfInits' => $this_port['adslAtucPerfInits'], 'AturPerfLofs' => $this_port['adslAturPerfLofs'], 'AturPerfLoss' => $this_port['adslAturPerfLoss'], 'AturPerfLprs' => $this_port['adslAturPerfLprs'], 'AturPerfESs' => $this_port['adslAturPerfESs'], 'AtucChanCorrectedBl' => $this_port['adslAtucChanCorrectedBl'], 'AtucChanUncorrectBl' => $this_port['adslAtucChanUncorrectBl'], 'AturChanCorrectedBl' => $this_port['adslAturChanCorrectedBl'], 'AturChanUncorrectBl' => $this_port['adslAturChanUncorrectBl']), get_port_rrdindex($port)); if ($GLOBALS['config']['statsd']['enable']) { foreach ($adsl_oids as $oid) { // Update StatsD/Carbon StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'port' . '.' . $port['ifIndex'] . '.' . $oid, $this_port[$oid]); } } //echo("ADSL (".$this_port['adslLineCoding']."/".formatRates($this_port['adslAtucChanCurrTxRate'])."/".formatRates($this_port['adslAturChanCurrTxRate']).")"); }
d_echo(" numasoclients: {$numasoclients}\n"); d_echo(" interference: {$interference}\n"); // if there is a numeric channel, assume the rest of the data is valid, I guess if (!is_numeric($channel)) { continue; } $rrd_name = array('arubaap', $name . $radionum); $rrd_def = array('DS:channel:GAUGE:600:0:200', 'DS:txpow:GAUGE:600:0:200', 'DS:radioutil:GAUGE:600:0:100', 'DS:nummonclients:GAUGE:600:0:500', 'DS:nummonbssid:GAUGE:600:0:200', 'DS:numasoclients:GAUGE:600:0:500', 'DS:interference:GAUGE:600:0:2000'); $fields = array('channel' => $channel, 'txpow' => $txpow, 'radioutil' => $radioutil, 'nummonclients' => $nummonclients, 'nummonbssid' => $nummonbssid, 'numasoclients' => $numasoclients, 'interference' => $interference); $tags = compact('name', 'radionum', 'rrd_name', 'rrd_def'); data_update($device, 'arubaap', $tags, $fields); $foundid = 0; for ($z = 0; $z < sizeof($ap_db); $z++) { if ($ap_db[$z]['name'] == $name && $ap_db[$z]['radio_number'] == $radionum) { $foundid = $ap_db[$z]['accesspoint_id']; $ap_db[$z]['seen'] = 1; continue; } } if ($foundid == 0) { $ap_id = dbInsert(array('device_id' => $device['device_id'], 'name' => $name, 'radio_number' => $radionum, 'type' => $type, 'mac_addr' => $mac, 'channel' => $channel, 'txpow' => $txpow, 'radioutil' => $radioutil, 'numasoclients' => $numasoclients, 'nummonclients' => $nummonclients, 'numactbssid' => $numactbssid, 'nummonbssid' => $nummonbssid, 'interference' => $interference), 'access_points'); } else { dbUpdate(array('mac_addr' => $mac, 'type' => $type, 'deleted' => 0, 'channel' => $channel, 'txpow' => $txpow, 'radioutil' => $radioutil, 'numasoclients' => $numasoclients, 'nummonclients' => $nummonclients, 'numactbssid' => $numactbssid, 'nummonbssid' => $nummonbssid, 'interference' => $interference), 'access_points', '`accesspoint_id` = ?', array($foundid)); } } //end foreach for ($z = 0; $z < sizeof($ap_db); $z++) { if (!isset($ap_db[$z]['seen']) && $ap_db[$z]['deleted'] == 0) { dbUpdate(array('deleted' => 1), 'access_points', '`accesspoint_id` = ?', array($ap_db[$z]['accesspoint_id'])); } }
<?php $rserver_array = snmpwalk_cache_oid($device, 'cesServerFarmRserverTable', array(), 'CISCO-ENHANCED-SLB-MIB'); $rserver_db = dbFetchRows('SELECT * FROM `loadbalancer_rservers` WHERE `device_id` = ?', array($device['device_id'])); foreach ($rserver_db as $serverfarm) { $serverfarms[$serverfarm['farm_id']] = $serverfarm; } foreach ($rserver_array as $index => $serverfarm) { $farm_id = preg_replace('@\\d+\\."(.*?)"\\.\\d+@', '\\1', $index); $oids = array('cesServerFarmRserverTotalConns', 'cesServerFarmRserverCurrentConns', 'cesServerFarmRserverFailedConns'); $db_oids = array($farm_id => 'farm_id', 'cesServerFarmRserverStateDescr' => 'StateDescr'); if (!is_array($serverfarms[$farm_id])) { $rserver_id = dbInsert(array('device_id' => $device['device_id'], 'farm_id' => $farm_id, 'StateDescr' => $serverfarm['cesServerFarmRserverStateDescr']), 'loadbalancer_rservers'); } else { foreach ($db_oids as $db_oid => $db_value) { $db_update[$db_value] = $serverfarm[$db_oid]; } $updated = dbUpdate($db_update, 'loadbalancer_rservers', '`rserver_id` = ?', $serverfarm['cesServerFarmRserverFailedConns']['farm_id']); } $rrd_name = array('rserver', $serverfarms[$farm_id]['rserver_id']); $rrd_def = array(); foreach ($oids as $oid) { $oid_ds = truncate(str_replace('cesServerFarm', '', $oid), 19, ''); $rrd_def[] = "DS:{$oid_ds}:GAUGE:600:-1:100000000"; } $fields = array(); foreach ($oids as $oid) { if (is_numeric($serverfarm[$oid])) { $value = $serverfarm[$oid]; } else { $value = '0';
function add_edit_rule() { global $config; $app = \Slim\Slim::getInstance(); $data = json_decode(file_get_contents('php://input'), true); $status = 'error'; $message = ''; $code = 500; $rule_id = mres($data['rule_id']); $device_id = mres($data['device_id']); if (empty($device_id) && !isset($rule_id)) { $message = 'Missing the device id or global device id (-1)'; } elseif ($device_id == 0) { $device_id = '-1'; } $rule = $data['rule']; if (empty($rule)) { $message = 'Missing the alert rule'; } $name = mres($data['name']); if (empty($name)) { $message = 'Missing the alert rule name'; } $severity = mres($data['severity']); $sevs = array('ok', 'warning', 'critical'); if (!in_array($severity, $sevs)) { $message = 'Missing the severity'; } $disabled = mres($data['disabled']); if ($disabled != '0' && $disabled != '1') { $disabled = 0; } $count = mres($data['count']); $mute = mres($data['mute']); $delay = mres($data['delay']); $delay_sec = convert_delay($delay); if ($mute == 1) { $mute = true; } else { $mute = false; } $extra = array('mute' => $mute, 'count' => $count, 'delay' => $delay_sec); $extra_json = json_encode($extra); if (dbFetchCell('SELECT `name` FROM `alert_rules` WHERE `name`=?', array($name)) == $name) { $message = 'Name has already been used'; } if (empty($message)) { if (is_numeric($rule_id)) { if (dbUpdate(array('name' => $name, 'rule' => $rule, 'severity' => $severity, 'disabled' => $disabled, 'extra' => $extra_json), 'alert_rules', 'id=?', array($rule_id)) >= 0) { $status = 'ok'; $code = 200; } else { $message = 'Failed to update existing alert rule'; } } elseif (dbInsert(array('name' => $name, 'device_id' => $device_id, 'rule' => $rule, 'severity' => $severity, 'disabled' => $disabled, 'extra' => $extra_json), 'alert_rules')) { $status = 'ok'; $code = 200; } else { $message = 'Failed to create new alert rule'; } } $output = array('status' => $status, 'err-msg' => $message); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); }
/** * Run all rules for a device * @param int $device Device-ID * @return void */ function RunRules($device) { global $debug; $chk = dbFetchRow("SELECT id FROM alert_schedule WHERE alert_schedule.device_id = ? AND NOW() BETWEEN alert_schedule.start AND alert_schedule.end", array($device)); if ($chk['id'] > 0) { return false; } foreach (dbFetchRows("SELECT * FROM alert_rules WHERE alert_rules.disabled = 0 && ( alert_rules.device_id = -1 || alert_rules.device_id = ? ) ORDER BY device_id,id", array($device)) as $rule) { echo " #" . $rule['id'] . ":"; $chk = dbFetchRow("SELECT state FROM alerts WHERE rule_id = ? && device_id = ? ORDER BY id DESC LIMIT 1", array($rule['id'], $device)); $sql = GenSQL($rule['rule']); $qry = dbFetchRows($sql, array($device)); if (sizeof($qry) > 0) { if ($chk['state'] === "2") { echo " SKIP "; } elseif ($chk['state'] === "1") { echo " NOCHG "; } else { $extra = gzcompress(json_encode(array('contacts' => GetContacts($qry), 'rule' => $qry)), 9); if (dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'details' => $extra), 'alert_log')) { if (!dbUpdate(array('state' => 1, 'open' => 1), 'alerts', 'device_id = ? && rule_id = ?', array($device, $rule['id']))) { dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1), 'alerts'); } echo " ALERT "; } } } else { if ($chk['state'] === "0") { echo " NOCHG "; } else { if (dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id']), 'alert_log')) { if (!dbUpdate(array('state' => 0, 'open' => 1), 'alerts', 'device_id = ? && rule_id = ?', array($device, $rule['id']))) { dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1), 'alerts'); } echo " OK "; } } } } }
dbDelete('ports_perms', "`port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id'])); } } if ($vars['action'] == "addifperm") { if (!dbFetchCell("SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id']))) { dbInsert(array('port_id' => $vars['port_id'], 'user_id' => $vars['user_id']), 'ports_perms'); } } if ($vars['action'] == "delbillperm") { if (dbFetchCell("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']))) { dbDelete('bill_perms', "`bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id'])); } } if ($vars['action'] == "addbillperm") { if (!dbFetchCell("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']))) { dbInsert(array('bill_id' => $vars['bill_id'], 'user_id' => $vars['user_id']), 'bill_perms'); } } echo '<div class="row"> <div class="col-md-4">'; // Display devices this users has access to echo "<h3>Device Access</h3>"; echo "<div class='panel panel-default panel-condensed'>\n <table class='table table-hover table-condensed table-striped'>\n <tr>\n <th>Device</th>\n <th>Action</th>\n </tr>"; $device_perms = dbFetchRows("SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id", array($vars['user_id'])); foreach ($device_perms as $device_perm) { echo "<tr><td><strong>" . $device_perm['hostname'] . "</td><td> <a href='edituser/action=deldevperm/user_id=" . $vars['user_id'] . "/device_id=" . $device_perm['device_id'] . "'><img src='images/16/cross.png' align=absmiddle border=0></a></strong></td></tr>"; $access_list[] = $device_perm['device_id']; $permdone = "yes"; } echo "</table>\n </div>"; if (!$permdone) {
//Create State Translation if ($state_index_id !== null) { if ($state_name == 'processorDeviceStatusStatus' || $state_name == 'memoryDeviceStatus' || $state_name == 'powerSupplyStatus' || $state_name == 'intrusionStatus') { $states = array(array($state_index_id, 'other', 0, 1, 3), array($state_index_id, 'unknown', 0, 2, 3), array($state_index_id, 'ok', 0, 3, 0), array($state_index_id, 'nonCritical', 0, 4, 1), array($state_index_id, 'critical', 0, 5, 2), array($state_index_id, 'nonRecoverable', 0, 6, 2)); } elseif ($state_name == 'controllerState') { $states = array(array($state_index_id, 'ready', 0, 1, 0), array($state_index_id, 'failed', 0, 2, 2), array($state_index_id, 'online', 0, 3, 0), array($state_index_id, 'offline', 0, 4, 1), array($state_index_id, 'degraded', 0, 6, 2)); } elseif ($state_name == 'arrayDiskState') { $states = array(array($state_index_id, 'ready', 0, 1, 0), array($state_index_id, 'failed', 0, 2, 2), array($state_index_id, 'online', 0, 3, 0), array($state_index_id, 'offline', 0, 4, 2), array($state_index_id, 'degraded', 0, 5, 2), array($state_index_id, 'recovering', 0, 6, 1), array($state_index_id, 'removed', 0, 7, 1), array($state_index_id, 'non-raid', 0, 8, 3), array($state_index_id, 'notReady', 0, 9, 1), array($state_index_id, 'resynching', 0, 10, 1), array($state_index_id, 'replacing', 0, 11, 1), array($state_index_id, 'spinningDown', 0, 12, 1), array($state_index_id, 'rebuild', 0, 13, 1), array($state_index_id, 'noMedia', 0, 14, 1), array($state_index_id, 'formatting', 0, 15, 1), array($state_index_id, 'diagnostics', 0, 16, 1), array($state_index_id, 'predictiveFailure', 0, 17, 2), array($state_index_id, 'initializing', 0, 18, 1), array($state_index_id, 'foreign', 0, 19, 1), array($state_index_id, 'clear', 0, 20, 1), array($state_index_id, 'unsupported', 0, 21, 2), array($state_index_id, 'incompatible', 0, 22, 2), array($state_index_id, 'readOnly', 0, 23, 2)); } elseif ($state_name == 'virtualDiskState') { $states = array(array($state_index_id, 'unknown', 0, 0, 3), array($state_index_id, 'ready', 1, 1, 0), array($state_index_id, 'failed', 1, 2, 2), array($state_index_id, 'online', 1, 3, 1), array($state_index_id, 'offline', 1, 4, 2), array($state_index_id, 'degraded', 1, 6, 2), array($state_index_id, 'verifying', 1, 7, 1), array($state_index_id, 'resynching', 1, 15, 1), array($state_index_id, 'regenerating', 1, 16, 1), array($state_index_id, 'failedRedundancy', 1, 18, 2), array($state_index_id, 'rebuilding', 1, 24, 1), array($state_index_id, 'formatting', 1, 26, 1), array($state_index_id, 'reconstructing', 1, 32, 1), array($state_index_id, 'initializing', 1, 35, 1), array($state_index_id, 'backgroundInit', 1, 36, 1), array($state_index_id, 'permanentlyDegraded', 1, 52, 2)); } elseif ($state_name == 'batteryState') { $states = array(array($state_index_id, 'ready', 0, 1, 0), array($state_index_id, 'failed', 1, 2, 2), array($state_index_id, 'degraded', 1, 6, 2), array($state_index_id, 'reconditioning', 1, 7, 1), array($state_index_id, 'high', 1, 9, 1), array($state_index_id, 'low', 1, 10, 1), array($state_index_id, 'charging', 1, 12, 1), array($state_index_id, 'missing', 1, 21, 2), array($state_index_id, 'learning', 1, 36, 1)); } foreach ($states as $value) { $insert = array('state_index_id' => $value[0], 'state_descr' => $value[1], 'state_draw_graph' => $value[2], 'state_value' => $value[3], 'state_generic_value' => $value[4]); dbInsert($insert, 'state_translations'); } } foreach ($temp as $index => $entry) { if (strpos($index, '54.') === false) { //Because Dell is buggy if ($state_name == 'intrusionStatus') { $descr = $tablevalue[3]; } elseif ($state_name == 'batteryState') { $descr = str_replace('"', "", snmp_get($device, "batteryConnectionControllerName." . $index . "", "-Ovqn", $tablevalue[4])) . ' - ' . $temp[$index][$tablevalue[3]]; } elseif ($state_name == 'arrayDiskState') { $descr = str_replace('"', "", snmp_get($device, "arrayDiskEnclosureConnectionEnclosureName." . $index . "", "-Ovqn", $tablevalue[4])) . ' - ' . $temp[$index][$tablevalue[3]]; } else { $descr = clean($temp[$index][$tablevalue[3]]); // Use clean as virtualDiskDeviceName is user defined }
echo str_pad("dot1d id", 10) . str_pad("ifIndex", 10) . str_pad("Port Name", 25) . str_pad("Priority", 10) . str_pad("State", 15) . str_pad("Cost", 10) . "\n"; } foreach ($vlan_data as $vlan_port_id => $vlan_port) { $port = get_port_by_index_cache($device, $vlan_port['dot1dBasePortIfIndex']); echo str_pad($vlan_port_id, 10) . str_pad($vlan_port['dot1dBasePortIfIndex'], 10) . str_pad($port['ifDescr'], 25) . str_pad($vlan_port['dot1dStpPortPriority'], 10) . str_pad($vlan_port['dot1dStpPortState'], 15) . str_pad($vlan_port['dot1dStpPortPathCost'], 10); $db_w = array('device_id' => $device['device_id'], 'port_id' => $port['port_id'], 'vlan' => $vlan_id); $db_a['baseport'] = $vlan_port_id; $db_a['priority'] = isset($vlan_port['dot1dStpPortPriority']) ? $vlan_port['dot1dStpPortPriority'] : 0; $db_a['state'] = isset($vlan_port['dot1dStpPortState']) ? $vlan_port['dot1dStpPortState'] : "unknown"; $db_a['cost'] = isset($vlan_port['dot1dStpPortPathCost']) ? $vlan_port['dot1dStpPortPathCost'] : 0; $from_db = dbFetchRow("SELECT * FROM `ports_vlans` WHERE device_id = ? AND port_id = ? AND `vlan` = ?", array($device['device_id'], $port['port_id'], $vlan_id)); if ($from_db['port_vlan_id']) { dbUpdate($db_a, 'ports_vlans', "`port_vlan_id` = ?", array($from_db['port_vlan_id'])); echo "Updated"; } else { dbInsert(array_merge($db_w, $db_a), 'ports_vlans'); echo "Inserted"; } echo "\n"; } } } } foreach ($vlans_db as $domain_id => $vlans) { foreach ($vlans as $vlan_id => $vlan) { if (empty($device['vlans'][$domain_id][$vlan_id])) { dbDelete('vlans', "`device_id` = ? AND vlan_domain = ? AND vlan_vlan = ?", array($device['device_id'], $domain_id, $vlan_id)); } } } unset($device['vlans']);
if ($cid == '') { $cid = 0; } $name = gpost('name'); // Form Title $mtitle = "Employee Level"; $mdialog = array('af' => 'Add new', 'uf' => 'Edit', 'df' => 'Delete'); // Function Module $fmod = "m_level"; // db Table $dbtable = "mstr_level"; // Post Variables if ($opt == 'a' || $opt == 'u' || $opt == 'd' || $opt == 'up' || $opt == 'dn') { if ($opt == 'a') { $urut = MstrLastUrut($dbtable) + 1; dbInsert($dbtable, array('name' => $name, 'urut' => $urut)); $cid = mysql_insert_id(); } else { if ($opt == 'u') { dbUpdate($dbtable, array('name' => $name), "dcid='{$cid}'"); } else { if ($opt == 'd') { dbUpdate("employee", array('level' => 0), "status='{$cid}'"); dbDel($dbtable, "dcid='{$cid}'"); } else { if ($opt == 'up') { $a = MstrGetNextUrut($dbtable, $cid); if ($a[0] != -1) { dbUpdate($dbtable, array('urut' => $a[1]), "dcid='{$cid}'"); dbUpdate($dbtable, array('urut' => $a[2]), "dcid='" . $a[0] . "'"); }
function add_config_item($new_conf_name, $new_conf_value, $new_conf_type, $new_conf_desc) { if (dbInsert(array('config_name' => $new_conf_name, 'config_value' => $new_conf_value, 'config_default' => $new_conf_value, 'config_type' => $new_conf_type, 'config_desc' => $new_conf_desc, 'config_group' => '500_Custom Settings', 'config_sub_group' => '01_Custom settings', 'config_hidden' => '0', 'config_disabled' => '0'), 'config')) { $db_inserted = 1; } else { $db_inserted = 0; } return $db_inserted; }
// Global Variables $mstr_level = MstrGet("mstr_level"); $mstr_division = MstrGet("mstr_division"); $mstr_group = MstrGet("mstr_group"); $mstr_position = MstrGet("mstr_position"); if ($opt == 'a' || $opt == 'u' || $opt == 'd' || $opt == 'up' || $opt == 'dn') { // Post Variables $inp = array(); $inp['nip'] = gpost('nip'); $inp['level'] = gpost('level'); $inp['division'] = gpost('division'); $inp['group'] = gpost('group'); $inp['position'] = gpost('position'); if ($opt == 'a') { $t = dbUpdate($dbtable, array('active' => 'N'), "empid='{$dcid}'"); dbInsert($dbtable, array('empid' => $dcid, 'status' => $status, 'date1' => $date1, 'date2' => $date2, 'position' => $position)); dbUpdate("employee", array('status' => $status), "dcid='{$dcid}'"); } else { if ($opt == 'u') { dbUpdate($dbtable, $inp, "dcid='{$cid}'"); } else { if ($opt == 'd') { if ($active == 'Y') { dbUpdate("employee", array('status' => 0), "dcid='{$dcid}'"); } dbDel($dbtable, "dcid='{$cid}'"); } } } $t = dbSel("*", "employee", "W/dcid='{$dcid}' LIMIT 0,1"); $r = dbFA($t);
$extras = explode('\\n', $config_extra); foreach ($extras as $option) { list($k, $v) = explode('=', $option, 2); if (!empty($k) || !empty($v)) { dbInsert(array('config_name' => 'alert.transports.boxcar.' . $config_id . '.' . $k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Boxcar ' . $v), 'config'); } } } else { $message = 'Could not create config item'; } } } else { if (empty($config_group) || empty($config_sub_group) || empty($config_name) || empty($config_value)) { $message = 'Missing config name or value'; } else { $config_id = dbInsert(array('config_name' => $config_name, 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'API Transport'), 'config'); if ($config_id > 0) { dbUpdate(array('config_name' => $config_name . $config_id), 'config', 'config_id=?', array($config_id)); $status = 'ok'; $message = 'Config item created'; } else { $message = 'Could not create config item'; } } } } } } } //end if $response = array('status' => $status, 'message' => $message, 'config_id' => $config_id, 'additional_id' => $additional_id);
$data = trim($data); list($oid, $ifIndex) = explode(' ', $data); $mask = trim(snmp_get($device, "ipAdEntNetMask.{$oid}", '-Oqv', 'IP-MIB')); $addr = Net_IPv4::parseAddress("{$oid}/{$mask}"); $network = $addr->network . '/' . $addr->bitmask; $cidr = $addr->bitmask; if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)) < '1') { dbInsert(array('ipv4_network' => $network), 'ipv4_networks'); // echo("Create Subnet $network\n"); echo 'S'; } $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', array($oid, $cidr, $port_id)) == '0') { dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id), 'ipv4_addresses'); // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); echo '+'; } else { echo '.'; } $full_address = "{$oid}/{$cidr}|{$ifIndex}"; $valid_v4[$full_address] = 1; } else { echo '!'; } //end if } //end foreach $sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '" . $device['device_id'] . "' AND A.port_id = I.port_id"; foreach (dbFetchRows($sql) as $row) {
$cid = gpost('cid'); if ($cid == '') { $cid = 0; } appmod_use('aka/tahunajaran', 'aka/pelajaran'); // form Module $fmod = 'guru'; $dbtable = 'aka_guru'; $fform = new fform($fmod, $opt, $cid); $inp = app_form_gpost('tahunajaran', 'pegawai', 'pelajaran', 'aktif', 'keterangan'); if ($opt == 'a' || $opt == 'u' || $opt == 'd') { //db operation : add , update, delete $q = false; if ($opt == 'a') { // add $q = dbInsert($dbtable, $inp); $y = mysql_query("SELECT * FROM admin WHERE pegawai='" . $inp['pegawai'] . "'"); // $y=mysql_query("SELECT * FROM admin WHERE pegawai='".$inp['pegawai']."'"); if (mysql_num_rows($y) == 0) { $y = mysql_query("SELECT hrd_pegawai.nip,hrd_pegawai.nama FROM hrd_pegawai WHERE hrd_pegawai.replid='" . $inp['pegawai'] . "'"); $u = mysql_fetch_array($y); $q = mysql_query("INSERT INTO admin SET app='gur', nama='" . $u['nama'] . "', uname='" . $u['nip'] . "', passwd='" . md5('admin') . "', pegawai='" . $inp['pegawai'] . "', level='2'"); } } else { if ($opt == 'u') { // edit $q = dbUpdate($dbtable, $inp, "replid='{$cid}'"); } else { if ($opt == 'd') { // delete $t = mysql_query("SELECT pegawai FROM aka_guru WHERE replid='{$cid}'");
if ($port_low['ifType'] == 'propVirtual') { continue; } //Skip stacking on Vlan ports (F.u. Cisco SB) $ifStackStatus = $entry_low['ifStackStatus']; if (isset($stack_db_array[$port_id_high][$port_id_low])) { if ($stack_db_array[$port_id_high][$port_id_low]['ifStackStatus'] == $ifStackStatus) { echo "."; } else { $update_array = array('ifStackStatus' => $ifStackStatus); dbUpdate($update_array, 'ports_stack', "`device_id` = ? AND `port_id_high` = ? AND `port_id_low` = ?", array($device['device_id'], $port_id_high, $port_id_low)); echo "U"; } unset($stack_db_array[$port_id_high][$port_id_low]); } else { $update_array = array('device_id' => $device['device_id'], 'port_id_high' => $port_id_high, 'port_id_low' => $port_id_low, 'ifStackStatus' => $ifStackStatus); dbInsert($update_array, 'ports_stack'); echo "+"; } } } foreach ($stack_db_array as $port_id_high => $array) { foreach ($array as $port_id_low => $blah) { print_debug("DELETE STACK: " . $device['device_id'] . " " . $port_id_low . " " . $port_id_high); dbDelete('ports_stack', "`device_id` = ? AND port_id_high = ? AND port_id_low = ?", array($device['device_id'], $port_id_high, $port_id_low)); echo "-"; } } unset($update_array); echo "\n"; // EOF
function scan_new_plugins() { global $config, $debug; $installed = 0; // Track how many plugins we install. if (file_exists($config['plugin_dir'])) { $plugin_files = scandir($config['plugin_dir']); foreach ($plugin_files as $name) { if (is_dir($config['plugin_dir'] . '/' . $name)) { if ($name != '.' && $name != '..') { if (is_file($config['plugin_dir'] . '/' . $name . '/' . $name . '.php') && is_file($config['plugin_dir'] . '/' . $name . '/' . $name . '.inc.php')) { $plugin_id = dbFetchRow("SELECT `plugin_id` FROM `plugins` WHERE `plugin_name` = '{$name}'"); if (empty($plugin_id)) { if (dbInsert(array('plugin_name' => $name, 'plugin_active' => '0'), 'plugins')) { $installed++; } } } } } } } return $installed; }
} dbUpdate(array('device_id' => $device['device_id'], 'app_type' => 'proxmox', 'app_instance' => $pmxcluster), 'applications', '`device_id` = ? AND `app_type` = ?', array($device['device_id'], 'proxmox')); if (count($pmxlines) > 0) { $pmxcache = []; foreach ($pmxlines as $vm) { list($vmid, $vmport, $vmpin, $vmpout, $vmdesc) = explode('/', $vm, 5); $rrd_filename = join('/', array($pmxcdir, $vmid . '_netif_' . $vmport . '.rrd')); if (!is_file($rrd_filename)) { rrdtool_create($rrd_filename, ' --step 300 DS:INOCTETS:DERIVE:600:0:12500000000 DS:OUTOCTETS:DERIVE:600:0:12500000000 ' . $config['rrd_rra']); } rrdtool_update($rrd_filename, array("INOCTETS" => $vmpin, "OUTOCTETS" => $vmpout)); print "Proxmox ({$pmxcluster}): {$vmdesc}: {$vmpin}/{$vmpout}/{$vmport}\n"; if (proxmox_vm_exists($vmid, $pmxcluster, $pmxcache) === true) { dbUpdate(array('device_id' => $device['device_id'], 'last_seen' => array('NOW()'), 'description' => $vmdesc), 'proxmox', '`vmid` = ? AND `cluster` = ?', array($vmid, $pmxcluster)); } else { $pmxcache[$pmxcluster][$vmid] = dbInsert(array('cluster' => $pmxcluster, 'vmid' => $vmid, 'description' => $vmdesc, 'device_id' => $device['device_id']), 'proxmox'); } if ($portid = proxmox_port_exists($vmid, $pmxcluster, $vmport) !== false) { dbUpdate(array('last_seen' => array('NOW()')), 'proxmox_ports', '`vm_id` = ? AND `port` = ?', array($pmxcache[$pmxcluster][$vmid], $vmport)); } else { dbInsert(array('vm_id' => $pmxcache[$pmxcluster][$vmid], 'port' => $vmport), 'proxmox_ports'); } } } unset($pmxlines); unset($pmxcluster); unset($pmxcdir); unset($proxmox); unset($pmxcache);
$param[] = substr($key, 4); $enabled[] = substr($key, 4); $replace[] = '?'; } } if (count($enabled)) { $updated += dbDelete('applications', '`device_id` = ? AND `app_type` NOT IN (' . implode(',', $replace) . ')', $param); } else { $updated += dbDelete('applications', '`device_id` = ?', array($param)); } foreach (dbFetchRows('SELECT `app_type` FROM `applications` WHERE `device_id` = ?', array($device['device_id'])) as $row) { $app_in_db[] = $row['app_type']; } foreach ($enabled as $app) { if (!in_array($app, $app_in_db)) { $updated += dbInsert(array('device_id' => $device['device_id'], 'app_type' => $app), 'applications'); } } if ($updated) { print_message('Applications updated!'); } else { print_message('No changes.'); } } //end if // Show list of apps with checkboxes echo '<div style="padding: 10px;">'; $apps_enabled = dbFetchRows('SELECT * from `applications` WHERE `device_id` = ? ORDER BY app_type', array($device['device_id'])); if (count($apps_enabled)) { foreach ($apps_enabled as $application) { $app_enabled[] = $application['app_type'];
* the source code distribution for details. */ /* * Code for Gridster.sort_by_row_and_col_asc(serialization) call is from http://gridster.net/demos/grid-from-serialize.html */ $no_refresh = true; $default_dash = 0; $tmp = dbFetchCell('SELECT dashboard FROM users WHERE user_id=?', array($_SESSION['user_id'])); if ($tmp != 0) { $default_dash = $tmp; } elseif ((int) $config['webui']['default_dashboard_id']) { // if the user hasn't set their default page, and there is a global default set $default_dash = dbFetchCell('SELECT `dashboard_id` FROM `dashboards` WHERE `dashboard_id` = ?', array((int) $config['webui']['default_dashboard_id'])); } if ($default_dash == 0 && dbFetchCell('SELECT dashboard_id FROM dashboards WHERE user_id=?', array($_SESSION['user_id'])) == 0) { $vars['dashboard'] = dbInsert(array('dashboard_name' => 'Default', 'user_id' => $_SESSION['user_id']), 'dashboards'); if (dbFetchCell('select 1 from users_widgets where user_id = ? && dashboard_id = ?', array($_SESSION['user_id'], 0)) == 1) { dbUpdate(array('dashboard_id' => $vars['dashboard']), 'users_widgets', 'user_id = ? && dashboard_id = ?', array($_SESSION['user_id'], 0)); } } if (!empty($vars['dashboard'])) { $orig = $vars['dashboard']; $vars['dashboard'] = dbFetchRow('select * from dashboards where user_id = ? && dashboard_id = ? order by dashboard_id limit 1', array($_SESSION['user_id'], $vars['dashboard'])); if (empty($vars['dashboard'])) { $vars['dashboard'] = dbFetchRow('select dashboards.*,users.username from dashboards inner join users on dashboards.user_id = users.user_id where dashboards.dashboard_id = ? && dashboards.access > 0', array($orig)); } } if (empty($vars['dashboard'])) { if ($default_dash != 0) { $vars['dashboard'] = dbFetchRow('select dashboards.*,users.username from dashboards inner join users on dashboards.user_id = users.user_id where dashboards.dashboard_id = ?', array($default_dash)); } else {
echo "-m Specify single module to be run\n"; echo "\n"; echo "Invalid arguments!\n"; exit; } include "includes/sql-schema/update.php"; $discovered_devices = 0; if ($config['distributed_poller'] === TRUE) { $where .= " AND poller_group IN(" . $config['distributed_poller_group'] . ")"; } foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 {$where} ORDER BY device_id DESC") as $device) { discover_device($device, $options); } $end = utime(); $run = $end - $start; $proctime = substr($run, 0, 5); if ($discovered_devices) { dbInsert(array('type' => 'discover', 'doing' => $doing, 'start' => $start, 'duration' => $proctime, 'devices' => $discovered_devices), 'perf_times'); } $string = $argv[0] . " {$doing} " . date($config['dateformat']['compact']) . " - {$discovered_devices} devices discovered in {$proctime} secs"; if ($debug) { echo "{$string}\n"; } if ($options['h'] != "new" && $config['version_check']) { include "includes/versioncheck.inc.php"; } if (!isset($options['q'])) { echo 'MySQL: Cell[' . ($db_stats['fetchcell'] + 0) . '/' . round($db_stats['fetchcell_sec'] + 0, 2) . 's]' . ' Row[' . ($db_stats['fetchrow'] + 0) . '/' . round($db_stats['fetchrow_sec'] + 0, 2) . 's]' . ' Rows[' . ($db_stats['fetchrows'] + 0) . '/' . round($db_stats['fetchrows_sec'] + 0, 2) . 's]' . ' Column[' . ($db_stats['fetchcol'] + 0) . '/' . round($db_stats['fetchcol_sec'] + 0, 2) . 's]' . ' Update[' . ($db_stats['update'] + 0) . '/' . round($db_stats['update_sec'] + 0, 2) . 's]' . ' Insert[' . ($db_stats['insert'] + 0) . '/' . round($db_stats['insert_sec'] + 0, 2) . 's]' . ' Delete[' . ($db_stats['delete'] + 0) . '/' . round($db_stats['delete_sec'] + 0, 2) . 's]'; echo "\n"; } logfile($string);
// First digit gives number of chars in VRF Name, then it's ASCII list($vrf_oid, $vrf_rd) = explode(" ", $oid); $oid_values = explode(".", $vrf_oid); $vrf_name = ""; for ($i = 1; $i <= $oid_values[0]; $i++) { $vrf_name .= chr($oid_values[$i]); } echo "\n [VRF {$vrf_name}] OID - " . $vrf_oid; echo "\n [VRF {$vrf_name}] RD - " . $vrf_rd; echo "\n [VRF {$vrf_name}] DESC - " . $descr_table[$vrf_oid]; if (dbFetchCell('SELECT COUNT(*) FROM `vrfs` WHERE `device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid))) { $update_array = array('mplsVpnVrfDescription' => $descr_table[$vrf_oid], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd); dbUpdate($update_array, 'vrfs', '`device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid)); } else { $insert_array = array('device_id' => $device['device_id'], 'vrf_oid' => $vrf_oid, 'vrf_name' => $vrf_name, 'mplsVpnVrfDescription' => $descr_table[$vrf_oid], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd); dbInsert($insert_array, 'vrfs'); } $vrf_id = dbFetchCell('SELECT vrf_id FROM `vrfs` WHERE `device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid)); $valid_vrf[$vrf_id] = 1; echo "\n [VRF {$vrf_name}] PORTS - "; foreach ($port_table[$vrf_oid] as $if_id) { $interface = dbFetchRow('SELECT ifDescr, port_id FROM ports WHERE ifIndex = ? AND device_id = ?', array($if_id, $device['device_id'])); echo short_ifname($interface['ifDescr']) . " "; dbUpdate(array('ifVrf' => $vrf_id), 'ports', '`port_id` = ?', array($interface['port_id'])); $if = $interface['port_id']; $valid_vrf_if[$vrf_id][$if] = 1; } } } echo "\n"; foreach (dbFetchRows('SELECT * FROM ports WHERE device_id = ?', array($device['device_id'])) as $row) {