Exemplo n.º 1
0
    def use(self, args):
        if 1:
            try:
                init = False
                if "modules." + args[0] not in sys.modules:
                    init = True
            except:
                printError("Please enter module name!")
                return

            if self.mm.moduleLoaded == 0:
                try:
                    self.modadd = importlib.import_module("modules." + args[0])
                    self.mm.moduleLoaded = 1
                    self.mm.setName(self.modadd.conf["name"])
                    try:
                        print(self.modadd.conf["message"])
                    except KeyError:
                        pass
                    try:
                        if self.modadd.conf["outdated"] == 1:
                            printWarning(
                                "This module is outdated and might not be working!"
                            )
                    except KeyError:
                        pass
                    try:
                        if self.modadd.conf["needroot"] == 1:
                            if not os.geteuid() == 0:
                                printWarning(
                                    "This module requires root permissions!")
                    except KeyError:
                        pass
                    if init == True:
                        try:
                            self.modadd.init()
                        except AttributeError:
                            pass
                except ImportError:
                    print("[" + colors.bold + colors.red + "err" + colors.end +
                          "] Module is not found!")
                    raise ModuleNotFound("[" + colors.bold + colors.red +
                                         "err" + colors.end +
                                         "] Module is not found!")
                except IndexError:
                    print("[" + colors.bold + colors.red + "err" + colors.end +
                          "] Module is not found!")
                    raise ModuleNotFound("[" + colors.bold + colors.red +
                                         "err" + colors.end +
                                         "] Module is not found!")
                except:
                    print("[" + colors.bold + colors.red + "err" + colors.end +
                          "] Unexpected error in module:\n")
                    traceback.print_exc(file=sys.stdout)
                    print(colors.end)
                    if api.enabled == True:
                        raise
            else:
                print("[" + colors.bold + colors.red + "err" + colors.end +
                      "] Module already in use!")
Exemplo n.º 2
0
    def use(self, args):
        init = False
        if "modules." + args[0] not in sys.modules:
            init = True

        if self.mm.moduleLoaded == 0:
            try:
                self.modadd = importlib.import_module("modules." + args[0])
                self.mm.moduleLoaded = 1
                self.mm.setName(self.modadd.conf["name"])
                try:
                    print(self.modadd.conf["message"])
                except KeyError:
                    pass
                try:
                    if self.modadd.conf["outdated"] == 1:
                        printWarning(
                            "this module is outdated and might not be working")
                except KeyError:
                    pass
                try:
                    if self.modadd.conf["needroot"] == 1:
                        if not os.geteuid() == 0:
                            printWarning(
                                "this module requires root permissions for full functionality!"
                            )
                except KeyError:
                    pass
                if init == True:
                    try:
                        self.modadd.init()
                    except AttributeError:
                        pass
            except ImportError:
                print(colors.red + "module not found" + colors.end)
                raise ModuleNotFound("module not found")
            except IndexError:
                print(colors.red + "please enter module name" + colors.end)
                raise ModuleNotFound("module not found")
            except:
                print(colors.red + "unexpected error in module:\n")
                traceback.print_exc(file=sys.stdout)
                print(colors.end)
                if api.enabled == True:
                    raise
        else:
            raise UnknownCommand("module in use")
Exemplo n.º 3
0
    def handle(self, command):
        # String to list
        command = command.split()

        # Custom command
        if self.mm.moduleLoaded == 1:
            try:
                return self.cm.mcu(command)
            except IndexError:
                return
            except UnknownCommand:
                pass

        # Validate command

        if len(command) != 0 and command[0] in self.notcommand:
            print("[" + colors.bold + colors.red + "err" + colors.end +
                  "] Unrecognized command!" + colors.end)
            return
        try:
            method = getattr(self.cm, command[0])
        except AttributeError:
            print("[" + colors.bold + colors.red + "err" + colors.end +
                  "] Unrecognized command!" + colors.end)
            return
        except IndexError:
            return

        try:
            return method(command[1:])
        except UnknownCommand:
            print("[" + colors.bold + colors.red + "err" + colors.end +
                  "] Unrecognized command!" + colors.end)

        except ModuleNotFound:
            if self.api == True:
                raise ModuleNotFound("[" + colors.bold + colors.red + "err" +
                                     colors.end + "] Module is not found!")

        except VariableError:
            if self.api == True:
                raise VariableError("[" + colors.bold + colors.red + "err" +
                                    colors.end + "] Variable error!")