Have a look at this page where someone already wrote some instructions on setting up WebDAV fully (I was going to do one myself, then found that so didn’t bother repeating it).
Basically you need to forward the WebDAV ports on your router to the MCM, and then from the wider internet access your home network via its public IP address. Depending on your ISP, this may be a static or a dynamic address, but if it’s dynamic you can make use of a service like No-IP.com or many others (just Google “free dynamic dns”) to give you a fixed URL which resolves to your router’s public IP address even if it changes.
For the scripting stuff it’s one that’s going to be quite specific to your set-up, so what you’re doing by trial and experiment is the best way to go.