flow change

This commit is contained in:
Adrien MALINGREY 2021-09-26 19:40:20 +02:00
parent f82aa4c734
commit b499bb1be0
14 changed files with 364 additions and 221 deletions

31
400.php Normal file
View File

@ -0,0 +1,31 @@
<?php
header("HTTP/1.1 400 Bad Request");
?>
<html>
<head>
<title>TablIP - Erreur</title>
<link rel="stylesheet" href="css/style.css"/>
<link rel="stylesheet" href="css/icons.css"/>
<link rel="stylesheet" href="css/materialize.css"/>
<script type="text/javascript" src="js/script.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<script type="text/javascript" src="js/materialize.js"></script>
<header>
<nav>
<div class="nav-wrapper navbar-fixed teal lighten-2">
<a href="." class="brand-logo center">TablIP</a>
<div>
<a href="." class="breadcrumb">Sites</a>
</div>
</div>
</nav>
</header>
<div class="container">
<h1>Erreur</h1>
<p>Données requises non reçues</p>
<a class="waves-effect waves-light btn" href='javascript:history.back(1);'><i class="material-icons left">arrow_back</i>Retour</a>
</div>
</body>
</html>

31
404.php Normal file
View File

@ -0,0 +1,31 @@
<?php
header("HTTP/1.1 404 Not Found");
?>
<html>
<head>
<title>TablIP - Erreur</title>
<link rel="stylesheet" href="css/style.css"/>
<link rel="stylesheet" href="css/icons.css"/>
<link rel="stylesheet" href="css/materialize.css"/>
<script type="text/javascript" src="js/script.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<script type="text/javascript" src="js/materialize.js"></script>
<header>
<nav>
<div class="nav-wrapper navbar-fixed teal lighten-2">
<a href="." class="brand-logo center">TablIP</a>
<div>
<a href="." class="breadcrumb">Sites</a>
</div>
</div>
</nav>
</header>
<div class="container">
<h1>Erreur</h1>
<p>La ressource demandée n'a pas été trouvée</p>
<a class="waves-effect waves-light btn" href='javascript:history.back(1);'><i class="material-icons left">arrow_back</i>Retour</a>
</div>
</body>
</html>

31
500.php Normal file
View File

@ -0,0 +1,31 @@
<?php
header("HTTP/1.1 500 Internal Server Error");
?>
<html>
<head>
<title>TablIP - Erreur</title>
<link rel="stylesheet" href="css/style.css"/>
<link rel="stylesheet" href="css/icons.css"/>
<link rel="stylesheet" href="css/materialize.css"/>
<script type="text/javascript" src="js/script.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<script type="text/javascript" src="js/materialize.js"></script>
<header>
<nav>
<div class="nav-wrapper navbar-fixed teal lighten-2">
<a href="." class="brand-logo center">TablIP</a>
<div>
<a href="." class="breadcrumb">Sites</a>
</div>
</div>
</nav>
</header>
<div class="container">
<h1>Erreur</h1>
<p>Problème côté serveur</p>
<a class="waves-effect waves-light btn" href='javascript:history.back(1);'><i class="material-icons left">arrow_back</i>Retour</a>
</div>
</body>
</html>

View File

@ -1,27 +1,22 @@
<?php <?php
if (!(isset($_POST['name']) $name = filter_input(INPUT_POST, "siteName", FILTER_SANITIZE_STRING);
&& isset($_POST['gateway']) $gateway = ip2long(filter_input(INPUT_POST, "gateway", FILTER_VALIDATE_IP));
&& isset($_POST['mask']) $mask = ip2long(filter_input(INPUT_POST, "mask", FILTER_VALIDATE_IP));
&& isset($_POST['siteId']) $siteId = filter_input(INPUT_POST, "siteId", FILTER_VALIDATE_INT);
&& isset($_POST['siteName']))) { if (!($name && $gateway && $mask && $siteId)) {
die("Erreur : données manquantes !<br/><a href='javascript:history.back(1);'>Revenir en arrière</a>"); header("Location: 400.php");
exit;
} }
$siteId = (int) $_POST['siteId'];
$gateway = ip2long($_POST['gateway']);
$mask = ip2long($_POST['mask']);
$networkAddress = $gateway & $mask; $networkAddress = $gateway & $mask;
include "connect.php"; include "connect.php";
try { try {
$insert = $db->prepare("INSERT INTO Networks(Name, Address, Mask, SiteId) VALUES(:name, $networkAddress, $mask, $siteId)"); $insert = $db->prepare("INSERT INTO Networks(Name, Address, Mask, SiteId) VALUES(:name, $networkAddress, $mask, $siteId)");
$insert->execute(['name' => $_POST['name']]); $insert->execute(['name' => $_POST['name']]);
$networkId = $db->lastInsertId(); $networkId = $db->lastInsertId();
$insert = $db->exec("INSERT INTO Hosts(IPAddress, NetworkId, Comments) VALUES($gateway, $networkId, 'Passerelle')"); $insert = $db->exec("INSERT INTO Hosts(IPAddress, NetworkId, Comments) VALUES($gateway, $networkId, 'Passerelle')");
header("Location: network.php?networkId=$networkId");
header("Location: .?site=${_POST['siteName']}");
} catch(Exception $e) { } catch(Exception $e) {
echo($e->getMessage() . "<br/><a href='javascript:history.back(1);'>Revenir en arrière</a>"); header("Location: 500.php");
}
exit; exit;
}
?> ?>

View File

@ -1,14 +1,17 @@
<?php <?php
if (!isset($_POST['siteName'])) { $siteName = filter_input(INPUT_POST, "siteName", FILTER_SANITIZE_STRING);
die("Nom du site manquant !<br/><a href='javascript:history.back(1);'>Revenir en arrière</a>"); if (!$siteName) {
header("Location: 400.php");
exit;
} }
include "connect.php"; include "connect.php";
try { try {
$insert = $db->prepare("INSERT INTO Sites(Name) VALUES(:name)"); $insert = $db->prepare("INSERT INTO Sites(Name) VALUES(:name)");
$insert->execute(['name' => $_POST['siteName']]); $insert->execute(['name' => $siteName]);
header("Location: .?site=${_POST['siteName']}"); $siteId = $db->lastInsertId();
exit; header("Location: site.php?id=$siteId");
} catch(Exception $e) { } catch(Exception $e) {
echo($e->getMessage() . "<br/><a href='javascript:history.back(1);'>Revenir en arrière</a>"); header("Location: 500.php");
exit;
} }
?> ?>

View File

@ -10,6 +10,6 @@ try {
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(Exception $e) { } catch(Exception $e) {
die($e->getMessage() . "<br/><a href='javascript:history.back(1);'>Revenir en arrière</a>"); header("Location: 500.php");
} }
?> ?>

View File

@ -5,6 +5,28 @@
.td-input input[type="text"]:not(.browser-default) { .td-input input[type="text"]:not(.browser-default) {
margin: 0; margin: 0;
background-repeat: no-repeat; }
background-position: right center;
.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;
} }

View File

@ -1,7 +1,6 @@
<?php include "connect.php"; ?>
<html> <html>
<head> <head>
<title>TablIP</title> <title>TablIP - Sites</title>
<link rel="stylesheet" href="css/style.css"/> <link rel="stylesheet" href="css/style.css"/>
<link rel="stylesheet" href="css/icons.css"/> <link rel="stylesheet" href="css/icons.css"/>
<link rel="stylesheet" href="css/materialize.css"/> <link rel="stylesheet" href="css/materialize.css"/>
@ -10,12 +9,38 @@
</head> </head>
<body> <body>
<script type="text/javascript" src="js/materialize.js"></script> <script type="text/javascript" src="js/materialize.js"></script>
<header>
<nav class="nav-wrapper navbar-fixed teal lighten-2">
<a class="breadcrumb">TablIP</a>
</nav>
</header>
<div class="container">
<div id="linksCard" class="card">
<div class="collection with-header">
<div class="collection-header"><h4>Sites</h4></div>
<?php <?php
if (isset($_GET["site"])) { include "connect.php";
include "siteNetworks.php"; foreach ($db->query("SELECT * FROM `Sites` ORDER BY `Name`") as $site) {
} else { print " </li><a href='site.php?id=${site['id']}' class='collection-item'>${site['Name']}</a>\n";
include "sitesList.php";
} }
?> ?>
</div>
<button id="addButton" type="button" class="btn-floating halfway-fab waves-effect waves-light teal scale-transition" onclick="showCard(addCard, this)"><i class="material-icons">add</i></button>
</div>
<div id="addCard" class="card teal lighten-5 scale-transition scale-out">
<div class="card-content">
<span class="card-title">Nouveau site</span>
<form name="addSite" id="addSite" action="addSite.php" method="post">
<div class="input-field">
<label for="siteName">Nom</label>
<input type="text" class="validate" id="siteName" name="siteName" placeholder="Site" required/>
</div>
<button class="btn waves-effect waves-light" type="submit" name="action">Ajouter
<i class="material-icons right">add</i>
</button>
</form>
</div>
</div>
</div>
</body> </body>
</html> </html>

View File

@ -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) { function updateHost(input) {
input.style.backgroundImage = 'url(img/wait.gif)' input.parentElement.classList.remove("ok")
input.style.fontStyle = "italic" input.parentElement.classList.remove("nok")
input.parentElement.classList.add("pending")
fetch(new Request("updateHost.php", { fetch(new Request("updateHost.php", {
method:"POST", method:"POST",
body:new FormData(input.form), body:new FormData(input.form),
mode:"cors" mode:"cors"
})).then(response => { })).then(response => {
input.parentElement.classList.remove("pending")
if (response.ok) { if (response.ok) {
input.style.backgroundImage = '' input.parentElement.classList.add("ok")
input.style.fontStyle = ""
} else { } else {
input.style.backgroundImage = 'url(img/nok.png)' input.parentElement.classList.add("nok")
} }
}) })
} }
function checkMask(input) {
if (input.checkValidity()) {
} else {
input.setCustomValidity("Masque incorrect")
}
}

90
network.php Normal file
View File

@ -0,0 +1,90 @@
<?php
$networkId = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);
if (!$networkId) {
header("Location: 400.php");
exit;
}
include "connect.php";
$network = $db->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;
}
?>
<html>
<head>
<title>TablIP - <?=$networkName?></title>
<link rel="stylesheet" href="css/style.css"/>
<link rel="stylesheet" href="css/icons.css"/>
<link rel="stylesheet" href="css/materialize.css"/>
<script type="text/javascript" src="js/script.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<script type="text/javascript" src="js/materialize.js"></script>
<header>
<nav class="nav-wrapper navbar-fixed teal lighten-2">
<a href="." class="breadcrumb">TablIP</a>
<a href="site.php?id=<?=$siteId?>" class="breadcrumb"><?=$siteName?></a>
<a class="breadcrumb"><?=$networkName?></a>
</nav>
</header>
<div class="container">
<div class="card">
<div class="card-content">
<table class="striped">
<thead>
<tr>
<th>Adresse IP</th>
<th>Nom d'hôte</th>
<th>FQDN</th>
<th>Adresse MAC</th>
<th>Commentaires</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>
</tr>
<?php
for ($ip = $networkAddress + 1; ($ip+1 & $networkMask) == $networkAddress; $ip++ ) {
$host = $db->query("SELECT * from `Hosts` WHERE IPAddress=$ip AND NetworkId=$networkId")->fetch();
?>
<tr>
<form>
<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>
</form>
</tr>
<?php
}
?>
<tr>
<td class="td-input"><input type="text" name='ip' value="<?=long2ip($ip)?>" disabled/></td>
<td class="td-input" colspan="4"><input type="text" value="Adresse de diffusion" disabled/></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>

71
site.php Normal file
View File

@ -0,0 +1,71 @@
<?php
$siteId = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);
if (!$siteId) {
header("Location: 400.php");
exit;
}
include "connect.php";
$site = $db->query("SELECT Name from `Sites` WHERE `id`=$siteId")->fetch();
$siteName = $site["Name"];
if (!$siteName) {
header("Location: 404.php");
exit;
}
?>
<html>
<head>
<title>TablIP - <?=$siteName?></title>
<link rel="stylesheet" href="css/style.css"/>
<link rel="stylesheet" href="css/icons.css"/>
<link rel="stylesheet" href="css/materialize.css"/>
<script type="text/javascript" src="js/script.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<script type="text/javascript" src="js/materialize.js"></script>
<header>
<nav class="nav-wrapper navbar-fixed teal lighten-2">
<a href="." class="breadcrumb">TablIP</a>
<a class="breadcrumb"><?=$siteName?></a>
</nav>
</header>
<div class="container">
<div id="linksCard" class="card">
<div class="collection with-header">
<div class="collection-header"><h4><?=$siteName?></h4></div>
<?php
include "connect.php";
foreach ($db->query("SELECT * FROM `Networks` WHERE `SiteId` = $siteId ORDER BY `Address`") as $network) {
print " <a href='network.php?id=${network['id']}' class='collection-item'>".$network['Name']." @ ".long2ip($network['Address'])." / ".long2ip($network['Mask'])."</a>\n";
}
?>
</div>
<button id="addButton" type="button" class="btn-floating halfway-fab waves-effect waves-light teal scale-transition" onclick="showCard(addCard, this)"><i class="material-icons">add</i></button>
</div>
<div id="addCard" class="card teal lighten-5 scale-transition scale-out">
<div class="card-content">
<span class="card-title">Nouveau réseau</span>
<form name="addNetwork" id="addNetwork" action="addNetwork.php" method="post">
<input type="hidden" name="siteId" value="<?=$siteId?>"/>
<div class="input-field">
<label for="nameInput">Nom</label>
<input type="text" class="validate" id="nameInput" name="name" placeholder="LAN" required/>
</div>
<div class="input-field">
<label for="gatewayInput">Passerelle</label>
<input type="text" class="validate" id="gatewayInput" name="gateway" placeholder="192.168.0.1" pattern="^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" title="XXX.XXX.XXX.XXX"/>
</div>
<div class="input-field">
<label for="maskInput">Masque</label>
<input type="text" class="validate" id="maskInput" name="mask" placeholder="255.255.255.0" pattern="^(255\.255\.(248|252|255)\.0|255\.255\.255\.(0|128|192|224|240|248|252|255))$" title="Plus grand masque autorisé : 255.255.248.0"/>
</div>
<button class="btn waves-effect waves-light" type="submit" name="action">Ajouter
<i class="material-icons right">add</i>
</button>
</form>
</div>
</div>
</div>
</body>
</html>

View File

@ -1,114 +0,0 @@
<?php
$MAX_LINES = 2500;
$siteName = $_GET["site"];
// Check if site is known
$site = $db->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"]}<br/><a href=".">Accueil</a>");
}
?>
<header>
<nav>
<div class="nav-wrapper navbar-fixed cyan lighten-2">
<a href="." class="brand-logo center">TablIP</a>
<div>
<a href="." class="breadcrumb">Sites</a>
<a href=".?Site=<?=$siteName?>" class="breadcrumb"><?=$siteName?></a>
</div>
</div>
</nav>
</header>
<div class="container">
<h1><?=$siteName?></h1>
<?php
$networks = $db->query("SELECT * FROM `Networks` WHERE `SiteId` = $siteId");
while ($network = $networks->fetch())
{
$networkId = $network["id"];
$networkAddress = (int) $network["Address"];
$networkMask = (int) $network["Mask"];
?>
<div class="card">
<div class="card-content">
<span class="card-title"><?=$network['Name']." @ ".long2ip($networkAddress)." / ".long2ip($networkMask)?></span>
<table class="striped responsive-table">
<thead>
<tr>
<th>Adresse IP</th>
<th>Nom d'hôte</th>
<th>FQDN</th>
<th>Adresse MAC</th>
<th>Commentaires</th>
<tr>
<td><em><?= long2ip($networkAddress)?></em></td>
<td colspan="4"><em>Adresse réseau</em></td>
</tr>
</tr>
</thead>
<tbody>
<?php
for ($ip = $networkAddress + 1; ($ip+1 & $networkMask) == $networkAddress && $ip < $networkAddress + $MAX_LINES; $ip++ ) {
$hosts = $db->query("SELECT * from `Hosts` WHERE IPAddress=$ip AND NetworkId=$networkId");
$host = $hosts->fetch();
?>
<tr>
<form>
<input type="hidden" name="Ip" value=<?=$ip?>/>
<input type="hidden" name="NetworkId" value=<?=$networkId?>/>
<td><?=long2ip($ip)?></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>
</form>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<td><em><?= long2ip($ip)?></em></td>
<td colspan="4"><em>Adresse de diffusion</em></td>
</tr>
</tfoot>
</table>
</div>
</div>
<?php
}
$networks->closeCursor();
?>
<div class="card teal lighten-5">
<div class="card-content">
<span class="card-title">Nouveau réseau</span>
<form name="addNetwork" id="addNetwork" action="addNetwork.php" method="post">
<input type="hidden" name="siteId" value="<?=$siteId?>"/>
<input type="hidden" name="siteName" value="<?=$siteName?>"/>
<div class="input-field">
<label for="nameInput">Nom</label>
<input type="text" class="validate" id="nameInput" name="name" placeholder="LAN" required/>
</div>
<div class="input-field">
<label for="gatewayInput">Passerelle</label>
<input type="text" class="validate" id="gatewayInput" name="gateway" placeholder="192.168.0.1" pattern="^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"/>
</div>
<div class="input-field">
<label for="maskInput">Masque</label>
<input type="text" class="validate" id="maskInput" name="mask" placeholder="255.255.255.0" pattern="^((0|128|192|224|240|248|252|255)\.0\.0.0|255\.(0|128|192|224|240|248|252|255)\.0\.0|255\.255\.(0|128|192|224|240|248|252|255)\.0|255\.255\.255\.(0|128|192|224|240|248|252|255))$"'/>
</div>
<button type="submit" class="btn-floating halfway-fab waves-effect waves-light teal"><i class="material-icons">add</i></button>
</form>
</div>
</div>
</div>

View File

@ -1,38 +0,0 @@
<header>
<nav>
<div class="nav-wrapper navbar-fixed teal lighten-2">
<a href="." class="brand-logo center">TablIP</a>
<div>
<a href="." class="breadcrumb">Sites</a>
</div>
</div>
</nav>
</header>
<div class="container">
<h1>Sites</h1>
<div class="collection">
<?php
include "connect.php";
$sites = $db->query('SELECT Name FROM Sites ORDER BY Name');
while ($site = $sites->fetch())
{
echo " <a href='.?site=${site['Name']}' class='collection-item'>${site['Name']}</a>\n";
}
$sites->closeCursor();
?>
</div>
<div class="card teal lighten-5">
<div class="card-content">
<span class="card-title">Nouveau site</span>
<form name="addSite" id="addSite" action="addSite.php" method="post">
<div class="input-field">
<label for="siteName">Nom</label>
<input type="text" class="validate" id="siteName" name="siteName" placeholder="Site" required/>
</div>
<button type="submit" class="btn-floating halfway-fab waves-effect waves-light teal"><i class="material-icons">add</i></button>
</form>
</div>
</div>
</div>

View File

@ -1,36 +1,33 @@
<?php <?php
if (!(isset($_POST["Ip"]) $ip = filter_input(INPUT_POST, "ip", FILTER_VALIDATE_INT);
&& isset($_POST["NetworkId"]) $networkId = filter_input(INPUT_POST, "networkId", FILTER_VALIDATE_INT);
&& isset($_POST["Hostname"]) $hostname = filter_input(INPUT_POST, "hostname", FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
&& isset($_POST["FQDN"]) $fqdn = filter_input(INPUT_POST, "fqdn", FILTER_VALIDATE_DOMAIN);
&& isset($_POST["MacAddress"]) $macAddress = filter_input(INPUT_POST, "macAddress", FILTER_VALIDATE_MAC);
&& isset($_POST["Comments"]))) { $comments = filter_input(INPUT_POST, "comments", FILTER_SANITIZE_STRING);
header("HTTP/1.x 400 Bad Request"); if (!($ip && $networkId)) {
die(); header("Location: 400.php");
exit;
} }
$ip = (int) $_POST["Ip"];
$networkId = (int) $_POST["NetworkId"];
try {
include "connect.php"; include "connect.php";
try {
$update = $db->prepare(" $update = $db->prepare("
INSERT INTO Hosts(IpAddress, NetworkId, Hostname, FQDN, MacAddress, Comments) INSERT INTO Hosts(IpAddress, NetworkId, Hostname, FQDN, MacAddress, Comments)
VALUES($ip, $networkId, :i_hostname, :i_fqdn, :i_macAddress, :i_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 ON DUPLICATE KEY UPDATE Hostname = :u_hostname, FQDN = :u_fqdn, MacAddress = :u_macAddress, Comments = :u_comments
"); ");
$update->execute([ $update->execute([
'i_hostname' => $_POST["Hostname"], 'i_hostname' => $hostname,
'i_fqdn' => $_POST["FQDN"], 'i_fqdn' => $fqdn,
'i_macAddress' => $_POST["MacAddress"], 'i_macAddress' => $macAddress,
'i_comments' => $_POST["Comments"], 'i_comments' => $comments,
'u_hostname' => $_POST["Hostname"], 'u_hostname' => $hostname,
'u_fqdn' => $_POST["FQDN"], 'u_fqdn' => $fqdn,
'u_macAddress' => $_POST["MacAddress"], 'u_macAddress' => $macAddress,
'u_comments' => $_POST["Comments"] 'u_comments' => $comments
]); ]);
} catch(Exception $e) { } catch(Exception $e) {
header("HTTP/1.x 500 " . $e->getMessage()); header("Location: 500.php");
die($e->getMessage()); exit;
} }
?> ?>