Esempio n. 1
0
    def start_quickscan(self):
        """
        Do necessary checks before starting Scheduler.
        """
        err = self.qscontrol.start(from_gui=True)

        if err:
            alertdlg = GenericAlert(_("QuickScan Launcher"),
                    _("QuickScan couldn't be started, reason:\n\n") +
                    str(err),
                  buttons={1: (gtk.RESPONSE_OK, gtk.STOCK_OK)})
            resp = alertdlg.run()
            alertdlg.destroy()
    def start_quickscan(self):
        """
        Do necessary checks before starting Scheduler.
        """
        err = self.qscontrol.start(from_gui=True)

        if err:
            alertdlg = GenericAlert(
                _("QuickScan Launcher"),
                _("QuickScan couldn't be started, reason:\n\n") + str(err),
                buttons={1: (gtk.RESPONSE_OK, gtk.STOCK_OK)})
            resp = alertdlg.run()
            alertdlg.destroy()
Esempio n. 3
0
    def _check_scans(self):
        """
        Check for finished scans.
        """
        todelete = [ ]

        for scan, inventory in self.running_scans.items():
            try:
                scan_state = scan.scan_state()
            except Exception, err:
                # scan failed to run.
                # probably a scan with args that requires root and a
                # normal user tried running.
                dlg = GenericAlert(_("Scan failed to run!"),
                        (_("You tried running scan for Inventory") +
                            (" %r,\n" % inventory) +
                            _("but it returned the following") +
                            (":\n\n%s" % err)),
                        buttons={1: (gtk.RESPONSE_OK, gtk.STOCK_OK)})
                dlg.run()
                dlg.destroy()
                todelete.append(scan)
                continue

            if not scan_state: # scan finished
                xmlstore = XMLStore(Path.umitdb_ng)
                try:
                    try:
                        xmlstore.store(scan.get_xml_output_file(),
                                inventory=inventory)
                    except Exception:
                        # failed while adding scan to the database
                        dlg = GenericAlert(_("Database couldn't be updated!"),
                                (_("The scan for the Inventory") +
                                    (" %r " % inventory) +
                                    _("finished but it couldn't be added to "
                                        "the database.") +
                                    ("\n\n%s" % traceback.format_exc())),
                                buttons={1: (gtk.RESPONSE_OK, gtk.STOCK_OK)})
                        dlg.run()
                        dlg.destroy()
                finally:
                    xmlstore.close() # close connection to the database
                    scan.close()
                    todelete.append(scan)
    def stop_scheduler(self):
        """
        Stop scheduler if possible.
        """
        err = self.schedcontrol.stop()

        if err: # user not allowed to stop scheduler
            alertdlg = GenericAlert(_("Scheduler Controller"),
                    _("The Scheduler couldn't be stopped, reason:\n\n") +
                    str(err),
                  buttons={1: (gtk.RESPONSE_HELP, gtk.STOCK_HELP),
                           2: (gtk.RESPONSE_OK, gtk.STOCK_OK)})

            resp = alertdlg.run()

            if resp == gtk.RESPONSE_HELP:
                show_help(self,"scheduler.html#stopping-scheduler")

            alertdlg.destroy()
