Ejemplo n.º 1
0
		def request(self, request):

			# check parameters.
			parameters, response = self.parameters.get(request, [
				"forced",
				"sudo",
			])
			if not response.success: return self.response(response)

			# make request.
			return self.response(automount.remount(
				forced=Boolean(parameters["forced"]),
				sudo=Boolean(parameters["sudo"]),))
Ejemplo n.º 2
0
		def view(request):

			# check parameters.
			parameters, success, response = utils.__get_request_params__(request, [
				"forced",
				"sudo",
			])
			if not success: return JsonResponse(response)

			# make request.
			return JsonResponse(automount.remount(
				forced=utils.__string_to_boolean__(parameters["forced"]),
				sudo=utils.__string_to_boolean__(parameters["sudo"]),))
Ejemplo n.º 3
0
    def start(self):

        # clear logs option.
        if not self.argument_present('-c'):
            os.system("clear")

        # help.
        if self.argument_present('-h') or self.argument_present('--help'):
            print(self.documentation)

        # automount.
        elif self.argument_present('--agent'):

            # start the ssh agent.
            if self.argument_present('--start'):

                # activate encryption.
                self.__activate_encryption__()

                # activate clients.
                response = manager.activate_clients()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

                # activate smart cards.
                response = ssht00ls.smart_cards.__single_key_plugged_in__()
                if response["success"]:
                    smart_card = response["smart_card"]
                    try:
                        attempts = int(smart_cards.info()["pin_attempts"])
                        if attempts == 1:
                            print(
                                "Warning your card will be blocked upon an incorrect pin!\nPin attempts left:",
                                attempts)
                        elif attempts == 2:
                            print("Warning! Pin attempts left:", attempts)
                        else:
                            print("Pin attempts left:", attempts)
                    except:
                        a = 1
                    serial_number = smart_card.serial_number
                    response = ssht00ls.agent(
                        path=ssht00ls.smart_cards.path,
                        smart_card=True,
                        pin=utils.__prompt_password__(
                            f"Enter the pin of smart card [{serial_number}]:",
                        ))
                    if response["error"] != None: print(response["error"])
                    else: print(response["message"])

            # start the ssh agent.
            elif self.argument_present('--stop'):
                os.system("ssh-add -D")

            # invalid.
            else:
                print(self.documentation)
                print("Selected an invalid mode.")

        # automount.
        elif self.argument_present('--automount'):

            # mount targets.
            if self.argument_present('--mount'):

                # activate clients.
                response = automount.mount()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

            # mount targets.
            elif self.argument_present('--unmount'):

                # activate clients.
                response = automount.unmount()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

            # mount targets.
            elif self.argument_present('--remount'):

                # activate clients.
                response = automount.remount()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

            # invalid.
            else:
                print(self.documentation)
                print("Selected an invalid mode.")

        # install a new key.
        elif self.argument_present('--install'):

            # smart card.
            if self.argument_present('--smart-cards'):

                # install client.
                serial_numbers = []
                for i in self.get_argument("--serial-numbers").split(','):
                    for x in range(101):
                        if len(i) > 0 and i[0] == " ": i = i[1:]
                        elif len(i) > 0 and i[len(i) - 1] == " ": i = i[:-1]
                        else: break
                    serial_numbers.append(i)
                response = manager.install_client(
                    # the username.
                    username=self.get_argument("--username"),
                    # the servers alias. (example:vandenberghinc.com)
                    server=self.get_argument("--server"),
                    # the lan ip address of the server.
                    lan_ip=self.get_argument("--lan-ip"),
                    # the wan ip address of the server.
                    wan_ip=self.get_argument("--wan-ip"),
                    # the lan ssh port of the server.
                    lan_ssh_port=self.get_argument("--lan-ssh-port"),
                    # the wan ssh port of the server.
                    wan_ssh_port=self.get_argument("--wan-ssh-port"),
                    # option 1:
                    # the new passphrase for the private key.
                    new_passphrase=None,
                    # the old passphrase for the private key.
                    old_passphrase="''",  # (no passphrase)
                    # the path to the private key.
                    private_key=None,
                    # the path to the private key.
                    public_key=None,
                    # option 2:
                    # enable for smart cards.
                    smart_cards=True,
                    # serial numbers of the smart cards.
                    serial_numbers=serial_numbers,
                )
                # response is already printed inside for this function only.

            # non smart card.
            else:

                # check encryption.
                if not os.path.exists(ENCRYPTION.key):

                    # create pass & install & activate encryption.
                    print(
                        f"{utils.color.red}WARNING:{utils.color.yellow} the passphrase of the master encryption key can not be recovered. If you lose this passphrase you will have to reinstall all installed clients.{utils.color.end}"
                    )
                    passphrase = utils.__prompt_password__(
                        "Enter a passphrase for the master encryption key:")
                    verify_passphrase = utils.__prompt_password__(
                        "Enter the same passphrase:")
                    response = manager.install_encryption(
                        passphrase=passphrase,
                        verify_passphrase=verify_passphrase,
                    )
                    if response["error"] != None:
                        print(response['error'])
                        sys.exit(1)

                else:

                    # activate encryption.
                    self.__activate_encryption__()

                # install client.
                old_passphrase = self.get_argument("--old-passphrase")
                if old_passphrase in ["none", ""]: old_passphrase = '""'
                response = manager.install_client(
                    # the username.
                    username=self.get_argument("--username"),
                    # the servers alias. (example:vandenberghinc.com)
                    server=self.get_argument("--server"),
                    # the lan ip address of the server.
                    lan_ip=self.get_argument("--lan-ip"),
                    # the wan ip address of the server.
                    wan_ip=self.get_argument("--wan-ip"),
                    # the lan ssh port of the server.
                    lan_ssh_port=self.get_argument("--lan-ssh-port"),
                    # the wan ssh port of the server.
                    wan_ssh_port=self.get_argument("--wan-ssh-port"),
                    # option 1:
                    # the new passphrase for the private key.
                    new_passphrase=Formats.String("").generate(length=48,
                                                               digits=True,
                                                               capitalize=True,
                                                               special=True),
                    # the old passphrase for the private key.
                    old_passphrase=old_passphrase,  # (no passphrase)
                    # the path to the private key.
                    private_key=self.get_argument("--private-key"),
                    # the path to the private key.
                    public_key=self.get_argument("--public-key"),
                    # option 2:
                    # enable for smart cards.
                    smart_cards=False,
                    # serial numbers of the smart cards.
                    serial_numbers=None,
                )
                # response is already printed inside for this function only.

        # start.
        elif self.argument_present('--start'):

            # start the web server.
            if not os.path.exists(f"{SOURCE_PATH}/{VERSION}/db.sqlite3"):
                os.system(
                    f"cd {SOURCE_PATH}/{VERSION}/ && ./manage.py migrate")
            os.system(f"cd {SOURCE_PATH}/{VERSION}/ && ./manage.py runserver")

        # invalid.
        else:
            print(self.documentation)
            print("Selected an invalid mode.")
