use sudo at will

This commit is contained in:
Adrien MALINGREY 2024-10-16 11:04:12 +02:00
parent cd6f64679b
commit 570e8f2252
3 changed files with 6 additions and 6 deletions

View File

@ -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;
```

View File

@ -17,6 +17,7 @@ $HOSTSCAN_OPTIONS = [
];
$refreshPeriod = 60;
$use_sudo = false;
$SCANSDIR = 'scans';
$DATADIR = '/usr/share/nmap';

View File

@ -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);