Пример #1
0
    def parameters(cls):
        """
        Return a dictionary, that describes the parameters and options for the
        SMS provider.
        Parameters are required keys to values.

        :return: dict
        """
        from privacyidea.lib.smtpserver import get_smtpservers
        params = {"options_allowed": False,
                  "parameters": {
                      "MAILTO": {
                          "required": True,
                          "description": "The recipient of the email. "
                                         "Use tags {phone} and {otp}."},
                      "SMTPIDENTIFIER": {
                          "required": True,
                          "description": "Your SMTP configuration, "
                                         "that should be used to send the "
                                         "email.",
                          "values": [
                              provider.config.identifier for
                              provider in get_smtpservers()]},
                      "SUBJECT": {
                          "description": "The optional subject of the email. "
                                         "Use tags {phone} and {otp}."},
                      "BODY": {
                          "description": "The optional body of the email. "
                                         "Use tags {phone} and {otp}.",
                          "type": "text" }
                  }
                  }
        return params
Пример #2
0
    def actions(cls):
        """
        This method returns a dictionary of allowed actions and possible
        options in this handler module.

        :return: dict with actions
        """
        smtpserver_objs = get_smtpservers()
        smtpservers = [s.config.identifier for s in smtpserver_objs]
        actions = {"sendmail": {"emailconfig":
                                     {"type": "str",
                                      "required": True,
                                      "description": _("Send notification "
                                                       "email via this "
                                                       "email server."),
                                      "value": smtpservers},
                                "subject": {"type": "str",
                                            "required": False,
                                            "description": _("The subject of "
                                                             "the mail that "
                                                             "is sent.")


                                },
                                "body": {"type": "text",
                                         "required": False,
                                         "description": _("The body of the "
                                                          "mail that is sent.")}
                                },
                   "sendsms (not implemented)": {"smsconfig":
                                                      {"type": "str"}
                                                  }
                   }
        return actions
Пример #3
0
    def test_01_create_smtpserver(self):
        r = add_smtpserver(identifier="myserver", server="1.2.3.4")
        self.assertTrue(r > 0)
        r = add_smtpserver(identifier="myserver1", server="1.2.3.4")
        r = add_smtpserver(identifier="myserver2", server="1.2.3.4")

        server_list = get_smtpservers()
        self.assertTrue(server_list)
        self.assertEqual(len(server_list), 3)
        server_list = get_smtpservers(identifier="myserver")
        self.assertTrue(server_list[0].config.identifier, "myserver")
        self.assertTrue(server_list[0].config.port, 25)

        for server in ["myserver", "myserver1", "myserver2"]:
            r = delete_smtpserver(server)
            self.assertTrue(r > 0)

        server_list = get_smtpservers()
        self.assertEqual(len(server_list), 0)
Пример #4
0
def list_smtpservers():
    """
    This call gets the list of SMTP server definitions
    """
    res = {}
    server_list = get_smtpservers()
    for server in server_list:
        res[server.config.identifier] = {"server": server.config.server,
                                         "tls": server.config.tls,
                                         "username": server.config.username,
                                         "port": server.config.port,
                                         "description":
                                             server.config.description,
                                         "sender": server.config.sender}
    g.audit_object.log({'success': True})
    return send_result(res)
Пример #5
0
def list_smtpservers():
    """
    This call gets the list of SMTP server definitions
    """
    res = {}
    server_list = get_smtpservers()
    for server in server_list:
        res[server.config.identifier] = {
            "server": server.config.server,
            "tls": server.config.tls,
            "username": server.config.username,
            "port": server.config.port,
            "description": server.config.description,
            "sender": server.config.sender
        }
    g.audit_object.log({'success': True})
    return send_result(res)
