flow change
This commit is contained in:
parent
f82aa4c734
commit
b499bb1be0
31
400.php
Normal file
31
400.php
Normal 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
31
404.php
Normal 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
31
500.php
Normal 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>
|
@ -1,27 +1,22 @@
|
||||
<?php
|
||||
if (!(isset($_POST['name'])
|
||||
&& isset($_POST['gateway'])
|
||||
&& isset($_POST['mask'])
|
||||
&& isset($_POST['siteId'])
|
||||
&& isset($_POST['siteName']))) {
|
||||
die("Erreur : données manquantes !<br/><a href='javascript:history.back(1);'>Revenir en arrière</a>");
|
||||
$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() . "<br/><a href='javascript:history.back(1);'>Revenir en arrière</a>");
|
||||
header("Location: 500.php");
|
||||
exit;
|
||||
}
|
||||
exit;
|
||||
?>
|
||||
|
15
addSite.php
15
addSite.php
@ -1,14 +1,17 @@
|
||||
<?php
|
||||
if (!isset($_POST['siteName'])) {
|
||||
die("Nom du site manquant !<br/><a href='javascript:history.back(1);'>Revenir en arrière</a>");
|
||||
$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() . "<br/><a href='javascript:history.back(1);'>Revenir en arrière</a>");
|
||||
header("Location: 500.php");
|
||||
exit;
|
||||
}
|
||||
?>
|
@ -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() . "<br/><a href='javascript:history.back(1);'>Revenir en arrière</a>");
|
||||
header("Location: 500.php");
|
||||
}
|
||||
?>
|
@ -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;
|
||||
}
|
37
index.php
37
index.php
@ -1,7 +1,6 @@
|
||||
<?php include "connect.php"; ?>
|
||||
<html>
|
||||
<head>
|
||||
<title>TablIP</title>
|
||||
<title>TablIP - Sites</title>
|
||||
<link rel="stylesheet" href="css/style.css"/>
|
||||
<link rel="stylesheet" href="css/icons.css"/>
|
||||
<link rel="stylesheet" href="css/materialize.css"/>
|
||||
@ -10,12 +9,38 @@
|
||||
</head>
|
||||
<body>
|
||||
<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
|
||||
if (isset($_GET["site"])) {
|
||||
include "siteNetworks.php";
|
||||
} else {
|
||||
include "sitesList.php";
|
||||
include "connect.php";
|
||||
foreach ($db->query("SELECT * FROM `Sites` ORDER BY `Name`") as $site) {
|
||||
print " </li><a href='site.php?id=${site['id']}' class='collection-item'>${site['Name']}</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 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>
|
||||
</html>
|
25
js/script.js
25
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")
|
||||
}
|
||||
}
|
90
network.php
Normal file
90
network.php
Normal 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
71
site.php
Normal 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>
|
||||
|
114
siteNetworks.php
114
siteNetworks.php
@ -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>
|
||||
|
||||
|
||||
|
@ -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>
|
@ -1,36 +1,33 @@
|
||||
<?php
|
||||
if (!(isset($_POST["Ip"])
|
||||
&& isset($_POST["NetworkId"])
|
||||
&& isset($_POST["Hostname"])
|
||||
&& isset($_POST["FQDN"])
|
||||
&& isset($_POST["MacAddress"])
|
||||
&& isset($_POST["Comments"]))) {
|
||||
header("HTTP/1.x 400 Bad Request");
|
||||
die();
|
||||
$ip = filter_input(INPUT_POST, "ip", FILTER_VALIDATE_INT);
|
||||
$networkId = filter_input(INPUT_POST, "networkId", FILTER_VALIDATE_INT);
|
||||
$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)) {
|
||||
header("Location: 400.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$ip = (int) $_POST["Ip"];
|
||||
$networkId = (int) $_POST["NetworkId"];
|
||||
|
||||
include "connect.php";
|
||||
try {
|
||||
include "connect.php";
|
||||
$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
|
||||
");
|
||||
$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;
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user