130 lines
5.7 KiB
PHP
130 lines
5.7 KiB
PHP
<?php
|
|
require_once "common.php";
|
|
|
|
if (preg_match("/^$namePtn$/", $_SERVER["QUERY_STRING"])) {
|
|
include_once "load-options.php";
|
|
include_once "load-ranges.php";
|
|
|
|
$tag = $_SERVER["QUERY_STRING"];
|
|
$option = $options[$tag];
|
|
$range = $ranges[$tag];
|
|
} else {
|
|
$tag = "";
|
|
$option = [];
|
|
$range = [];
|
|
}
|
|
|
|
$placeholder = [];
|
|
if (preg_match(
|
|
"/\n\d+: (?P<iface>[a-z0-9]+) inet (?<ipaddr>$ipPtn)\/(?<cidr_mask>\d+) brd (?<broadcast>$ipPtn)/",
|
|
`ip -o -4 a`,
|
|
$this_server
|
|
)) {
|
|
$placeholder["netmask"] = long2ip($long_mask[(int)$this_server["cidr_mask"]]);
|
|
}
|
|
if (preg_match(
|
|
"/default via ($ipPtn)/",
|
|
`ip -4 route`,
|
|
$router
|
|
)) {
|
|
$placeholder["router"] = $router[1];
|
|
}
|
|
$placeholder["dns-server"] = $_SERVER['SERVER_ADDR'];
|
|
|
|
preg_match_all("/\d+ (?<name>$namePtn)/", `dnsmasq --help dhcp`, $option_names, PREG_SET_ORDER);
|
|
?>
|
|
<!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 text 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>
|
|
<h4 class="ui header">Paramètres</h4>
|
|
<div id="optionsDiv" class="three fields" style="flex-wrap: wrap">
|
|
<?php foreach(array_merge($option, $placeholder) as $name => $value) : ?>
|
|
<div class="field">
|
|
<label for="<?=$name?>"><?=$name?></label>
|
|
<input id="<?=$name?>" name="<?=$name?>" type="text"
|
|
<?=isset($option[$name]) ? "value='{$option[$name]}'": ""?>
|
|
<?=isset($placeholder[$name]) ? "placeholder='{$placeholder[$name]}'": ""?>
|
|
<?=($name == "netmask") || ($name == "router") || (strpos($name, "server") !== false) ? 'pattern="^(?:(?:25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})\.){3}(?:25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})$"' : "" ?>
|
|
/>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<div class="field">
|
|
<label for="addOptionSelect">Ajouter un paramètre</label>
|
|
<select id="addOptionSelect" class="ui search selection dropdown">
|
|
<?php foreach ($option_names as $option) :?>
|
|
<option value="<?=$option["name"]?>"><?=$option["name"]?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<script>
|
|
addOptionSelect.oninput = function(event) {
|
|
var name = addOptionSelect.value
|
|
var field = document.createElement("div")
|
|
field.className = "field"
|
|
var label = document.createElement("label")
|
|
label.setAttribute("for", name)
|
|
label.textContent = name
|
|
field.appendChild(label)
|
|
var input = document.createElement("input")
|
|
input.setAttribute("id", name)
|
|
input.setAttribute("name", name)
|
|
input.setAttribute("type", "text")
|
|
if (name == "netmask" || name == "router" || name.includes("server")) {
|
|
input.setAttribute("pattern", "^(?:(?:25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})\.){3}(?:25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})$")
|
|
}
|
|
field.appendChild(input)
|
|
optionsDiv.appendChild(field)
|
|
}
|
|
</script>
|
|
</div>
|
|
<h4 class="ui header">Plage 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="<?=$range["start-addr"] ?? "" ?>"/>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label for="end-addr">Dernière adresse ou mode</label>
|
|
<select id="end-addr" name="end-addr" class="ui search dropdown">
|
|
<?php if (isset($range["end-addr"])): ?>
|
|
<option value="<?=$range["end-addr"]?>"><?=$range["end-addr"]?></option>
|
|
<?php endif; ?>
|
|
<option value="">Adresse IP</option>
|
|
<option value="static">static</option>
|
|
<option value="proxya-only">proxy</option>
|
|
</select>
|
|
<script>$('#end-addr').dropdown({allowAdditions: true})</script>
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="ui button">Enregistrer</button>
|
|
</form>
|
|
</main>
|
|
</body>
|
|
</html>
|