query("SET time_zone = '+00:00'"); } return $handle; } function flash_message(string $msg, string $type = 'info', bool $unsafe = false): void { if (session_status() === PHP_SESSION_NONE) session_start(); $types = [ "info", "success", "danger", "warning" ]; if (!in_array($type, $types)) { throw new InvalidArgumentException("Flash type: \"$type\" does not exist"); } $key = 'flash_messages'; if (!isset($_SESSION[$key])) { $_SESSION[$key] = []; } if (count($_SESSION[$key]) >= 100) { $_SESSION[$key] = []; throw new Exception('Too many flashed messages!'); } $_SESSION[$key][] = [ "message" => ($unsafe) ? $msg : htmlspecialchars($msg), "type" => $type ]; } function get_flash_messages(): ?array { if (session_status() === PHP_SESSION_NONE) session_start(); $key = 'flash_messages'; if (empty($_SESSION[$key])) { return null; } $msgs = $_SESSION[$key]; $_SESSION[$key] = []; return $msgs; } function page_header(string $title, array $toolbar_links = []) { $ref_uuid = filter_input(INPUT_GET, 'ref_uuid'); $prefer_ref_uuid = !empty($ref_uuid); if ($prefer_ref_uuid) $ref_uuid = htmlspecialchars($ref_uuid); $host = strtolower(filter_input(INPUT_GET, 'host')); if (!empty($host) && !is_valid_host($host)) { $host = NULL; } ?> <?=$title?>

Kunne ikke fortsette

Feilmelding:

Klikk her for å gå tilbake prepare($sql); $stmt->bind_param("s", $param); $stmt->execute(); $result = $stmt->get_result(); $assoc = $result->fetch_assoc(); return $assoc; } function pinglerr_get_scan_history(?string $host = null, ?string $ref_uuid = null, ?int $max_rows = null): ?array { if ($host !== null) { $sql = "SELECT * FROM pinglerr_scans WHERE host = ? AND ref_uuid IS NULL ORDER BY start_date DESC"; $param = $host; } if ($ref_uuid !== null) { $sql = "SELECT * FROM pinglerr_scans WHERE ref_uuid= ? ORDER BY start_date DESC"; $param = $ref_uuid; } if ($max_rows !== null) { $sql = $sql . ' LIMIT ' . $max_rows; } $scans = (function() use ($sql, $param): ?array { $stmt = get_mysqli()->prepare($sql); $stmt->bind_param("s", $param); $stmt->execute(); $result = $stmt->get_result(); $assoc_array = []; while ($row = $result->fetch_assoc()) { $assoc_array[] = $row; } if (empty($assoc_array)) { return null; } return $assoc_array; })(); return $scans; } $route['default'] = function() { $ref_uuid = filter_input(INPUT_GET, 'ref_uuid'); $prefer_ref_uuid = !empty($ref_uuid); if ($prefer_ref_uuid) $ref_uuid = htmlspecialchars($ref_uuid); $host = strtolower(filter_input(INPUT_GET, 'host')); if (!empty($host) && !is_valid_host($host)) { suicide_user_bad_request('Ugyldig vert adresse'); } if ($prefer_ref_uuid) { $scan = pinglerr_get_scan(ref_uuid: $ref_uuid); } else { $scan = pinglerr_get_scan(host: $host); } $function['show_form'] = function() use($ref_uuid, $prefer_ref_uuid, $host) { ?>

Pinglerr

Sjekk tilkobling status til IP-adresse eller annen tjeneste







Historikk

Tidligere skanninger som er gjort på denne verten eller referanse.

Start Dato Handling
Detaljer ]

Sanntid statistikk

TilkoblingUkjent
Vert
Referanse

Ping (siste)
Vent
Pakke tap
Vent
Suksess-rate
Vent

'?p=stop_scanning&scan_id=' . $scan['id'] . ($prefer_ref_uuid ? '&ref_uuid=' . $ref_uuid : '') . (!empty($host) ? '&host=' . $host : ''), 'name' => 'Stop skanning', 'type' => 'danger' ] ]); } else { page_header('Pinglerr'); } ?> get_referer(), 'name' => 'Gå tilbake' ] ]); ?>

Fullstendig statistikk

StatusAktiv StatusFerdig Vert ID
prepare( "INSERT INTO pinglerr_scans (host, ref_uuid, status_code, end_date) VALUES (?, ?, ?, NOW() + INTERVAL ? SECOND)" ); $status_code = 'WAITING'; $time_limit_in_seconds = filter_input(INPUT_POST, 'time_limit'); if (!is_numeric($time_limit_in_seconds)) suicide_user_bad_request('time_limit is not numeric'); if ($time_limit_in_seconds > 31536000) suicide_user_bad_request('time_limit should not be above 1 year'); if ($time_limit_in_seconds < 0) suicide_user_bad_request('time_limit should not be a negative value'); // run forever if ($time_limit_in_seconds == 0) $time_limit_in_seconds = 315569260; $stmt->bind_param("sssi", $host, $ref_uuid, $status_code, $time_limit_in_seconds); $stmt->execute(); } else { flash_message('Det eksisterer allerede en aktiv skanning på denne verten eller referansen'); if ($prefer_ref_uuid) { header('Location: ?p=default&ref_uuid=' . $ref_uuid); } else { header('Location: ?p=default&host=' . $host); } die(); } if ($prefer_ref_uuid) { header('Location: ?p=default&ref_uuid=' . $ref_uuid); } else { header('Location: ?p=default&host=' . $host); } }; $route['stop_scanning'] = function() { $confirm = filter_input(INPUT_GET, 'confirm'); $scan_id = filter_input(INPUT_GET, 'scan_id'); $ref_uuid = filter_input(INPUT_GET, 'ref_uuid'); $prefer_ref_uuid = !empty($ref_uuid); if ($prefer_ref_uuid) $ref_uuid = htmlspecialchars($ref_uuid); $host = strtolower(filter_input(INPUT_GET, 'host')); if (!$prefer_ref_uuid && !empty($host) && !is_valid_host($host)) { suicide_user_bad_request('Ugyldig vertsnavn'); } if (boolval($confirm)) { $scan = pinglerr_get_scan(scan_id: $scan_id); if (empty($scan)) { suicide_user_bad_request('Fant ikke noen aktiv skanning'); } $stmt = get_mysqli()->prepare( "UPDATE pinglerr_scans SET status_code = ?, end_date = NOW(), error_message = ? WHERE status_code IN ('ACTIVE', 'WAITING') AND id = ?" ); $status_code = 'DONE'; $error_message = 'Manually stopped by user'; $stmt->bind_param("sss", $status_code, $error_message, $scan['id'] ); $stmt->execute(); if ($prefer_ref_uuid) { header('Location: ?p=default&host=' . $host . '&ref_uuid=' . $ref_uuid); } else { header('Location: ?p=default&host=' . $host); } flash_message('Du har nå stanset skanningen', 'success'); die(); } else { page_header('Er du sikker? - Pingler'); ?>

Er du sikker?

Vil du virkelig stanse denne skanningen?

