I would like to create a website on my server, which runs Apache2, to allow a user to fill in a form containing a desired subdomain name to be created on the server. For example, a user could go to the site on the server at
example.com, fill out the form with a desired subdomain 'custom_subdomain', and on the server-side, a script will create the appropriate
Vhost file in
apache2/sites-available, a2ensite it, and restart the apache2 server.
This will effectively create
custom_subdomain.example.com on the server. What I'm unsure of is how to create a server-side script which can actually perform these actions since they require root level access (both to create a new vhost file and restart the server). I DO NOT want apache2 running as ROOT and lets assume I properly escape the user's desired subdomain entry so that it does not contain malicious code. Also my website will have some form of login security.
How can I go about writing such a script? My back-end will be written in (Django) Python or Node.js.
The reason I wish to create this interface is that I have some collaborators who should have the ability to create subdomains easily, but who should not have the ability to tinker with any apache configuration manually.