|
3 | 3 |
|
4 | 4 | ################### |
5 | 5 | # This tool runs CLI scripts and displays output in a Web Interface. |
6 | | -# Copyright (C) 2021, 2022, 2023 Maurice Lambert |
| 6 | +# Copyright (C) 2021, 2022, 2023, 2024 Maurice Lambert |
7 | 7 |
|
8 | 8 | # This program is free software: you can redistribute it and/or modify |
9 | 9 | # it under the terms of the GNU General Public License as published by |
|
25 | 25 | This file hardens the WebScripts installation and configuration. |
26 | 26 | """ |
27 | 27 |
|
28 | | -__version__ = "0.0.8" |
| 28 | +__version__ = "0.0.9" |
29 | 29 | __author__ = "Maurice Lambert" |
30 | 30 | __author_email__ = "[email protected]" |
31 | 31 | __maintainer__ = "Maurice Lambert" |
|
39 | 39 | __url__ = "https://github.com/mauricelambert/WebScripts" |
40 | 40 |
|
41 | 41 | copyright = """ |
42 | | -WebScripts Copyright (C) 2021, 2022, 2023 Maurice Lambert |
| 42 | +WebScripts Copyright (C) 2021, 2022, 2023, 2024 Maurice Lambert |
43 | 43 | This program comes with ABSOLUTELY NO WARRANTY. |
44 | 44 | This is free software, and you are welcome to redistribute it |
45 | 45 | under certain conditions. |
|
71 | 71 | abspath, |
72 | 72 | basename, |
73 | 73 | exists, |
| 74 | + normpath, |
74 | 75 | ) |
75 | 76 | from importlib.util import spec_from_loader, module_from_spec |
76 | 77 | from logging import FileHandler, Formatter, getLogger, Logger |
@@ -207,6 +208,7 @@ def __init__( |
207 | 208 | directory: str = None, |
208 | 209 | ): |
209 | 210 | self.admin_password = admin_password |
| 211 | + self.documentation_paths = [] |
210 | 212 | self.json_only = json_only |
211 | 213 | self.owner = owner or getuser() |
212 | 214 | self.directory = directory or getcwd() |
@@ -293,7 +295,11 @@ def harden_server(self, section: dict, directory: str) -> None: |
293 | 295 | if self.is_windows: |
294 | 296 | path_.insert(1, "..") |
295 | 297 |
|
296 | | - section["modules_path"] = abspath(join(*path_, "modules")) |
| 298 | + self.documentation_paths = section["documentations_path"] = [ |
| 299 | + normpath(abspath(join(self.directory, x))) |
| 300 | + for x in section["documentations_path"] |
| 301 | + ] |
| 302 | + section["modules_path"] = [normpath(abspath(join(*path_, "modules")))] |
297 | 303 | section["data_dir"] = abspath(join(self.directory, "data")) |
298 | 304 | section["json_scripts_config"] = self.get_files_from_glob_path( |
299 | 305 | path_, section["json_scripts_config"] |
@@ -369,6 +375,12 @@ def linux_hardening_file_permissions(self) -> None: |
369 | 375 | chmod(logs, 0o700) # nosec |
370 | 376 | chown(logs, pw_uid, pw_gid) |
371 | 377 |
|
| 378 | + for documentation_path in self.documentation_paths: |
| 379 | + documentation_directory = dirname(documentation_path) |
| 380 | + makedirs(documentation_directory, exist_ok=True) |
| 381 | + chmod(documentation_directory, 0o700) # nosec |
| 382 | + chown(documentation_directory, pw_uid, pw_gid) |
| 383 | + |
372 | 384 | def linux_file_permissions(self, filename: str) -> None: |
373 | 385 | """ |
374 | 386 | This method changes files permissions on Linux. |
|
0 commit comments