diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f6830d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +connect.php diff --git a/addNetwork.php b/addNetwork.php new file mode 100644 index 0000000..7533693 --- /dev/null +++ b/addNetwork.php @@ -0,0 +1,27 @@ +Revenir en arrière"); +} + +$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']}"); +} catch(Exception $e) { + echo($e->getMessage() . "
Revenir en arrière"); +} +exit; +?> diff --git a/addSite.php b/addSite.php new file mode 100644 index 0000000..795e4eb --- /dev/null +++ b/addSite.php @@ -0,0 +1,14 @@ +Revenir en arrière"); +} +include "connect.php"; +try { + $insert = $db->prepare("INSERT INTO Sites(Name) VALUES(:name)"); + $insert->execute(['name' => $_POST['siteName']]); + header("Location: .?site=${_POST['siteName']}"); + exit; +} catch(Exception $e) { + echo($e->getMessage() . "
Revenir en arrière"); +} +?> \ No newline at end of file diff --git a/connect.inc.php b/connect.inc.php new file mode 100644 index 0000000..78c8b48 --- /dev/null +++ b/connect.inc.php @@ -0,0 +1,15 @@ +setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch(Exception $e) { + die($e->getMessage() . "
Revenir en arrière"); +} +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..47ccd13 --- /dev/null +++ b/index.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/nok.png b/nok.png new file mode 100644 index 0000000..1efd421 Binary files /dev/null and b/nok.png differ diff --git a/ok.png b/ok.png new file mode 100644 index 0000000..54bd3d5 Binary files /dev/null and b/ok.png differ diff --git a/script.js b/script.js new file mode 100644 index 0000000..497a48f --- /dev/null +++ b/script.js @@ -0,0 +1,24 @@ +function updateHost(input) { + input.style.backgroundImage = 'url(wait.gif)' + input.style.fontStyle = "italic" + fetch(new Request("updateHost.php", { + method:"POST", + body:new FormData(input.form), + mode:"cors" + })).then(response => { + if (response.ok) { + input.style.backgroundImage = '' + input.style.fontStyle = "" + } else { + input.style.backgroundImage = 'url(nok.png)' + } + }) +} + +function checkMask(input) { + if (input.checkValidity()) { + + } else { + input.setCustomValidity("Masque incorrect") + } +} \ No newline at end of file diff --git a/siteNetworks.php b/siteNetworks.php new file mode 100644 index 0000000..f90acd3 --- /dev/null +++ b/siteNetworks.php @@ -0,0 +1,103 @@ +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"); +} +?> + + + + TablIP - <?=$siteName?> + + + + +
+

TablIP

+

+
+ +query("SELECT * FROM `Networks` WHERE `SiteId` = $siteId"); +while ($network = $networks->fetch()) +{ + $networkId = $network["id"]; + $networkAddress = (int) $network["Address"]; + $networkMask = (int) $network["Mask"]; +?> + + + + + + + + + + + + + + + +query("SELECT * from `Hosts` WHERE IPAddress=$ip AND NetworkId=$networkId"); + $host = $hosts->fetch(); +?> + + + /> + /> + + + + + + + + + + + + + + + +
+
Adresse IPNom d'hôteFQDNAdresse MACCommentaires
Adresse réseau
"/>"/>"/>"/>
Adresse de diffusion
+closeCursor(); +?> + +
+
+ Ajouter un réseau + + + + + + + + + +
+
+ + + + \ No newline at end of file diff --git a/sitesList.php b/sitesList.php new file mode 100644 index 0000000..ca3dcd3 --- /dev/null +++ b/sitesList.php @@ -0,0 +1,32 @@ + + + TablIP + + + +
+

TablIP

+
+ +
+
+ Ajouter un site + + + +
+
+ + \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..096487f --- /dev/null +++ b/style.css @@ -0,0 +1,45 @@ +body { + margin: auto 1em; +} + +header { + text-align: center; +} + +li { + list-style: none; +} + +table { + border-collapse: collapse; +} + +th, td { + border: solid 1px; +} + +td { + padding: 0; +} + +td input { + border: 0; + background-repeat: no-repeat; + background-position: right center; + width: 100%; +} + +.add { + display: grid; + grid-template-columns: 1fr 2fr; + grid-gap: 1em; +} +.add button { + width: 100%; + margin: auto; + grid-column: 1/3; +} + +footer { + text-align: center; +} \ No newline at end of file diff --git a/updateHost.php b/updateHost.php new file mode 100644 index 0000000..d7250cd --- /dev/null +++ b/updateHost.php @@ -0,0 +1,36 @@ +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"] + ]); +} catch(Exception $e) { + header("HTTP/1.x 500 " . $e->getMessage()); + die($e->getMessage()); +} +?> \ No newline at end of file diff --git a/wait.gif b/wait.gif new file mode 100644 index 0000000..4e06bb9 Binary files /dev/null and b/wait.gif differ