golli53 Posted July 15, 2019 Share Posted July 15, 2019 (edited) 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, 2019 by golli53 solved/workaround Quote Link to comment
golli53 Posted July 30, 2019 Author Share Posted July 30, 2019 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. Quote Link to comment
testdasi Posted July 30, 2019 Share Posted July 30, 2019 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. Quote Link to comment
golli53 Posted July 30, 2019 Author Share Posted July 30, 2019 (edited) 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, 2019 by golli53 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.