Пример #6
0
    def parameters(cls):
        """
        Return a dictionary, that describes the parameters and options for the
        SMS provider.
        Parameters are required keys to values.

        :return: dict
        """
        from privacyidea.lib.smtpserver import get_smtpservers
        params = {
            "options_allowed": False,
            "headers_allowed": False,
            "parameters": {
                "MAILTO": {
                    "required":
                    True,
                    "description":
                    "The recipient of the email. "
                    "Use tags {phone} and {otp}."
                },
                "SMTPIDENTIFIER": {
                    "required":
                    True,
                    "description":
                    "Your SMTP configuration, "
                    "that should be used to send the "
                    "email.",
                    "values": [
                        provider.config.identifier
                        for provider in get_smtpservers()
                    ]
                },
                "SUBJECT": {
                    "description":
                    "The optional subject of the email. "
                    "Use tags {phone} and {otp}."
                },
                "BODY": {
                    "description": "The optional body of the email. "
                    "Use tags {phone} and {otp}.",
                    "type": "text"
                }
            }
        }
        return params
Пример #7
0
def list_smtpservers():
    """
    This call gets the list of SMTP server definitions
    """
    res = {}
    server_list = get_smtpservers()
    for server in server_list:
        decrypted_password = decryptPassword(server.config.password)
        # If the database contains garbage, use the empty password as fallback
        if decrypted_password == FAILED_TO_DECRYPT_PASSWORD:
            decrypted_password = ""
        res[server.config.identifier] = {"server": server.config.server,
                                         "tls": server.config.tls,
                                         "username": server.config.username,
                                         "password": decrypted_password,
                                         "port": server.config.port,
                                         "description":
                                             server.config.description,
                                         "sender": server.config.sender,
                                         "timeout": server.config.timeout}
    g.audit_object.log({'success': True})
    return send_result(res)
Пример #8
0
def list_smtpservers():
    """
    This call gets the list of SMTP server definitions
    """
    res = {}
    server_list = get_smtpservers()
    for server in server_list:
        decrypted_password = decryptPassword(server.config.password)
        # If the database contains garbage, use the empty password as fallback
        if decrypted_password == FAILED_TO_DECRYPT_PASSWORD:
            decrypted_password = ""
        res[server.config.identifier] = {
            "server": server.config.server,
            "tls": server.config.tls,
            "username": server.config.username,
            "password": decrypted_password,
            "port": server.config.port,
            "description": server.config.description,
            "sender": server.config.sender,
            "timeout": server.config.timeout
        }
    g.audit_object.log({'success': True})
    return send_result(res)
Пример #9
0
 def test_03_updateserver(self):
     r = add_smtpserver(identifier="myserver", server="100.2.3.4")
     self.assertTrue(r > 0)
     server_list = get_smtpservers(identifier="myserver")
     self.assertTrue(server_list[0].config.server, "100.2.3.4")
Пример #10
0
 def test_03_updateserver(self):
     r = add_smtpserver(identifier="myserver", server="100.2.3.4")
     self.assertTrue(r > 0)
     server_list = get_smtpservers(identifier="myserver")
     self.assertTrue(server_list[0].config.server, "100.2.3.4")