Ja det vil jeg! ] Nei ta meg tilbake igjen ] prepare( "SELECT * FROM pinglerr_scans WHERE status_code IN ('ACTIVE', 'WAITING')" ); $stmt->execute(); $result = $stmt->get_result(); $assoc_array = []; while ($row = $result->fetch_assoc()) { $assoc_array[] = $row; } return $assoc_array; })(); header('Content-type: application/json'); echo json_encode($scans); }; // not in use anymore, replaced with daemon_bulk_update $route['daemon_update'] = function() { $scan_id = filter_input(INPUT_GET, 'scan_id'); if (empty($scan_id)) { suicide_user_bad_request('Mangler scan_id query parameter'); } $scan = pinglerr_get_scan(scan_id: $scan_id); if ($scan === null) { suicide_user_bad_request('Kunne ikke finne scan fra scan_id'); } // if time is up change the status to DONE and also exit the script // TODO: this would probably be more suitable in the route daemon_jobs or some other // endpoint that the daemon would periodically call (function() use($scan) { $current_epoch = time(); $end_epoch = strtotime($scan['end_date']); if ($current_epoch > $end_epoch) { $stmt = get_mysqli()->prepare( "UPDATE pinglerr_scans SET status_code = ?, error_message = ? WHERE status_code IN ('ACTIVE', 'WAITING') AND id = ?" ); $status_code = 'DONE'; $error_message = 'Stopped because end_date was reached'; $stmt->bind_param("sss", $status_code, $error_message, $scan['id'] ); $stmt->execute(); die(); } })(); // set scan status from WAITING to ACTIVE (function() use($scan) { $stmt = get_mysqli()->prepare( "UPDATE pinglerr_scans SET status_code = ? WHERE id = ?" ); $status_code = 'ACTIVE'; $stmt->bind_param("si", $status_code, $scan['id'], ); $stmt->execute(); })(); (function() use($scan) { $pkt_transmitted = filter_input(INPUT_GET, 'pkt_transmitted'); $pkt_received = filter_input(INPUT_GET, 'pkt_received'); $ping_avg = filter_input(INPUT_GET, 'ping_avg'); $stmt = get_mysqli()->prepare( "INSERT INTO pinglerr_pings (scan_id, ping_avg, pkt_transmitted, pkt_received) VALUES (?,?,?,?)" ); $stmt->bind_param("idii", $scan['id'], $ping_avg, $pkt_transmitted, $pkt_received, ); $stmt->execute(); })(); }; $route['daemon_bulk_update'] = function() { $bulk_pings = json_decode(file_get_contents('php://input'), true); foreach ($bulk_pings as $ping) { $scan_id = $ping['scan_id']; $pkt_transmitted = $ping['pkt_transmitted']; $pkt_received = $ping['pkt_received']; if (!isset($ping['ping_avg'])) { $ping_avg = null; } else { $ping_avg = $ping['ping_avg']; } $scan = pinglerr_get_scan(scan_id: $scan_id); if ($scan === null) { suicide_user_bad_request('Kunne ikke finne scan for scan_id'); } $time_is_up = (function() use($scan) { $current_epoch = time(); $end_epoch = strtotime($scan['end_date']); if ($current_epoch > $end_epoch) { $stmt = get_mysqli()->prepare( "UPDATE pinglerr_scans SET status_code = ?, error_message = ? WHERE status_code IN ('ACTIVE', 'WAITING') AND id = ?" ); $status_code = 'DONE'; $error_message = 'Stopped because end_date was reached'; $stmt->bind_param("sss", $status_code, $error_message, $scan['id'] ); $stmt->execute(); return true; } return false; })(); if ($time_is_up) { continue; } // set scan status from WAITING to ACTIVE (function() use($scan) { $stmt = get_mysqli()->prepare( "UPDATE pinglerr_scans SET status_code = ? WHERE id = ?" ); $status_code = 'ACTIVE'; $stmt->bind_param("si", $status_code, $scan['id'], ); $stmt->execute(); })(); (function() use($scan, $pkt_transmitted, $pkt_received, $ping_avg) { $stmt = get_mysqli()->prepare( "INSERT INTO pinglerr_pings (scan_id, ping_avg, pkt_transmitted, pkt_received) VALUES (?,?,?,?)" ); $stmt->bind_param("idii", $scan['id'], $ping_avg, $pkt_transmitted, $pkt_received, ); $stmt->execute(); })(); } }; $route['api_chart'] = function() { $scan_id = filter_input(INPUT_GET, 'scan_id'); $since = intval(filter_input(INPUT_GET, 'since')); $limit_length = intval(filter_input(INPUT_GET, 'limit_length')); $pings = (function() use($scan_id, $since): array { $stmt = get_mysqli()->prepare( "SELECT ping_avg, pkt_transmitted, pkt_received, date_added FROM pinglerr_pings WHERE scan_id = ? AND date_added > FROM_UNIXTIME(?) ORDER BY date_added ASC" ); $stmt->bind_param("ii", $scan_id, $since); $stmt->execute(); $result = $stmt->get_result(); $assoc_array = []; while ($row = $result->fetch_assoc()) { $assoc_array[] = $row; } return $assoc_array; })(); if (empty($pings)) { http_response_code(204); die(); } if ($limit_length > 0 && $limit_length < count($pings)) { $merged_pings = []; $merge_gap = count($pings) / $limit_length; $merge_iteration = 0; $merge_remainder = 0; $ping_avg_sum_storage = []; $ping_pkt_transmitted_storage = []; $ping_pkt_received_storage = []; foreach ($pings as $ping) { if ($merge_iteration >= $merge_gap - $merge_remainder) { $merge_remainder+= $merge_iteration - $merge_gap; $how_many_nulls = 0; for ($i=0; $i < count($ping_avg_sum_storage); $i++) { if ($ping_avg_sum_storage[$i] === null) { $how_many_nulls++; } } if ($how_many_nulls > count($ping_avg_sum_storage) / 2) { $ping_avg = null; } else { for ($i=0; $i < count($ping_avg_sum_storage); $i++) { if ($ping_avg_sum_storage[$i] === null) { unset($ping_avg_sum_storage[$i]); } } $ping_avg = round(array_sum($ping_avg_sum_storage) / count($ping_avg_sum_storage), 3); } $merged_pings[] = [ 'ping_avg' => $ping_avg, 'date_added' => $ping['date_added'], 'pkt_transmitted' => round(array_sum($ping_pkt_transmitted_storage) / count($ping_pkt_transmitted_storage), 3), 'pkt_received' => round(array_sum($ping_pkt_received_storage) / count($ping_pkt_received_storage), 3), ]; $ping_pkt_transmitted_storage = []; $ping_pkt_received_storage = []; $ping_avg_sum_storage = []; $merge_iteration = 0; } $ping_pkt_transmitted_storage[] = $ping['pkt_transmitted']; $ping_pkt_received_storage[] = $ping['pkt_received']; $ping_avg_sum_storage[] = $ping['ping_avg']; $merge_iteration++; } $pings = $merged_pings; } //echo 'Gap: ' . htmlspecialchars($merge_gap) . ' Antall: ' . count($pings) . ' Remains: ' . $merge_remainder; //die(); header('Content-type: application/json'); echo json_encode([ 'latest' => strtotime($pings[count($pings) - 1]['date_added']), 'pings' => $pings, ]); }; $route['api_stats'] = function() { $ref_uuid = filter_input(INPUT_GET, 'ref_uuid'); $prefer_ref_uuid = !empty($ref_uuid); if ($prefer_ref_uuid) $ref_uuid = htmlspecialchars($ref_uuid); $host = strtolower(filter_input(INPUT_GET, 'host')); if (!$prefer_ref_uuid && !empty($host) && !is_valid_host($host)) { suicide_user_bad_request('Ugyldig vertsnavn'); } $scan_id = filter_input(INPUT_GET, 'scan_id'); if ($prefer_ref_uuid) { $scan = pinglerr_get_scan(ref_uuid: $ref_uuid); } elseif(!empty($host)) { $scan = pinglerr_get_scan($host); } elseif(!empty($scan_id)) { $scan = pinglerr_get_scan( scan_id: $scan_id, must_be_active_or_waiting: false ); } else { suicide_user_bad_request('Mangler ref_uuid, host eller scan_id parameter'); } if ($scan === null) { suicide_user_bad_request('Kunne ikke finne noen aktive skanninger for denne verten eller referanse'); } $since = intval(filter_input(INPUT_GET, 'since')); $pings = (function() use($scan, $since): array { $stmt = get_mysqli()->prepare( "SELECT * FROM pinglerr_pings WHERE scan_id = ? AND date_added > FROM_UNIXTIME(?) ORDER BY date_added DESC" ); $stmt->bind_param("is", $scan['id'], $since); $stmt->execute(); $result = $stmt->get_result(); $assoc_array = []; while ($row = $result->fetch_assoc()) { $assoc_array[] = $row; } return $assoc_array; })(); if (empty($pings)) { http_response_code(204); die(); } $pkt_transmitted = (function() use($pings): int { $pkts = 0; foreach ($pings as $ping_row) { if ($ping_row['pkt_transmitted'] === null) { continue; } $pkts = $pkts + $ping_row['pkt_transmitted']; } return $pkts; })(); $pkt_received = (function() use($pings): int { $pkts = 0; foreach ($pings as $ping_row) { if ($ping_row['pkt_received'] === null) { continue; } $pkts = $pkts + $ping_row['pkt_received']; } return $pkts; })(); $packet_loss_percentage = (function() use($pkt_transmitted, $pkt_received): float { try { $packet_loss_percentage = $pkt_received / $pkt_transmitted * 100; } catch (\DivisionByZeroError $th) { return 100; } if ($packet_loss_percentage > 100) { $packet_loss_percentage = 100; } else { $packet_loss_percentage = 100 - $packet_loss_percentage; } return $packet_loss_percentage; })(); // TODO: this is just packet_loss_percentage reversed! make a more proper uptime calculation $uptime_percentage = (function() use($packet_loss_percentage): float { return 100 - $packet_loss_percentage; })(); // TODO: this is too simple, but it works for now. make a more proper calculation using jitter $connection_status = (function() use($pings, $packet_loss_percentage) { if ($pings[0]['ping_avg'] === null) { return 'OFFLINE'; } if ($packet_loss_percentage >= 2) { return 'UNSTABLE'; } return 'ONLINE'; })(); header('Content-type: application/json'); return json_encode([ 'latest' => strtotime($pings[0]['date_added']), 'scan_id' => $scan['id'], 'host' => $scan['host'], 'ref_uuid' => $scan['ref_uuid'], 'status_code' => $scan['status_code'], 'connection_status' => $connection_status, 'pkt_transmitted' => $pkt_transmitted, 'pkt_received' => $pkt_received, 'ping_latest' => round($pings[0]['ping_avg'], 0, PHP_ROUND_HALF_EVEN), 'packet_loss_percentage' => round($packet_loss_percentage, 0, PHP_ROUND_HALF_UP), 'uptime_percentage' => round($uptime_percentage, 0, PHP_ROUND_HALF_DOWN), ]); }; $page = filter_input(INPUT_GET, 'p'); if (empty($page)) { $page = 'default'; } if (isset($route[$page])) { die($route[$page]()); } http_response_code(404); page_header('Kunne ikke finne siden') ?>

Siden ble ikke funnet

Klikk her for å gå tilbake