Ejemplo n.º 4
0
    def start(self):

        # check args.
        self.arguments.check(json=dev0s.defaults.options.json,
                             exceptions=[
                                 "--log-level", "--version", "--create-alias",
                                 "--non-interactive", "--developer", "--sudo",
                                 "--global", "--debug"
                             ])

        # migrations.
        self.__check_migrations__()

        # generate encryption.
        if not ssht00ls_agent.generated:
            response = manager.install_encryption(interactive=True)
            if response["error"] != None: self.stop(response=response)

        # activate encryption.
        else:
            response = manager.activate_encryption(interactive=True)
            if response["error"] != None: self.stop(response=response)

        ########################################################################
        #
        # Basics.
        #

        # help.
        if self.arguments.present(['-h', '--help']):
            self.docs(success=True, json=dev0s.defaults.options.json)

        # version.
        elif self.arguments.present(['--version']):
            self.stop(message=f"{ALIAS} version: " +
                      Files.load(f"{SOURCE}/.version").replace("\n", ""),
                      json=dev0s.defaults.options.json)

        # config.
        elif self.arguments.present('--config'):
            if dev0s.defaults.options.json:
                os.system(f"cat {ROOT_DIR.fp.path}/config/settings")
            else:
                os.system(f"nano {ROOT_DIR.fp.path}/config/settings")

        ########################################################################
        #
        # Web Server.
        #

        # developer start.
        elif self.arguments.present('--start') and self.arguments.present(
                '--developer'):
            response = website.django.start(
                host=self.arguments.get("--host",
                                        required=False,
                                        default="127.0.0.1"),
                port=self.arguments.get("--port", required=False,
                                        default=8001),
            )
            self.stop(response=response)

        # start.
        elif self.arguments.present('--start'):
            response = manager.service.start()
            self.stop(response=response)

        # stop.
        elif self.arguments.present('--stop'):
            response = manager.service.stop()
            self.stop(response=response)

        # restart.
        elif self.arguments.present('--restart'):
            response = manager.service.restart()
            self.stop(response=response)

        # status.
        elif self.arguments.present('--status'):
            response = manager.service.status()
            if not response.success:
                self.stop(response=response)
            else:
                print(response.status)

        # reset logs.
        elif self.arguments.present('--reset-logs'):
            response = manager.service.reset_logs()
            self.stop(response=response)

        # tail.
        elif self.arguments.present('--tail'):
            response = manager.service.tail(
                global_=self.arguments.present("--global"),
                debug=self.arguments.present("--debug"))
            if not response.success:
                self.stop(response=response)
            else:
                print(response.logs)

        ########################################################################
        #
        # Installation.
        #

        # install a new key.
        elif self.arguments.present('--install'):
            response = Client().install(
                encoded=self.arguments.get("--encoded"))
            self.stop(response=response)

        ########################################################################
        #
        # Clients.
        #

        # client.
        elif self.arguments.present('--client'):
            alias = self.arguments.get("--client", chapter="clients")
            if "@" not in alias:
                self.docs(
                    error=f"Invalid <username>:<server> format.",
                    chapter="clients",
                    notes={
                        "<username>@<server>":
                        "Pack the username & server together as the client argument in the following format [<username>:<server>]."
                    },
                    json=dev0s.defaults.options.json,
                )
            username, server = alias.split("@")
            if server not in manager.servers.list():
                self.stop(
                    error=f"Specified server [{server}]  does not exist.")
            if client not in manager.servers[server].list():
                self.stop(
                    f"Specified client [{username}@{server}] does not exist.")
            server = manager.servers[server]
            client = server[username]

            # activate encryption & client key..
            response = manager.activate_encryption()
            if not response.success: self.stop(response=response)
            response = client.client.activate()
            if not response.success: self.stop(response=response)

            # vnc.
            if self.arguments.present('--vnc'):
                response = client.vnc.create_connection()
                if response.success:
                    print(response['message'])
                    print(
                        f"Visit url: {color.orange}{response['url']}{color.end}"
                    )
                else:
                    self.stop(response=response)

            # invalid.
            else:
                self.invalid(chapter="clients")

        ########################################################################
        #
        # AutoMount.
        #

        # automount.
        elif self.arguments.present('--automount'):

            # mount targets.
            if self.arguments.present('--mount'):

                # activate clients.
                response = automount.mount()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

            # mount targets.
            elif self.arguments.present('--unmount'):

                # activate clients.
                response = automount.unmount()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

            # mount targets.
            elif self.arguments.present('--remount'):

                # activate clients.
                response = automount.remount()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

            # invalid.
            else:
                self.invalid(chapter="automount")

        ########################################################################
        #
        # Invalid.
        #

        # invalid.
        else:
            self.invalid()
        """
Ejemplo n.º 5
0
    def start(self):

        # clear logs option.
        if not self.arguments.present('-c'):
            os.system("clear")

        # help.
        if self.arguments.present('-h') or self.arguments.present('--help'):
            print(self.documentation)

        # automount.
        elif self.arguments.present('--agent'):

            # start the ssh agent.
            if self.arguments.present('--start'):

                # activate encryption.
                self.__activate_encryption__()

                # activate clients.
                response = manager.activate_clients()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

                # activate smart cards.
                response = ssht00ls.smartcards.__single_key_plugged_in__()
                if response["success"]:
                    smartcard = response["smartcard"]
                    try:
                        attempts = int(smartcards.info()["pin_attempts"])
                        if attempts == 1:
                            print(
                                "Warning your card will be blocked upon an incorrect pin!\nPin attempts left:",
                                attempts)
                        elif attempts == 2:
                            print("Warning! Pin attempts left:", attempts)
                        else:
                            print("Pin attempts left:", attempts)
                    except:
                        a = 1
                    serial_number = smartcard.serial_number
                    response = ssht00ls.agent(
                        path=ssht00ls.smartcards.path,
                        smartcard=True,
                        pin=utils.__prompt_password__(
                            f"Enter the pin of smart card [{serial_number}]:",
                        ))
                    if response["error"] != None: print(response["error"])
                    else: print(response["message"])

            # start the ssh agent.
            elif self.arguments.present('--stop'):
                os.system("ssh-add -D")

            # invalid.
            else:
                print(self.documentation)
                print("Selected an invalid mode.")

        # automount.
        elif self.arguments.present('--automount'):

            # mount targets.
            if self.arguments.present('--mount'):

                # activate clients.
                response = automount.mount()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

            # mount targets.
            elif self.arguments.present('--unmount'):

                # activate clients.
                response = automount.unmount()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

            # mount targets.
            elif self.arguments.present('--remount'):

                # activate clients.
                response = automount.remount()
                if response["error"] != None: print(response["error"])
                else: print(response["message"])

            # invalid.
            else:
                print(self.documentation)
                print("Selected an invalid mode.")

        # install a new key.
        elif self.arguments.present('--install'):
            self.__check_migrations__()

            # smart card.
            if self.arguments.present('--smart-cards'):

                # install client.
                serial_numbers = []
                for i in self.arguments.get("--serial-numbers").split(','):
                    for x in range(101):
                        if len(i) > 0 and i[0] == " ": i = i[1:]
                        elif len(i) > 0 and i[len(i) - 1] == " ": i = i[:-1]
                        else: break
                    serial_numbers.append(i)
                response = manager.install_client(
                    # the username.
                    username=self.arguments.get("--username"),
                    # the servers alias. (example:vandenberghinc.com)
                    server=self.arguments.get("--server"),
                    # the lan ip address of the server.
                    lan_ip=self.arguments.get("--lan-ip"),
                    # the wan ip address of the server.
                    wan_ip=self.arguments.get("--wan-ip"),
                    # the lan ssh port of the server.
                    lan_ssh_port=self.arguments.get("--lan-ssh-port"),
                    # the wan ssh port of the server.
                    wan_ssh_port=self.arguments.get("--wan-ssh-port"),
                    # the client's api key.
                    api_key=self.arguments.get("--api-key"),
                    # option 1:
                    # the old passphrase for the private key.
                    old_passphrase="''",  # (no passphrase)
                    # the path to the private key.
                    private_key=None,
                    # the path to the private key.
                    public_key=None,
                    # the path to the vpn key.
                    vpn_key=self.arguments.get("--vpn-key"),
                    # option 2:
                    # enable for smart cards.
                    smartcards=True,
                    # serial numbers of the smart cards.
                    serial_numbers=serial_numbers,
                )
                # response is already printed inside for this function only.

            # non smart card.
            else:

                # check encryption.
                if not Files.exists(ENCRYPTION.directory):

                    # create pass & install & activate encryption.
                    self.__install_encryption__()

                else:

                    # activate encryption.
                    self.__activate_encryption__()

                # install client.
                old_passphrase = self.arguments.get("--old-passphrase")
                if old_passphrase in ["none", ""]: old_passphrase = '""'
                response = manager.install_client(
                    # the username.
                    username=self.arguments.get("--username"),
                    # the servers alias. (example:vandenberghinc.com)
                    server=self.arguments.get("--server"),
                    # the lan ip address of the server.
                    lan_ip=self.arguments.get("--lan-ip"),
                    # the wan ip address of the server.
                    wan_ip=self.arguments.get("--wan-ip"),
                    # the lan ssh port of the server.
                    lan_ssh_port=self.arguments.get("--lan-ssh-port"),
                    # the wan ssh port of the server.
                    wan_ssh_port=self.arguments.get("--wan-ssh-port"),
                    # the client's api key.
                    api_key=self.arguments.get("--api-key"),
                    # option 1:
                    # the old passphrase for the private key.
                    old_passphrase=old_passphrase,  # (no passphrase)
                    # the path to the private key.
                    private_key=self.arguments.get("--private-key"),
                    # the path to the private key.
                    public_key=self.arguments.get("--public-key"),
                    # the path to the vpn key.
                    vpn_key=self.arguments.get("--vpn-key"),
                    # option 2:
                    # enable for smart cards.
                    smartcards=False,
                    # serial numbers of the smart cards.
                    serial_numbers=None,
                )
                # response is already printed inside for this function only.

        # start.
        elif self.arguments.present('--start'):

            # start the web server.
            self.__check_migrations__()
            port = int(
                self.arguments.get('--start', required=False, default=8001))
            os.system(
                f"cd {SOURCE_PATH}/ && ./manage.py runserver 127.0.0.1:{port}")

        # client.
        else:
            self.__check_migrations__()

            # get client.
            try:
                alias = sys.argv[1]
                if "@" in alias:
                    username, servername = alias.split("@")
                elif "." in alias:
                    username, servername = alias.split(".")
                else:
                    print(self.documentation)
                    print(
                        f"Invalid alias format [{alias}], required format: user@server."
                    )
                    quit()
                try:
                    server = manager.servers[servername]
                except KeyError:
                    print(
                        f"Specified server [{servername}] from alias [{alias}] does not exist."
                    )
                    quit()
                try:
                    client = server["clients"][username]
                except KeyError:
                    print(
                        f"Specified client [{username}] from alias [{alias}] does not exist."
                    )
                    quit()

            # invalid.
            except IndexError:
                print(self.documentation)
                print("Selected an invalid mode.")
                quit()

            # activate encryption & client key..
            self.__activate_encryption__()
            response = client.key.add_to_agent(load_passphrase=True)
            if not response.success:
                print("Error: " + response["error"])
                quit()

            # vnc.
            if self.arguments.present('--vnc'):
                response = client.vnc.create_connection()
                if response.success:
                    print(response['message'])
                    print(
                        f"Visit url: {syst3m.color.orange}{response['url']}{syst3m.color.end}"
                    )
                else:
                    print(f"Error: {response['error']}")

            # invalid.
            else:
                print(self.documentation)
                print("Selected an invalid mode.")
                quit()