Project

General

Profile

Feature #12963 » nmap-complete-v4-ok.patch

Phil Wardt, 03/22/2022 03:20 PM

View differences:

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>View Results</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/pkg/nmap.inc
56
++ b/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 View Results 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/www/nmap_view_results.php
100
++ 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
 * All rights reserved.
8
 *
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 * http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 */
21

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

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

  
28
require_once("head.inc");
29

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

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

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

  
52
$form->add($section);
53
?>
54

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

  
75
?>
76
		</div>
77
	</div>
78
</div>
79
<?php
80

  
81
/* check if nmap scan is already running */
82
$processcheck = (trim(shell_exec("/bin/ps axw -O pid= | /usr/bin/grep 'tee {$fp}{$fn}' | /usr/bin/egrep -v '(pflog|grep)'")));
83

  
84
$processisrunning = ($processcheck != "");
85

  
86
if ($_POST) {
87
	if ($_POST['clearbtn'] != "") {
88
		$action = gettext("Clear Results");
89

  
90
		//delete previous scan result if it exists
91
		if (file_exists($fp.$fn) and $processisrunning != true) {
92
			unlink ($fp.$fn);
93
			header("Refresh: 0");
94
		}
95
	} else if ($_POST['refreshbtn'] != "") {
96
		$action = gettext("Refresh Results");
97
		header("Refresh: 0");
98
	}
99
}
100

  
101
if (file_exists($fp.$fn) and $processisrunning != true) {
102
	$group = new Form_Group('');
103
	$group->add(new Form_Button(
104
		'clearbtn',
105
		'Clear Results',
106
		null,
107
		'fa-undo'
108
	))->setHelp('Clear scan results file.')->addClass('btn-danger restore');
109

  
110
	$section->add($group);
111

  
112
} else if ($processisrunning) {
113
		$group = new Form_Group('');
114
		$group->add(new Form_Button(
115
			'refreshbtn',
116
			' Refresh Results',
117
			null,
118
			'fa-retweet'
119
		))->setHelp('Reload scan results.')->addClass('btn-success');
120

  
121
	$section->add($group);
122
}
123

  
124
print($form);
125

  
126
include("foot.inc");
127

  
(11-11/30)