Automatic user and domain creation in Virtualmin

I`m trying to offer free hosting with Virtualmin and i want to create a PHP script that will create a new top level domain / administration username .
The only way i can do it is by using shell_exec() and this URL:
https://192.168.1.101:10000/virtual-server/domain_setup.cgi?dom=googlee.ro&owner=creat_automat_prin_link&vpass=daniel20&template=0&plan=13363914562904&vuser_def=1&email=anturaju_daniel@yahoo.com&mgroup_def=1&prefix_def=1&db_def=1&dns=1&web=1&mysql=1&virtualmin-awstats=1&mail=1&webalizer=1&webmin=1&fwdto_def=1&virt=0&virt6=0&dns_ip_def=1/

but it gives me one big problem, the administration username is not created. The administration username is vuser_def=1 (automatic) in the above URL, but still i get this error:
Failed to create virtual server : Mail for the domain cannot be enabled unless an administration user is created

How can i fix this, or can you guide my to a bether way to create new domains/users by user imput with PHP?
Thanks.

Hi,

You should make use of the “remote” or “cli” API.

To create a domain via the “remote” API, make a call to:

https://192.168.1.101:10000/virtual-server/remote.cgi?program=create-domain&domain=yourdomain.com&user=username&pass=password&json=1

*** above is a minimal example which will output to your script a JSON response ***

For more information visit the following pages.

Virtualmin CLI API:

http://www.virtualmin.com/documentation/developer/cli

Virtualmin Remote API

http://www.virtualmin.com/documentation/developer/http

Best Regards, Peter Knowles TPN Solutions

E: pknowles@tpnsolutions.com
P: 604-782-9342
W: http://www.tpnsolutions.com

Thanks for the replay.
I want to create a HTML form where the user will input only the desired domain name, domain description and password. A php script will collect this info and will use Virtualmin CLI or PHP API to execute the command to create a new user with a toplevel domain, but how can i do this with Virtualim CLI? How to execute the CLI command from a PHP script that collects the data from my HTML form ?

Hi,

You’d use the above “remote.cgi” script on the backend of your script… For instance when the person clicks “submit” on your form, after going through whatever form validation you have setup, you’d eventually issue something like:

exec(‘https://192.168.1.101:10000/virtual-server/remote.cgi?program=create-domain&domain=yourdomain.com&user=username&pass=password&json=1’);

*** the above uses the “exec” command from PHP as an example ***

If you require a more complex method of accomplishing this task, I am available at a rate of $40.00/hr. to offer web development.

As noted above, you should refer to the CLI/Remote API documentation for all the available options which can be passed to the API.

Best Regards, Peter Knowles TPN Solutions

E: pknowles@tpnsolutions.com
P: 604-782-9342
W: http://www.tpnsolutions.com

Okay, how much do i have to pay for this:
A HTML form where the user inserts only domain name, password and contact email
A php script that collects the data from the form and executes the Virtualmin Remote API and creates a new toplevel domain for that user, like $domain = $_POST[“domain”]; $pass = $_POST[“pass”]; $contact_email = $_POST[“c_email”];
I dont want the user to specify a username, i want Virtualmin to automatically create a administration username from the domain name, like if domain is = abcdownload.ro , administration username will be abcdownload
Can you do this for me ?

Hi,

Drop me an email, and we can work out a reasonable deal, don’t worry I don’t bite :slight_smile:

Best Regards, Peter Knowles TPN Solutions

E: pknowles@tpnsolutions.com
P: 604-782-9342
W: http://www.tpnsolutions.com

I have a problem with --web parameter, witch is if the --web parameter is present in the LINK structure, Virtualmin will not create the Administration username and domain creation will fail with Exit status: 256 : A website cannot be enabled without an administration user , LINK user was: 192.168.1.101:10000/virtual-server/remote.cgi?program=create-domain&domain=roedu.ro&pass=daniel20&email=anturaju_daniel@yahoo.com&web&dns&logrotate&mysql&webmin - notice that the web parameter was included in the link.
If i use the same LINK but without the --web parameter, Virtualmin will create the Administration username, domain, webmin login, dns and other settings, but the domain is not active on the Virtualmin server because the --web parameter is not present in the LINK -> 192.168.1.101:10000/virtual-server/remote.cgi?program=create-domain&domain=roedu.ro&pass=daniel20&email=anturaju_daniel@yahoo.com&dns&logrotate&mysql&webmin
Is this a bug, or i`m doing something wrong.

I finally figured out what was wrong:
from my URL was missing this parameters: --unix (for creating the user) and --dir (for home dire creation)
It work great now :slight_smile:

Please show an example of your complete cgi code. I am also having the same problem as you but I cannot follow your solution

This is my working code:
See the file hosting.txt, you can upload it to your server and give it a try. Change the root password and the virtualmin server hostname and port., and rename the file to hosting.php .

Hello,

Im curious about this as well, as i am planning on rolling out free web hosting as well. I am not seeing the text file mentioned? would be cool to take a gander and see if I could implement this onto my server.

Thanks,
TIm Salas