mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-22 07:30:25 +00:00
74 lines
2.3 KiB
Text
74 lines
2.3 KiB
Text
<?php
|
|
|
|
/* Need to have cookie visible from parent directory */
|
|
session_set_cookie_params(0, '/', '', true, true);
|
|
/* Create signon session */
|
|
$session_name = 'SignonSession';
|
|
session_name($session_name);
|
|
// Uncomment and change the following line to match your $cfg['SessionSavePath']
|
|
// session_save_path('');
|
|
@session_start();
|
|
|
|
|
|
function validate_token($token, $panel_url = false) {
|
|
|
|
// Current server ip
|
|
$server_ip = $_SERVER['SERVER_ADDR'];
|
|
|
|
$sso_server = "https://".$server_ip.":8443/";
|
|
if ($panel_url) {
|
|
$sso_server = $panel_url . "/";
|
|
}
|
|
$sso_server_endpoint = $sso_server . "api/customer/phpMyAdmin/validate-token?token=" . $token;
|
|
|
|
// Curl get request
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $sso_server_endpoint);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
// ssl verification off
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
|
$output = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
$output = json_decode($output, true);
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
/* Was data posted? */
|
|
if (isset($_GET['token'])) {
|
|
|
|
$token = (isset($_GET['token']) ? $_GET['token'] : '');
|
|
$panel_url = (isset($_GET['panel_url']) ? $_GET['panel_url'] : '');
|
|
|
|
// Request credentials from remote server
|
|
$response = validate_token($token, $panel_url);
|
|
|
|
if (!isset($response['success'])) {
|
|
$_SESSION['PMA_single_signon_error_message'] = 'Token invalid';
|
|
header('Location: phyre-sso.php');
|
|
exit;
|
|
}
|
|
|
|
/* Store there credentials */
|
|
$_SESSION['PMA_single_signon_host'] = $response['databaseLoginDetails']['host'];
|
|
$_SESSION['PMA_single_signon_user'] = $response['databaseLoginDetails']['username'];
|
|
$_SESSION['PMA_single_signon_password'] = $response['databaseLoginDetails']['password'];
|
|
/* Update another field of server configuration */
|
|
$_SESSION['PMA_single_signon_cfgupdate'] = array('verbose' => 'PhyrePanel');
|
|
$id = session_id();
|
|
/* Close that session */
|
|
@session_write_close();
|
|
|
|
setcookie($session_name, $id , 0, "/");
|
|
|
|
/* Redirect to phpMyAdmin (should use absolute URL here!) */
|
|
header('Location: ../index.php');
|
|
|
|
} else {
|
|
header('Location: ../index.php');
|
|
}
|
|
?>
|