Esempio n. 1
0
    def action(self):
        if not html.check_transaction():
            return

        vs = self._valuespec()
        self._connection_cfg = vs.from_html_vars("connection")
        vs.validate_value(self._connection_cfg, "connection")

        self._connection_cfg["type"] = "ldap"

        if self._new:
            self._connections.insert(0, self._connection_cfg)
            self._connection_id = self._connection_cfg["id"]
        else:
            self._connection_cfg["id"] = self._connection_id
            self._connections[self._connection_nr] = self._connection_cfg

        assert self._connection_id is not None

        if self._new:
            log_what = "new-ldap-connection"
            log_text = _("Created new LDAP connection")
        else:
            log_what = "edit-ldap-connection"
            log_text = _("Changed LDAP connection %s") % self._connection_id
        self._add_change(log_what, log_text)

        save_connection_config(self._connections)
        config.user_connections = self._connections  # make directly available on current page
        if html.request.var("_save"):
            return "ldap_config"
        # Fix the case where a user hit "Save & Test" during creation
        html.request.set_var('id', self._connection_id)
Esempio n. 2
0
    def action(self) -> ActionResult:
        if not transactions.check_transaction():
            return redirect(self.mode_url())

        connections = load_connection_config(lock=True)
        if html.request.has_var("_delete"):
            index = html.request.get_integer_input_mandatory("_delete")
            connection = connections[index]
            self._add_change(
                "delete-ldap-connection",
                _("Deleted LDAP connection %s") % (connection["id"]))
            del connections[index]
            save_connection_config(connections)

        elif html.request.has_var("_move"):
            from_pos = html.request.get_integer_input_mandatory("_move")
            to_pos = html.request.get_integer_input_mandatory("_index")
            connection = connections[from_pos]
            self._add_change(
                "move-ldap-connection",
                _("Changed position of LDAP connection %s to %d") %
                (connection["id"], to_pos))
            del connections[from_pos]  # make to_pos now match!
            connections[to_pos:to_pos] = [connection]
            save_connection_config(connections)

        return redirect(self.mode_url())
Esempio n. 3
0
    def action(self):
        connections = load_connection_config(lock=True)
        if html.request.has_var("_delete"):
            index = html.request.get_integer_input_mandatory("_delete")
            connection = connections[index]
            c = wato_confirm(
                _("Confirm deletion of LDAP connection"),
                _("Do you really want to delete the LDAP connection <b>%s</b>?"
                  ) % (connection["id"]))
            if c:
                self._add_change(
                    "delete-ldap-connection",
                    _("Deleted LDAP connection %s") % (connection["id"]))
                del connections[index]
                save_connection_config(connections)
            elif c is False:
                return ""
            else:
                return

        elif html.request.has_var("_move"):
            if not html.check_transaction():
                return

            from_pos = html.request.get_integer_input_mandatory("_move")
            to_pos = html.request.get_integer_input_mandatory("_index")
            connection = connections[from_pos]
            self._add_change(
                "move-ldap-connection",
                _("Changed position of LDAP connection %s to %d") %
                (connection["id"], to_pos))
            del connections[from_pos]  # make to_pos now match!
            connections[to_pos:to_pos] = [connection]
            save_connection_config(connections)
Esempio n. 4
0
    def action(self) -> ActionResult:
        if not transactions.check_transaction():
            return None

        vs = self._valuespec()
        self._connection_cfg = vs.from_html_vars("connection")
        vs.validate_value(self._connection_cfg, "connection")

        self._connection_cfg["type"] = "ldap"

        if self._new:
            self._connections.insert(0, self._connection_cfg)
            self._connection_id = self._connection_cfg["id"]
        else:
            self._connection_cfg["id"] = self._connection_id
            self._connections[self._connection_nr] = self._connection_cfg

        assert self._connection_id is not None

        if self._new:
            log_what = "new-ldap-connection"
            log_text = _("Created new LDAP connection")
        else:
            log_what = "edit-ldap-connection"
            log_text = _("Changed LDAP connection %s") % self._connection_id
        self._add_change(log_what, log_text)

        save_connection_config(self._connections)
        config.user_connections = self._connections  # make directly available on current page
        if request.var("_save"):
            return redirect(mode_url("ldap_config"))
        # Handle the case where a user hit "Save & Test" during creation
        return redirect(self.mode_url(_test="1", id=self._connection_id))
Esempio n. 5
0
    def _add_missing_type_to_ldap_connections(self):
        """Each user connections needs to declare it's connection type.

        This is done using the "type" attribute. Previous versions did not always set this
        attribute, which is corrected with this update method."""
        connections = load_connection_config()
        if not connections:
            return

        for connection in connections:
            connection.setdefault("type", "ldap")
        save_connection_config(connections)