Ejemplo n.º 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))
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
class TestNotifications(TestCase):
    def __init__(self, name):
        TestCase.__init__(self, name)

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

    def test_notification(self):
        notification = Notification()
        notification.title = "Test"
        notification.sender = "*****@*****.**"
        notification.recipients.append("*****@*****.**")
        notification.body["text"] = "JOJOJOJO"

        self.notifier.send(notification)
Ejemplo n.º 4
0
class TestNotifications(TestCase):
    
    def __init__(self, name):
        TestCase.__init__(self, name)

        self.notifier = EmailNotifier("10.2.1.2", 25)
        
    def test_notification(self):
        notification = Notification()
        notification.title = "Test"
        notification.sender = "*****@*****.**"
        notification.recipients.append("*****@*****.**")
        notification.body["text"] = "JOJOJOJO"
           
        self.notifier.send(notification)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
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))
Ejemplo n.º 9
0
    def __init__(self, name):
        TestCase.__init__(self, name)

        self.notifier = EmailNotifier("10.2.1.2", 25)
Ejemplo n.º 10
0
    def __init__(self, name):
        TestCase.__init__(self, name)

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