use sudo at will
This commit is contained in:
parent
cd6f64679b
commit
570e8f2252
@ -10,3 +10,7 @@ Pour donner les droits à lanScan sous Linux, installer `sudo` au besoin, puis c
|
||||
```
|
||||
www-data ALL = NOPASSWD: /usr/bin/nmap
|
||||
````
|
||||
et modifier le fichier `config.php` avec :
|
||||
```php
|
||||
$use_sudo = true;
|
||||
```
|
||||
|
@ -17,6 +17,7 @@ $HOSTSCAN_OPTIONS = [
|
||||
];
|
||||
|
||||
$refreshPeriod = 60;
|
||||
$use_sudo = false;
|
||||
|
||||
$SCANSDIR = 'scans';
|
||||
$DATADIR = '/usr/share/nmap';
|
||||
|
7
scan.php
7
scan.php
@ -32,15 +32,10 @@ foreach ($inputs as $arg => $value) {
|
||||
|
||||
$tempPath = tempnam(sys_get_temp_dir(), 'scan_').".xml";
|
||||
|
||||
$command = "nmap$args -oX '$tempPath' $targets 2>&1";
|
||||
$command = ($use_sudo? "sudo " : "") . "nmap$args -oX '$tempPath' $targets 2>&1";
|
||||
|
||||
exec($command, $stderr, $retcode);
|
||||
|
||||
if ($retcode && strpos(implode($stderr), " root ") !== false) {
|
||||
// Retry with sudo
|
||||
exec("sudo $command", $stderr, $retcode);
|
||||
}
|
||||
|
||||
if ($retcode) {
|
||||
http_response_code(500);
|
||||
$errorMessage = implode("<br/>\n", $stderr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user