/** * Execute an sql query in the database. The correct database connection * will be chosen and the query will be logged with the success status. * * @param $query query to execute as string */ function exec_query($query) { global $conn, $pdo_conn, $errors, $db_layer; $success = false; if ($db_layer == "pdo") { if (is_object($pdo_conn)) { $pdo_query = $pdo_conn->prepare($query); $success = $pdo_query->execute(array()); $errorInfo = serialize($pdo_query->errorInfo()); } else { $errorInfo = "No connection object."; } } else { if (is_object($conn)) { $success = $conn->Query($query); $errorInfo = serialize($conn->Error()); } else { $errorInfo = "No connection object."; } } logfile($query); if (!$success) { logfile($errorInfo); $errors = true; } }
function error_log_print($errno, $errstr, $errfile, $errline) { $backtrace = (new Exception())->getTraceAsString(); $err = "Error #{$errno}: '{$errstr}' at line {$errline} of file {$errfile}. Debug Backtrace:\r\n{$backtrace}\r\n"; logfile('err', $err); //Printing out global $DEBUG_MODE; if ($DEBUG_MODE) { echo "An error occurred:<br><pre>{$err}</pre><br>(logged as above)"; } else { echo getErrPage(); } }
/** * Execute an sql query in the database. The correct database connection * will be chosen and the query will be logged with the success status. * * @param $query query to execute as string */ function exec_query($query) { global $conn, $pdo_conn, $kga, $errors, $executed_queries; $success = false; if ($kga['server_conn'] == "pdo") { if (is_object($pdo_conn)) { $pdo_query = $pdo_conn->prepare($query); $success = $pdo_query->execute(array()); } else { $errorInfo = "No connection object."; } } else { if (is_object($conn)) { $success = $conn->Query($query); } else { $errorInfo = "No connection object."; } } logfile($query); if (!$success) { logfile($errorInfo); $errors = true; } }
logfile("cleanup.log", "Database cleanup for table {$table}: deleted {$count} entries"); } } else { if ($prompt) { print_message("No orphaned rows found in table {$table}."); } } } // Cleanup duplicate entries in the device_graphs table foreach (dbFetchRows("SELECT * FROM `device_graphs`") as $entry) { $graphs[$entry['device_id']][$entry['graph']][] = $entry['device_graph_id']; } foreach ($graphs as $device_id => $device_graph) { foreach ($device_graph as $graph => $data) { if (count($data) > 1) { // More than one entry for a single graph type for this device, let's clean up. // Leave the first entry intact, chop it off the array $device_graph_ids = array_slice($data, 1); if ($prompt) { $answer = print_prompt(count($device_graph_ids) . " duplicate graph rows of type {$graph} for device {$device_id} will be deleted"); } if ($answer) { $table_status = dbDelete('device_graphs', "`device_graph_id` IN (?)", array($device_graph_ids)); print_debug("Deleted " . count($device_graph_ids) . " duplicate graph rows of type {$graph} for device {$device_id}"); logfile("cleanup.log", "Deleted " . count($device_graph_ids) . " duplicate graph rows of type {$graph} for device {$device_id}"); } } } } } // EOF
* @copyright (C) 2006-2015 Adam Armstrong * */ chdir(dirname($argv[0])); $scriptname = basename($argv[0]); include_once "includes/defaults.inc.php"; include_once "config.php"; $options = getopt("d"); if (isset($options['d'])) { array_shift($argv); } // for compatability include_once "includes/definitions.inc.php"; include "includes/functions.inc.php"; $entry = explode(",", $argv[1]); logfile('SNMPTRAP: ' . $argv[1]); #print_vars($entry); $device = @dbFetchRow("SELECT * FROM devices WHERE `hostname` = ?", array($entry['0'])); if (!$device['device_id']) { $device = @dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id", array($entry['0'])); } if (!$device['device_id']) { exit; } $file = $config['install_dir'] . "/includes/snmptrap/" . $entry['1'] . ".inc.php"; if (is_file($file)) { include "{$file}"; } else { echo "未知的陷阱 ({$file})"; } // EOF
} } print_debug("Timing housekeeping: deleted {$rows} entries (per-device)"); logfile("housekeeping.log", "Timing: deleted {$rows} entries older than " . format_unixtime($cutoff) . " (per-device)"); $rows = dbDelete('perf_times', $where); if ($rows === FALSE) { // Use LIMIT with big tables print_debug("Performance table (per-run) is too big, using LIMIT for delete entries"); $rows = 0; $i = 1000; while ($i && $rows < $count_run) { $iter = dbDelete('perf_times', $where . ' LIMIT 1000000'); if ($iter === FALSE) { break; } $rows += $iter; $i--; } } print_debug("Timing housekeeping: deleted {$rows} entries (per-run)"); logfile("housekeeping.log", "Timing: deleted {$rows} entries older than " . format_unixtime($cutoff) . " (per-run)"); } } else { if ($prompt) { print_message("No perfomance entries found older than " . format_unixtime($cutoff)); } } } else { print_message("Timing housekeeping disabled in configuration or less than 24h."); } // EOF
function get_http_request($request) { global $config; if (OBS_HTTP_REQUEST === FALSE) { print_debug("HTTP requests skipped since previous request exit with timeout."); return FALSE; } $response = ''; $opts = array('http' => array('timeout' => '15')); if (isset($config['http_proxy']) && $config['http_proxy']) { $opts['http']['proxy'] = 'tcp://' . $config['http_proxy']; $opts['http']['request_fulluri'] = TRUE; } // Basic proxy auth if (isset($config['proxy_user']) && $config['proxy_user'] && isset($config['proxy_password'])) { $auth = base64_encode($config['proxy_user'] . ':' . $config['proxy_password']); $opts['http']['header'] = 'Proxy-Authorization: Basic ' . $auth; } $start = utime(); $context = stream_context_create($opts); $response = file_get_contents($request, FALSE, $context); $runtime = utime() - $start; if (OBS_DEBUG) { if (OBS_DEBUG < 2 && strpos($request, 'update.observium.org')) { $request = preg_replace('/&stats=.+/', '&stats=***', $request); } print_message(PHP_EOL . 'REQUEST[%y' . $request . '%n]' . PHP_EOL . 'RUNTIME[' . ($runtime > 3 ? '%r' : '%g') . round($runtime, 4) . 's%n]', 'console'); if (OBS_DEBUG > 1) { print_message("RESPONSE[\n" . $response . "\n]", 'console', FALSE); } } // Set OBS_HTTP_REQUEST for skip all other requests if (!defined('OBS_HTTP_REQUEST')) { if ($response === FALSE) { define('OBS_HTTP_REQUEST', FALSE); print_debug(__FUNCTION__ . '() exit with timeout. Access to outside localnet is blocked by firewall or network problems. Check proxy settings.'); logfile(__FUNCTION__ . '() exit with timeout. Access to outside localnet is blocked by firewall or network problems. Check proxy settings.'); } else { define('OBS_HTTP_REQUEST', TRUE); } } // FIXME. what if first request fine, but second broken? //else if ($response === FALSE) //{ // if (function_exists('runkit_constant_redefine')) { runkit_constant_redefine('OBS_HTTP_REQUEST', FALSE); } //} return $response; }
if ($file_data['mtime'] < $cutoff) { print_debug("File modification time is " . format_unixtime($file_data['mtime']) . " - deleting"); logfile("housekeeping.log", "File {$file} modification time is " . format_unixtime($file_data['mtime']) . " - deleting"); unlink($file); $count_notmodified++; } } // Not using finfo functions from PHP, whatever I tried always resulted in application/octet-stream. Dumb thing. if ($config['housekeeping']['rrd']['invalid'] && file_exists($file)) { if (!file_exists($config['file'])) { print_debug("Magic 'file' binary not found in configured path!"); } else { $filetype = $this_data = trim(external_exec($config['file'] . " -b " . $file)); if (substr($filetype, 0, 10) != "RRDTool DB") { print_debug("Invalid file type for {$file} ({$filetype}) - deleting"); logfile("housekeeping.log", "File {$file} has invalid type: {$filetype} - deleting"); unlink($file); $count_notvalid++; } } } } } if ($prompt && $cutoff) { if ($count_notmodified) { print_message("Deleted {$count_notmodified} not modified RRD files older than " . format_unixtime($cutoff)); } else { print_message("No RRD files found last modified before " . format_unixtime($cutoff)); } } if ($prompt && $config['housekeeping']['rrd']['invalid']) {
/** * Checks device availability by icmp echo response * If flag OBS_PING_SKIP passed, pings skipped and returns 0.001 (1ms) * * @param string $hostname Device hostname or IP address * @param int Flags. Supported OBS_DNS_A, OBS_DNS_AAAA and OBS_PING_SKIP * @return float Average response time for used retries count (default retries is 3) */ function isPingable($hostname, $flags = OBS_DNS_ALL) { global $config; $ping_debug = isset($config['ping']['debug']) && $config['ping']['debug']; $try_a = is_flag_set(OBS_DNS_A, $flags); if (is_flag_set(OBS_PING_SKIP, $flags)) { return 0.001; // Ping is skipped, just return 1ms } $timeout = isset($config['ping']['timeout']) ? (int) $config['ping']['timeout'] : 500; if ($timeout < 50) { $timeout = 50; } else { if ($timeout > 2000) { $timeout = 2000; } } $retries = isset($config['ping']['retries']) ? (int) $config['ping']['retries'] : 3; if ($retries < 1) { $retries = 3; } else { if ($retries > 10) { $retries = 10; } } $sleep = floor(1000000 / $retries); // interval between retries, max 1 sec if ($ip_version = get_ip_version($hostname)) { // Ping by IP if ($ip_version === 6) { $cmd = $config['fping6'] . " -t {$timeout} -c 1 -q {$hostname} 2>&1"; } else { if (!$try_a) { if ($ping_debug) { logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | Passed IPv4 address but device use IPv6 transport"); } print_debug('Into function ' . __FUNCTION__ . '() passed IPv4 address (' . $hostname . 'but device use IPv6 transport'); return 0; } // Forced check for actual IPv4 address $cmd = $config['fping'] . " -t {$timeout} -c 1 -q {$hostname} 2>&1"; } } else { // First try IPv4 $ip = $try_a ? gethostbyname($hostname) : FALSE; // Do not check IPv4 if transport IPv6 if ($ip && $ip != $hostname) { $cmd = $config['fping'] . " -t {$timeout} -c 1 -q {$ip} 2>&1"; } else { $ip = gethostbyname6($hostname, OBS_DNS_AAAA); // Second try IPv6 if ($ip) { $cmd = $config['fping6'] . " -t {$timeout} -c 1 -q {$ip} 2>&1"; } else { // No DNS records if ($ping_debug) { logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | NO DNS record found"); } return 0; } } } for ($i = 1; $i <= $retries; $i++) { $output = external_exec($cmd); if ($GLOBALS['exec_status']['exitcode'] === 0) { // normal $output = '8.8.8.8 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 1.21/1.21/1.21' $tmp = explode('/', $output); $ping = $tmp[7]; if (!$ping) { $ping = 0.001; } // Protection from zero (exclude false status) } else { $ping = 0; } if ($ping) { break; } if ($ping_debug) { logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | FPING OUT ({$i}): " . $output[0]); if ($i == $retries) { $mtr = $config['mtr'] . " -r -n -c 5 {$ip}"; logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | MTR OUT:\n" . external_exec($mtr)); } } if ($i < $retries) { usleep($sleep); } } return $ping; }
/** * Just edit the comment an entry. This is used for editing the comment * of a running entry. * * @param $zef_ID id of the timesheet entry * @param $comment_type new type of the comment * @param $comment the comment text */ function zef_edit_comment($zef_ID, $comment_type, $comment) { global $kga, $conn; $zef_ID = MySQL::SQLValue($zef_ID, MySQL::SQLVALUE_NUMBER); $comment_type = MySQL::SQLValue($comment_type); $comment = MySQL::SQLValue($comment); $table = $kga['server_prefix'] . "zef"; $filter['zef_ID'] = $zef_ID; $values['zef_comment_type'] = $comment_type; $values['zef_comment'] = $comment; $query = MySQL::BuildSQLUpdate($table, $values, $filter); logfile($query); return $conn->Query($query); }
if ($prompt) { $answer = print_prompt("{$count} eventlog entries older than " . format_unixtime($cutoff) . " will be deleted"); } if ($answer) { $rows = dbDelete('eventlog', $where); if ($rows === FALSE) { // Use LIMIT with big tables print_debug("Event log table is too big, using LIMIT to delete entries"); $rows = 0; $i = 1000; while ($i && $rows < $count) { $iter = dbDelete('eventlog', $where . ' LIMIT 1000000'); if ($iter === FALSE) { break; } $rows += $iter; $i--; } } print_debug("Event log housekeeping: deleted {$rows} entries"); logfile("housekeeping.log", "Event log: deleted {$rows} entries older than " . format_unixtime($cutoff)); } } else { if ($prompt) { print_message("No event log entries found older than " . format_unixtime($cutoff)); } } } else { print_message("Event log housekeeping is disabled in configuration or less than 24h."); } // EOF
* @package observium * @subpackage housekeeping * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ $cutoff = age_to_unixtime($config['housekeeping']['deleted_ports']['age']); if ($cutoff) { $where = "`deleted` = 1 AND UNIX_TIMESTAMP(`ifLastChange`) < {$cutoff}"; $ports = dbFetchRows("SELECT `port_id` FROM `ports` WHERE {$where}"); $count = count($ports); if ($count) { if ($prompt) { $answer = print_prompt("{$count} ports marked as deleted before " . format_unixtime($cutoff) . " will be deleted"); } if ($answer) { foreach ($ports as $entry) { delete_port($entry['port_id']); } print_debug("Deleted ports housekeeping: deleted {$count} entries"); logfile("housekeeping.log", "Deleted ports: deleted {$count} entries older than " . format_unixtime($cutoff)); } } else { if ($prompt) { print_message("No ports found marked as deleted before " . format_unixtime($cutoff)); } } } else { print_message("Deleted ports housekeeping disabled in configuration."); } // EOF
global $valid, $agent_sensors; if ($device['os_group'] == "unix") { echo "Observium UNIX Agent: "; // Use port configured in config (or defaults) $agent_port = $config['unix-agent']['port']; // ... Unless user configured a port for this specific device, and it's valid (numeric and within 16-bit port range) $override_port = get_dev_attrib($device, 'agent_port'); if (is_numeric($override_port) && $override_port < 65536) { $agent_port = $override_port; } $agent_start = utime(); $agent_socket = "tcp://" . $device['hostname'] . ":" . $agent_port; $agent = @stream_socket_client($agent_socket, $errno, $errstr, 10); if (!$agent) { print_warning("Connection to UNIX agent on " . $agent_socket . " failed. ERROR: " . $errno . " " . $errstr); logfile("UNIX-AGENT: Connection on " . $agent_socket . " failed. ERROR: " . $errno . " " . $errstr); } else { $agent_raw = stream_get_contents($agent); } $agent_end = utime(); $agent_time = round(($agent_end - $agent_start) * 1000); if (!empty($agent_raw)) { echo "execution time: " . $agent_time . "ms"; rrdtool_update_ng($device, 'agent', array('time' => $agent_time)); $graphs['agent'] = TRUE; foreach (explode("<<<", $agent_raw) as $section) { list($section, $data) = explode(">>>", $section); $sa = ''; $sb = ''; $sc = ''; # DO -NOT- ADD NEW CASES BELOW -- use <<<app-$foo>>> in your application script
$comment_types = array($kga['lang']['ctype0'], $kga['lang']['ctype1'], $kga['lang']['ctype2']); // ================== // = security check = // ================== if (isset($_REQUEST['axAction']) && !is_array($_REQUEST['axAction']) && $_REQUEST['axAction'] != "") { $axAction = strip_tags($_REQUEST['axAction']); } else { $axAction = ''; } $axValue = isset($_REQUEST['axValue']) ? strip_tags($_REQUEST['axValue']) : ''; $id = isset($_REQUEST['id']) ? strip_tags($_REQUEST['id']) : null; // ============================================ // = initialize currently displayed timespace = // ============================================ $timespace = get_timespace(); $in = $timespace[0]; $out = $timespace[1]; if (isset($_REQUEST['first_day'])) { $in = (int) $_REQUEST['first_day']; } if (isset($_REQUEST['last_day'])) { $out = mktime(23, 59, 59, date("n", $_REQUEST['last_day']), date("j", $_REQUEST['last_day']), date("Y", $_REQUEST['last_day'])); } if ($axAction != "reloadLogfile") { logfile("KSPI axAction (" . (array_key_exists('customer', $kga) ? $kga['customer']['knd_name'] : $kga['usr']['usr_name']) . "): " . $axAction); } // prevent IE from caching the response header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache");
function CollectData($bill_id) { $port_list = dbFetchRows("SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.port_id = P.port_id AND D.device_id = I.device_id", array($bill_id)); print_r($port_list); $now = dbFetchCell("SELECT NOW()"); foreach ($port_list as $port_data) { $port_id = $port_data['port_id']; $host = $port_data['hostname']; $port = $port_data['port']; echo "\nPolling " . $port_data['ifDescr'] . " on " . $port_data['hostname'] . "\n"; $port_data['in_measurement'] = getValue($port_data['hostname'], $port_data['port'], $port_data['ifIndex'], "In"); $port_data['out_measurement'] = getValue($port_data['hostname'], $port_data['port'], $port_data['ifIndex'], "Out"); $last_data = getLastPortCounter($port_id, in); if ($last_data['state'] == "ok") { $port_data['last_in_measurement'] = $last_data[counter]; $port_data['last_in_delta'] = $last_data[delta]; if ($port_data['in_measurement'] > $port_data['last_in_measurement']) { $port_data['in_delta'] = $port_data['in_measurement'] - $port_data['last_in_measurement']; } else { $port_data['in_delta'] = $port_data['last_in_delta']; } } else { $port_data['in_delta'] = '0'; } dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_data['in_measurement'], 'delta' => $port_data['in_delta']), 'port_in_measurements'); $last_data = getLastPortCounter($port_id, out); if ($last_data[state] == "ok") { $port_data['last_out_measurement'] = $last_data[counter]; $port_data['last_out_delta'] = $last_data[delta]; if ($port_data['out_measurement'] > $port_data['last_out_measurement']) { $port_data['out_delta'] = $port_data['out_measurement'] - $port_data['last_out_measurement']; } else { $port_data['out_delta'] = $port_data['last_out_delta']; } } else { $port_data['out_delta'] = '0'; } dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_data['out_measurement'], 'delta' => $port_data['out_delta']), 'port_out_measurements'); $delta = $delta + $port_data['in_delta'] + $port_data['out_delta']; $in_delta = $in_delta + $port_data['in_delta']; $out_delta = $out_delta + $port_data['out_delta']; } $last_data = getLastMeasurement($bill_id); if ($last_data[state] == "ok") { $prev_delta = $last_data[delta]; $prev_in_delta = $last_data[in_delta]; $prev_out_delta = $last_data[out_delta]; $prev_timestamp = $last_data[timestamp]; $period = dbFetchCell("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('" . mres($prev_timestamp) . "')"); } else { $prev_delta = '0'; $period = '0'; $prev_in_delta = '0'; $prev_out_delta = '0'; } if ($delta < '0') { $delta = $prev_delta; $in_delta = $prev_in_delta; $out_delta = $prev_out_delta; } if ($period < "0") { logfile("BILLING: negative period! id:{$bill_id} period:{$period} delta:{$delta} in_delta:{$in_delta} out_delta:{$out_delta}"); } else { dbInsert(array('bill_id' => $bill_id, 'timestamp' => $now, 'period' => $period, 'delta' => $delta, 'in_delta' => $in_delta, 'out_delta' => $out_delta), 'bill_data'); } }
logfile('update-errors.log', "====== 架构更新 " . sprintf("%03d", $db_rev) . " -> " . sprintf("%03d", $filename) . " =============="); foreach ($errors as $error) { logfile('update-errors.log', "查询: " . $error['query']); logfile('update-errors.log', "错误: " . $error['error']); } fclose($fd); unset($errors); } else { echo " 完成.\n"; } } } else { echo " 无法打开文件!\n"; // Critical errors, stop update logfile('update-errors.log', "====== Schema update " . sprintf("%03d", $db_rev) . " -> " . sprintf("%03d", $filename) . " =============="); logfile('update-errors.log', "Error: Could not open file {$filepath}!"); exit(1); } } } $updating++; $db_rev = $filename; } } if ($updating) { $GLOBALS['cache']['db_version'] = $db_rev; // Cache new db version if ($insert) { dbInsert(array('version' => $db_rev), 'dbSchema'); } else { dbUpdate(array('version' => $db_rev), 'dbSchema');
* * Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa> * * This program 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. Please see LICENSE.txt at the top level of * the source code distribution for details. */ header('Content-type: application/json'); $status = 'error'; $descr = mres($_POST['descr']); $device_id = mres($_POST['device_id']); $ifName = mres($_POST['ifName']); $port_id = mres($_POST['port_id']); logfile($descr . ',' . $device_id . ',' . $ifName . ',' . $port_id); if (!empty($ifName) && is_numeric($port_id)) { // We have ifName and port id so update ifAlias if (empty($descr)) { $descr = 'repoll'; // Set to repoll so we avoid using ifDescr on port poll } if (dbUpdate(array('ifAlias' => $descr), 'ports', '`port_id`=?', array($port_id)) > 0) { $device = device_by_id_cache($device_id); if ($descr === 'repoll') { del_dev_attrib($device, 'ifName:' . $ifName); } else { set_dev_attrib($device, 'ifName:' . $ifName, 1); } $status = 'ok'; } else {
function poll_bill($bill) { $ports = dbFetchRows("SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.port_id = P.port_id AND D.device_id = I.device_id", array($bill['bill_id'])); if (isset($options['d'])) { print_r($ports); } foreach ($ports as $port) { echo "\nPolling " . $port['ifDescr'] . " on " . $port['hostname'] . "\n"; $now = time(); if (is_numeric($port['bill_port_polled'])) { $period = $now - $port['bill_port_polled']; } echo "time: " . $now . "|" . $port['bill_port_polled'] . " period:" . $period . "\n"; if ($port['snmpver'] == "1") { // SNMPv1 - Use non 64-bit counters $oids = "IF-MIB::ifInOctets." . $port['ifIndex'] . " IF-MIB::ifOutOctets." . $port['ifIndex']; $data = snmp_get_multi($port, $oids, "-OQUs", "IF-MIB"); $data = $data[$port['ifIndex']]; $data = array('in' => $data['ifInOctets'], 'out' => $data['ifOutOctets']); } else { // Not SNMPv1 - Use 64-bit counters $oids = "IF-MIB::ifHCInOctets." . $port['ifIndex'] . " IF-MIB::ifHCOutOctets." . $port['ifIndex']; $data = snmp_get_multi($port, $oids, "-OQUs", "IF-MIB"); $data = $data[$port['ifIndex']]; $data = array('in' => $data['ifHCInOctets'], 'out' => $data['ifHCOutOctets']); // Fallback on 32-bit counters if 64-bit fails if (empty($data['in']) && empty($data['out'])) { $oids = "IF-MIB::ifInOctets." . $port['ifIndex'] . " IF-MIB::ifOutOctets." . $port['ifIndex']; $data = snmp_get_multi($port, $oids, "-OQUs", "IF-MIB"); $data = $data[$port['ifIndex']]; $data = array('in' => $data['ifInOctets'], 'out' => $data['ifOutOctets']); } if (isset($options['d'])) { print_r($data); } } if (is_numeric($data['in']) && is_numeric($data['out'])) { echo $period . "|" . $port['bill_port_counter_in'] . "|" . $port['bill_port_counter_out'] . "|" . $data['in'] . "|" . $port['bill_port_counter_in'] . "\n"; // The port returned counters if (is_numeric($period) && is_numeric($port['bill_port_counter_in']) && is_numeric($port['bill_port_counter_out']) && $data['in'] >= $port['bill_port_counter_in'] && $data['out'] >= $port['bill_port_counter_out']) { // Counters are higher or equal to before, seems legit. $in_delta = $data['in'] - $port['bill_port_counter_in']; $out_delta = $data['out'] - $port['bill_port_counter_out']; echo "Counters valid, delta generated.\n"; } elseif (is_numeric($period) && is_numeric($port['bill_port_counter_in']) && is_numeric($port['bill_port_counter_out'])) { // Counters are lower, we must have wrapped. We'll take the measurement as the amount for this period. $in_delta = $data['in']; $out_delta = $data['out']; echo "Counters wrapped, delta fudged.\n"; } else { // First update. delta is zero, only insert counters. echo "No existing counters.\n"; $in_delta = 0; $out_delta = 0; } if ($in_delta == $data['in'] || $in_delta == $data['in']) { // Deltas are equal to counters. Clearly fail. echo "Deltas equal counters. Resetting."; $in_delta = 0; $out_delta = 0; } $update = array('bill_port_polled' => $now, 'bill_port_period' => $period, 'bill_port_counter_in' => $data['in'], 'bill_port_counter_out' => $data['out'], 'bill_port_delta_in' => $in_delta, 'bill_port_delta_out' => $out_delta); dbUpdate($update, 'bill_ports', '`bill_id` = ? AND `port_id` = ?', array($port['bill_id'], $port['port_id'])); echo "data: in(N:" . $data['in'] . "|P:" . $port['bill_port_counter_in'] . ") delta:" . $in_delta . "\n"; echo " out(N:" . $data['out'] . "|P:" . $port['bill_port_counter_out'] . ") delta:" . $out_delta . "\n"; } else { // No counters were returned // We don't need to update the database. echo "No data.\n"; } dbInsert(array('port_id' => $port['port_id'], 'timestamp' => $now, 'counter' => $data['in'], 'delta' => $in_delta), 'bill_port_in_data'); dbInsert(array('port_id' => $port['port_id'], 'timestamp' => $now, 'counter' => $data['out'], 'delta' => $out_delta), 'bill_port_out_data'); $bill_delta += $in_delta + $out_delta; $bill_in_delta += $in_delta; $bill_out_delta += $out_delta; echo "deltas: i:" . $bill_in_delta . " o:" . $bill_out_delta . " t:" . $bill_delta . "\n"; } echo "Bill processing...\n"; $now = time(); if (is_numeric($bill['bill_polled'])) { $period = $now - $bill['bill_polled']; } echo "time: " . $now . "|" . $bill['bill_polled'] . " period:" . $period . "\n\n\n"; if ($period <= '0') { $bill_delta = '0'; $bill_in_delta = '0'; $bill_out_delta = '0'; } dbUpdate(array('bill_polled' => $now), 'bills', '`bill_id` = ?', array($port['bill_id'])); if ($period < "0" || !is_numeric($period)) { logfile("BILLING: negative period! id:" . $bill['bill_id'] . " period:{$period} delta:{$bill_delta} in_delta:{$bill_in_delta} out_delta:{$bill_out_delta}"); } else { dbInsert(array('bill_id' => $bill['bill_id'], 'timestamp' => array("NOW()"), 'period' => $period, 'delta' => $bill_delta, 'in_delta' => $bill_in_delta, 'out_delta' => $bill_out_delta), 'bill_data'); } }
/** * Execute an sql query in the database. The correct database connection * will be chosen and the query will be logged with the success status. * * As third parameter an alternative query can be passed, which should be * displayed instead of the executed query. This prevents leakage of * confidential information like password salts. The logfile will still * contain the executed query. * * @param $query query to execute as string * @param $errorProcessing true if it's an error when the query fails. */ function exec_query($query, $errorProcessing = false, $displayQuery = null) { global $conn, $pdo_conn, $kga, $errors, $executed_queries; $executed_queries++; echo "<tr>"; if ($kga['server_conn'] == "pdo") { if (is_object($pdo_conn)) { $pdo_query = $pdo_conn->prepare($query); $success = $pdo_query->execute(array()); } } else { if (is_object($conn)) { $success = $conn->Query($query); } } logfile($query, $success); if ($kga['server_conn'] == "pdo") { if (is_object($pdo_conn)) { $err = $pdo_query->errorInfo(); $err = serialize($err); } } else { if (is_object($conn)) { $err = $conn->Error(); } } $query = htmlspecialchars($query); $displayQuery = htmlspecialchars($displayQuery); echo "<td>" . ($displayQuery == null ? $query : $displayQuery) . "<br/>"; echo "<span class='error_info'>" . $err . "</span>"; echo "</td>"; if ($success) { echo "<td class='green'> </td>"; } else { if ($errorProcessing) { echo "<td class='red'>!</td>"; $errors++; } else { echo "<td class='orange'> </td>"; } } if (!$success) { logfile("An error has occured in query: {$query}"); if ($kga['server_conn'] == "pdo") { if (is_object($pdo_conn)) { $err = $pdo_query->errorInfo(); $err = serialize($err); } } else { if (is_object($conn)) { $err = $conn->Error(); } } logfile("Error text: {$err}"); } }
$agent_port = $config['unix-agent']['port']; // Try Official port $agent_start = utime(); $agent_socket = "tcp://" . $device['hostname'] . ":" . $agent_port; $agent = @stream_socket_client($agent_socket, $errno, $errstr, 10); if (!$agent) { echo "Connection to UNIX agent on " . $agent_socket . " failed. ERROR: " . $errno . " " . $errstr . "\n"; logfile("Connection to UNIX agent on " . $agent_socket . " failed. ERROR: " . $errno . " " . $errstr); /// Try check_mk port if the official one doesn't work. $agent_port = "6556"; $agent_start = utime(); $agent_socket = "tcp://" . $device['hostname'] . ":" . $agent_port; $agent = @stream_socket_client($agent_socket, $errno, $errstr, 10); if (!$agent) { echo "Connection to UNIX agent on " . $agent_socket . " failed. ERROR: " . $errno . " " . $errstr . "\n"; logfile("Connection to UNIX agent on " . $agent_socket . " failed. ERROR: " . $errno . " " . $errstr); } else { $agent_raw = stream_get_contents($agent); } } else { $agent_raw = stream_get_contents($agent); } $agent_end = utime(); $agent_time = round(($agent_end - $agent_start) * 1000); if (!empty($agent_raw)) { echo "execution time: " . $agent_time . "ms"; $agent_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/agent.rrd"; if (!is_file($agent_rrd)) { rrdtool_create($agent_rrd, "DS:time:GAUGE:600:0:U " . $config['rrd_rra']); } rrdtool_update($agent_rrd, "N:" . $agent_time);
* @copyright (C) 2006-2014 Adam Armstrong * */ include_once "includes/defaults.inc.php"; include_once "config.php"; include_once "includes/definitions.inc.php"; include $config['install_dir'] . "/includes/functions.inc.php"; // Disable sql profiling, this is a background process without any way to display it $config['profile_sql'] = FALSE; $i = 1; if (isset($config['syslog']['fifo']) && $config['syslog']['fifo'] !== FALSE) { // FIFO configured, try to grab logs from it #echo 'Opening FIFO: '.$config['syslog']['fifo'].PHP_EOL; //No any echo to STDOUT/STDERR! $s = fopen($config['syslog']['fifo'], 'r'); } else { // No FIFO configured, take logs from stdin #echo '开启 STDIN'.PHP_EOL; //No any echo to STDOUT/STDERR! $s = fopen('php://stdin', 'r'); } while ($line = fgets($s)) { if (isset($config['syslog']['debug']) && $config['syslog']['debug']) { // Store RAW syslog line into debug.log logfile('debug.log', $line); } // host || facility || priority || level || tag || timestamp || msg || program list($entry['host'], $entry['facility'], $entry['priority'], $entry['level'], $entry['tag'], $entry['timestamp'], $entry['msg'], $entry['program']) = explode("||", trim($line)); process_syslog($entry, 1); unset($entry, $line); $i++; } // EOF
function rrdtool($command, $filename, $options) { global $config, $rrd_pipes; $cmd = "{$command} {$filename} {$options}"; if ($command != 'create' && $config['rrdcached']) { $cmd .= ' --daemon ' . $config['rrdcached']; } $GLOBALS['rrd_status'] = FALSE; $GLOBALS['exec_status'] = array('command' => $config['rrdtool'] . ' ' . $cmd, 'exitcode' => 1); if ($config['norrd']) { print_message("[%rRRD Disabled - {$cmd}%n]", 'color'); return NULL; } else { // FIXME, need add check if pipes exist $start = microtime(TRUE); fwrite($rrd_pipes[0], $cmd . "\n"); usleep(1000); } $stdout = trim(stream_get_contents($rrd_pipes[1])); $stderr = trim(stream_get_contents($rrd_pipes[2])); $runtime = microtime(TRUE) - $start; // Check rrdtool's output for the command. if (strpos($stdout, 'ERROR') !== FALSE) { if (isset($config['rrd']['debug']) && $config['rrd']['debug']) { logfile('rrd.log', "RRD {$stdout}, CMD: {$cmd}"); } } else { $GLOBALS['rrd_status'] = TRUE; $GLOBALS['exec_status']['exitcode'] = 0; } $GLOBALS['exec_status']['stdout'] = $stdout; $GLOBALS['exec_status']['stdin'] = $stdin; $GLOBALS['exec_status']['runtime'] = $runtime; $GLOBALS['rrdtool'][$command]['time'] += $runtime; $GLOBALS['rrdtool'][$command]['count']++; if (OBS_DEBUG) { print_message(PHP_EOL . 'RRD CMD[%y' . $cmd . '%n]', 'console', FALSE); $debug_msg = 'RRD RUNTIME[' . ($runtime > 1 ? '%r' : '%g') . round($runtime, 4) . 's%n]' . PHP_EOL; $debug_msg .= 'RRD STDOUT[' . ($GLOBALS['rrd_status'] ? '%g' : '%r') . $stdout . '%n]' . PHP_EOL; if ($stderr) { $debug_msg .= 'RRD STDERR[%r' . $stderr . '%n]' . PHP_EOL; } $debug_msg .= 'RRD_STATUS[' . ($GLOBALS['rrd_status'] ? '%gTRUE' : '%rFALSE') . '%n]'; print_message($debug_msg . PHP_EOL, 'console'); } }
function wikilogin($username, $password, $project, $useragent) { global $cookies; $getrequest = substr($project, -1) == "/" ? "w/api.php?action=login" : "/w/api.php?action=login"; $project = substr($project, 0, 7) == "http://" ? $project : "http://" . $project; logfile("Login via API to {$project} as {$username}..."); $postlogin = "******" . urlencode($username) . "&lgpassword="******"&format=php"; if (!$useragent) { $useragent = "Luxo (Toolserver; php) luxo@ts.wikimedia.org"; } $ch = curl_init($project . $getrequest); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin); curl_setopt($ch, CURLOPT_USERAGENT, $useragent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks"); $rx = curl_exec($ch); $data = unserialize($rx); curl_close($ch); if ($data['login']['result'] == "NeedToken") { $postlogin = "******" . urlencode($username) . "&lgpassword="******"&lgtoken=" . urlencode($data['login']['token']) . "&format=php"; $ch = curl_init($project . $getrequest); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin); curl_setopt($ch, CURLOPT_USERAGENT, $useragent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEFILE, "/home/luxo/cks"); curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks"); $ry = curl_exec($ch); $data = unserialize($ry); } if ($data['login']['result'] == "Success") { logfile("Login erfolgreich"); //Cookie aufbauen $cookies = array($data['login']['cookieprefix'] . "_session" => $data['login']['cookieprefix'] . "_session=" . $data['login']['sessionid'], $data['login']['cookieprefix'] . "UserID" => $data['login']['cookieprefix'] . "UserID=" . $data['login']['lguserid'], $data['login']['cookieprefix'] . "UserName" => $data['login']['cookieprefix'] . "UserName="******"Token" => $data['login']['cookieprefix'] . "Token=" . $data['login']['lgtoken']); } else { die("Login nicht erfolgreich!"); } curl_close($ch); return $cookies; }
function get404() { header("HTTP/1.0 404 Not Found"); $ru = basename($_SERVER['REQUEST_URI']); $str = <<<HEREDOC <p>Oops, the page <a href="{$_SERVER['REQUEST_URI']}">{$ru}</a> wasn't found.</p> <p>If you typed the address, check that it's entered correctly.</p> <p>Otherwise, you can try waiting a bit then reloading the page.</p> <p>-DOEQs Dev Team</p> HEREDOC; logfile('err', '404 Not Found'); return $str; }
function CollectData($bill_id) { $port_list = dbFetchRows('SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.port_id = P.port_id AND D.device_id = I.device_id', array($bill_id)); $now = dbFetchCell('SELECT NOW()'); $delta = 0; $in_delta = 0; $out_delta = 0; foreach ($port_list as $port_data) { $port_id = $port_data['port_id']; $host = $port_data['hostname']; $port = $port_data['port']; echo " Polling {$port_data['ifName']} ({$port_data['ifDescr']}) on {$port_data['hostname']}\n"; $port_data['in_measurement'] = getValue($port_data['hostname'], $port_data['port'], $port_data['ifIndex'], 'In'); $port_data['out_measurement'] = getValue($port_data['hostname'], $port_data['port'], $port_data['ifIndex'], 'Out'); $last_counters = getLastPortCounter($port_id, $bill_id); if ($last_counters['state'] == 'ok') { $port_data['last_in_measurement'] = $last_counters[in_counter]; $port_data['last_in_delta'] = $last_counters[in_delta]; $port_data['last_out_measurement'] = $last_counters[out_counter]; $port_data['last_out_delta'] = $last_counters[out_delta]; $tmp_period = dbFetchCell("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('" . mres($last_counters['timestamp']) . "')"); if ($port_data['ifSpeed'] > 0 && delta_to_bits($port_data['in_measurement'], $tmp_period) - delta_to_bits($port_data['last_in_measurement'], $tmp_period) > $port_data['ifSpeed']) { $port_data['in_delta'] = $port_data['last_in_delta']; } elseif ($port_data['in_measurement'] >= $port_data['last_in_measurement']) { $port_data['in_delta'] = $port_data['in_measurement'] - $port_data['last_in_measurement']; } else { $port_data['in_delta'] = $port_data['last_in_delta']; } if ($port_data['ifSpeed'] > 0 && delta_to_bits($port_data['out_measurement'], $tmp_period) - delta_to_bits($port_data['last_out_measurement'], $tmp_period) > $port_data['ifSpeed']) { $port_data['out_delta'] = $port_data['last_out_delta']; } elseif ($port_data['out_measurement'] >= $port_data['last_out_measurement']) { $port_data['out_delta'] = $port_data['out_measurement'] - $port_data['last_out_measurement']; } else { $port_data['out_delta'] = $port_data['last_out_delta']; } } else { $port_data['in_delta'] = '0'; $port_data['out_delta'] = '0'; } $fields = array('timestamp' => $now, 'in_counter' => $port_data['in_measurement'], 'out_counter' => $port_data['out_measurement'], 'in_delta' => $port_data['in_delta'], 'out_delta' => $port_data['out_delta']); if (dbUpdate($fields, 'bill_port_counters', "`port_id`='" . mres($port_id) . "' AND `bill_id`='{$bill_id}'") == 0) { $fields['bill_id'] = $bill_id; $fields['port_id'] = $port_id; dbInsert($fields, 'bill_port_counters'); } $delta = $delta + $port_data['in_delta'] + $port_data['out_delta']; $in_delta = $in_delta + $port_data['in_delta']; $out_delta = $out_delta + $port_data['out_delta']; } //end foreach $last_data = getLastMeasurement($bill_id); if ($last_data[state] == 'ok') { $prev_delta = $last_data[delta]; $prev_in_delta = $last_data[in_delta]; $prev_out_delta = $last_data[out_delta]; $prev_timestamp = $last_data[timestamp]; $period = dbFetchCell("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('" . mres($prev_timestamp) . "')"); } else { $prev_delta = '0'; $period = '0'; $prev_in_delta = '0'; $prev_out_delta = '0'; } if ($delta < '0') { $delta = $prev_delta; $in_delta = $prev_in_delta; $out_delta = $prev_out_delta; } if (!empty($period) && $period < '0') { logfile("BILLING: negative period! id:{$bill_id} period:{$period} delta:{$delta} in_delta:{$in_delta} out_delta:{$out_delta}"); } else { dbInsert(array('bill_id' => $bill_id, 'timestamp' => $now, 'period' => $period, 'delta' => $delta, 'in_delta' => $in_delta, 'out_delta' => $out_delta), 'bill_data'); } }
* @package observium * @subpackage snmptraps * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006 - 2012 Adam Armstrong * */ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); ini_set('log_errors', 1); ini_set('error_reporting', E_ALL); include "includes/defaults.inc.php"; include "config.php"; include "includes/definitions.inc.php"; include "includes/functions.php"; $entry = explode(",", $argv[1]); logfile($argv[1]); #print_r($entry); $device = @dbFetchRow("SELECT * FROM devices WHERE `hostname` = ?", array($entry['0'])); if (!$device['device_id']) { $device = @dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id", array($entry['0'])); } if (!$device['device_id']) { exit; } else { } $file = $config['install_dir'] . "/includes/snmptrap/" . $entry['1'] . ".inc.php"; if (is_file($file)) { include "{$file}"; } else { echo "unknown trap ({$file})"; }
function isPingable($hostname, $try_a = TRUE) { global $config; $timeout = isset($config['ping']['timeout']) ? (int) $config['ping']['timeout'] : 500; if ($timeout < 50) { $timeout = 50; } else { if ($timeout > 2000) { $timeout = 2000; } } $retries = isset($config['ping']['retries']) ? (int) $config['ping']['retries'] : 3; if ($retries < 1) { $retries = 1; } else { if ($retries > 10) { $retries = 10; } } $sleep = floor(1000000 / $retries); // interval between retries, max 1 sec $ping_debug = isset($config['ping']['debug']) && $config['ping']['debug']; if (Net_IPv4::validateIP($hostname)) { if (!$try_a) { logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | 通过的IPv4地址, 但是设备使用了IPv6通信"); print_debug('进入函数 ' . __FUNCTION__ . '() 通过IPv4地址 (' . $hostname . '但使用IPv6的通信设置'); return 0; } // Forced check for actual IPv4 address $cmd = $config['fping'] . " -t {$timeout} -c 1 -q {$hostname} 2>&1"; } else { if (Net_IPv6::checkIPv6($hostname)) { // Forced check for actual IPv6 address $cmd = $config['fping6'] . " -t {$timeout} -c 1 -q {$hostname} 2>&1"; } else { // First try IPv4 $ip = $try_a ? gethostbyname($hostname) : FALSE; // Do not check IPv4 if transport IPv6 if ($ip && $ip != $hostname) { $cmd = $config['fping'] . " -t {$timeout} -c 1 -q {$ip} 2>&1"; } else { $ip = gethostbyname6($hostname, FALSE); // Second try IPv6 if ($ip) { $cmd = $config['fping6'] . " -t {$timeout} -c 1 -q {$ip} 2>&1"; } else { // No DNS records logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | NO DNS record found"); return 0; } } } } for ($i = 1; $i <= $retries; $i++) { $output = external_exec($cmd); if ($GLOBALS['exec_status']['exitcode'] === 0) { // normal $output = '8.8.8.8 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 1.21/1.21/1.21' $tmp = explode('/', $output); $ping = $tmp[7]; if (!$ping) { $ping = 0.01; } // Protection from zero (exclude false status) } else { $ping = 0; } if ($ping) { break; } if ($ping_debug) { logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | FPING OUT ({$i}): " . $output[0]); if ($i == $retries) { $mtr = $config['mtr'] . " -r -n -c 5 {$ip}"; logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | MTR OUT:\n" . external_exec($mtr)); } } if ($i < $retries) { usleep($sleep); } } return $ping; }
$kga['server_password'] = $server_ext_password[$dbnr]; } if ($server_ext_prefix[$dbnr] != '') { $kga['server_prefix'] = $server_ext_prefix[$dbnr]; } } } // =========================================================================== $link = @mysql_connect($kga['server_hostname'], $kga['server_username'], $kga['server_password']); if (!$link) { logfile("CONNECTION ERROR (STD MYSQL): " . mysql_error()); header("Location: error.php"); exit; } if (isset($utf8)) { if ($utf8) { mysql_query("SET CHARACTER SET utf-8"); } } @mysql_select_db($kga['server_database']); /* Preparing for PDO :-) */ $pdo_dsn = $kga['server_type'] . ':dbname=' . $kga['server_database'] . ';host=' . $kga['server_hostname']; $pdo_user = $kga['server_username']; $pdo_password = $kga['server_password']; try { $pdo_conn = new PDO($pdo_dsn, $pdo_user, $pdo_password); } catch (PDOException $pdo_ex) { logfile('PDO CONNECTION FAILED: ' . $pdo_ex->getMessage()); header("Location: error.php"); } // logfile("******************** PDO database connection established.");
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);
* ================== * * Called via AJAX from the Kimai user interface. Depending on $axAction * actions are performed, e.g. editing preferences or returning a list * of customers. */ // insert KSPI $isCoreProcessor = 1; $dir_templates = "templates/core/"; require "../includes/kspi.php"; switch ($axAction) { /** * Append a new entry to the logfile. */ case 'logfile': logfile("JavaScript: " . $axValue); break; /** * Remember which project and event the user has selected for * the quick recording via the buzzer. */ /** * Remember which project and event the user has selected for * the quick recording via the buzzer. */ case 'saveBuzzerPreselection': if (!isset($kga['usr'])) { return; } $data = array(); if (isset($_REQUEST['project'])) {