Hello,
Using the UAPI as instructed here: https://api.docs.cpanel.net/openapi/cpanel/operation/create_webmail_session_for_mail_user/
But experiencing a weird problem: after successful post request I am being redirected to:
instead of:
---
an ideal case would be to redirect to $hostname for example: but even would be okay for a start.
Did anyone else play with this UAPI webmail authentification, is there a way to redirect users to the correct url?
Appreciate any feedback!
Using the UAPI as instructed here: https://api.docs.cpanel.net/openapi/cpanel/operation/create_webmail_session_for_mail_user/
But experiencing a weird problem: after successful post request I am being redirected to:
instead of:
---
Code:
$ip_address = $_SERVER['REMOTE_ADDR'];
list($email, $login_domain) = explode('@', $_POST['login_email']);
$createSessionUrl = "https://$hostname:2083/cpsess1235467/execute/Session/create_webmail_session_for_mail_user?login=" . urlencode($email) . "&domain=" . urlencode($domain) . "&remote_address=" . $ip_address;
// echo $createSessionUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $createSessionUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic ' . base64_encode(get_option('cpanel_username') . ':' . get_option('cpanel_password'))
));
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
$session = $data['data']['session'];
$token = $data['data']['token'];
$postUrl = "https://$hostname:2096" . $token."/login";
$postData = "session=" . urlencode($session);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// echo "POST URL: $postUrl<br>";
// echo "POST Data: $postData<br>";
$response = curl_exec($ch);
curl_close($ch);
echo $response;
}
an ideal case would be to redirect to $hostname for example: but even would be okay for a start.
Did anyone else play with this UAPI webmail authentification, is there a way to redirect users to the correct url?
Appreciate any feedback!
Last edited by a moderator: