Include bootstrap file, cleanup/simplify html

This commit is contained in:
Marc Hagen 2022-11-23 12:50:12 +01:00
parent 35cb2241be
commit f7737e933e
No known key found for this signature in database

123
index.php
View file

@ -1,4 +1,4 @@
<?php <?php declare(strict_types=1);
/** /**
* Hybula Looking Glass * Hybula Looking Glass
* *
@ -11,16 +11,10 @@
* @link https://github.com/hybula/lookingglass * @link https://github.com/hybula/lookingglass
*/ */
declare(strict_types=1); require __DIR__.'/bootstrap.php';
require __DIR__.'/config.php';
require __DIR__.'/LookingGlass.php';
use Hybula\LookingGlass; use Hybula\LookingGlass;
LookingGlass::validateConfig();
LookingGlass::startSession();
$detectIpAddress = LookingGlass::detectIpAddress();
if (!empty($_POST)) { if (!empty($_POST)) {
do { do {
@ -71,11 +65,15 @@ if (!empty($_POST)) {
} while (true); } while (true);
} }
$_SESSION['CSRF'] = bin2hex(random_bytes(12));
if (LG_BLOCK_CUSTOM) { if (LG_BLOCK_CUSTOM) {
include LG_CUSTOM_PHP; include LG_CUSTOM_PHP;
ob_start();
include LG_CUSTOM_HTML;
$templateData['custom_html'] = ob_get_clean();
} }
$templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(random_bytes(12));
?> ?>
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
@ -84,9 +82,9 @@ if (LG_BLOCK_CUSTOM) {
<meta content="width=device-width, initial-scale=1" name="viewport"> <meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description"> <meta content="" name="description">
<meta content="Hybula" name="author"> <meta content="Hybula" name="author">
<title><?php echo LG_TITLE; ?></title> <title><?php echo $templateData['title'] ?></title>
<link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" rel="stylesheet"> <link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" rel="stylesheet">
<?php if (LG_CSS_OVERRIDES) { echo '<link href="'.LG_CSS_OVERRIDES.'" rel="stylesheet">'; } ?> <?php if ($templateData['custom_css']) { echo '<link href="'.$templateData['custom_css'].'" rel="stylesheet">'; } ?>
</head> </head>
<body> <body>
@ -94,23 +92,23 @@ if (LG_BLOCK_CUSTOM) {
<header class="d-flex align-items-center pb-3 mb-5 border-bottom"> <header class="d-flex align-items-center pb-3 mb-5 border-bottom">
<div class="col-8"> <div class="col-8">
<a class="d-flex align-items-center text-dark text-decoration-none" href="<?php echo LG_LOGO_URL; ?>" target="_blank"> <a class="d-flex align-items-center text-dark text-decoration-none" href="<?php echo $templateData['logo_url'] ?>" target="_blank">
<?php echo LG_LOGO; ?> <?php echo $templateData['logo_data'] ?>
</a> </a>
</div> </div>
<div class="col-4 float-end"> <div class="col-4 float-end">
<select class="form-select" onchange="window.location = this.options[this.selectedIndex].value"> <select class="form-select" onchange="window.location = this.options[this.selectedIndex].value">
<option selected><?php echo LG_LOCATION; ?></option> <option selected><?php echo $templateData['current_location'] ?></option>
<?php foreach (LG_LOCATIONS as $location => $link) { ?> <?php foreach ($templateData['locations'] as $location => $link): ?>
<option value="<?php echo $link; ?>"><?php echo $location; ?></option> <option value="<?php echo $link ?>"><?php echo $location ?></option>
<?php } ?> <?php endforeach ?>
</select> </select>
</div> </div>
</header> </header>
<main> <main>
<?php if (LG_BLOCK_NETWORK) { ?> <?php if (LG_BLOCK_NETWORK): ?>
<div class="row mb-5"> <div class="row mb-5">
<div class="card shadow-lg"> <div class="card shadow-lg">
<div class="card-body p-3"> <div class="card-body p-3">
@ -120,23 +118,23 @@ if (LG_BLOCK_CUSTOM) {
<div class="col-md-7"> <div class="col-md-7">
<label class="mb-2 text-muted">Location</label> <label class="mb-2 text-muted">Location</label>
<div class="input-group mb-3"> <div class="input-group mb-3">
<input type="text" class="form-control" value="<?php echo LG_LOCATION; ?>" onfocus="this.select()" readonly=""> <input type="text" class="form-control" value="<?php echo $templateData['current_location'] ?>" onfocus="this.select()" readonly="">
<a class="btn btn-outline-secondary" href="https://www.openstreetmap.org/search?query=<?php echo urlencode(LG_LOCATION); ?>" target="_blank">Map</a> <a class="btn btn-outline-secondary" href="https://www.openstreetmap.org/search?query=<?php echo urlencode($templateData['maps_query']); ?>" target="_blank">Map</a>
<?php if (!empty(LG_LOCATIONS)) { ?> <?php if (!empty($templateData['locations'])): ?>
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Locations</button> <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Locations</button>
<ul class="dropdown-menu dropdown-menu-end"> <ul class="dropdown-menu dropdown-menu-end">
<?php foreach (LG_LOCATIONS as $location => $link) { ?> <?php foreach ($templateData['locations'] as $location => $link): ?>
<li><a class="dropdown-item" href="<?php echo $link; ?>"><?php echo $location; ?></a></li> <li><a class="dropdown-item" href="<?php echo $link ?>"><?php echo $location ?></a></li>
<?php } ?> <?php endforeach ?>
</ul> </ul>
<?php } ?> <?php endif ?>
</div> </div>
</div> </div>
<div class="col-md-5"> <div class="col-md-5">
<label class="mb-2 text-muted">Facility</label> <label class="mb-2 text-muted">Facility</label>
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" value="<?php echo LG_FACILITY; ?>" onfocus="this.select()" readonly=""> <input type="text" class="form-control" value="<?php echo $templateData['facility'] ?>" onfocus="this.select()" readonly="">
<a href="<?php echo LG_FACILITY_URL; ?>" class="btn btn-outline-secondary" target="_blank">PeeringDB</a> <a href="<?php echo $templateData['facility_url'] ?>" class="btn btn-outline-secondary" target="_blank">PeeringDB</a>
</div> </div>
</div> </div>
</div> </div>
@ -145,22 +143,22 @@ if (LG_BLOCK_CUSTOM) {
<div class="col-md-3"> <div class="col-md-3">
<label class="mb-2 text-muted">Test IPv4</label> <label class="mb-2 text-muted">Test IPv4</label>
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" value="<?php echo LG_IPV4; ?>" onfocus="this.select()" readonly=""> <input type="text" class="form-control" value="<?php echo $templateData['ipv4'] ?>" onfocus="this.select()" readonly="">
<button class="btn btn-outline-secondary" onclick="copyToClipboard('<?php echo LG_IPV4; ?>', this)">Copy</button> <button class="btn btn-outline-secondary" onclick="copyToClipboard('<?php echo $templateData['ipv4'] ?>', this)">Copy</button>
</div> </div>
</div> </div>
<div class="col-md-5"> <div class="col-md-5">
<label class="mb-2 text-muted">Test IPv6</label> <label class="mb-2 text-muted">Test IPv6</label>
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" value="<?php echo LG_IPV6; ?>" onfocus="this.select()" readonly=""> <input type="text" class="form-control" value="<?php echo $templateData['ipv6'] ?>" onfocus="this.select()" readonly="">
<button class="btn btn-outline-secondary" onclick="copyToClipboard('<?php echo LG_IPV6; ?>', this)">Copy</button> <button class="btn btn-outline-secondary" onclick="copyToClipboard('<?php echo $templateData['ipv6'] ?>', this)">Copy</button>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<label class="mb-2 text-muted">Your IP</label> <label class="mb-2 text-muted">Your IP</label>
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" value="<?php echo $detectIpAddress; ?>" onfocus="this.select()" readonly=""> <input type="text" class="form-control" value="<?php echo $templateData['user_ip'] ?>" onfocus="this.select()" readonly="">
<button class="btn btn-outline-secondary" onclick="copyToClipboard('<?php echo $detectIpAddress; ?>', this)">Copy</button> <button class="btn btn-outline-secondary" onclick="copyToClipboard('<?php echo $templateData['user_ip'] ?>', this)">Copy</button>
</div> </div>
</div> </div>
</div> </div>
@ -168,48 +166,50 @@ if (LG_BLOCK_CUSTOM) {
</div> </div>
</div> </div>
</div> </div>
<?php } ?> <?php endif ?>
<?php if (LG_BLOCK_LOOKINGGLAS) { ?> <?php if (LG_BLOCK_LOOKINGGLAS): ?>
<div class="row pb-5"> <div class="row pb-5">
<div class="card shadow-lg"> <div class="card shadow-lg">
<div class="card-body p-3"> <div class="card-body p-3">
<h1 class="fs-4 card-title mb-4">Looking Glass</h1> <h1 class="fs-4 card-title mb-4">Looking Glass</h1>
<form method="POST" action="/" autocomplete="off"> <form method="POST" action="/" autocomplete="off">
<input type="hidden" name="csrfToken" value="<?php echo $_SESSION['CSRF']; ?>"> <input type="hidden" name="csrfToken" value="<?php echo $templateData['csrfToken'] ?>">
<div class="row"> <div class="row">
<div class="col-md-7 mb-3"> <div class="col-md-7 mb-3">
<div class="input-group"> <div class="input-group">
<span class="input-group-text" id="basic-addon1">Target</span> <span class="input-group-text" id="basic-addon1">Target</span>
<input type="text" class="form-control" placeholder="IP address or host..." name="targetHost" value="<?php if (isset($_SESSION['TARGET'])) { echo $_SESSION['TARGET']; } ?>" required=""> <input type="text" class="form-control" placeholder="IP address or host..." name="targetHost" value="<?php echo $templateData['session_target'] ?>" required="">
</div> </div>
</div> </div>
<div class="col-md-5 mb-3"> <div class="col-md-5 mb-3">
<div class="input-group"> <div class="input-group">
<label class="input-group-text">Method</label> <label class="input-group-text">Method</label>
<select class="form-select" name="backendMethod" id="backendMethod"> <select class="form-select" name="backendMethod" id="backendMethod">
<?php foreach (LG_METHODS as $method) { ?> <?php foreach ($templateData['methods'] as $method): ?>
<option value="<?php echo $method; ?>"<?php if (isset($_SESSION['METHOD']) && $_SESSION['METHOD'] == $method) { echo 'selected'; } ?>><?php echo $method; ?></option> <option value="<?php echo $method ?>"<?php if($templateData['session_method'] === $method): ?> selected<?php endif ?>><?php echo $method ?></option>
<?php } ?> <?php endforeach ?>
</select> </select>
</div> </div>
</div> </div>
</div> </div>
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<?php if (LG_TERMS) { ?> <?php if ($templateData['tos']): ?>
<div class="form-check"> <div class="form-check">
<input type="checkbox" id="checkTerms" name="checkTerms" class="form-check-input"<?php if (isset($_SESSION['TERMS'])) { echo 'checked'; } ?>> <input type="checkbox" id="checkTerms" name="checkTerms" class="form-check-input"<?php echo $templateData['session_tos_checked'] ?>>
<label for="checkTerms" class="form-check-label">I agree with the <a href="<?php echo LG_TERMS; ?>" target="_blank">Terms of Use</a></label> <label for="checkTerms" class="form-check-label">I agree with the <a href="<?php echo $templateData['tos'] ?>" target="_blank">Terms of Use</a></label>
</div> </div>
<?php } ?> <?php endif ?>
<button type="submit" class="btn btn-primary ms-auto" id="executeButton" name="submitForm"> <button type="submit" class="btn btn-primary ms-auto" id="executeButton" name="submitForm">
Execute Execute
</button> </button>
</div> </div>
<?php if (isset($errorMessage)) echo '<div class="alert alert-danger mt-3" role="alert">'.$errorMessage.'</div>'; ?> <?php if ($templateData['error_message']): ?>
<div class="alert alert-danger mt-3" role="alert"><?php echo $templateData['error_message'] ?></div>
<?php endif ?>
<div class="card card-body bg-light mt-4" style="display: none;" id="outputCard"> <div class="card card-body bg-light mt-4" style="display: none;" id="outputCard">
<pre id="outputContent" style="overflow: hidden; white-space: pre; word-wrap: normal;"></pre> <pre id="outputContent" style="overflow: hidden; white-space: pre; word-wrap: normal;"></pre>
@ -219,45 +219,44 @@ if (LG_BLOCK_CUSTOM) {
</div> </div>
</div> </div>
</div> </div>
<?php } ?> <?php endif ?>
<?php if (LG_BLOCK_SPEEDTEST) { ?> <?php if (LG_BLOCK_SPEEDTEST): ?>
<div class="row pb-5"> <div class="row pb-5">
<div class="card shadow-lg"> <div class="card shadow-lg">
<div class="card-body p-3"> <div class="card-body p-3">
<h1 class="fs-4 card-title mb-4">Speedtest</h1> <h1 class="fs-4 card-title mb-4">Speedtest</h1>
<?php if (LG_SPEEDTEST_IPERF) { ?> <?php if ($templateData['speedtest_iperf']): ?>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-md-6"> <div class="col-md-6">
<label class="mb-2 text-muted"><?php echo LG_SPEEDTEST_LABEL_INCOMING; ?></label> <label class="mb-2 text-muted"><?php echo $templateData['speedtest_incoming_label'] ?></label>
<p><code><?php echo LG_SPEEDTEST_CMD_INCOMING; ?></code></p> <p><code><?php echo $templateData['speedtest_incoming_cmd']; ?></code></p>
<button class="btn btn-sm btn-outline-secondary" onclick="copyToClipboard('<?php echo LG_SPEEDTEST_CMD_INCOMING; ?>', this)">Copy</button> <button class="btn btn-sm btn-outline-secondary" onclick="copyToClipboard('<?php echo $templateData['speedtest_incoming_cmd'] ?>', this)">Copy</button>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label class="mb-2 text-muted"><?php echo LG_SPEEDTEST_LABEL_OUTGOING; ?></label> <label class="mb-2 text-muted"><?php echo $templateData['speedtest_outgoing_label'] ?></label>
<p><code><?php echo LG_SPEEDTEST_CMD_OUTGOING; ?></code></p> <p><code><?php echo $templateData['speedtest_outgoing_cmd'] ?></code></p>
<button class="btn btn-sm btn-outline-secondary" onclick="copyToClipboard('<?php echo LG_SPEEDTEST_CMD_OUTGOING; ?>', this)">Copy</button> <button class="btn btn-sm btn-outline-secondary" onclick="copyToClipboard('<?php echo $templateData['speedtest_outgoing_cmd'] ?>', this)">Copy</button>
</div> </div>
</div> </div>
<?php } ?> <?php endif ?>
<div class="row"> <div class="row">
<label class="mb-2 text-muted">Test Files</label> <label class="mb-2 text-muted">Test Files</label>
<div class="btn-group input-group mb-3"> <div class="btn-group input-group mb-3">
<?php foreach (LG_SPEEDTEST_FILES as $file => $link) { ?> <?php foreach ($templateData['speedtest_files'] as $file => $link): ?>
<a href="<?php echo $link; ?>" class="btn btn-outline-secondary"><?php echo $file; ?></a> <a href="<?php echo $link ?>" class="btn btn-outline-secondary"><?php echo $file ?></a>
<?php } ?> <?php endforeach ?>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<?php } ?> <?php endif ?>
<?php if (LG_BLOCK_CUSTOM) { include LG_CUSTOM_HTML; } ?>
<?php echo $templateData['custom_html'] ?>
</main> </main>
<footer class="pt-3 mt-5 my-5 text-muted border-top"> <footer class="pt-3 mt-5 my-5 text-muted border-top">