diff --git a/400.php b/400.php
new file mode 100644
index 0000000..72ff40c
--- /dev/null
+++ b/400.php
@@ -0,0 +1,31 @@
+
+
+
+ TablIP - Erreur
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/404.php b/404.php
new file mode 100644
index 0000000..b7f22dd
--- /dev/null
+++ b/404.php
@@ -0,0 +1,31 @@
+
+
+
+ TablIP - Erreur
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/500.php b/500.php
new file mode 100644
index 0000000..ab1bae5
--- /dev/null
+++ b/500.php
@@ -0,0 +1,31 @@
+
+
+
+ TablIP - Erreur
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/addNetwork.php b/addNetwork.php
index 7533693..6d2be57 100644
--- a/addNetwork.php
+++ b/addNetwork.php
@@ -1,27 +1,22 @@
Revenir en arrière");
+$name = filter_input(INPUT_POST, "siteName", FILTER_SANITIZE_STRING);
+$gateway = ip2long(filter_input(INPUT_POST, "gateway", FILTER_VALIDATE_IP));
+$mask = ip2long(filter_input(INPUT_POST, "mask", FILTER_VALIDATE_IP));
+$siteId = filter_input(INPUT_POST, "siteId", FILTER_VALIDATE_INT);
+if (!($name && $gateway && $mask && $siteId)) {
+ header("Location: 400.php");
+ exit;
}
-
-$siteId = (int) $_POST['siteId'];
-$gateway = ip2long($_POST['gateway']);
-$mask = ip2long($_POST['mask']);
$networkAddress = $gateway & $mask;
-
include "connect.php";
try {
$insert = $db->prepare("INSERT INTO Networks(Name, Address, Mask, SiteId) VALUES(:name, $networkAddress, $mask, $siteId)");
$insert->execute(['name' => $_POST['name']]);
$networkId = $db->lastInsertId();
$insert = $db->exec("INSERT INTO Hosts(IPAddress, NetworkId, Comments) VALUES($gateway, $networkId, 'Passerelle')");
-
- header("Location: .?site=${_POST['siteName']}");
+ header("Location: network.php?networkId=$networkId");
} catch(Exception $e) {
- echo($e->getMessage() . "
Revenir en arrière");
+ header("Location: 500.php");
+ exit;
}
-exit;
?>
diff --git a/addSite.php b/addSite.php
index 795e4eb..622263d 100644
--- a/addSite.php
+++ b/addSite.php
@@ -1,14 +1,17 @@
Revenir en arrière");
+$siteName = filter_input(INPUT_POST, "siteName", FILTER_SANITIZE_STRING);
+if (!$siteName) {
+ header("Location: 400.php");
+ exit;
}
include "connect.php";
try {
$insert = $db->prepare("INSERT INTO Sites(Name) VALUES(:name)");
- $insert->execute(['name' => $_POST['siteName']]);
- header("Location: .?site=${_POST['siteName']}");
- exit;
+ $insert->execute(['name' => $siteName]);
+ $siteId = $db->lastInsertId();
+ header("Location: site.php?id=$siteId");
} catch(Exception $e) {
- echo($e->getMessage() . "
Revenir en arrière");
+ header("Location: 500.php");
+ exit;
}
?>
\ No newline at end of file
diff --git a/connect.inc.php b/connect.inc.php
index 78c8b48..9d6309f 100644
--- a/connect.inc.php
+++ b/connect.inc.php
@@ -10,6 +10,6 @@ try {
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(Exception $e) {
- die($e->getMessage() . "
Revenir en arrière");
+ header("Location: 500.php");
}
?>
\ No newline at end of file
diff --git a/css/style.css b/css/style.css
index 303f503..949b568 100644
--- a/css/style.css
+++ b/css/style.css
@@ -1,10 +1,32 @@
.td-input {
- padding: 0;
- }
+ padding: 0;
+}
.td-input input[type="text"]:not(.browser-default) {
- margin: 0;
- background-repeat: no-repeat;
- background-position: right center;
+ margin: 0;
+}
+
+.pending::after {
+ content: "sync";
+ font-family: 'Material Icons';
+ -moz-font-feature-settings: 'liga';
+ color: grey;
+ position: absolute;
+}
+
+.ok::after {
+ content: "done";
+ font-family: 'Material Icons';
+ -moz-font-feature-settings: 'liga';
+ color: green;
+ position: absolute;
+}
+
+.nok::after {
+ content: "sync_problem";
+ font-family: 'Material Icons';
+ -moz-font-feature-settings: 'liga';
+ color: red;
+ position: absolute;
}
\ No newline at end of file
diff --git a/index.php b/index.php
index dee80e4..022d12f 100644
--- a/index.php
+++ b/index.php
@@ -1,7 +1,6 @@
-
- TablIP
+ TablIP - Sites
@@ -10,12 +9,38 @@
+
+
\ No newline at end of file
diff --git a/js/script.js b/js/script.js
index ef3d446..3f44238 100644
--- a/js/script.js
+++ b/js/script.js
@@ -1,24 +1,23 @@
+function showCard(card, button) {
+ card.classList.remove('scale-out')
+ card.classList.add('scale-in')
+ button.classList.add('scale-out')
+}
+
function updateHost(input) {
- input.style.backgroundImage = 'url(img/wait.gif)'
- input.style.fontStyle = "italic"
+ input.parentElement.classList.remove("ok")
+ input.parentElement.classList.remove("nok")
+ input.parentElement.classList.add("pending")
fetch(new Request("updateHost.php", {
method:"POST",
body:new FormData(input.form),
mode:"cors"
})).then(response => {
+ input.parentElement.classList.remove("pending")
if (response.ok) {
- input.style.backgroundImage = ''
- input.style.fontStyle = ""
+ input.parentElement.classList.add("ok")
} else {
- input.style.backgroundImage = 'url(img/nok.png)'
+ input.parentElement.classList.add("nok")
}
})
-}
-
-function checkMask(input) {
- if (input.checkValidity()) {
-
- } else {
- input.setCustomValidity("Masque incorrect")
- }
}
\ No newline at end of file
diff --git a/network.php b/network.php
new file mode 100644
index 0000000..f3121bb
--- /dev/null
+++ b/network.php
@@ -0,0 +1,90 @@
+query("SELECT * from `Networks` WHERE id=$networkId")->fetch();
+$networkName = $network["Name"];
+if (!$networkName) {
+ header("Location: 404.php");
+ exit;
+}
+$networkAddress = $network["Address"];
+$networkAddressStr = long2ip($networkAddress);
+$networkMask = $network["Mask"];
+$networkMaskStr = long2ip($networkMask);
+$siteId = $network["SiteId"];
+$site = $db->query("SELECT Name from `Sites` WHERE id=$siteId")->fetch();
+$siteName = $site["Name"];
+if (!$siteName) {
+ header("Location: 404.php");
+ exit;
+}
+?>
+
+
+ TablIP - =$networkName?>
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/site.php b/site.php
new file mode 100644
index 0000000..6b932b9
--- /dev/null
+++ b/site.php
@@ -0,0 +1,71 @@
+query("SELECT Name from `Sites` WHERE `id`=$siteId")->fetch();
+$siteName = $site["Name"];
+if (!$siteName) {
+ header("Location: 404.php");
+ exit;
+}
+?>
+
+
+ TablIP - =$siteName?>
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/siteNetworks.php b/siteNetworks.php
deleted file mode 100644
index afe4324..0000000
--- a/siteNetworks.php
+++ /dev/null
@@ -1,114 +0,0 @@
-prepare('SELECT id from Sites WHERE Name=:siteName');
-$site->execute(['siteName' => $siteName]);
-$siteId = $site->fetch()["id"];
-if (!$siteId) {
- header("HTTP/1.1 404 Not Found");
- die("Erreur ! Site inconnu : ${_GET["site"]}
Accueil");
-}
-?>
-
-
-
-
=$siteName?>
-
-query("SELECT * FROM `Networks` WHERE `SiteId` = $siteId");
-while ($network = $networks->fetch())
-{
- $networkId = $network["id"];
- $networkAddress = (int) $network["Address"];
- $networkMask = (int) $network["Mask"];
-?>
-
-
-
=$network['Name']." @ ".long2ip($networkAddress)." / ".long2ip($networkMask)?>
-
-
-
- Adresse IP |
- Nom d'hôte |
- FQDN |
- Adresse MAC |
- Commentaires |
-
- = long2ip($networkAddress)?> |
- Adresse réseau |
-
-
-
-
-query("SELECT * from `Hosts` WHERE IPAddress=$ip AND NetworkId=$networkId");
- $host = $hosts->fetch();
-?>
-
-
-
-
-
-
-
- = long2ip($ip)?> |
- Adresse de diffusion |
-
-
-
-
-
-closeCursor();
-?>
-
-
-
-
-
-
diff --git a/sitesList.php b/sitesList.php
deleted file mode 100644
index 762110b..0000000
--- a/sitesList.php
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
Sites
-
-
-query('SELECT Name FROM Sites ORDER BY Name');
-while ($site = $sites->fetch())
-{
- echo "
${site['Name']}\n";
-}
-$sites->closeCursor();
-?>
-
-
-
-
\ No newline at end of file
diff --git a/updateHost.php b/updateHost.php
index d7250cd..f4a2e25 100644
--- a/updateHost.php
+++ b/updateHost.php
@@ -1,36 +1,33 @@
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
");
$update->execute([
- 'i_hostname' => $_POST["Hostname"],
- 'i_fqdn' => $_POST["FQDN"],
- 'i_macAddress' => $_POST["MacAddress"],
- 'i_comments' => $_POST["Comments"],
- 'u_hostname' => $_POST["Hostname"],
- 'u_fqdn' => $_POST["FQDN"],
- 'u_macAddress' => $_POST["MacAddress"],
- 'u_comments' => $_POST["Comments"]
+ 'i_hostname' => $hostname,
+ 'i_fqdn' => $fqdn,
+ 'i_macAddress' => $macAddress,
+ 'i_comments' => $comments,
+ 'u_hostname' => $hostname,
+ 'u_fqdn' => $fqdn,
+ 'u_macAddress' => $macAddress,
+ 'u_comments' => $comments
]);
} catch(Exception $e) {
- header("HTTP/1.x 500 " . $e->getMessage());
- die($e->getMessage());
+ header("Location: 500.php");
+ exit;
}
?>
\ No newline at end of file