Пример #1
0
def main():
    try:
        # Load system configuration
        conf = parse_arguments()

        # Send logging output to a file if specified
        configure_log(conf["log.file"])

        # Look for available commands
        commands = find_commands("cmds/", conf["home.dir"])

        # Core components
        auth = AuthManager(conf["home.dir"] + "/users.auth")
        commander = Commander(auth)
        scanner = MailScanner(Parsers(commands))
        notifier = EmailNotifier(conf["smtp.host"], conf["smtp.port"])

        # Read the email from stdin
        email = UnicodeParser().parse(sys.stdin)

        cmd_id, data, sprops, authkey = scanner.scan(email)
        auth_users = [ key.user for key in auth.keys[cmd_id] if key.user ]

        command = commands[cmd_id]
        output = commander.execute(command, data, authkey)

        if output:
            notifier.send(SuccessNotification(conf["notification.sender"], \
                                              auth_users, command, sprops))
    except AuthException, err:
        notifier.send(AuthNotification(cmd_id, conf["commander.address"], \
                                       auth_users, email, data))
Пример #2
0
def main():
    try:
        # Load system configuration
        conf = parse_arguments()

        # Send logging output to a file if specified
        configure_log(conf["log.file"])

        # Look for available commands
        commands = find_commands("cmds/", conf["home.dir"])

        # Core components
        auth = AuthManager(conf["home.dir"] + "/users.auth")
        commander = Commander(auth)
        scanner = MailScanner(Parsers(commands))
        notifier = EmailNotifier(conf["smtp.host"], conf["smtp.port"])

        # Read the email from stdin
        email = UnicodeParser().parse(sys.stdin)

        cmd_id, data, sprops, authkey = scanner.scan(email)
        auth_users = [key.user for key in auth.keys[cmd_id] if key.user]

        command = commands[cmd_id]
        output = commander.execute(command, data, authkey)

        if output:
            notifier.send(SuccessNotification(conf["notification.sender"], \
                                              auth_users, command, sprops))
    except AuthException, err:
        notifier.send(AuthNotification(cmd_id, conf["commander.address"], \
                                       auth_users, email, data))
Пример #3
0
    def test_scanner(self):
        scanner = MailScanner()

        email_file = os.getcwd() + "/test/data/cmd.email"
        email = open(email_file).read()

        cmd_id, data, authkey = scanner.scan(email, PropertiesParser())

        print cmd_id
        print authkey.items()
        print data
Пример #4
0
    def test_scanner(self):
        scanner = MailScanner()

        email_file = os.getcwd() + "/test/data/cmd.email"
        email = open(email_file).read()

        cmd_id, data, authkey = scanner.scan(email, PropertiesParser())

        print cmd_id
        print authkey.items()
        print data
    def __init__(self, name):
        TestCase.__init__(self, name)

        self.commands = find_commands("test/cmds/")

        self.auth = AuthManager("test/etc/users.auth")
        self.commander = Commander(self.auth)

        self.scanner = MailScanner(Parsers(self.commands))
        self.email = UnicodeParser().parse(open("test/data/cmd.email"))

        self.notifier = EmailNotifier("10.2.1.2", 25)
class TestMailCommander(TestCase):
    
    def __init__(self, name):
        TestCase.__init__(self, name)
        
        self.commands = find_commands("test/cmds/")

        self.auth = AuthManager("test/etc/users.auth")
        self.commander = Commander(self.auth)
        
        self.scanner = MailScanner(Parsers(self.commands))
        self.email = UnicodeParser().parse(open("test/data/cmd.email"))

        self.notifier = EmailNotifier("10.2.1.2", 25)

    def test_commander(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)

        command = self.commands[cmd_id]
        self.commander.execute(command, data, authkey)

        print command.output["text"]

    def test_auth_notification(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)
        command = self.commands[cmd_id]

        self.commander.execute(command, data, authkey)

        sender = "*****@*****.**"
        recipients = ["*****@*****.**"]

        notification = AuthNotification(cmd_id, sender, recipients,
                                        self.email, data)

        self.notifier.send(notification)

    def test_success_notification(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)
        command = self.commands[cmd_id]

        self.commander.execute(command, data, authkey)

        sender = "*****@*****.**"
        recipients = []

        notification = SuccessNotification(sender, recipients, command, sprops)
        self.notifier.send(notification)
class TestMailCommander(TestCase):
    def __init__(self, name):
        TestCase.__init__(self, name)

        self.commands = find_commands("test/cmds/")

        self.auth = AuthManager("test/etc/users.auth")
        self.commander = Commander(self.auth)

        self.scanner = MailScanner(Parsers(self.commands))
        self.email = UnicodeParser().parse(open("test/data/cmd.email"))

        self.notifier = EmailNotifier("10.2.1.2", 25)

    def test_commander(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)

        command = self.commands[cmd_id]
        self.commander.execute(command, data, authkey)

        print command.output["text"]

    def test_auth_notification(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)
        command = self.commands[cmd_id]

        self.commander.execute(command, data, authkey)

        sender = "*****@*****.**"
        recipients = ["*****@*****.**"]

        notification = AuthNotification(cmd_id, sender, recipients, self.email,
                                        data)

        self.notifier.send(notification)

    def test_success_notification(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)
        command = self.commands[cmd_id]

        self.commander.execute(command, data, authkey)

        sender = "*****@*****.**"
        recipients = []

        notification = SuccessNotification(sender, recipients, command, sprops)
        self.notifier.send(notification)
    def __init__(self, name):
        TestCase.__init__(self, name)
        
        self.commands = find_commands("test/cmds/")

        self.auth = AuthManager("test/etc/users.auth")
        self.commander = Commander(self.auth)
        
        self.scanner = MailScanner(Parsers(self.commands))
        self.email = UnicodeParser().parse(open("test/data/cmd.email"))

        self.notifier = EmailNotifier("10.2.1.2", 25)