114 lines
5.5 KiB
PHP
114 lines
5.5 KiB
PHP
<?php
|
|
include_once "load-networks.php";
|
|
|
|
$tag = "";
|
|
$network = [];
|
|
if (isset($_SERVER["QUERY_STRING"]) && preg_match(
|
|
"/^$namePtn$/", $_SERVER["QUERY_STRING"], $matches
|
|
)) {
|
|
$tag = $matches[0];
|
|
|
|
if (isset($networks[$tag])) {
|
|
$network = $networks[$tag];
|
|
}
|
|
}
|
|
|
|
preg_match("/\n\d+: (?P<iface>[a-z0-9]+) inet (?<ipaddr>$ipPtn)\/(?<cidr_mask>\d+) brd (?<broadcast>$ipPtn)/", `ip -o -4 a`, $placeholder);
|
|
$ip_addr = ip2long($placeholder["ipaddr"]);
|
|
$mask = $long_mask[(int)$placeholder["cidr_mask"]];
|
|
$placeholder["network-addr"] = $ip_addr & $netmask;
|
|
$placeholder["netmask"] = long2ip($mask);
|
|
$placeholder["broadcast"] = ip2long($placeholder["broadcast"]);
|
|
if (preg_match("/default via ($ipPtn)/", `ip -4 route`, $router)) {
|
|
$placeholder["router"] = $router[1];
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>IPAM</title>
|
|
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fomantic-ui@2.9.4/dist/semantic.min.css">
|
|
<script src="https://cdn.jsdelivr.net/npm/fomantic-ui@2.9.4/dist/semantic.min.js"></script>
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
<body>
|
|
<nav class="ui inverted teal menu">
|
|
<a class="header item" href=".">IP<em>AM</em></a>
|
|
</nav>
|
|
<main class="ui container">
|
|
<h1>Éditer un réseau</h1>
|
|
<form action="update-network.php" method="post" class="ui form">
|
|
<input type="hidden" name="previous-tag" value="<?=$tag?>"/>
|
|
<div class="field">
|
|
<label for="tag" class="required">Nom</label>
|
|
<input id="tag" name="tag" type="text" pattern="[a-zA-Z_][\w\-]*" placeholder="Reseau-local" required value="<?=$tag?>"
|
|
title="une lettre suivie par des lettres, des chiffres ou des tirets"/>
|
|
</div>
|
|
<div class="two fields">
|
|
<div class="field">
|
|
<label for="router" class="required">Passerelle ou adresse réseau</label>
|
|
<input id="router" name="router" type="text" title="xxx.xxx.xxx.xxx" required
|
|
pattern="(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)"
|
|
placeholder="<?=$placeholder["router"] ?? $placeholder["network-addr"] ?? "192.168.1.1"?>"
|
|
value="<?=$network["router"] ?? ""?>"/>
|
|
</div>
|
|
<div class="field">
|
|
<label for="netmask" class="required">Masque</label>
|
|
<select id="netmask" name="netmask" class="ui search selection dropdown">
|
|
<?php foreach ($long_mask as $cidr_mask => $netmask) :
|
|
$netmask = long2ip($netmask);
|
|
?>
|
|
<option value="<?=$netmask?>"<?=$netmask == ($network["netmask"] ?? $placeholder["netmask"] ?? 24) ? " selected" : ""?>>/<?=$cidr_mask?> <?=$netmask?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<script>$('#netmask').dropdown()</script>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label for="dns-server">Serveur(s) DNS (laisser vide pour ce serveur)</label>
|
|
<select id="dns-server" name="dns-server" multiple class="ui search multiple selection dropdown" autocomplete="off">
|
|
<option value=""><?=$_SERVER['REMOTE_ADDR']?></option>
|
|
</select>
|
|
<script>
|
|
const ipRegex = /^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$/;
|
|
$('#dns-server').dropdown({
|
|
allowAdditions: true,
|
|
forceSelection: false,
|
|
onAdd: function(value, text, $choice) {
|
|
if (!ipRegex.test(value)) {
|
|
$(this).dropdown('remove selected', value);
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
</div>
|
|
<h4 class="ui header">DHCP dynamique</h4>
|
|
<div class="two fields">
|
|
<div class="field">
|
|
<label for="start-addr">Première adresse</label>
|
|
<div class="ui labeled input">
|
|
<input id="start-addr" name="start-addr" type="text" title="xxx.xxx.xxx.xxx"
|
|
pattern="(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)"
|
|
placeholder="192.168.1.100"
|
|
value="<?=$network["dhcp-range"]["start_addr"] ?? "" ?>"/>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label for="end-addr">Dernière adresse</label>
|
|
<div class="ui labeled input">
|
|
<input id="end-addr" name="end-addr" type="text" title="xxx.xxx.xxx.xxx"
|
|
pattern="(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)"
|
|
placeholder="192.168.1.200"
|
|
value="<?=$network["dhcp-range"]["end"] ?? "" ?>"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="ui button">Enregistrer</button>
|
|
</form>
|
|
</main>
|
|
</body>
|
|
</html>
|