Esempio n. 5
0
    def _get_command_from_schemas(self, inventory):
        """
        Get scan command from schemas profiles.
        """
        schemas = ConfigParser()
        schemas.read(Path.sched_schemas)

        try:
            scan_args = schemas.get(inventory, "command")
            return scan_args

        except NoSectionError, err:
            dlg = GenericAlert(_("Scan will not run!"),
                _("You tried running scan for Inventory") +
                (" %r,\n" % inventory) +
                _("but it has no data in Scheduler schemas file, neither in "
                    "database.\n\nError returned:") + (" %s" % err),
                buttons={1: (gtk.RESPONSE_OK, gtk.STOCK_OK)})
            dlg.run()
            dlg.destroy()
    def start_scheduler(self):
        """
        Do necessary checks before starting Scheduler.
        """
        err = None
        if not amiroot(): # running as normal user
            alertdlg = GenericAlert(_("Scheduler Controller"),
                  _("You are requesting to start Scheduler as a normal \
user.\n\nIn case some scheduled scan contains any \noptions that requires \
root previlegies they will end \nup not running.\n\nIf you don't want to \
start the Scheduler now, \nselect Cancel, if you want to run it as a normal \
user \nanyway, select OK, otherwise, select Help to learn \nhow you can \
start it as root."), buttons={1: (gtk.RESPONSE_HELP, gtk.STOCK_HELP),
                              2: (gtk.RESPONSE_CANCEL, gtk.STOCK_CANCEL),
                              3: (gtk.RESPONSE_OK, gtk.STOCK_OK)})

            resp = alertdlg.run()

            if resp == gtk.RESPONSE_OK:
                err = self.schedcontrol.start(from_gui=True)
            elif resp == gtk.RESPONSE_HELP:
                show_help(self,"scheduler.html#starting-scheduler-as-root")

            alertdlg.destroy()
        else: # running as root
            err = self.schedcontrol.start(from_gui=True)

        if err:
            alertdlg = GenericAlert(_("Scheduler Controller"),
                    _("The Scheduler couldn't be started, reason:\n\n") +
                    str(err),
                  buttons={1: (gtk.RESPONSE_HELP, gtk.STOCK_HELP),
                           2: (gtk.RESPONSE_OK, gtk.STOCK_OK)})
            resp = alertdlg.run()
            if resp == gtk.RESPONSE_HELP:
                show_help(self,"scheduler.html#starting-scheduler")
            alertdlg.destroy()
    def _get_command_from_schemas(self, inventory):
        """
        Get scan command from schemas profiles.
        """
        schemas = ConfigParser()
        schemas.read(Path.sched_schemas)

        try:
            scan_args = schemas.get(inventory, "command")
            return scan_args

        except NoSectionError, err:
            dlg = GenericAlert(
                _("Scan will not run!"),
                _("You tried running scan for Inventory") +
                (" %r,\n" % inventory) +
                _("but it has no data in Scheduler schemas file, neither in "
                  "database.\n\nError returned:") + (" %s" % err),
                buttons={1: (gtk.RESPONSE_OK, gtk.STOCK_OK)})
            dlg.run()
            dlg.destroy()
    def _check_scans(self):
        """
        Check for finished scans.
        """
        todelete = []

        for scan, inventory in self.running_scans.items():
            try:
                scan_state = scan.scan_state()
            except Exception, err:
                # scan failed to run.
                # probably a scan with args that requires root and a
                # normal user tried running.
                dlg = GenericAlert(
                    _("Scan failed to run!"),
                    (_("You tried running scan for Inventory") +
                     (" %r,\n" % inventory) +
                     _("but it returned the following") + (":\n\n%s" % err)),
                    buttons={1: (gtk.RESPONSE_OK, gtk.STOCK_OK)})
                dlg.run()
                dlg.destroy()
                todelete.append(scan)
                continue

            if not scan_state:  # scan finished
                xmlstore = XMLStore(Path.umitdb_ng)
                try:
                    try:
                        xmlstore.store(scan.get_xml_output_file(),
                                       inventory=inventory)
                    except Exception:
                        # failed while adding scan to the database
                        dlg = GenericAlert(
                            _("Database couldn't be updated!"),
                            (_("The scan for the Inventory") +
                             (" %r " % inventory) +
                             _("finished but it couldn't be added to "
                               "the database.") +
                             ("\n\n%s" % traceback.format_exc())),
                            buttons={1: (gtk.RESPONSE_OK, gtk.STOCK_OK)})
                        dlg.run()
                        dlg.destroy()
                finally:
                    xmlstore.close()  # close connection to the database
                    scan.close()
                    todelete.append(scan)