Created
October 18, 2017 14:50
-
-
Save heavygale/ea95e9636904a4d7cb3cba7949e7916a to your computer and use it in GitHub Desktop.
PHP example on how to use https://github.com/snowblindroan/mod_admin_rest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// replace everything that's written in uppercase with your own values | |
// USERNAME@DOMAIN.TLD needs to be a user who has administrative privileges | |
function jabber_add_user($username, $password) | |
{ | |
$data = json_encode(array('password' => $password)); | |
curl_setopt_array( | |
$ch = curl_init(), | |
array( | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_URL => 'http://localhost:5280/admin_rest/user/'.$username, | |
CURLOPT_USERPWD => 'USERNAME@DOMAIN.TLD:PASSWORD', | |
CURLOPT_POST => true, | |
CURLOPT_POSTFIELDS => $data, | |
CURLOPT_HTTPHEADER => array('Host: DOMAIN.TLD', 'Content-Type: application/json', 'Content-Length: '.strlen($data)) | |
) | |
); | |
curl_exec($ch); | |
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
return $code; | |
} | |
jabber_add_user('NEW_USER', 'PASSWORD'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment