remote api auth php example

8 posts / 0 new
Last post
#1 Mon, 03/17/2008 - 04:15
mac2000

remote api auth php example

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.

Mon, 03/17/2008 - 20:45
mac2000

does anybody do not know issue?

to use remote http api i need to authorise - how can i do it from php?

Tue, 03/18/2008 - 10:12 (Reply to #2)
balzercomp

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.

Tue, 03/18/2008 - 11:39 (Reply to #3)
DanLong

but but but someone already registered foo and foobar.com hehehe ;-)

Tue, 03/18/2008 - 16:00 (Reply to #4)
mac2000

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

Sun, 06/07/2009 - 07:21 (Reply to #5)
chortle

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!

Mon, 03/17/2008 - 23:32
balzercomp

[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.

Tue, 03/18/2008 - 08:17
mac2000

:)

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...

Topic locked