July 15, 20196 yr I am trying to turn on/off certain samba shares on a schedule using cron. What's the best command to pass? All I can think of is using sed to edit /etc/samba/smb-shares.conf, but this seems really complicated and would break the webgui options that were set. Is there a command that mimics what the webgui is doing when it turns on/off samba export or changes security options for a given share? Edited July 30, 20196 yr by golli53 solved/workaround
July 30, 20196 yr Author Couldn't figure this out using the shell, but ended up writing a short Python script to toggle options through HTTP to the webgui. CSRF tokens made it a bit trickier. Can send it out if anyone is also looking for a solution.
July 30, 20196 yr 1 hour ago, golli53 said: Couldn't figure this out using the shell, but ended up writing a short Python script to toggle options through HTTP to the webgui. CSRF tokens made it a bit trickier. Can send it out if anyone is also looking for a solution. So how did you do it? Would be very useful for me to be able to interact with the GUI but I don't know how to do it with Python.
July 30, 20196 yr Author 6 hours ago, testdasi said: So how did you do it? Would be very useful for me to be able to interact with the GUI but I don't know how to do it with Python. def toggle_unraid_share(url, setting=True, share_name='share'): from requests_html import HTMLSession session = HTMLSession() r = session.get(url) r.html.render() token = re.search(r"csrf_token=([A-Z0-9]+)", r.html.full_text).groups()[0] r2 = session.post(f"{url}/update.htm", data={'shareName': share_name, 'shareExport': 'e' if setting else '-', 'shareSecurity': 'public', 'changeShareSecurity': 'Apply', 'csrf_token': token}) r2.raise_for_status() session.close() Here's the script in function form. Requires Python 3 and requests_html. Should be fairly easy to generalize it to other settings changes (by changing the data argument in the sessions.post call). URL is your unraid address, incl http(s):// Edited July 30, 20196 yr by golli53
Archived
This topic is now archived and is closed to further replies.