| 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&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&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 | ?> | 
  |  | 55 |  | 
  |  | 56 | <div class="panel panel-default"> | 
  |  | 57 | 	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Last scan log')?></h2></div> | 
  |  | 58 | 	<div class="panel-body"> | 
  |  | 59 | 		<div class="form-group"> | 
  |  | 60 | <?php | 
  |  | 61 | 		print('<textarea class="form-control" rows="20" style="font-size: 13px; font-family: consolas,monaco,roboto mono,liberation mono,courier;">'); | 
  |  | 62 | 		$max_display_size = 50*1024*1024; // 50MB limit on GUI capture display. See https://redmine.pfsense.org/issues/9239 | 
  |  | 63 | 		if (file_exists($fp.$fn) && (filesize($fp.$fn) > $max_display_size)) { | 
  |  | 64 | 			print(gettext("Nmap scan results file is too large to display in the GUI.") . | 
  |  | 65 | 				"\n" . | 
  |  | 66 | 				gettext("Download the file, or view it in the console or ssh shell.") . | 
  |  | 67 | 				"\n" . | 
  |  | 68 | 				gettext("Results file: {$fp}{$fn}")); | 
  |  | 69 | 		} elseif (!file_exists($fp.$fn) || (filesize($fp.$fn) === 0)) { | 
  |  | 70 | 			print(gettext("No nmap scan results to display.")); | 
  |  | 71 | 		} else { | 
  |  | 72 | 			system("/bin/cat {$fp}{$fn}"); | 
  |  | 73 | 		} | 
  |  | 74 | 		print('</textarea>'); | 
  |  | 75 |  | 
  |  | 76 | ?> | 
  |  | 77 | 		</div> | 
  |  | 78 | 	</div> | 
  |  | 79 | </div> | 
  |  | 80 | <?php | 
  |  | 81 |  | 
  |  | 82 | /* check if nmap scan is already running */ | 
  |  | 83 | $processcheck = (trim(shell_exec("/bin/ps axw -O pid= | /usr/bin/grep 'tee {$fp}{$fn}' | /usr/bin/egrep -v '(pflog|grep)'"))); | 
  |  | 84 |  | 
  |  | 85 | $processisrunning = ($processcheck != ""); | 
  |  | 86 |  | 
  |  | 87 | if ($_POST) { | 
  |  | 88 | 	if ($_POST['clearbtn'] != "") { | 
  |  | 89 | 		$action = gettext("Clear log"); | 
  |  | 90 |  | 
  |  | 91 | 		//delete previous scan result if it exists | 
  |  | 92 | 		if (file_exists($fp.$fn) and $processisrunning != true) { | 
  |  | 93 | 			unlink ($fp.$fn); | 
  |  | 94 | 			header("Refresh: 0"); | 
  |  | 95 | 		} | 
  |  | 96 | 	} else if ($_POST['refreshbtn'] != "") { | 
  |  | 97 | 		$action = gettext("Refresh results"); | 
  |  | 98 | 		header("Refresh: 0"); | 
  |  | 99 | 	} | 
  |  | 100 | } | 
  |  | 101 |  | 
  |  | 102 | if (file_exists($fp.$fn) and $processisrunning != true) { | 
  |  | 103 | 	$group = new Form_Group(''); | 
  |  | 104 | 	$group->add(new Form_Button( | 
  |  | 105 | 		'clearbtn', | 
  |  | 106 | 		'Clear log', | 
  |  | 107 | 		null, | 
  |  | 108 | 		'fa-undo' | 
  |  | 109 | 	))->setHelp('Clear scan results file.')->addClass('btn-danger restore'); | 
  |  | 110 |  | 
  |  | 111 | 	$section->add($group); | 
  |  | 112 |  | 
  |  | 113 | } else if ($processisrunning) { | 
  |  | 114 | 		$group = new Form_Group(''); | 
  |  | 115 | 		$group->add(new Form_Button( | 
  |  | 116 | 			'refreshbtn', | 
  |  | 117 | 			' Refresh results', | 
  |  | 118 | 			null, | 
  |  | 119 | 			'fa-retweet' | 
  |  | 120 | 		))->setHelp('Reload scan results.')->addClass('btn-success'); | 
  |  | 121 |  | 
  |  | 122 | 	$section->add($group); | 
  |  | 123 | } | 
  |  | 124 |  | 
  |  | 125 | print($form); | 
  |  | 126 |  | 
  |  | 127 | include("foot.inc"); | 
  |  | 128 |  |