Пример #11
0
    def actions(cls):
        """
        This method returns a dictionary of allowed actions and possible
        options in this handler module.

        :return: dict with actions
        """
        smtpserver_objs = get_smtpservers()
        smsgateway_dicts = get_smsgateway()
        smsgateways = [sms.identifier for sms in smsgateway_dicts]
        smtpservers = [s.config.identifier for s in smtpserver_objs]
        actions = {"sendmail": {"emailconfig":
                                     {"type": "str",
                                      "required": True,
                                      "description": _("Send notification "
                                                       "email via this "
                                                       "email server."),
                                      "value": smtpservers},
                                "subject": {"type": "str",
                                            "required": False,
                                            "description": _("The subject of "
                                                             "the mail that "
                                                             "is sent.")


                                },
                                "body": {"type": "text",
                                         "required": False,
                                         "description": _("The body of the "
                                                          "mail that is "
                                                          "sent.")},
                                "To": {"type": "str",
                                       "required": True,
                                       "description": _("Send notification to "
                                                        "this user."),
                                       "value": [
                                           NOTIFY_TYPE.TOKENOWNER,
                                           NOTIFY_TYPE.LOGGED_IN_USER,
                                           NOTIFY_TYPE.INTERNAL_ADMIN,
                                           NOTIFY_TYPE.ADMIN_REALM,
                                           NOTIFY_TYPE.EMAIL]},
                                "To "+NOTIFY_TYPE.ADMIN_REALM: {
                                    "type": "str",
                                    "value": current_app.config.get(
                                        "SUPERUSER_REALM", []),
                                    "visibleIf": "To",
                                    "visibleValue": NOTIFY_TYPE.ADMIN_REALM},
                                "To "+NOTIFY_TYPE.INTERNAL_ADMIN: {
                                    "type": "str",
                                    "value": [a.username for a in
                                              get_db_admins()],
                                    "visibleIf": "To",
                                    "visibleValue":
                                         NOTIFY_TYPE.INTERNAL_ADMIN},
                                "To "+NOTIFY_TYPE.EMAIL: {
                                    "type": "str",
                                    "description": _("Any email address, to "
                                                     "which the notification "
                                                     "should be sent."),
                                    "visibleIf": "To",
                                    "visibleValue": NOTIFY_TYPE.EMAIL}
                                },
                   "sendsms": {"smsconfig":
                                   {"type": "str",
                                    "required": True,
                                    "description": _("Send the user "
                                                     "notification via a "
                                                     "predefined SMS "
                                                     "gateway."),
                                    "value": smsgateways},
                               "body": {"type": "text",
                                        "required": False,
                                        "description": _("The text of the "
                                                         "SMS.")},
                               "To": {"type": "str",
                                      "required": True,
                                      "description": _("Send notification to "
                                                       "this user."),
                                      "value": [NOTIFY_TYPE.TOKENOWNER]}
                               }
                   }
        return actions
