Compare commits
9 commits
feature/ro
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
8bfd63caac | ||
|
834c4da7c4 | ||
|
b0c3eca177 | ||
|
45c25fa5f3 | ||
|
a763bf1d8c | ||
|
1ace4c95b5 | ||
|
df6abe3ed3 | ||
|
8e1a050be4 | ||
|
6cc70e3982 |
7 changed files with 83 additions and 46 deletions
|
@ -40,7 +40,27 @@ class Subnet
|
||||||
throw new Exception("CIDR must be between 0 and 32.");
|
throw new Exception("CIDR must be between 0 and 32.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$hosts = (1 << (32 - $cidr)) - 2; // Excludes network and broadcast
|
if ($cidr === 32) {
|
||||||
|
return [
|
||||||
|
'network' => $ip,
|
||||||
|
'first' => $ip,
|
||||||
|
'last' => $ip,
|
||||||
|
'hosts' => 1,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cidr === 31) {
|
||||||
|
$ipLong = ip2long($ip);
|
||||||
|
$network = $ipLong & (-1 << (32 - $cidr));
|
||||||
|
return [
|
||||||
|
'network' => long2ip($network),
|
||||||
|
'first' => long2ip($network),
|
||||||
|
'last' => long2ip($network + 1),
|
||||||
|
'hosts' => 2,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$hosts = (1 << (32 - $cidr)) - 2;
|
||||||
$ipLong = ip2long($ip);
|
$ipLong = ip2long($ip);
|
||||||
$mask = -1 << (32 - $cidr);
|
$mask = -1 << (32 - $cidr);
|
||||||
$network = $ipLong & $mask;
|
$network = $ipLong & $mask;
|
||||||
|
@ -56,6 +76,7 @@ class Subnet
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate IPv6
|
* Calculate IPv6
|
||||||
*
|
*
|
||||||
|
@ -70,35 +91,50 @@ class Subnet
|
||||||
throw new Exception("CIDR must be between 0 and 128.");
|
throw new Exception("CIDR must be between 0 and 128.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert IP to binary representation
|
if ($cidr === 128) {
|
||||||
$binaryIP = inet_pton($ip);
|
return [
|
||||||
if ($binaryIP === false) {
|
'network' => $ip,
|
||||||
throw new Exception("Failed to parse IPv6 address.");
|
'first' => $ip,
|
||||||
|
'last' => $ip,
|
||||||
|
'hosts' => 1,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate network address
|
if ($cidr === 127) {
|
||||||
|
$binaryIP = inet_pton($ip);
|
||||||
|
$network = substr($binaryIP, 0, intval($cidr / 8));
|
||||||
|
$firstHost = inet_ntop($network);
|
||||||
|
$lastHost = inet_ntop($binaryIP);
|
||||||
|
return [
|
||||||
|
'network' => $firstHost,
|
||||||
|
'first' => $firstHost,
|
||||||
|
'last' => $lastHost,
|
||||||
|
'hosts' => 2,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// General case for other IPv6 subnets
|
||||||
|
$totalHosts = bcpow(2, 128 - $cidr); // Number of total IPs
|
||||||
|
$binaryIP = inet_pton($ip);
|
||||||
|
|
||||||
|
// Calculate the network address
|
||||||
$network = substr($binaryIP, 0, intval($cidr / 8));
|
$network = substr($binaryIP, 0, intval($cidr / 8));
|
||||||
$remainder = $cidr % 8;
|
$remainder = $cidr % 8;
|
||||||
|
|
||||||
if ($remainder > 0) {
|
if ($remainder > 0) {
|
||||||
$lastByte = ord($binaryIP[$cidr / 8]) & (0xFF << (8 - $remainder));
|
$lastByte = ord($binaryIP[intval($cidr / 8)]) & (0xFF << (8 - $remainder));
|
||||||
$network .= chr($lastByte);
|
$network .= chr($lastByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pad the rest with zeros
|
|
||||||
$network = str_pad($network, 16, "\0");
|
$network = str_pad($network, 16, "\0");
|
||||||
|
|
||||||
// Calculate first and last addresses
|
|
||||||
$networkAddress = inet_ntop($network);
|
$networkAddress = inet_ntop($network);
|
||||||
$totalHosts = $cidr == 128 ? 1 : bcpow(2, 128 - $cidr);
|
|
||||||
$firstHost = ($cidr == 128) ? $networkAddress : inet_ntop($network);
|
|
||||||
$lastHost = inet_ntop(pack("H*", str_repeat("F", 32)));
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'network' => $networkAddress,
|
'network' => $networkAddress,
|
||||||
'first' => $firstHost,
|
'first' => $cidr == 128 ? $networkAddress : inet_ntop($network),
|
||||||
'last' => $lastHost,
|
'last' => $cidr == 128 ? $networkAddress : inet_ntop($network), // Adjusted for simplicity
|
||||||
'hosts' => $totalHosts,
|
'hosts' => $totalHosts,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -10,7 +10,8 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.3.0",
|
"php": ">=8.3.0",
|
||||||
"filp/whoops": "^2.16",
|
"filp/whoops": "^2.16",
|
||||||
"vlucas/phpdotenv": "^5.6"
|
"vlucas/phpdotenv": "^5.6",
|
||||||
|
"ext-bcmath": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/var-dumper": "^7.1",
|
"symfony/var-dumper": "^7.1",
|
||||||
|
|
|
@ -73,7 +73,7 @@ const errorMsg = (message: string): void => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex justify-center items-center min-h-screen">
|
<div class="flex justify-center items-center min-h-screen">
|
||||||
<div class="w-3/4 sm:w-3/4 md:w-2/3 lg:w-2/4 xl:w-2/5 2xl:w-1/5 -translate-y-24">
|
<div class="w-3/4 sm:w-3/4 md:w-2/3 lg:w-2/4 xl:w-2/5 2xl:w-1/4 translate-y-0 md:-translate-y-2">
|
||||||
<img src="https://www.bit.nl/assets/images/bit_logo_white.png" alt="BIT Logo" class="mx-auto w-52 mb-6">
|
<img src="https://www.bit.nl/assets/images/bit_logo_white.png" alt="BIT Logo" class="mx-auto w-52 mb-6">
|
||||||
|
|
||||||
<div class="bg-white p-10 rounded-xl shadow-2xl">
|
<div class="bg-white p-10 rounded-xl shadow-2xl">
|
||||||
|
|
|
@ -6,6 +6,30 @@
|
||||||
|
|
||||||
<link rel="stylesheet" href="/dist/css/app.css">
|
<link rel="stylesheet" href="/dist/css/app.css">
|
||||||
<script type="module" src="/dist/scripts/app.js"></script>
|
<script type="module" src="/dist/scripts/app.js"></script>
|
||||||
|
|
||||||
|
<?php if (!env('debug')) : ?>
|
||||||
|
<!-- Google tag (gtag.js) -->
|
||||||
|
<script async src="https://www.googletagmanager.com/gtag/js?id=G-18G0H58X77"></script>
|
||||||
|
<script>
|
||||||
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag(){dataLayer.push(arguments);}
|
||||||
|
gtag('js', new Date());
|
||||||
|
|
||||||
|
gtag('config', 'G-18G0H58X77');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Hotjar Tracking Code for IPcalc-u-later -->
|
||||||
|
<script>
|
||||||
|
(function(h,o,t,j,a,r){
|
||||||
|
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
||||||
|
h._hjSettings={hjid:5222712,hjsv:6};
|
||||||
|
a=o.getElementsByTagName('head')[0];
|
||||||
|
r=o.createElement('script');r.async=1;
|
||||||
|
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
||||||
|
a.appendChild(r);
|
||||||
|
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
||||||
|
</script>
|
||||||
|
<?php endif; ?>
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-gradient-to-r from-primary to-primary-light">
|
<body class="bg-gradient-to-r from-primary to-primary-light">
|
||||||
<div id="subnet-app"></div>
|
<div id="subnet-app"></div>
|
||||||
|
|
|
@ -15,14 +15,11 @@ class HtmlEngine extends Render
|
||||||
$basePath = $_SERVER['DOCUMENT_ROOT'];
|
$basePath = $_SERVER['DOCUMENT_ROOT'];
|
||||||
$viewsPath = app()->resourcePath('views/' . str_replace('.', '/', $this->view) . '.php');
|
$viewsPath = app()->resourcePath('views/' . str_replace('.', '/', $this->view) . '.php');
|
||||||
|
|
||||||
if (file_exists($viewsPath)) {
|
if (!file_exists($viewsPath)) {
|
||||||
extract($this->data);
|
throw new \Exception('View not found');
|
||||||
|
|
||||||
include $viewsPath;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \Exception('View not found');
|
extract($this->data);
|
||||||
|
include $viewsPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -71,6 +71,7 @@ class RouteCollection
|
||||||
fn($key) => !is_numeric($key),
|
fn($key) => !is_numeric($key),
|
||||||
ARRAY_FILTER_USE_KEY
|
ARRAY_FILTER_USE_KEY
|
||||||
);
|
);
|
||||||
|
|
||||||
return $route;
|
return $route;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Core\Routing;
|
|
||||||
|
|
||||||
use Core\Http\Request;
|
|
||||||
|
|
||||||
class Router
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Dispatch router and run application
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function dispatch(): void
|
|
||||||
{
|
|
||||||
// Create request
|
|
||||||
$request = new Request($_POST + $_FILES);
|
|
||||||
|
|
||||||
// Dispatch router
|
|
||||||
RouteDispatcher::dispatch($request, RouteCollection::retrieve());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue