This commit is contained in:
Adrien MALINGREY 2025-02-14 11:28:59 +01:00
parent 234cfbf860
commit 4d4d8f1864
2 changed files with 326 additions and 201 deletions

145
index2.php Normal file
View File

@ -0,0 +1,145 @@
<?php include_once "config.php"; ?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<title>lanScan</title>
<link rel="icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css"
href="https://cdn.jsdelivr.net/npm/fomantic-ui@2.9.3/dist/semantic.min.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<style>
body {
background-image: url(bg.jpg);
background-size: cover;
}
body>.grid {
height: 100%;
}
h2.logo {
filter: drop-shadow(0 0 2px);
}
.ui.inverted.segment {
background: #1b1c1dc0;
backdrop-filter: blur(7px);
}
</style>
</head>
<body class="inverted">
<div class="ui middle aligned center aligned inverted grid">
<div class="column" style="max-width: 450px;">
<h2 class="ui inverted teal fluid image header logo">
lan<?php include 'logo.svg'; ?>can
</h2>
<?php if (isset($errorMessage)) { ?>
<div class="ui negative message">
<i class="close icon"></i>
<div class="header">Erreur</div>
<p><?= $errorMessage ?></p>
</div>
<?php } ?>
<form id="scanForm" class="ui large form initial inverted" action="scan.php" method="get">
<div class="ui left aligned raised segment inverted">
<h2 class="ui header">Découvrir ou superviser un réseau</h2>
<div class="inverted field">
<div class="ui large input">
<input id="nameInput" type="text" name="target" placeholder="<?= $_SERVER['REMOTE_ADDR']; ?>/24"
list="targetList" pattern="[a-zA-Z0-9._\/ \-]+" required title="Les cibles peuvent être spécifiées par des noms d'hôtes, des adresses IP, des adresses de réseaux, etc.
Exemples: <?= $_SERVER['REMOTE_ADDR']; ?>/24 <?= $_SERVER['SERVER_NAME']; ?> 10.0-255.0-255.1-254" />
</div>
</div>
<input type="hidden" name="preset" value="lanScan" />
<div class="field">
<label for="nameInput">Enregistrer sous le nom (optionnel)</label>
<div class="ui small input">
<input id="nameInput" type="text" name="name" placeholder="Reseau local" pattern='[0-9a-zA-Z\-_\. ]+'
title="Caractères autorisés: a-z A-Z 0-9 - _ ." />
</div>
</div>
<div class="ui error message"></div>
<button type="submit" class="ui fluid large teal labeled icon submit button">
<i class="satellite dish icon"></i>Scanner
</button>
<div class="ui divider"></div>
<a href="options.php">Options avancées</a>
</div>
</form>
<?php if (file_exists($SCANSDIR)) { ?>
<div class="ui left aligned raised segment inverted">
<div class="ui inverted accordion">
<div class="title"><i class="dropdown icon"></i></i>Scans enregistrés</div>
<div class="content">
<table class="ui very basic inverted compact table">
<tbody>
<?php
foreach (scandir($SCANSDIR) as $filename) {
if (substr($filename, -4) == '.xml') {
$name = str_replace('!', '/', substr_replace($filename, '', -4));
echo "<tr><td class='selectable'><a href='$SCANSDIR/" . rawurlencode($filename) . "'><i class='tasks icon'></i>$name</a></td><td class='collapsing'><a href='rescan.php?name=$name' class='ui mini labelled button' onclick='rescan(this)'><i class='sync icon'></i>Rescanner</a></td><td class='collapsing'><a href='rm.php?name=$name' class='ui mini negative icon button'><i class='trash icon'></i></a></td></td></tr>\n";
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<datalist id='targetList'>
<option value="<?= $_SERVER['REMOTE_ADDR']; ?>/24"></option>
<option value="<?= $_SERVER['SERVER_NAME']; ?>"></option>
</datalist>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.js"></script>
<script>
$('.ui.accordion').accordion()
scanForm.onsubmit = function (event) {
if (this.checkValidity()) {
scanForm.classList.add("loading")
$.toast({
title: 'Scan en cours...',
message: 'Merci de patienter',
class: 'info',
showIcon: 'satellite dish',
displayTime: 0,
closeIcon: true,
position: 'bottom right',
})
return true
} else {
event.preventDefault()
this.reportValidity()
}
}
function rescan(link) {
link.getElementsByTagName('i')[0].className = 'loading spinner icon'
$.toast({
title: 'Scan en cours...',
message: 'Merci de patienter',
class: 'info',
showIcon: 'satellite dish',
displayTime: 0,
closeIcon: true,
position: 'bottom right',
})
}
</script>
</body>
</html

View File

@ -9,18 +9,14 @@
<xsl:output method="html" encoding="UTF-8" indent="yes" /> <xsl:output method="html" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements='*' /> <xsl:strip-space elements='*' />
<xsl:variable name="stylesheetURL" <xsl:variable name="stylesheetURL" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'), '?')" />
select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'), '?')" />
<xsl:variable name="base" select="concat($stylesheetURL, '/../../')" /> <xsl:variable name="base" select="concat($stylesheetURL, '/../../')" />
<xsl:variable name="name" <xsl:variable name="name" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'name='), '&quot;')" />
select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'name='), '&quot;')" />
<xsl:template match="nmaprun"> <xsl:template match="nmaprun">
<xsl:variable name="target" select="substring-after(@args, '-oX - ')" /> <xsl:variable name="target" select="substring-after(@args, '-oX - ')" />
<xsl:variable <xsl:variable name="current" select="." />
name="current" select="." /> <xsl:variable name="init" select="document(concat($base, 'scans/', $name, '.xml'))/nmaprun" />
<xsl:variable name="init"
select="document(concat($base, 'scans/', $name, '.xml'))/nmaprun" />
<html lang="fr"> <html lang="fr">
<xsl:apply-templates select="." mode="head"> <xsl:apply-templates select="." mode="head">
@ -51,8 +47,7 @@
</xsl:choose> </xsl:choose>
</h1> </h1>
<table id="scanResultsTable" style="width:100%" role="grid" <table id="scanResultsTable" style="width:100%" role="grid" class="ui sortable small compact stuck striped table">
class="ui sortable small compact stuck striped table">
<thead> <thead>
<tr> <tr>
<th style="width: min-content">État</th> <th style="width: min-content">État</th>
@ -68,8 +63,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<xsl:apply-templates <xsl:apply-templates select="host | $init/host[not(address/@addr=$current/host/address/@addr)][not(status/@state='down')]">
select="host | $init/host[not(address/@addr=$current/host/address/@addr)][not(status/@state='down')]">
<xsl:with-param name="init" select="$init" /> <xsl:with-param name="init" select="$init" />
<xsl:with-param name="current" select="$current" /> <xsl:with-param name="current" select="$current" />
</xsl:apply-templates> </xsl:apply-templates>
@ -110,8 +104,8 @@ var table = $('#scanResultsTable').DataTable({
bottomEnd: 'paging', bottomEnd: 'paging',
bottom2Start: 'info', bottom2Start: 'info',
}, },
order: [[0, 'asc'], [1, 'asc']]
}) })
table.order([1, 'asc']).draw()
$('.ui.dropdown').dropdown() $('.ui.dropdown').dropdown()
</script> </script>
@ -122,17 +116,14 @@ $('.ui.dropdown').dropdown()
</body> </body>
</html> </html>
</xsl:template> </xsl:template>
<xsl:template match="host"> <xsl:template match="host">
<xsl:param name="init" /> <xsl:param name="init" />
<xsl:param name="current" /> <xsl:param name="current" />
<xsl:variable name="addr" <xsl:variable name="addr" select="address/@addr" />
select="address/@addr" /> <xsl:variable name="initHost" select="$init/host[address/@addr=$addr]" />
<xsl:variable name="initHost" <xsl:variable name="currentHost" select="$current/host[address/@addr=$addr]" />
select="$init/host[address/@addr=$addr]" />
<xsl:variable name="currentHost"
select="$current/host[address/@addr=$addr]" />
<xsl:variable name="hostAddress"> <xsl:variable name="hostAddress">
<xsl:choose> <xsl:choose>
<xsl:when test="hostnames/hostname/@name"> <xsl:when test="hostnames/hostname/@name">
@ -179,8 +170,7 @@ $('.ui.dropdown').dropdown()
<xsl:if test="substring-after(hostnames/hostname/@name, '.')"> <xsl:if test="substring-after(hostnames/hostname/@name, '.')">
<wbr /> <wbr />
<xsl:text>.</xsl:text> <xsl:text>.</xsl:text>
<xsl:value-of <xsl:value-of select="substring-after(hostnames/hostname/@name, '.')" />
select="substring-after(hostnames/hostname/@name, '.')" />
</xsl:if> </xsl:if>
</td> </td>
<xsl:if test="../host/address[@addrtype='mac']/@vendor"> <xsl:if test="../host/address[@addrtype='mac']/@vendor">
@ -189,8 +179,7 @@ $('.ui.dropdown').dropdown()
</td> </td>
</xsl:if> </xsl:if>
<td> <td>
<xsl:apply-templates <xsl:apply-templates select="$currentHost/ports/port[not(state/@state='closed')] | $initHost/ports/port[not(state/@state='closed')][not(@portid=$currentHost/ports/port/@portid)]">
select="$currentHost/ports/port[not(state/@state='closed')] | $initHost/ports/port[not(state/@state='closed')][not(@portid=$currentHost/ports/port/@portid)]">
<xsl:with-param name="initHost" select="$initHost" /> <xsl:with-param name="initHost" select="$initHost" />
<xsl:with-param name="currentHost" select="$currentHost" /> <xsl:with-param name="currentHost" select="$currentHost" />
<xsl:with-param name="hostAddress" select="$hostAddress" /> <xsl:with-param name="hostAddress" select="$hostAddress" />
@ -208,24 +197,20 @@ $('.ui.dropdown').dropdown()
</a> </a>
</td> </td>
</tr> </tr>
</xsl:template> </xsl:template>
<xsl:template match="port"> <xsl:template match="port">
<xsl:param name="hostAddress" /> <xsl:param name="hostAddress" />
<xsl:param name="initHost" /> <xsl:param name="initHost" />
<xsl:param name="currentHost" /> <xsl:param name="currentHost" />
<xsl:variable <xsl:variable name="portid" select="@portid" />
name="portid" select="@portid" /> <xsl:variable name="initPort" select="$initHost/ports/port[@portid=$portid]" />
<xsl:variable name="initPort" <xsl:variable name="currentPort" select="$currentHost/ports/port[@portid=$portid]" />
select="$initHost/ports/port[@portid=$portid]" />
<xsl:variable name="currentPort"
select="$currentHost/ports/port[@portid=$portid]" />
<a target="_blank"> <a target="_blank">
<xsl:attribute name="class"> <xsl:attribute name="class">
<xsl:text>ui mini label </xsl:text> <xsl:text>ui mini label </xsl:text>
<xsl:if <xsl:if test="$currentPort/script[@id='smb-shares-size']/table">dropdown button share-size </xsl:if>
test="$currentPort/script[@id='smb-shares-size']/table">dropdown button share-size </xsl:if>
<xsl:choose> <xsl:choose>
<xsl:when test="$currentPort/script[@id='http-info']/elem[@key='status']>=500"> red</xsl:when> <xsl:when test="$currentPort/script[@id='http-info']/elem[@key='status']>=500"> red</xsl:when>
<xsl:when test="$currentPort/script[@id='http-info']/elem[@key='status']>=400"> orange</xsl:when> <xsl:when test="$currentPort/script[@id='http-info']/elem[@key='status']>=400"> orange</xsl:when>
@ -238,20 +223,17 @@ $('.ui.dropdown').dropdown()
<xsl:if test="$currentPort/script[@id='smb-shares-size']/table"> <xsl:if test="$currentPort/script[@id='smb-shares-size']/table">
<xsl:attribute name="style"> <xsl:attribute name="style">
<xsl:for-each select="$currentPort/script[@id='smb-shares-size']/table"> <xsl:for-each select="$currentPort/script[@id='smb-shares-size']/table">
<xsl:sort select="elem[@key='FreeSize'] div elem[@key='TotalSize']" <xsl:sort select="elem[@key='FreeSize'] div elem[@key='TotalSize']" order="ascending" />
order="ascending" />
<xsl:if test="position()=1"> <xsl:if test="position()=1">
<xsl:text>--free: </xsl:text> <xsl:text>--free: </xsl:text>
<xsl:value-of select="elem[@key='FreeSize']" /> <xsl:value-of select="elem[@key='FreeSize']" />
<xsl:text>; --total: </xsl:text> <xsl:text>; --total: </xsl:text>
<xsl:value-of <xsl:value-of select="elem[@key='TotalSize']" />
select="elem[@key='TotalSize']" />
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
</xsl:attribute> </xsl:attribute>
</xsl:if> </xsl:if>
<xsl:if <xsl:if test="service/@name='ftp' or service/@name='ssh' or service/@name='http' or service/@name='https'">
test="service/@name='ftp' or service/@name='ssh' or service/@name='http' or service/@name='https'">
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:choose> <xsl:choose>
<xsl:when test="service/@name='http' and service/@tunnel='ssl'"> <xsl:when test="service/@name='http' and service/@tunnel='ssl'">
@ -262,8 +244,7 @@ $('.ui.dropdown').dropdown()
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
<xsl:text>://</xsl:text> <xsl:text>://</xsl:text>
<xsl:value-of <xsl:value-of select="$hostAddress" />
select="$hostAddress" />
<xsl:text>:</xsl:text> <xsl:text>:</xsl:text>
<xsl:value-of select="@portid" /> <xsl:value-of select="@portid" />
</xsl:attribute> </xsl:attribute>
@ -273,21 +254,22 @@ $('.ui.dropdown').dropdown()
<xsl:text>rdp.php?v=</xsl:text> <xsl:text>rdp.php?v=</xsl:text>
<xsl:value-of select="$hostAddress" /> <xsl:value-of select="$hostAddress" />
<xsl:text>&amp;p=</xsl:text> <xsl:text>&amp;p=</xsl:text>
<xsl:value-of <xsl:value-of select="@portid" />
select="@portid" />
</xsl:attribute> </xsl:attribute>
</xsl:if> </xsl:if>
<xsl:attribute name="title"> <xsl:attribute name="title">
<xsl:value-of select="@protocol" />:<xsl:value-of select="@portid" /> <xsl:value-of select="@protocol" />
: <xsl:value-of select="@portid" />
</xsl:attribute> </xsl:attribute>
<xsl:choose> <xsl:choose>
<xsl:when test="service/@name='unknown'"> <xsl:when test="service/@name='unknown'">
<xsl:choose> <xsl:choose>
<xsl:when test="@protocol='tcp'">:</xsl:when> <xsl:when test="@protocol='tcp'">:</xsl:when>
<xsl:otherwise><xsl:value-of select="substring(@protocol, 1, 1)" />:</xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="substring(@protocol, 1, 1)" />
:</xsl:otherwise>
</xsl:choose> </xsl:choose>
<xsl:value-of <xsl:value-of select="@portid" />
select="@portid" />
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="service/@name" /> <xsl:value-of select="service/@name" />
@ -302,15 +284,13 @@ $('.ui.dropdown').dropdown()
</div> </div>
</xsl:if> </xsl:if>
</a> </a>
</xsl:template> </xsl:template>
<xsl:template match="table"> <xsl:template match="table">
<xsl:param name="hostAddress" /> <xsl:param name="hostAddress" />
<a class="item share-size" <a class="item share-size" href="file://///{$hostAddress}/{@key}" target="_blank" rel="noopener noreferrer" style="--free: {elem[@key='FreeSize']}; --total: {elem[@key='TotalSize']}">
href="file://///{$hostAddress}/{@key}" target="_blank" rel="noopener noreferrer"
style="--free: {elem[@key='FreeSize']}; --total: {elem[@key='TotalSize']}">
<xsl:value-of select="@key" /> <xsl:value-of select="@key" />
</a> </a>
</xsl:template> </xsl:template>
</xsl:stylesheet> </xsl:stylesheet>