Пример #12
0
    def actions(cls):
        """
        This method returns a dictionary of allowed actions and possible
        options in this handler module.

        :return: dict with actions
        """
        realm_list = list(get_realms())
        actions = {ACTION_TYPE.SET_TOKENREALM:
                       {"realm":
                            {"type": "str",
                             "required": True,
                             "description": _("set a new realm of the token"),
                             "value": realm_list},
                        "only_realm":
                            {"type": "bool",
                             "description": _("The new realm will be the only "
                                              "realm of the token. I.e. all "
                                              "other realms will be removed "
                                              "from this token. Otherwise the "
                                              "realm will be added to the token.")
                            }
                        },
                   ACTION_TYPE.DELETE: {},
                   ACTION_TYPE.UNASSIGN: {},
                   ACTION_TYPE.DISABLE: {},
                   ACTION_TYPE.ENABLE: {},
                   ACTION_TYPE.SET_RANDOM_PIN: {
                       "length":
                           {"type": "int",
                            "required": True,
                            "description": _("set the PIN of the token to a random PIN of this length."),
                            "value": list(range(1,32))}
                   },
                   ACTION_TYPE.INIT:
                       {"tokentype":
                            {"type": "str",
                             "required": True,
                             "description": _("Token type to create"),
                             "value": get_token_types()
                             },
                        "user":
                            {"type": "bool",
                             "description": _("Assign token to user in "
                                              "request or to tokenowner.")},
                        "realm":
                            {"type": "str",
                             "required": False,
                             "description": _("Set the realm of the newly "
                                              "created token."),
                             "value": realm_list},
                        "dynamic_phone": {
                            "type": "bool",
                            "visibleIf": "tokentype",
                            "visibleValue": "sms",
                            "description": _("Dynamically read the mobile number "
                                             "from the user store.")
                        },
                        "dynamic_email": {
                            "type": "bool",
                            "visibleIf": "tokentype",
                            "visibleValue": "email",
                            "description": _("Dynamically read the email address "
                                             "from the user store.")
                        },
                        "smtp_identifier": {
                            "type": "str",
                            "visibleIf": "tokentype",
                            "visibleValue": "email",
                            "description": _("Use a specific SMTP server configuration for this token."),
                            "value": [server.config.identifier for server in get_smtpservers()]
                        },
                        "sms_identifier": {
                            "type": "str",
                            "visibleIf": "tokentype",
                            "visibleValue": "sms",
                            "description": _("Use a specific SMS gateway configuration for this token."),
                            "value": [gateway.identifier for gateway in get_smsgateway()]
                        },
                        "additional_params": {
                            "type": "str",
                            "description": _("A dictionary of additional init parameters.")
                        },
                        "motppin": {
                            "type": "str",
                            "visibleIf": "tokentype",
                            "visibleValue": "motp",
                            "description": _("Set the MOTP PIN of the MOTP "
                                             "token during enrollment. This "
                                             "is a required value for "
                                             "enrolling MOTP tokens.")}
                        },
                   ACTION_TYPE.SET_DESCRIPTION:
                       {"description":
                            {
                                "type": "str",
                                "description": _("The new description of the "
                                                 "token.")
                            }
                       },
                   ACTION_TYPE.SET_VALIDITY:
                       {VALIDITY.START: {
                           "type": "str",
                           "description": _("The token will be valid starting "
                                            "at the given date. Can be a fixed "
                                            "date or an offset like +10m, "
                                            "+24h, +7d.")
                       },
                        VALIDITY.END: {
                            "type": "str",
                            "description": _("The token will be valid until "
                                             "the given date. Can be a fixed "
                                             "date or an offset like +10m, "
                                             "+24h, +7d.")
                        }
                       },
                   ACTION_TYPE.SET_COUNTWINDOW:
                       {"count window":
                            {
                                # TODO: should be "int" but we do not support
                                #  this at the moment.
                                "type": "str",
                                "required": True,
                                "description": _("Set the new count window of "
                                                 "the token.")
                            }
                       },
                   ACTION_TYPE.SET_FAILCOUNTER:
                       {
                           "fail counter":
                               {
                                   "type": "str",
                                   "required": True,
                                   "description": _("Set the failcounter of "
                                                    "the token.")
                               }
                       },
                   ACTION_TYPE.CHANGE_FAILCOUNTER:
                       {
                           "change fail counter":
                               {
                                   "type": "str",
                                   "required": True,
                                   "description": _("Increase or decrease the fail counter of the token. "
                                                    "Values of +n, -n with n being an integer are accepted.")
                               }
                       },
                   ACTION_TYPE.SET_TOKENINFO:
                       {"key":
                           {
                               "type": "str",
                               "required": True,
                               "description": _("Set this tokeninfo key.")
                           },
                        "value":
                            {
                                "type": "str",
                                "description": _("Set the above key the this "
                                                 "value.")
                            }
                       },
                   ACTION_TYPE.DELETE_TOKENINFO:
                       {"key":
                            {
                                "type": "str",
                                "required": True,
                                "description": _("Delete this tokeninfo key.")
                            }
                       }
                   }
        return actions
