Class: NetMap::ScriptEngine
- Inherits:
-
Object
- Object
- NetMap::ScriptEngine
- Defined in:
- lib/netmap/script_engine.rb
Instance Method Summary collapse
-
#initialize(script_dir) ⇒ ScriptEngine
constructor
A new instance of ScriptEngine.
- #load_scripts ⇒ Object
- #run_scripts(result) ⇒ Object
Constructor Details
#initialize(script_dir) ⇒ ScriptEngine
Returns a new instance of ScriptEngine.
3 4 5 6 |
# File 'lib/netmap/script_engine.rb', line 3 def initialize(script_dir) @script_dir = script_dir @scripts = load_scripts end |
Instance Method Details
#load_scripts ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/netmap/script_engine.rb', line 8 def load_scripts scripts = [] return scripts unless Dir.exist?(@script_dir) Dir.glob(File.join(@script_dir, "*.rb")).each do |script_path| begin script_code = File.read(script_path) scripts << { name: File.basename(script_path), code: script_code } rescue => e puts "Error loading script #{script_path}: #{e.}".red end end scripts end |
#run_scripts(result) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/netmap/script_engine.rb', line 23 def run_scripts(result) @scripts.each do |script| begin # Lingkungan eksekusi skrip sederhana # Skrip harus mengembalikan string jika ada temuan, atau nil # Konteks: ip, port, banner, os context = result finding = eval_script(script[:code], context) if finding && !finding.empty? result[:banner] = "#{result[:banner]} | [#{script[:name]}: #{finding}]" end rescue # Abaikan error skrip agar scan tetap jalan end end end |