update host fix
This commit is contained in:
parent
b499bb1be0
commit
8be07a291c
@ -3,7 +3,7 @@
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.td-input input[type="text"]:not(.browser-default) {
|
||||
.td-input input:not(.browser-default) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
|
21
js/script.js
21
js/script.js
@ -5,19 +5,28 @@ function showCard(card, button) {
|
||||
}
|
||||
|
||||
function updateHost(input) {
|
||||
input.parentElement.classList.remove("ok")
|
||||
input.parentElement.classList.remove("nok")
|
||||
input.parentElement.classList.add("pending")
|
||||
if (input.form.checkValidity()) {
|
||||
var td = input.parentElement
|
||||
var tr = td.parentElement
|
||||
tr.classList.remove("ok")
|
||||
tr.classList.remove("nok")
|
||||
tr.classList.add("pending")
|
||||
fetch(new Request("updateHost.php", {
|
||||
method:"POST",
|
||||
body:new FormData(input.form),
|
||||
mode:"cors"
|
||||
})).then(response => {
|
||||
input.parentElement.classList.remove("pending")
|
||||
tr.classList.remove("pending")
|
||||
if (response.ok) {
|
||||
input.parentElement.classList.add("ok")
|
||||
tr.classList.add("ok")
|
||||
var linkInput = tr.getElementsByTagName('input')[7]
|
||||
var linkA = tr.getElementsByTagName('a')[0]
|
||||
linkA.href = linkInput.value
|
||||
} else {
|
||||
input.parentElement.classList.add("nok")
|
||||
tr.classList.add("nok")
|
||||
}
|
||||
})
|
||||
} else {
|
||||
input.form.reportValidity()
|
||||
}
|
||||
}
|
13
network.php
13
network.php
@ -52,12 +52,13 @@ if (!$siteName) {
|
||||
<th>FQDN</th>
|
||||
<th>Adresse MAC</th>
|
||||
<th>Commentaires</th>
|
||||
<th>Lien</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="td-input"><input type="text" name='ip' value="<?=$networkAddressStr?>" disabled/></td>
|
||||
<td class="td-input" colspan="4"><input type="text" value="Adresse réseau" disabled/></td>
|
||||
<td class="td-input" colspan="5"><input type="text" value="Adresse réseau" disabled/></td>
|
||||
</tr>
|
||||
<?php
|
||||
for ($ip = $networkAddress + 1; ($ip+1 & $networkMask) == $networkAddress; $ip++ ) {
|
||||
@ -68,10 +69,12 @@ if (!$siteName) {
|
||||
<input type="hidden" name="ip" value="<?=$ip?>"/>
|
||||
<input type="hidden" name="networkId" value="<?=$networkId?>"/>
|
||||
<td class="td-input"><input type="text" value="<?=long2ip($ip)?>" disabled/></td>
|
||||
<td class="td-input"><input type="text" onchange="updateHost(this)" name='hostname' value="<?=$host["Hostname"]?>"/></td>
|
||||
<td class="td-input"><input type="text" onchange="updateHost(this)" name='fqdn' value="<?=$host["FQDN"]?>"/></td>
|
||||
<td class="td-input"><input type="text" onchange="updateHost(this)" name='macAddress' value="<?=$host["MacAddress"]?>"/></td>
|
||||
<td class="td-input"><input type="text" onchange="updateHost(this)" name='comments' value="<?=$host["Comments"]?>"/></td>
|
||||
<td class="td-input"><input type="text" onchange="updateHost(this)" name="hostname" pattern="^[A-Za-z0-9_-]*$" value="<?=$host["Hostname"]?>"/></td>
|
||||
<td class="td-input"><input type="text" onchange="updateHost(this)" name="fqdn" pattern="^[a-zA-Z0-9._-]*$" value="<?=$host["FQDN"]?>"/></td>
|
||||
<td class="td-input"><input type="text" onchange="updateHost(this)" name="macAddress" pattern="^([a-fA-F0-9]{2}[:-]{1}){5}[a-fA-F0-9]{2}$" title="XX:XX:XX:XX:XX:XX" value="<?=$host["MacAddress"]?>"/></td>
|
||||
<td class="td-input"><input type="text" onchange="updateHost(this)" name="comments" value="<?=$host["Comments"]?>"/></td>
|
||||
<td class="td-input"><input type="url" onchange="updateHost(this)" name="link" value="<?=$host["Link"]?>"/></td>
|
||||
<td><a href="<?=$host["Link"]?>" target="_blank"><i class="material-icons">launch</i></a></td>
|
||||
</form>
|
||||
</tr>
|
||||
<?php
|
||||
|
@ -1,29 +1,34 @@
|
||||
<?php
|
||||
$ip = filter_input(INPUT_POST, "ip", FILTER_VALIDATE_INT);
|
||||
$networkId = filter_input(INPUT_POST, "networkId", FILTER_VALIDATE_INT);
|
||||
$ip = filter_input(INPUT_POST, "ip", FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
|
||||
$networkId = filter_input(INPUT_POST, "networkId", FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
|
||||
$hostname = filter_input(INPUT_POST, "hostname", FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
|
||||
$fqdn = filter_input(INPUT_POST, "fqdn", FILTER_VALIDATE_DOMAIN);
|
||||
$macAddress = filter_input(INPUT_POST, "macAddress", FILTER_VALIDATE_MAC);
|
||||
$comments = filter_input(INPUT_POST, "comments", FILTER_SANITIZE_STRING);
|
||||
if (!($ip && $networkId)) {
|
||||
$link = filter_input(INPUT_POST, "link", FILTER_VALIDATE_URL);
|
||||
|
||||
if (is_null($ip)
|
||||
|| is_null($networkId)) {
|
||||
header("Location: 400.php");
|
||||
exit;
|
||||
}
|
||||
include "connect.php";
|
||||
try {
|
||||
$update = $db->prepare("
|
||||
INSERT INTO Hosts(IpAddress, NetworkId, Hostname, FQDN, MacAddress, Comments)
|
||||
VALUES($ip, $networkId, :i_hostname, :i_fqdn, :i_macAddress, :i_comments)
|
||||
ON DUPLICATE KEY UPDATE Hostname = :u_hostname, FQDN = :u_fqdn, MacAddress = :u_macAddress, Comments = :u_comments
|
||||
INSERT INTO Hosts(IpAddress, NetworkId, Hostname, FQDN, MacAddress, Link, Comments)
|
||||
VALUES($ip, $networkId, :i_hostname, :i_fqdn, :i_macAddress, :i_link, :i_comments)
|
||||
ON DUPLICATE KEY UPDATE Hostname = :u_hostname, FQDN = :u_fqdn, MacAddress = :u_macAddress, Comments = :u_comments, Link = :u_link
|
||||
");
|
||||
$update->execute([
|
||||
'i_hostname' => $hostname,
|
||||
'i_fqdn' => $fqdn,
|
||||
'i_macAddress' => $macAddress,
|
||||
'i_link' => $link,
|
||||
'i_comments' => $comments,
|
||||
'u_hostname' => $hostname,
|
||||
'u_fqdn' => $fqdn,
|
||||
'u_macAddress' => $macAddress,
|
||||
'u_link' => $link,
|
||||
'u_comments' => $comments
|
||||
]);
|
||||
} catch(Exception $e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user