Пример #13
0
    def actions(cls):
        """
        This method returns a dictionary of allowed actions and possible
        options in this handler module.

        :return: dict with actions
        """
        smtpserver_objs = get_smtpservers()
        smsgateway_dicts = get_smsgateway()
        smsgateways = [sms.identifier for sms in smsgateway_dicts]
        smtpservers = [s.config.identifier for s in smtpserver_objs]
        actions = {
            "sendmail": {
                "emailconfig": {
                    "type":
                    "str",
                    "required":
                    True,
                    "description":
                    _("Send notification email via this email server."),
                    "value":
                    smtpservers
                },
                "mimetype": {
                    "type": "str",
                    "description":
                    _("Either send email as plain text or HTML."),
                    "value": ["plain", "html"]
                },
                "attach_qrcode": {
                    "type":
                    "bool",
                    "description":
                    _("Send QR-Code image as an attachment "
                      "(cid URL: token_image)")
                },
                "subject": {
                    "type": "str",
                    "required": False,
                    "description": _("The subject of the mail that is sent.")
                },
                "reply_to": {
                    "type":
                    "str",
                    "required":
                    False,
                    "description":
                    _("The Reply-To header in the sent email."),
                    "value": [
                        NOTIFY_TYPE.NO_REPLY_TO, NOTIFY_TYPE.TOKENOWNER,
                        NOTIFY_TYPE.LOGGED_IN_USER, NOTIFY_TYPE.INTERNAL_ADMIN,
                        NOTIFY_TYPE.ADMIN_REALM, NOTIFY_TYPE.EMAIL
                    ]
                },
                "reply_to " + NOTIFY_TYPE.ADMIN_REALM: {
                    "type": "str",
                    "value": get_app_config_value("SUPERUSER_REALM", []),
                    "visibleIf": "reply_to",
                    "visibleValue": NOTIFY_TYPE.ADMIN_REALM
                },
                "reply_to " + NOTIFY_TYPE.INTERNAL_ADMIN: {
                    "type": "str",
                    "value": [a.username for a in get_db_admins()],
                    "visibleIf": "reply_to",
                    "visibleValue": NOTIFY_TYPE.INTERNAL_ADMIN
                },
                "reply_to " + NOTIFY_TYPE.EMAIL: {
                    "type":
                    "str",
                    "description":
                    _("Any email address, to which the notification "
                      "should be sent."),
                    "visibleIf":
                    "reply_to",
                    "visibleValue":
                    NOTIFY_TYPE.EMAIL
                },
                "body": {
                    "type": "text",
                    "required": False,
                    "description": _("The body of the mail that is sent.")
                },
                "To": {
                    "type":
                    "str",
                    "required":
                    True,
                    "description":
                    _("Send notification to this user."),
                    "value": [
                        NOTIFY_TYPE.TOKENOWNER, NOTIFY_TYPE.LOGGED_IN_USER,
                        NOTIFY_TYPE.INTERNAL_ADMIN, NOTIFY_TYPE.ADMIN_REALM,
                        NOTIFY_TYPE.EMAIL
                    ]
                },
                "To " + NOTIFY_TYPE.ADMIN_REALM: {
                    "type": "str",
                    "value": get_app_config_value("SUPERUSER_REALM", []),
                    "visibleIf": "To",
                    "visibleValue": NOTIFY_TYPE.ADMIN_REALM
                },
                "To " + NOTIFY_TYPE.INTERNAL_ADMIN: {
                    "type": "str",
                    "value": [a.username for a in get_db_admins()],
                    "visibleIf": "To",
                    "visibleValue": NOTIFY_TYPE.INTERNAL_ADMIN
                },
                "To " + NOTIFY_TYPE.EMAIL: {
                    "type":
                    "str",
                    "description":
                    _("Any email address, to which the notification "
                      "should be sent."),
                    "visibleIf":
                    "To",
                    "visibleValue":
                    NOTIFY_TYPE.EMAIL
                }
            },
            "sendsms": {
                "smsconfig": {
                    "type":
                    "str",
                    "required":
                    True,
                    "description":
                    _("Send the user notification via a "
                      "predefined SMS gateway."),
                    "value":
                    smsgateways
                },
                "body": {
                    "type": "text",
                    "required": False,
                    "description": _("The text of the SMS.")
                },
                "To": {
                    "type": "str",
                    "required": True,
                    "description": _("Send notification to this user."),
                    "value": [NOTIFY_TYPE.TOKENOWNER]
                }
            },
            "savefile": {
                "body": {
                    "type":
                    "text",
                    "required":
                    True,
                    "description":
                    _("This is the template content of "
                      "the new file. Can contain the tags "
                      "as specified in the documentation.")
                },
                "filename": {
                    "type":
                    "str",
                    "required":
                    True,
                    "description":
                    _("The filename of the notification. Existing files "
                      "are overwritten. The name can contain tags as specified "
                      "in the documentation and can also contain the tag {random}."
                      )
                }
            }
        }
        return actions
