<commit_before>#
# = openvas-omp.rb: communicate with OpenVAS manager over OMP
#
# Author:: <NAME>
#
# (C) <NAME>, Kost. Distributed under MIT license:
# http://www.opensource.org/licenses/mit-license.php
# 
# == What is this library? 
# 
# This library is used for communication with OpenVAS manager over OMP
# You can start, stop, pause and resume scan. Watch progress and status of 
# scan, download report, etc.
#
# == Requirements
# 
# Required libraries are standard Ruby libraries: socket,timeout,openssl,
# rexml/document, rexml/text, base64
#
# == Usage:
# 
#  require 'openvas-omp'
#
#  ov=OpenVASOMP::OpenVASOMP.new("user"=>'openvas',"password"=>'<PASSWORD>')
#  config=ov.config_get().index("Full and fast")
#  target=ov.target_create({"name"=>"t", "hosts"=>"127.0.0.1", "comment"=>"t"})
#  taskid=ov.task_create({"name"=>"t","comment"=>"t", "target"=>target, "config"=>config})
#  ov.task_start(taskid)
#  while not ov.task_finished(taskid) do
#         stat=ov.task_get_byid(taskid)
#         puts "Status: #{stat['status']}, Progress: #{stat['progress']} %"
#         sleep 10
#  end
#  stat=ov.task_get_byid(taskid)
#  content=ov.report_get_byid(stat["lastreport"],'HTML')
#  File.open('report.html', 'w') {|f| f.write(content) }

require 'socket' 
require 'timeout'
require 'openssl'
require 'rexml/document'
require 'rexml/text'
require 'base64'

# OpenVASOMP module
# 
# Usage:
# 
#  require 'openvas-omp'
# 
#  ov=OpenVASOMP::OpenVASOMP.new("user"=>'openvas',"password"=>'<PASSWORD>')

module OpenVASOMP

	class OMPError < :: RuntimeError
		attr_accessor :req, :reason
		def initialize(req, reason = '')
			self.req = req
			self.reason = reason
		end
		def to_s
			"OpenVAS OMP: #{self.reason}"
		end
	end

	class OMPResponseError < OMPError
		def initialize
			self.reason = "Error in OMP request/response"
		end
	end

	class OMPAuthError < OMPError
		def initialize
			self.reason = "Authentication failed"
		end
	end

	class XMLParsingError < OMPError
		def initialize
			self.reason = "XML parsing failed"
		end
	end

	# Class which uses standard REXML to parse OpenVAS replies.
	class OpenVASOMP
		# initialize object: try to connect to OpenVAS using URL, user and password
		#
		# Usage:
		#
		#  ov=OpenVASOMP.new(user=>'user',password=>'<PASSWORD>') 
		#  # default: host=>'localhost', port=>'9390'
		# 
		def initialize(p={})
			if p.has_key?("host")
				@host=p["host"]<commit_msg>Better description of core class<commit_after>#
# = openvas-omp.rb: communicate with OpenVAS manager over OMP
#
# Author:: <NAME>
#
# (C) <NAME>, Kost. Distributed under MIT license:
# http://www.opensource.org/licenses/mit-license.php
# 
# == What is this library? 
# 
# This library is used for communication with OpenVAS manager over OMP
# You can start, stop, pause and resume scan. Watch progress and status of 
# scan, download report, etc.
#
# == Requirements
# 
# Required libraries are standard Ruby libraries: socket,timeout,openssl,
# rexml/document, rexml/text, base64
#
# == Usage:
# 
#  require 'openvas-omp'
#
#  ov=OpenVASOMP::OpenVASOMP.new("user"=>'openvas',"password"=>'<PASSWORD>')
#  config=ov.config_get().index("Full and fast")
#  target=ov.target_create({"name"=>"t", "hosts"=>"127.0.0.1", "comment"=>"t"})
#  taskid=ov.task_create({"name"=>"t","comment"=>"t", "target"=>target, "config"=>config})
#  ov.task_start(taskid)
#  while not ov.task_finished(taskid) do
#         stat=ov.task_get_byid(taskid)
#         puts "Status: #{stat['status']}, Progress: #{stat['progress']} %"
#         sleep 10
#  end
#  stat=ov.task_get_byid(taskid)
#  content=ov.report_get_byid(stat["lastreport"],'HTML')
#  File.open('report.html', 'w') {|f| f.write(content) }

require 'socket' 
require 'timeout'
require 'openssl'
require 'rexml/document'
require 'rexml/text'
require 'base64'

# OpenVASOMP module
# 
# Usage:
# 
#  require 'openvas-omp'
# 
#  ov=OpenVASOMP::OpenVASOMP.new("user"=>'openvas',"password"=>'<PASSWORD>')

module OpenVASOMP

	class OMPError < :: RuntimeError
		attr_accessor :req, :reason
		def initialize(req, reason = '')
			self.req = req
			self.reason = reason
		end
		def to_s
			"OpenVAS OMP: #{self.reason}"
		end
	end

	class OMPResponseError < OMPError
		def initialize
			self.reason = "Error in OMP request/response"
		end
	end

	class OMPAuthError < OMPError
		def initialize
			self.reason = "Authentication failed"
		end
	end

	class XMLParsingError < OMPError
		def initialize
			self.reason = "XML parsing failed"
		end
	end

	# Core class for OMP communication protocol 
	class OpenVASOMP
		# initialize object: try to connect to OpenVAS using URL, user and password
		#
		# Usage:
		#
		#  ov=OpenVASOMP.new(user=>'user',password=>'<PASSWORD>') 
		#  # default: host=>'localhost', port=>'9390'
		# 
		def initialize(p={})
			if p.has_key?("host")
				@host=p["host"]
{'fraction_non_alphanumeric': 0.1559652029826015, 'fraction_numerical': 0.006628003314001657, 'mean_word_length': 4.389508928571429, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7204310', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1761, 'n_words': 402}