--- a/src/usr/local/pkg/nmap.xml +++ b/src/usr/local/pkg/nmap.xml @@ -27,7 +27,7 @@ ]]> nmap - Diagnostics: NMap + Diagnostics: Nmap Scan fa-rss btn-primary @@ -35,10 +35,21 @@ true /usr/local/pkg/nmap.inc - NMap + Nmap
Diagnostics
nmap.xml
+ + + Scan + /pkg_edit.php?xml=nmap.xml&id=0 + + + + View Results + /nmap_view_results.php + + IP or Hostname --- a/src/usr/local/pkg/nmap.inc +++ b/src/usr/local/pkg/nmap.inc @@ -39,6 +39,17 @@ } function nmap_custom_add_php_command() { + $fp = "/root/"; + $fn = "nmap.result"; + /* check if nmap scan is already running */ + $processcheck = (trim(shell_exec("/bin/ps axw -O pid= | /usr/bin/grep 'tee {$fp}{$fn}' | /usr/bin/egrep -v '(pflog|grep)'"))); + + $processisrunning = ($processcheck != ""); + + if ($processisrunning) { + echo "Nmap is already running. Please wait for current scan to complete
"; + echo '

'; + } else { $nmap_options = ""; if (is_ipaddrv6($_POST['hostname']) || is_subnetv6($_POST['hostname'])) { @@ -77,9 +88,12 @@ } $nmap_options .= " " . escapeshellarg($_POST['hostname']); - echo "Running: /usr/local/bin/nmap {$nmap_options}
"; - system("/usr/local/bin/nmap" . $nmap_options); - echo '

'; + $cmd = "/usr/local/bin/nmap {$nmap_options} | /usr/bin/tee {$fp}{$fn}"; + echo "Running: {$cmd}
"; + mwexec_bg($cmd); + echo "Check results in View Results TAB
"; + echo '

'; + } } function nmap_get_interfaces() { --- a/src/usr/local/www/nmap_view_results.php +++ b/src/usr/local/www/nmap_view_results.php @@ -0,0 +1,127 @@ +addInput(new Form_StaticText( + 'Last scan completed on:', + date("F jS, Y g:i:s a.", filemtime($fp.$fn)) + )); +} else { + $section->addInput(new Form_StaticText( + 'Last scan completed on:', + 'none' + )); +} + +$form->add($section); +?> + +
+

+
+
+'); + $max_display_size = 50*1024*1024; // 50MB limit on GUI capture display. See https://redmine.pfsense.org/issues/9239 + if (file_exists($fp.$fn) && (filesize($fp.$fn) > $max_display_size)) { + print(gettext("Nmap scan results file is too large to display in the GUI.") . + "\n" . + gettext("Download the file, or view it in the console or ssh shell.") . + "\n" . + gettext("Results file: {$fp}{$fn}")); + } elseif (!file_exists($fp.$fn) || (filesize($fp.$fn) === 0)) { + print(gettext("No nmap scan results to display.")); + } else { + print(file_get_contents($fp.$fn)); + } + print(''); + +?> +
+
+
+add(new Form_Button( + 'clearbtn', + 'Clear Results', + null, + 'fa-undo' + ))->setHelp('Clear scan results file.')->addClass('btn-danger restore'); + + $section->add($group); + +} else if ($processisrunning) { + $group = new Form_Group(''); + $group->add(new Form_Button( + 'refreshbtn', + ' Refresh Results', + null, + 'fa-retweet' + ))->setHelp('Reload scan results.')->addClass('btn-success'); + + $section->add($group); +} + +print($form); + +include("foot.inc"); +