Пример #14
0
    def actions(cls):
        """
        This method returns a dictionary of allowed actions and possible
        options in this handler module.

        :return: dict with actions
        """
        smtpserver_objs = get_smtpservers()
        smsgateway_dicts = get_smsgateway()
        smsgateways = [sms.identifier for sms in smsgateway_dicts]
        smtpservers = [s.config.identifier for s in smtpserver_objs]
        actions = {
            "sendmail": {
                "emailconfig": {
                    "type":
                    "str",
                    "required":
                    True,
                    "description":
                    _("Send notification "
                      "email via this "
                      "email server."),
                    "value":
                    smtpservers
                },
                "subject": {
                    "type": "str",
                    "required": False,
                    "description": _("The subject of "
                                     "the mail that "
                                     "is sent.")
                },
                "body": {
                    "type": "text",
                    "required": False,
                    "description": _("The body of the "
                                     "mail that is sent.")
                }
            },
            "sendsms": {
                "smsconfig": {
                    "type":
                    "str",
                    "required":
                    True,
                    "description":
                    _("Send the user "
                      "notification via a "
                      "predefined SMS "
                      "gateway."),
                    "value":
                    smsgateways
                },
                "body": {
                    "type": "text",
                    "required": False,
                    "description": _("The text of the SMS.")
                }
            }
        }
        return actions
Пример #15
0
    def actions(cls):
        """
        This method returns a dictionary of allowed actions and possible
        options in this handler module.

        :return: dict with actions
        """
        smtpserver_objs = get_smtpservers()
        smsgateway_dicts = get_smsgateway()
        smsgateways = [sms.identifier for sms in smsgateway_dicts]
        smtpservers = [s.config.identifier for s in smtpserver_objs]
        actions = {"sendmail": {"emailconfig":
                                     {"type": "str",
                                      "required": True,
                                      "description": _("Send notification "
                                                       "email via this "
                                                       "email server."),
                                      "value": smtpservers},
                                "mimetype": {"type": "str",
                                             "description": _("Either send "
                                                              "email as plain text or HTML."),
                                             "value": ["plain", "html"]},
                                "subject": {"type": "str",
                                            "required": False,
                                            "description": _("The subject of "
                                                             "the mail that "
                                                             "is sent.")},
                                "reply_to": {"type": "str",
                                             "required": False,
                                             "description": _("The Reply-To "
                                                              "header in the "
                                                              "sent email.")},
                                "body": {"type": "text",
                                         "required": False,
                                         "description": _("The body of the "
                                                          "mail that is "
                                                          "sent.")},
                                "To": {"type": "str",
                                       "required": True,
                                       "description": _("Send notification to "
                                                        "this user."),
                                       "value": [
                                           NOTIFY_TYPE.TOKENOWNER,
                                           NOTIFY_TYPE.LOGGED_IN_USER,
                                           NOTIFY_TYPE.INTERNAL_ADMIN,
                                           NOTIFY_TYPE.ADMIN_REALM,
                                           NOTIFY_TYPE.EMAIL]},
                                "To "+NOTIFY_TYPE.ADMIN_REALM: {
                                    "type": "str",
                                    "value": get_app_config_value("SUPERUSER_REALM", []),
                                    "visibleIf": "To",
                                    "visibleValue": NOTIFY_TYPE.ADMIN_REALM},
                                "To "+NOTIFY_TYPE.INTERNAL_ADMIN: {
                                    "type": "str",
                                    "value": [a.username for a in
                                              get_db_admins()],
                                    "visibleIf": "To",
                                    "visibleValue":
                                         NOTIFY_TYPE.INTERNAL_ADMIN},
                                "To "+NOTIFY_TYPE.EMAIL: {
                                    "type": "str",
                                    "description": _("Any email address, to "
                                                     "which the notification "
                                                     "should be sent."),
                                    "visibleIf": "To",
                                    "visibleValue": NOTIFY_TYPE.EMAIL}
                                },
                   "sendsms": {"smsconfig":
                                   {"type": "str",
                                    "required": True,
                                    "description": _("Send the user "
                                                     "notification via a "
                                                     "predefined SMS "
                                                     "gateway."),
                                    "value": smsgateways},
                               "body": {"type": "text",
                                        "required": False,
                                        "description": _("The text of the "
                                                         "SMS.")},
                               "To": {"type": "str",
                                      "required": True,
                                      "description": _("Send notification to "
                                                       "this user."),
                                      "value": [NOTIFY_TYPE.TOKENOWNER]}
                               }
                   }
        return actions