Project

General

Profile

Feature #12963 » nmap.patch

Phil Wardt, 03/20/2022 08:48 AM

View differences:

src/usr/local/pkg/nmap.inc
39 39
}
40 40

  
41 41
function nmap_custom_add_php_command() {
42
	$fp = "/root/";
43
	$fn = "nmap.result";
44
	/* check if nmap scan is already running */
45
	$processcheck = (trim(shell_exec("/bin/ps axw -O pid= | /usr/bin/grep 'tee {$fp}{$fn}' | /usr/bin/egrep -v '(pflog|grep)'")));
46

  
47
	$processisrunning = ($processcheck != "");
48

  
49
	if ($processisrunning) {
50
		echo "<strong>NMap is already running. Please wait for current scan to complete</strong><br />";
51
		echo '<br /><br /><button class="btn btn-info" type="button" value="' . gettext("Back to NMap") . '" onclick="history.back()"><i class="fa fa-undo icon-embed-btn"></i> ' . gettext("Back to NMap") . '</button>';
52
	} else {
42 53
		$nmap_options = "";
43 54

  
44 55
		if (is_ipaddrv6($_POST['hostname']) || is_subnetv6($_POST['hostname'])) {
......
77 88
	}
78 89

  
79 90
	$nmap_options .= " " . escapeshellarg($_POST['hostname']);
80
	echo "<strong>Running: /usr/local/bin/nmap {$nmap_options}</strong><br />";
81
	system("/usr/local/bin/nmap" . $nmap_options);
91
		$cmd = "/usr/local/bin/nmap {$nmap_options} | /usr/bin/tee {$fp}{$fn}";
92
		echo "<strong>Running: {$cmd}</strong><br />";
93
		mwexec_bg($cmd);
94
		echo "<strong>Check results in Results log TAB</strong><br />";
82 95
		echo '<br /><br /><button class="btn btn-info" type="button" value="' . gettext("Back to NMap") . '" onclick="history.back()"><i class="fa fa-undo icon-embed-btn"></i> ' . gettext("Back to NMap") . '</button>';
96
	}
83 97
}
84 98

  
85 99
function nmap_get_interfaces() {
86
-- a/src/usr/local/pkg/nmap.xml
100
++ b/src/usr/local/pkg/nmap.xml
......
39 39
		<section>Diagnostics</section>
40 40
		<configfile>nmap.xml</configfile>
41 41
	</menu>
42
	<tabs>
43
		<tab>
44
			<text>Scan</text>
45
			<url>/pkg_edit.php?xml=nmap.xml&amp;id=0</url>
46
			<active/>
47
		</tab>
48
		<tab>
49
			<text>Results log</text>
50
			<url>/nmap_view_results.php</url>
51
		</tab>
52
	</tabs>
42 53
	<fields>
43 54
		<field>
44 55
			<fielddescr>IP or Hostname</fielddescr>
45
-- a/src/usr/local/www/nmap_view_results.php
56
++ b/src/usr/local/www/nmap_view_results.php
......
1
<?php
2
/*
3
 * nmap_view_results.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2022-2022 Rubicon Communications, LLC (Netgate)
7
 * Copyright (C) 2022 Phil Wart <phytowardt@gmail.com>
8
 * All rights reserved.
9
 *
10
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13
 *
14
 * http://www.apache.org/licenses/LICENSE-2.0
15
 *
16
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21
 */
22

  
23
require("guiconfig.inc");
24
#require_once("pfsense-utils.inc");
25
require("/usr/local/pkg/nmap.inc");
26

  
27
$pgtitle = array("Package", "Diagnostics: NMap", "NMap Results");
28

  
29
require_once("head.inc");
30

  
31
$tab_array = array();
32
$tab_array[] = array("Scan", false, "/pkg_edit.php?xml=nmap.xml&amp;id=0");
33
$tab_array[] = array("Results log", true, "/nmap_view_results.php");
34
display_top_tabs($tab_array);
35

  
36
$fp = "/root/";
37
$fn = "nmap.result";
38

  
39
$form = new Form(false);
40
$section = new Form_Section('NMap Scan Results:');
41
if (file_exists($fp.$fn)) {
42
	$section->addInput(new Form_StaticText(
43
		'Last scan completed on:',
44
		date("F jS, Y g:i:s a.", filemtime($fp.$fn))
45
	));
46
} else {
47
	$section->addInput(new Form_StaticText(
48
		'Last scan completed on:',
49
		'none'
50
	));
51
}
52

  
53
$form->add($section);
54
print($form);
55
?>
56

  
57
<div class="panel panel-default">
58
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Last scan log')?></h2></div>
59
	<div class="panel-body">
60
		<div class="form-group">
61
<?php
62
		print('<textarea class="form-control" rows="20" style="font-size: 13px; font-family: consolas,monaco,roboto mono,liberation mono,courier;">');
63
		$max_display_size = 50*1024*1024; // 50MB limit on GUI capture display. See https://redmine.pfsense.org/issues/9239
64
		if (file_exists($fp.$fn) && (filesize($fp.$fn) > $max_display_size)) {
65
			print(gettext("Nmap scan results file is too large to display in the GUI.") .
66
			    "\n" .
67
			    gettext("Download the file, or view it in the console or ssh shell.") .
68
				"\n" .
69
				gettext("Results file: {$fp}{$fn}"));
70
		} elseif (!file_exists($fp.$fn) || (filesize($fp.$fn) === 0)) {
71
			print(gettext("No nmap scan results to display."));
72
		} else {
73
			system("/bin/cat {$fp}{$fn}");
74
		}
75
		print('</textarea>');
76

  
77
?>
78
		</div>
79
	</div>
80
</div>
81
<?php
82

  
83
include("foot.inc");
84

  
(5-5/30)