76
76
#![ allow( clippy:: module_name_repetitions) ]
77
77
78
78
use crate :: input:: ScriptsRequired ;
79
- use anyhow:: { anyhow, Result } ;
79
+ use anyhow:: { anyhow, Context , Result } ;
80
80
use log:: debug;
81
81
use serde_derive:: { Deserialize , Serialize } ;
82
82
use std:: convert:: TryInto ;
@@ -87,6 +87,7 @@ use std::path::PathBuf;
87
87
use std:: string:: ToString ;
88
88
use subprocess:: { Exec , ExitStatus } ;
89
89
use text_placeholder:: Template ;
90
+ use which:: which;
90
91
91
92
static DEFAULT : & str = r#"tags = ["core_approved", "RustScan", "default"]
92
93
developer = [ "RustScan", "https://github.com/RustScan" ]
@@ -101,8 +102,12 @@ pub fn init_scripts(scripts: &ScriptsRequired) -> Result<Vec<ScriptFile>> {
101
102
match scripts {
102
103
ScriptsRequired :: None => { }
103
104
ScriptsRequired :: Default => {
105
+ which ( "nmap" )
106
+ . with_context ( || "nmap: command not found. See <https://nmap.org/download>" ) ?;
107
+
104
108
let default_script =
105
109
toml:: from_str :: < ScriptFile > ( DEFAULT ) . expect ( "Failed to parse Script file." ) ;
110
+
106
111
scripts_to_run. push ( default_script) ;
107
112
}
108
113
ScriptsRequired :: Custom => {
@@ -184,14 +189,14 @@ struct ExecPartsScript {
184
189
script : String ,
185
190
ip : String ,
186
191
port : String ,
187
- ipversion : String
192
+ ipversion : String ,
188
193
}
189
194
190
195
#[ derive( Serialize ) ]
191
196
struct ExecParts {
192
197
ip : String ,
193
198
port : String ,
194
- ipversion : String
199
+ ipversion : String ,
195
200
}
196
201
197
202
impl Script {
@@ -248,8 +253,8 @@ impl Script {
248
253
port : ports_str,
249
254
ipversion : match & self . ip {
250
255
IpAddr :: V4 ( _) => String :: from ( "4" ) ,
251
- IpAddr :: V6 ( _) => String :: from ( "6" )
252
- }
256
+ IpAddr :: V6 ( _) => String :: from ( "6" ) ,
257
+ } ,
253
258
} ;
254
259
to_run = default_template. fill_with_struct ( & exec_parts_script) ?;
255
260
} else {
@@ -258,8 +263,8 @@ impl Script {
258
263
port : ports_str,
259
264
ipversion : match & self . ip {
260
265
IpAddr :: V4 ( _) => String :: from ( "4" ) ,
261
- IpAddr :: V6 ( _) => String :: from ( "6" )
262
- }
266
+ IpAddr :: V6 ( _) => String :: from ( "6" ) ,
267
+ } ,
263
268
} ;
264
269
to_run = default_template. fill_with_struct ( & exec_parts) ?;
265
270
}
0 commit comments