diff --git a/README.org b/README.org index 7484556..97697bb 100644 --- a/README.org +++ b/README.org @@ -23,11 +23,11 @@ ├── alice │   ├── big_buck_bunny.mkv │   ├── elephants_dream.mkv - │   ├── rc.toml + │   ├── rc.conf │   └── the_daily_dweebs.mkv └── inbox ├── logo.svg - └── rc.toml + └── rc.conf #+end_example Then the following two routes exist: @@ -35,8 +35,8 @@ - =https://cloud.example.com/alice= - =https://cloud.example.com/inbox= - This is determined by the presence of a =rc.toml= file in subdirectories in which the individual permissions for the routes can be set. - The configuration options can be [[#rctoml][seen below]]. + This is determined by the presence of a =rc.conf= file in subdirectories in which the individual permissions for the routes can be set. + The configuration options can be [[#rcconf][seen below]]. All other routes, including =http://cloud.example.com=, return =404 Not Found=. This repository contains the above listed =public= directory for testing /raincloud/ locally. @@ -45,7 +45,7 @@ : $ pip install -r requirements.txt : $ ./run.py - Play around with the =rc.toml= files and create new directories to see how /raincloud/ behaves. + Play around with the =rc.conf= files and create new directories to see how /raincloud/ behaves. No restarting is needed. The password for the =alice= directory is =movie_night!=. @@ -100,20 +100,22 @@ Set them for example like this: : >>> app = raincloud.create_app(base_path='/home/alice/public', secret_key='super_secret', cloud_name='myCloud') -*** =rc.toml= +*** =rc.conf= :properties: - :custom_id: rctoml + :custom_id: rcconf :end: - A =rc.toml= file can contain up to three configuration parameters: + A =rc.conf= file can contain up to three configuration parameters: + + #+begin_src conf + [raincloud] - #+begin_src toml # Insert a password hash to enable password protection for this directory # Use one of the following commands to create a hash: # mkpasswd -m sha-256 # mkpasswd -m sha-512 # - #hashed_password = "" + #hashed_password = # Set this to 'true' to allow file downloads from this directory download = false diff --git a/flake.nix b/flake.nix index 144a53c..53a7cdb 100644 --- a/flake.nix +++ b/flake.nix @@ -16,7 +16,6 @@ flask = nixpkgs.legacyPackages.${system}.python3Packages.flask; gunicorn = nixpkgs.legacyPackages.${system}.python3Packages.gunicorn; raincloud = self.packages.${system}.raincloud; - toml = nixpkgs.legacyPackages.${system}.python3Packages.toml; cfg = config.services.raincloud; @@ -80,7 +79,7 @@ environment = let penv = python.buildEnv.override { - extraLibs = [ flask raincloud toml ]; + extraLibs = [ flask raincloud ]; }; in { @@ -131,7 +130,6 @@ src = self; propagatedBuildInputs = with pkgs; [ python3Packages.flask - python3Packages.toml ]; }; defaultPackage = self.packages.${system}.raincloud; @@ -142,7 +140,6 @@ python3 python3Packages.flask python3Packages.gunicorn - python3Packages.toml ]; }; } diff --git a/public/alice/rc.toml b/public/alice/rc.conf similarity index 77% rename from public/alice/rc.toml rename to public/alice/rc.conf index 98979f9..3f9476d 100644 --- a/public/alice/rc.toml +++ b/public/alice/rc.conf @@ -1,9 +1,11 @@ +[raincloud] + # Insert a password hash to enable password protection for this directory # Use one of the following commands to create a hash: # mkpasswd -m sha-256 # mkpasswd -m sha-512 # -hashed_password = "$5$s9bLebSgS9O4CPDR$xQF4/bWQqv5rqaq3Or2oTpXBW4TZdjFtBeH9CwZiw72" # movie_night! +hashed_password = $5$s9bLebSgS9O4CPDR$xQF4/bWQqv5rqaq3Or2oTpXBW4TZdjFtBeH9CwZiw72 # Set this to 'true' to allow file downloads from this directory download = true diff --git a/public/inbox/rc.toml b/public/inbox/rc.conf similarity index 91% rename from public/inbox/rc.toml rename to public/inbox/rc.conf index ea5fba6..ea7d7b1 100644 --- a/public/inbox/rc.toml +++ b/public/inbox/rc.conf @@ -1,9 +1,11 @@ +[raincloud] + # Insert a password hash to enable password protection for this directory # Use one of the following commands to create a hash: # mkpasswd -m sha-256 # mkpasswd -m sha-512 # -#hashed_password = "" +#hashed_password = # Set this to 'true' to allow file downloads from this directory download = false diff --git a/raincloud/directory_handler.py b/raincloud/directory_handler.py index ea23f11..266b95e 100644 --- a/raincloud/directory_handler.py +++ b/raincloud/directory_handler.py @@ -1,6 +1,6 @@ from datetime import datetime from pathlib import Path -import toml +import configparser class RaincloudIOException(Exception): @@ -16,31 +16,37 @@ class DirectoryHandler: ) def get_config(self, directory): - """Load a 'rc.toml' file from given directory. + """Load a 'rc.conf' file from given directory. Parameters: - directory - basepath of 'rc.toml' + directory - basepath of 'rc.conf' Returns: Dictionary of config parameters """ - path = self.base_path / directory / "rc.toml" + path = self.base_path / directory / "rc.conf" if path.exists(): config = {} config["directory"] = directory - parsed_config = toml.load(path) + config_parser = configparser.ConfigParser() + config_parser.read(path) + + parsed_config = dict(config_parser["raincloud"]) config["hashed_password"] = ( parsed_config["hashed_password"] if "hashed_password" in parsed_config else None ) - config["download"] = ( - parsed_config["download"] if "download" in parsed_config else False - ) - config["upload"] = ( - parsed_config["upload"] if "upload" in parsed_config else False - ) + config["download"] = False + if ( + "download" in parsed_config + and parsed_config["download"].lower() == "true" + ): + config["download"] = True + config["upload"] = False + if "upload" in parsed_config and parsed_config["upload"].lower() == "true": + config["upload"] = True return config else: @@ -52,7 +58,7 @@ class DirectoryHandler: file_paths = [f for f in path.glob("*") if f.is_file()] files = [] for p in file_paths: - if p.name != "rc.toml": + if p.name != "rc.conf": files.append(p.name) return files diff --git a/raincloud/raincloud.py b/raincloud/raincloud.py index 9b2bb35..66c4d6a 100755 --- a/raincloud/raincloud.py +++ b/raincloud/raincloud.py @@ -82,7 +82,7 @@ def create_app(base_path, secret_key, cloud_name="raincloud"): # Download else: - if config["download"] and filename != "rc.toml": + if config["download"] and filename != "rc.conf": return send_from_directory( dh.get_absolute_path(directory), filename ) @@ -94,7 +94,7 @@ def create_app(base_path, secret_key, cloud_name="raincloud"): if config["upload"]: f = request.files["file"] filename = secure_filename(f.filename) - if filename != "rc.toml": + if filename != "rc.conf": dh.save_to_directory(f, directory, filename) # Reload diff --git a/requirements.txt b/requirements.txt index f9ecb16..7e10602 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ flask -toml diff --git a/setup.py b/setup.py index b1ae010..73f62bc 100644 --- a/setup.py +++ b/setup.py @@ -6,5 +6,5 @@ setup( packages=find_packages(), include_package_data=True, zip_safe=False, - install_requires=["flask", "toml"], + install_requires=["flask"], )