* @copyright 2005-2008 Janrain, Inc.
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache
*/
$path_extra = dirname(dirname(dirname(__FILE__)));
$path = ini_get('include_path');
$path = $path_extra . PATH_SEPARATOR . $path;
ini_set('include_path', $path);
require_once "Auth/OpenID.php";
/**
* Data.
*/
$store_types = array("Filesystem" => "Auth_OpenID_FileStore",
"MySQL" => "Auth_OpenID_MySQLStore",
"PostgreSQL" => "Auth_OpenID_PostgreSQLStore",
"SQLite" => "Auth_OpenID_SQLiteStore");
/**
* Main.
*/
$messages = array();
session_start();
init_session();
if (!check_session() ||
isset($_GET['add_openid'])) {
render_form();
} else {
print generate_config(isset($_GET['download']));
}
/**
* Functions.
*/
function check_url($url) {
return (Auth_OpenID::normalizeUrl($url) !== null);
}
function build_url() {
$port = (($_SERVER['SERVER_PORT'] == 80) ? null : $_SERVER['SERVER_PORT']);
$parts = explode("/", $_SERVER['SERVER_PROTOCOL']);
$scheme = strtolower($parts[0]);
if ($port) {
return sprintf("%s://%s:%s%s/server.php", $scheme, $_SERVER['SERVER_NAME'],
$port, dirname($_SERVER['PHP_SELF']));
} else {
return sprintf("%s://%s%s/server.php", $scheme, $_SERVER['SERVER_NAME'],
dirname($_SERVER['PHP_SELF']));
}
}
function check_open_basedir($path) {
if (ini_get('open_basedir')) {
$parts = explode(PATH_SEPARATOR, ini_get('open_basedir'));
$found = false;
foreach ($parts as $p) {
if (strpos($path, $p) === 0) {
$found = true;
break;
}
}
return $found;
} else {
return true;
}
}
function check_session() {
global $messages;
if ($_GET && isset($_GET['clear'])) {
session_destroy();
$_SESSION = array();
init_session();
return false;
}
$bad_path = false;
if (isset($_GET['generate'])) {
if (!$_SESSION['server_url']) {
$messages[] = "Please enter a server URL.";
}
if (!isset($_SESSION['store_type'])) {
$messages[] = "No store type chosen.";
} else {
switch ($_SESSION['store_type']) {
case "Filesystem":
if (!@$_SESSION['store_data']['fs_path']) {
$messages[] = "Please specify a filesystem store path.";
} else {
if (!check_open_basedir($_SESSION['store_data']['fs_path'])) {
$messages[] = "The filesystem store path violates PHP's open_basedir
setting.";
$bad_path = true;
}
}
break;
case "SQLite":
if (!@$_SESSION['store_data']['sqlite_path']) {
$messages[] = "Please specify a SQLite database path.";
} else {
if (!check_open_basedir($_SESSION['store_data']['sqlite_path'])) {
$messages[] = "The SQLite store path violates PHP's open_basedir
setting.";
$bad_path = true;
}
}
break;
default:
if (!($_SESSION['store_data']['host'] &&
$_SESSION['store_data']['database'] &&
$_SESSION['store_data']['username'] &&
$_SESSION['store_data']['password'])) {
$messages[] = "Please specify database connection details.";
}
}
}
}
if ($_SESSION['store_type'] &&
$_SESSION['server_url'] &&
(parse_url($_SESSION['server_url']) !== false) &&
((($_SESSION['store_type'] == 'Filesystem') &&
$_SESSION['store_data']['fs_path']) ||
(($_SESSION['store_type'] == 'SQLite') &&
$_SESSION['store_data']['sqlite_path']) ||
($_SESSION['store_data']['host'] &&
$_SESSION['store_data']['username'] &&
$_SESSION['store_data']['database'] &&
$_SESSION['store_data']['password'])) &&
!$bad_path) {
return true;
}
return false;
}
function render_form() {
global $store_types, $fields, $messages;
$basedir_msg = "";
if (ini_get('open_basedir')) {
$basedir_msg = "Note: Due to the ".
"open_basedir
php.ini setting, be sure to ".
"choose a path in one of the following directories:
";
}
$sqlite_found = false;
if (extension_loaded('sqlite') ||
(function_exists('dl') && @dl('sqlite.' . PHP_SHLIB_SUFFIX))) {
$sqlite_found = true;
}
$mysql_found = false;
if (extension_loaded('mysql') ||
(function_exists('dl') && @dl('mysql.' . PHP_SHLIB_SUFFIX))) {
$mysql_found = true;
}
$pgsql_found = false;
if (extension_loaded('pgsql') ||
(function_exists('dl') && @dl('pgsql.' . PHP_SHLIB_SUFFIX))) {
$pgsql_found = true;
}
?>
Your browser has been redirected to this page so you can configure the server example. This form will auto-generate an OpenID example server configuration for use with the OpenID server example.
Put the following text into config.php.
Back to form (resets settings)
/** * Set any extra include paths needed to use the library */ set_include_path(get_include_path() . PATH_SEPARATOR . ""); /** * The URL for the server. * * This is the location of server.php. For example: * * $server_url = 'http://example.com/~user/server.php'; * * This must be a full URL. */ $server_url = ""; /** * Initialize an OpenID store * * @return object $store an instance of OpenID store (see the * documentation for how to create one) */ function getOpenIDStore() { createTables();\n "; print "return \$s;\n"; break; case "MySQL": ?>require_once 'Auth/OpenID/MySQLStore.php'; require_once 'DB.php'; $dsn = array( 'phptype' => 'mysql', 'username' => '', 'password' => '', 'hostspec' => '' ); $db = DB::connect($dsn); if (PEAR::isError($db)) { return null; } $db->query("USE "); $s = new Auth_OpenID_MySQLStore($db); $s->createTables(); return $s; require_once 'Auth/OpenID/PostgreSQLStore.php'; require_once 'DB.php'; $dsn = array( 'phptype' => 'pgsql', 'username' => '', 'password' => '', 'hostspec' => '', 'database' => '' ); $db = DB::connect($dsn); if (PEAR::isError($db)) { return null; } $s = new Auth_OpenID_PostgreSQLStore($db); $s->createTables(); return $s; } "; if (!$download) { ?>