Im writing a php application for a client and it would be very nice for him if I could have it create an email account for his domain via php instead of having to log into the vm control panel to do this as a 2nd step.
Is this possible and how would you do it?
To do that, you could call the command line API (via running the “virtualmin” program, or you could use the remote API as documented here:
That looks like it will work fine once I am able to access the remote api via http. I have gone into webmin and granted this user access to “Can accept RPC calls?” however I still receive an “ERROR: You are not allowed to run remote commands” error.
I was using this as en example:
$result = shell_exec(“wget -O - --quiet --http-user=root --http-passwd=pass --no-check-certificate ‘https://localhost:10000/virtual-server/remote.cgi?program=list-domains’”);
with the user and pass adjusted for this user.
I tried using wget directly from ssh as well. It works as root user but that won’t cut it.
Also is there an alternative URL for the command line api? None of the categories are working here: http://www.virtualmin.com/documentation/id,command_line_api/
This also worked fine using curl under php5. Again it works for root user but not domain user. Maybe it will help someone. I just need to get it working using the domain owner.
//init curl and set options
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://mydomain.com:10000/virtual-server/remote.cgi');
curl_setopt($ch, CURLOPT_USERPWD, 'root:rootpass');
//using self signed ssl cert, so dont verify
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT , 300);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POST, TRUE);
//set command to execute here
curl_setopt($ch, CURLOPT_POSTFIELDS, ‘program=list-domains’);
//execute curl request
$result = curl_exec($ch);
this code is working beautifully, thank you
i think it should be in the documentation rather than the shell_exec/wget method