예제 #1
0
    def delete_client(self, server=None, username=None):
        success, response = utils.__check_parameter__(server, "server", None)
        if not success: return response
        success, response = utils.__check_parameter__(username, "username",
                                                      None)
        if not success: return response

        # initialize default response.
        response = utils.__default_response__()

        # check existance.
        if server not in list(self.servers.keys()):
            response["error"] = f"Server [{server}] does not exist."
            return response
        if username not in list(self.servers[server]["clients"].keys()):
            response["error"] = f"Client [{username}] does not exist."
            return response

        # delete.
        os.system(f"rm -fr {ROOT_DIR}/servers/{server}/{username}")

        # response.
        response["success"] = True
        response[
            "message"] = f"Successfully deleted client [{username}@{server}]."
        self.__initialize_servers__()
        return response
예제 #2
0
        def edit_passphrase(self, old=None, new=None):

            # initialize default response.
            response = utils.__default_response__()

            # check encryptiom.
            if self.defaults.smartcard:
                return r3sponse.error("This client uses a smart card.")

            # check encryptiom.
            if PASSPHRASES.passphrase == None or ENCRYPTION.passphrase == None:
                return r3sponse.error(
                    "The encryption requires to be activated when making client edits. Go to [Dashboard > Encryption > Activate] to activate the encryption."
                )

            # checks.
            success, response = utils.__check_parameter__(old, "old", None)
            if not success: return response
            success, response = utils.__check_parameter__(new, "new", None)
            if not success: return response

            # response.
            response = ssht00ls.keys.edit_passphrase(
                path=self.defaults.private_key,
                old=old,
                new=new,
            )
            if response["error"] != None: return response

            # save pass.
            if smartcard:
                PASSPHRASES.dictionary["smartcards"][
                    self.defaults.public_key_id] = str(new)
            else:
                PASSPHRASES.dictionary["ssh_keys"][
                    self.defaults.public_key_id] = str(new)
            l_response = PASSPHRASES.save()
            if l_response["error"] != None:
                return r3sponse.error(
                    'Successfully edited the passphrase but failed to store the passphrase in the encrypted dictionary, error: '
                    + l_response["error"])
            return response
예제 #3
0
    def edit_server(
        self,
        server=None,
        # the lan ip address of the server.
        lan_ip=None,
        # the wan ip address of the server.
        wan_ip=None,
        # the lan ssh port of the server.
        lan_ssh_port=None,
        # the wan ssh port of the server.
        wan_ssh_port=None,
    ):
        success, resposne = utils.__check_parameter__(server, "server", None)
        if not success: return response
        success, response = utils.__check_parameter__(lan_ip, "lan_ip", None)
        if not success: return response
        success, response = utils.__check_parameter__(wan_ip, "wan_ip", None)
        if not success: return response
        success, response = utils.__check_parameter__(lan_ssh_port,
                                                      "lan_ssh_port", None)
        if not success: return response
        success, response = utils.__check_parameter__(wan_ssh_port,
                                                      "wan_ssh_port", None)
        if not success: return response

        # initialize default response.
        response = utils.__default_response__()

        # check existance.
        if server not in list(self.servers.keys()):
            response["error"] = f"Server [{server}] does not exist."
            return response

        # save.
        try:
            utils.__save_json__(
                f'{ROOT_DIR}/servers/{server}/settings.json', {
                    "ip": {
                        "wan": wan_ip,
                        "lan": lan_ip,
                    },
                    "ports": {
                        "wan": {
                            "ssh": wan_ssh_port,
                        },
                        "lan": {
                            "ssh": lan_ssh_port,
                        },
                    }
                })
        except:
            response[
                "error"] = f"Failed to edit the settings of server [{server}]."
            return response

        # response.
        response["success"] = True
        response[
            "message"] = f"Successfully edited the settings of server [{server}]."
        self.__initialize_servers__()
        return response
예제 #4
0
        def add_to_agent(self,
                         passphrase=None,
                         load_passphrase=False,
                         smartcard=False,
                         pin=None):

            # initialize default response.
            response = utils.__default_response__()

            if load_passphrase:
                # check encryptiom.
                if PASSPHRASES.passphrase == None or ENCRYPTION.passphrase == None:
                    response[
                        "error"] = "The encryption requires to be activated when making client edits. Go to [Dashboard > Encryption > Activate] to activate the encryption."
                    return response
                if smartcard:
                    try:
                        passphrase = PASSPHRASES.dictionary["smartcards"][
                            self.defaults.public_key_id]
                    except KeyError:
                        response[
                            "error"] = f"There are no passphrases stored for client [{self.defaults.id}]."
                        return response
                else:
                    try:
                        passphrase = PASSPHRASES.dictionary["ssh_keys"][
                            self.defaults.public_key_id]
                    except KeyError:
                        response[
                            "error"] = f"There are no passphrases stored for client [{self.defaults.id}]."
                        return response

            # checks.
            success, response = utils.__check_parameter__(
                passphrase, "passphrase", None)
            if not success: return response

            # check if not already added.
            response = self.check_agent()
            if response[
                    "error"] != None and " is not added to the ssh agent" not in response[
                        "error"]:
                return response
            elif response["success"]:
                response[
                    "message"] = f"The key from client [{self.defaults.id}] is already added to the ssh agent."
                return response

            # response.
            if not smartcard:
                response = ssht00ls.agent.add(
                    private_key=self.defaults.private_key,
                    passphrase=passphrase,
                )
            else:
                response = ssht00ls.agent.add(
                    private_key=self.defaults.private_key,
                    smartcard=True,
                    pin=pin,
                )
            if response["success"]:
                response[
                    "message"] = f"Successfully added key from client [{self.defaults.id}] to the ssh agent."
            return response