From 04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 9 Jan 2020 10:55:03 +0100 Subject: phpmyadmin working --- srcs/phpmyadmin/examples/config.manyhosts.inc.php | 53 +++++++ srcs/phpmyadmin/examples/openid.php | 177 ++++++++++++++++++++++ srcs/phpmyadmin/examples/signon-script.php | 39 +++++ srcs/phpmyadmin/examples/signon.php | 76 ++++++++++ 4 files changed, 345 insertions(+) create mode 100644 srcs/phpmyadmin/examples/config.manyhosts.inc.php create mode 100644 srcs/phpmyadmin/examples/openid.php create mode 100644 srcs/phpmyadmin/examples/signon-script.php create mode 100644 srcs/phpmyadmin/examples/signon.php (limited to 'srcs/phpmyadmin/examples') diff --git a/srcs/phpmyadmin/examples/config.manyhosts.inc.php b/srcs/phpmyadmin/examples/config.manyhosts.inc.php new file mode 100644 index 0000000..b9ea893 --- /dev/null +++ b/srcs/phpmyadmin/examples/config.manyhosts.inc.php @@ -0,0 +1,53 @@ + [ + 'user' => 'root', + 'password' => '', + ], +]; + +/** + * Simple function to show HTML page with given content. + * + * @param string $contents Content to include in page + * + * @return void + */ +function Show_page($contents) +{ + header('Content-Type: text/html; charset=utf-8'); + echo '' , "\n"; + ?> + + + + + + + phpMyAdmin OpenID signon example + + + ' , $_SESSION['PMA_single_signon_message'] , '

'; + unset($_SESSION['PMA_single_signon_message']); + } + echo $contents; + ?> + + + \n"; + $contents .= "
" . htmlspecialchars($e->getMessage()) . "
\n"; + $contents .= ""; + Show_page($contents); + exit; +} + + +/* Need to have cookie visible from parent directory */ +session_set_cookie_params(0, '/', '', $secure_cookie, true); +/* Create signon session */ +$session_name = 'SignonSession'; +session_name($session_name); +@session_start(); + +// Determine realm and return_to +$base = 'http'; +if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { + $base .= 's'; +} +$base .= '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']; + +$realm = $base . '/'; +$returnTo = $base . dirname($_SERVER['PHP_SELF']); +if ($returnTo[strlen($returnTo) - 1] != '/') { + $returnTo .= '/'; +} +$returnTo .= 'openid.php'; + +/* Display form */ +if (! count($_GET) && ! count($_POST) || isset($_GET['phpMyAdmin'])) { + /* Show simple form */ + $content = '
+OpenID:
+ +
+ +'; + Show_page($content); + exit; +} + +/* Grab identifier */ +if (isset($_POST['identifier']) && is_string($_POST['identifier'])) { + $identifier = $_POST['identifier']; +} elseif (isset($_SESSION['identifier']) && is_string($_SESSION['identifier'])) { + $identifier = $_SESSION['identifier']; +} else { + $identifier = null; +} + +/* Create OpenID object */ +try { + $o = new OpenID_RelyingParty($returnTo, $realm, $identifier); +} catch (Exception $e) { + Die_error($e); +} + +/* Redirect to OpenID provider */ +if (isset($_POST['start'])) { + try { + $authRequest = $o->prepare(); + } catch (Exception $e) { + Die_error($e); + } + + $url = $authRequest->getAuthorizeURL(); + + header("Location: $url"); + exit; +} else { + /* Grab query string */ + if (! count($_POST)) { + list(, $queryString) = explode('?', $_SERVER['REQUEST_URI']); + } else { + // I hate php sometimes + $queryString = file_get_contents('php://input'); + } + + /* Check reply */ + try { + $message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP); + } catch (Exception $e) { + Die_error($e); + } + + $id = $message->get('openid.claimed_id'); + + if (! empty($id) && isset($AUTH_MAP[$id])) { + $_SESSION['PMA_single_signon_user'] = $AUTH_MAP[$id]['user']; + $_SESSION['PMA_single_signon_password'] = $AUTH_MAP[$id]['password']; + session_write_close(); + /* Redirect to phpMyAdmin (should use absolute URL here!) */ + header('Location: ../index.php'); + } else { + Show_page('

User not allowed!

'); + exit; + } +} diff --git a/srcs/phpmyadmin/examples/signon-script.php b/srcs/phpmyadmin/examples/signon-script.php new file mode 100644 index 0000000..175c7f7 --- /dev/null +++ b/srcs/phpmyadmin/examples/signon-script.php @@ -0,0 +1,39 @@ + 'Signon test']; + $id = session_id(); + /* Close that session */ + @session_write_close(); + /* Redirect to phpMyAdmin (should use absolute URL here!) */ + header('Location: ../index.php'); +} else { + /* Show simple form */ + header('Content-Type: text/html; charset=utf-8'); + echo '' , "\n"; + ?> + + + + + + + phpMyAdmin single signon example + + + '; + echo $_SESSION['PMA_single_signon_error_message']; + echo '

'; + } + ?> +
+ Username:
+ Password:
+ Host: (will use the one from config.inc.php by default) +
+ Port: (will use the one from config.inc.php by default) +
+ +
+ + + -- cgit