示例#1
0
	def unmount(self, forced=False, sudo=False):

		# iterate targets.
		self.targets.load()
		for id, target in self.targets.dictionary.items():

			# get client.
			try:
				username, server = target["client"].split('@')
			except:
				return dev0s.response.error(f"Invalid client [{client}] format, valid format: [username@server].")
			if server not in servers.list():
				return dev0s.response.error(f"Server [{server}] does not exist.")
			if username not in servers[server].list():
				return dev0s.response.error(f"Server [{server}] does contain client [{username}].")

			# unmount.
			client = servers[server][username]
			if os.path.ismount(target["path"]):
				response = client.client.sshfs.unmount(
					path=target["path"],
					sudo=sudo,
					forced=forced,)
				if response["error"] != None: return response

		# success.
		return dev0s.response.success(f"Successfully unmounted all {len(self.targets.dictionary)} target(s).")
示例#2
0
    def view(self, request):
        # map clients.
        clients = {}
        for id, server in servers.iterate():
            clients[id] = []
            for username in server.list():
                clients[id].append(username)

        # get server param.
        server, response = self.parameters.get(request, "server")
        if not response.success:
            return self.error(request,
                              title="Error!",
                              message=response["error"],
                              icon="/media/icons/warning.png",
                              redirect="/dashboard/servers/",
                              redirect_button="Back",
                              template_data=website.template())
        if server not in servers.list():
            return self.error(request,
                              title="Warning!",
                              message=f"Server [{server}] does not exist.",
                              icon="/media/icons/warning.png",
                              redirect="/dashboard/servers/",
                              redirect_button="Back",
                              template_data=website.template())

        # get username param.
        client, response = self.parameters.get(request, "client")
        if not response.success:
            return self.error(request,
                              title="Error!",
                              message=response["error"],
                              icon="/media/icons/warning.png",
                              redirect="/dashboard/servers/",
                              redirect_button="Back",
                              template_data=website.template())
        if client not in servers[server].list():
            return self.error(
                request,
                title="Warning!",
                message=
                f"Client [{client}] from server [{server}] does not exist.",
                icon="/media/icons/warning.png",
                redirect="/dashboard/servers/server/?server=" + server,
                redirect_button="Back",
                template_data=website.template())

        # return render.
        return self.render(
            request,
            website.template({
                "INSTALLED": manager.installed,
                "CLIENT": client,
            }))
示例#3
0
	def create(self, 
		# the selected client (str).
		client=None,
		# the client path (str).
		path=None,
		# the server path (str).
		remote=None,
	):

		# check parameters.
		response = dev0s.response.parameters.check({
			"client:str,String":client,
			"path:str,String":path,
			"remote:str,String":remote,
		})
		if response["error"] != None: return response

		# check target.
		if path in self.list(load=True):
			return dev0s.response.error(f"Automount target with client path [{path}] already exists.")

		# check client.
		try:
			username, server = client.split('@')
		except:
			return dev0s.response.error(f"Invalid client [{client}] format, valid format: [username@server].")
		if server not in servers.list():
			return dev0s.response.error(f"Server [{server}] does not exist.")
		if username not in servers[server].list():
			return dev0s.response.error(f"Server [{server}] does contain client [{username}].")
		client_tag = str(client)
		client = servers[server][username]

		# delete.
		self.__edit__({
			path: {
				"client":client_tag,
				"id":gfp.name(path),
				"path":path,
				"remote":remote,
			}
		})

		# success.
		return dev0s.response.success(f"Successfully created target [{path}].")
示例#4
0
	def mount(self):

		# iterate targets.
		for id, target in self.targets.iterate(load=True):

			# get client.
			try:
				username, server = target["client"].split('@')
			except:
				return dev0s.response.error(f"Invalid client [{client}] format, valid format: [username@server].")
			if server not in servers.list():
				return dev0s.response.error(f"Server [{server}] does not exist.")
			if username not in servers[server].list():
				return dev0s.response.error(f"Server [{server}] does contain client [{username}].")
			client = servers[server][username]

			# check client active.
			if client.client.smartcard:
				set = False
				for id, smartcard in client.client.smartcards.iterate():
					if smartcard.activated:
						set = True
						break
				if not set: return dev0s.response.error(f"The smart card from client [{username}@{server}] is not activated.")
			else:
				response = ssht00ls.original_agent.check(client.client.public_key)
				if response["error"] != None: return response

			# mount.
			response = client.client.sshfs.mount(
				remote=target["remote"],
				path=target["path"],)
			if response["error"] != None: return response

		# success.
		return dev0s.response.success(f"Successfully mounted all {len(self.targets)} target(s).")
