Add editable Samba global configuration with net conf setparm
Backend: - Use 'net conf setparm' to update individual parameters - Accept dictionary of key-value pairs in API Frontend: - Add Edit/Cancel/Save buttons to Samba Config tab - Inline editing of configuration values - Save changes back to registry Changes are applied immediately via net conf setparm. Co-Authored-By: Patrick <patrick@perlbach24.de>
This commit is contained in:
+13
-34
@@ -216,42 +216,21 @@ class SharesManager:
|
||||
logger.error(f"Error reading Samba registry config: {e}")
|
||||
return {"parameters": []}
|
||||
|
||||
def set_samba_global_config(self, config_text: str) -> bool:
|
||||
"""Write Samba global configuration section"""
|
||||
if not SAMBA_CONFIG.exists():
|
||||
return False
|
||||
|
||||
def set_samba_global_config(self, parameters: Dict[str, str]) -> bool:
|
||||
"""Update Samba global configuration parameters using 'net conf setparm'"""
|
||||
try:
|
||||
with open(SAMBA_CONFIG, 'r') as f:
|
||||
lines = f.readlines()
|
||||
for key, value in parameters.items():
|
||||
result = subprocess.run(
|
||||
['/usr/bin/net', 'conf', 'setparm', 'global', key, value],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10
|
||||
)
|
||||
if result.returncode != 0:
|
||||
logger.error(f"Failed to set {key}={value}: {result.stderr}")
|
||||
return False
|
||||
|
||||
# Find global section and shares
|
||||
output_lines = []
|
||||
skip_global = False
|
||||
for i, line in enumerate(lines):
|
||||
if line.strip().startswith('[global]'):
|
||||
skip_global = True
|
||||
output_lines.append('[global]\n')
|
||||
# Add config lines
|
||||
for config_line in config_text.split('\n'):
|
||||
if config_line.strip():
|
||||
output_lines.append(' ' + config_line + '\n')
|
||||
output_lines.append('\n')
|
||||
continue
|
||||
|
||||
if skip_global:
|
||||
if line.strip().startswith('['):
|
||||
skip_global = False
|
||||
output_lines.append(line)
|
||||
continue
|
||||
|
||||
output_lines.append(line)
|
||||
|
||||
with open(SAMBA_CONFIG, 'w') as f:
|
||||
f.writelines(output_lines)
|
||||
|
||||
subprocess.run(['smbcontrol', 'smbd', 'reload-config'], capture_output=True, timeout=10)
|
||||
logger.info("Samba global config updated")
|
||||
logger.info(f"Samba global config updated: {len(parameters)} parameters")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error writing Samba global config: {e}")
|
||||
|
||||
Reference in New Issue
Block a user