--- 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); + $cmd = "/usr/local/bin/nmap {$nmap_options} | /usr/bin/tee {$fp}{$fn}"; + echo "Running: {$cmd}
"; + mwexec_bg($cmd); + echo "Check results in Results log TAB
"; echo '

'; + } } function nmap_get_interfaces() { --- a/src/usr/local/pkg/nmap.xml +++ b/src/usr/local/pkg/nmap.xml @@ -39,6 +39,17 @@
Diagnostics
nmap.xml + + + Scan + /pkg_edit.php?xml=nmap.xml&id=0 + + + + Results log + /nmap_view_results.php + + IP or Hostname --- a/src/usr/local/www/nmap_view_results.php +++ b/src/usr/local/www/nmap_view_results.php @@ -0,0 +1,128 @@ + + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +require("guiconfig.inc"); +#require_once("pfsense-utils.inc"); +require("/usr/local/pkg/nmap.inc"); + +$pgtitle = array("Package", "Diagnostics: NMap", "NMap Results"); + +require_once("head.inc"); + +$tab_array = array(); +$tab_array[] = array("Scan", false, "/pkg_edit.php?xml=nmap.xml&id=0"); +$tab_array[] = array("Results log", true, "/nmap_view_results.php"); +display_top_tabs($tab_array); + +$fp = "/root/"; +$fn = "nmap.result"; + +$form = new Form(false); +$section = new Form_Section('NMap Scan Results:'); +if (file_exists($fp.$fn)) { + $section->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 log', + 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"); +