示例#5
0
    def view(self, request):
        # get server param.
        server, response = self.parameters.get(request, "server")
        if not response.success:
            return self.error(request,
                              title="Error!",
                              message=response["error"],
                              icon="/media/icons/warning.png",
                              redirect="/dashboard/servers/",
                              redirect_button="Back",
                              template_data=website.template())
        if server not in servers.list():
            return self.error(request,
                              title="Warning!",
                              message=f"Server [{server}] does not exist.",
                              icon="/media/icons/warning.png",
                              redirect="/dashboard/home/",
                              redirect_button="Back",
                              template_data=website.template())
        username, response = self.parameters.get(request, "client")
        if not response.success:
            return self.error(request,
                              title="Error!",
                              message=response["error"],
                              icon="/media/icons/warning.png",
                              redirect="/dashboard/servers/",
                              redirect_button="Back",
                              template_data=website.template())
        if username not in servers[server].list():
            return self.error(
                request,
                title="Warning!",
                message=
                f"Client [{username}] from server [{server}] does not exist.",
                icon="/media/icons/warning.png",
                redirect="/dashboard/home/",
                redirect_button="Back",
                template_data=website.template())

        # check client key active.
        client, error = servers[server][username], False
        if client.client.smartcard:
            set = False
            for serial_number in client.client.serial_numbers:
                if serial_number in ACTIVATED_SMARTCARDS:
                    set = True
                    break
            if set == False:
                error = True
        else:
            # check client.
            response = client.client.check()
            if response["error"] != None: error = True
        if error:
            if client.client.smartcard:
                error = f'Client [{username}@{server}] is not activated. Press "Activate Smart Cards" to activate client [{username}@{server}].'
                redirect = "/dashboard/home/?activate_smartcards=true"
            else:
                error = f'Client [{username}@{server}] is not activated. Press "Activate Clients" to activate client [{username}@{server}].'
                redirect = "/dashboard/home/?activate_clients=true"
            return self.error(request,
                              title="Warning!",
                              message=error,
                              icon="/media/icons/warning.png",
                              redirect=redirect,
                              redirect_button="Activate",
                              template_data=website.template())

        # map servers & clients.
        _servers_, clients, active_clients = {}, {}, {}
        for id, server in servers.iterate():
            _servers_[id] = server.info
            for l_username, l_client in server.iterate():
                active = False
                if l_client.client.smartcard:
                    for serial_number in l_client.client.serial_numbers:
                        if serial_number in ACTIVATED_SMARTCARDS:
                            active = True
                            break
                else:
                    # check client.
                    response = client.client.check()
                    active = response["success"]
                clients[f'{l_username}@{id}'] = {
                    "active": active,
                    "smartcard": l_client.client.smartcard,
                }
                active_clients[f'{l_username}@{id}'] = {
                    "smartcard": l_client.client.smartcard,
                }

        # get storages info.
        os.system("rm -fr /tmp/storages")
        response = client.storages.download()
        if not response.success:
            return self.error(
                request,
                title="Warning!",
                message=
                f"Unable to connect with client [{username}] from server [{client.server}], error: {response.error}",
                icon="/media/icons/warning.png",
                redirect="/dashboard/home/",
                redirect_button="Back",
                template_data=website.template())
        donwloaded = response.storages

        # map storages.
        storages = {}
        for storage, info in donwloaded.items():
            if username in info["users"].split(","):
                storages[storage] = info

        # return render.
        return self.render(
            request,
            website.template({
                "INSTALLED": manager.installed,
                "NO_STORAGES": len(storages) == 0,
                "STORAGES": storages,
                "USERNAME": username,
                "SERVER_NAME": server,
                "CLIENTS": clients,
                "ACTIVE_CLIENTS": active_clients,
                "NO_ACTIVE_CLIENTS": len(active_clients) == 0,
                "ACTIVE_SMART_CARDS": ACTIVATED_SMARTCARDS,
            }))