Extract _ensure_conf_dir(); call it from both _save_credentials and _write_webdav_conf
Guarantees /etc/micronas is created with 750 root:www-data on any code path that writes config — first-time setup OR first WebDAV share. Fixes fresh-install permission issue without manual chmod. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
7ec926ddf7
commit
1ef4f6f743
1 file changed
+8
-2
@@ -49,8 +49,7 @@ def _verify_password(password):
|
||||
|
||||
def _save_credentials(user, password):
|
||||
h = _hash_password(password)
|
||||
os.makedirs(_CONF_DIR, mode=0o750, exist_ok=True)
|
||||
subprocess.run(['chown', 'root:www-data', _CONF_DIR], capture_output=True)
|
||||
_ensure_conf_dir()
|
||||
Path(_ENV_FILE).write_text(f'MICRONAS_USER={user}\nMICRONAS_PASS_HASH={h}\n')
|
||||
os.chmod(_ENV_FILE, 0o600)
|
||||
_creds['user'] = user
|
||||
@@ -321,7 +320,14 @@ def _parse_webdav_conf():
|
||||
return shares
|
||||
|
||||
|
||||
def _ensure_conf_dir():
|
||||
"""Create /etc/micronas with correct ownership so Apache can traverse it."""
|
||||
os.makedirs(_CONF_DIR, mode=0o750, exist_ok=True)
|
||||
subprocess.run(['chown', 'root:www-data', _CONF_DIR], capture_output=True)
|
||||
|
||||
|
||||
def _write_webdav_conf(shares):
|
||||
_ensure_conf_dir()
|
||||
os.makedirs('/var/lib/apache2/webdav', exist_ok=True)
|
||||
lines = ['# Managed by MicroNAS — do not edit manually\n\n',
|
||||
'DavLockDB /var/lib/apache2/webdav/DavLock\n\n']
|
||||
|
||||
Reference in new issue
Block a user