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