These forums are locked and archived, but all topics have been migrated to the new forum. You can search for this topic on the new forum: Search for remote api auth php example on the new forum.
Please can anybody show me an example of authentification by using php to get access to remote api of webmin.
I try to use example from documentation [code:1]wget --http-user=root --http-passwd=smeg 'https://yourserver:10000/server-manager/remote.cgi?program=list-systems'[/code:1] but it doesnot works, wget retrives welcome page with login form.
does anybody do not know issue?
to use remote http api i need to authorise - how can i do it from php?
I don't expect anyone to post private information, but I've seen so many post in forums like this where people simply try the template call, wondering why it doesn't work.
but but but someone already registered foo and foobar.com hehehe ;-)
as i think if i interested in remote api i understand some stufs, but this is all not the reason...
how i can use remote api from php?
regards for cooments, mac
Using cURL, it would look something like this:
$c = curl_init(); //initialize the curl object
curl_setopt($c,CURLOPT_URL,$url); //set the URL
curl_setopt($c,CURLOPT_RETURNTRANSFER,true); //we want HTTP headers returned
curl_setopt($c, CURLOPT_TIMEOUT, 30); //set the connection timeout to 30 seconds
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0); //turn off SSL verifications
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0); //turn off SSL verifications
curl_setopt($c, CURLINFO_HEADER_OUT, true); //allows printing of headers
//if a username was passed in, setup basic authorization
if($username){
$credentials = "$username:$password";
curl_setopt($c,CURLOPT_USERPWD,$credentials);
}
$results=curl_exec($c);
Enjoy!
[code:1] wget --http-user=root --http-passwd=smeg 'https://yourserver:10000/server-manager/remote.cgi?program=list-systems'
[/code:1]
"yourserver" must be replaced by either the IP or the url of your server. Otherwise it cannot work since yourserver is not a valid url. If you're calling the api from the same machine as webmin, replacing "yourserver" with "localhost" or "127.0.0.1" might work, but I would strongly recommend to use the real url or IP.
:)
are you realy think i paste the original copy of url to this post with server ip, login and password?
the problem is that wget parameters http-user and http-password does not work...
url works fine and there is no problem with this....
also if i loged in virtualmin (my browser has session cookies) and call remote.cgi with parameters - it works fine... but if i log out from virtualmin - response from server is login webpage...