Esempio n. 1
0
 def __init__(self):
     # Invoke Engine
     try:
         super(Core, self).__init__()
     except KeyboardInterrupt:
         print "\n[!] Job was interrupted by user."
         exit(1)
     # inherited attributes:
     #   self.executions - dict with executions that could be executed like keywords by invoking plugin 'execute_command'
     #                    {action_name: command}
     #   self.config - dict with vm objects {vm_name: object(vm)}
     #   self.config_sequence - sequence to work with virtual machines list[vm_name, ...]
     #   self.loaded_keywords - dict with loaded keywords {keyword_name: object(keyword)}
     STREAM.notice("==> BEGIN.")
     # Connect notification module
     self.reports = Reporter(self.config)
     # Current working vm object
     self.current_vm_obj = None
     # Contains list of already done actions for current working vm object
     self.actions_progress = []
     try:
         self.main()
     except KeyboardInterrupt:
         LoggerOptions.set_component("Core")
         LoggerOptions.set_action(None)
         STREAM.error("[!] Job was interrupted by user.")
         STREAM.notice("==> Clearing ourselves")
         self.clearing()
Esempio n. 2
0
 def _restore(exception, action):
     """ The function reverse actions and add ERROR report to reporter """
     LoggerOptions.set_component("Core")
     LoggerOptions.set_action(None)
     self.reports.add_report(self.current_vm_obj.__name__, "ERROR",
                             action)
     STREAM.error(" -> %s" % exception)
     STREAM.error(" -> Can't proceed with this vm")
     STREAM.notice("==> Clearing ourselves")
     self.clearing()
Esempio n. 3
0
 def _get_connection_settings(self):
     self.SMTP_SERVER = LoadSettings.SMTP_SERVER
     self.SMTP_PORT = LoadSettings.SMTP_PORT
     self.SMTP_USER = LoadSettings.SMTP_USER
     self.SMTP_PASS = LoadSettings.SMTP_PASS
     self.SMTP_MAIL_FROM = LoadSettings.SMTP_MAIL_FROM
     if self.SMTP_SERVER != "":
         self.ENABLE_HARVESTER = True
         STREAM.notice("Email notifications: ON")
     else:
         STREAM.notice("Email notifications: OFF")
Esempio n. 4
0
 def main(self):
     for vm in self.config_sequence:
         self.current_vm_obj = self.config[vm]
         self.actions_progress = []
         # Set logger filter
         LoggerOptions.set_component(self.current_vm_obj.__name__)
         result = self.do_actions(self.current_vm_obj.actions)
         if result:
             STREAM.notice("==> There are no more Keywords, going next vm.")
             self.reports.add_report(self.current_vm_obj.__name__,
                                     "Success")
         else:
             pass
     self.reports.send_reports()
     STREAM.notice("==> There are no more virtual machines, exiting")
     STREAM.notice("==> END.")
Esempio n. 5
0
    def generate_default_config(config_file):
        template = """; You can create vm objects and assign them any actions.
; Specify preffered section name.
[debian9-x86-template]
; Mandatory keys.
;   Key specifies, which type of object will be created (vm, group, alias).
type = vm
;   Key specifies Keywords which will be performed for this VirtualMachine
actions = port_forwarding, vbox_start, execute_command, vbox_stop
; Variable keys
;   Key specifies to which group this object belongs.
group = linux
; You may specify email to receive notifications about Keyword's errors.
;alert = [email protected]
; That description will be shown in subject of the email
;alert_description = install curl in vm
; Attributes needed for the correct work of a Keyword's
; name of the virtual machine in VirtualBox.
vm_name = debian9-x86-template
; Command which will be executed in VirtualMachine by Keyword "execute_command"
execute_command = apt-get install -y clamav

[fedora27-amd64]
type = vm
; actions will be inherited from group
group = linux
vm_name = fedora27-amd64
execute_command = dnf install -y clamav
 
[freebsd10-amd64]
type = vm
group = linux
vm_name = freebsd10-amd64
execute_command = pkg install -y clamav

; You can create groups and combine it with other objects.
;   Groups support attribute inheritance (groups attributes have a lower priority than vm attributes).
;   Specify name of the group.
[linux]
; Mandatory key.
type = group
;   Key specifies keywords which will be performed for the group of VirtualMachines.
actions = port_forwarding, vbox_start, execute_command, vbox_stop
; You can specify a timeout for each Keyword after which the process will be terminated (ex: <Keyword_name>_timeout)
execute_command_timeout = 10

; You can combine some Keywords in one action, named alias.
[linux_aliases]
type = alias
; By default aliases extends to all objects, but you can assign aliases at specific group
;group = linux
reboot = vbox_stop, vbox_start
"""
        STREAM.info("==> Generating default configuration file...")
        if os.path.exists(config_file):
            STREAM.warning(" -> File %s already exists!" % config_file)
            STREAM.warning(" -> Do you want to overwrite it? (y/n): ")
            answers = ["y", "n"]
            while 1:
                choice = raw_input().lower()
                if choice in answers:
                    break
                STREAM.error("Choose y or n! : ")
            if choice == answers[0]:
                with open(config_file, "w") as config:
                    config.write(template)
                STREAM.success(" -> Generated %s" % config_file)
            else:
                STREAM.notice(" -> Cancelled by user.")
                sys.exit()
        else:
            with open(config_file, "w") as config:
                config.write(template)
            STREAM.success(" -> Generated %s" % config_file)