// Loading SAML library require_once '../openssophp/config/config.php'; require_once '../openssophp/lib/saml-lib.php'; // Needs a function to get the token from the php session require_once '../openssophp/spi/sessionhandling/' . $LIGHTBULB_CONFIG['spi-sessionhandling'] . '.php'; // Needs a function to get the token from the php session require_once '../openssophp/spi/namemapping/' . $LIGHTBULB_CONFIG['spi-namemapping'] . '.php'; // Load functions... require_once "example-lib.php"; // URL to return user to after authentication. Will be this page :D $return_url = selfURL(); // URL initiating SSO with lighbulb, contains some configuration parameters. $ssoinit_url = $LIGHTBULB_CONFIG['baseurl'] . "spSSOInit.php?" . "metaAlias=/sp&" . "RelayState=" . urlencode($return_url); // Logout URL. Also a openssophp service with some parameters and a return url. $logout_url = $LIGHTBULB_CONFIG['baseurl'] . "spSLOInit.php?" . "metaAlias=/sp&" . "RelayState=" . urlencode($return_url); $userid = $_POST["username"]; $password = $_POST["password"]; $username = authenticateLocalUser($userid, $password); if (is_null($username)) { echo "Error login, probably bad credentials. Sorry."; exit; } else { if (!is_null(spi_sessionhandling_getNameID())) { // The user is already authenticated to an IdP so we federate the accounts.. $nameId = getNameID(spi_sessionhandling_getResponse()); spi_namemapping_mapNameIdToLocalId($nameId["NameQualifier"], $nameId["SPNameQualifier"], spi_sessionhandling_getNameID(), $userid); } spi_sessionhandling_setUserId($userid); header("Location: " . urldecode($_POST["goto"])); exit; }
session_start(); // 记录下 HTTP 和 HTTPS 的实际访问端口(由于存在 NAT,所以可能与 Server 端的配置不同) if ($_SERVER['HTTPS']) { $_SESSION['https_port'] = $_SERVER['SERVER_PORT']; } else { $_SESSION['http_port'] = $_SERVER['SERVER_PORT']; } // 如果没有认证身份…… if (empty($_SESSION['wfs_user_id'])) { // 以下部分代码来自 /var/www/Admin/webapp/htdocs/secureCommon.inc ini_set('include_path', implode(':', array('.', $_SERVER["__ADMIN_API_ROOT"] . '/webapp/includes/', $_SERVER["__ADMIN_API_ROOT"] . '/webapp/classes/api/', ini_get('include_path')))); if (isset($_REQUEST['login_user'])) { $username = $_REQUEST['login_user']; $password = $_REQUEST['login_pass']; require_once "security.inc"; $_SESSION['wfs_user_id'] = authenticateLocalUser($username, $password); header('Location: ' . getThisUrl(false)); exit; } } if (isset($_REQUEST['logout'])) { session_destroy(); header('Location: ' . getThisUrl(true)); exit; } } // 当浏览器通过 mybooklive-deviceXXXXXX.wd2go.com 访问时,由于 wd2go.com 的中转 // 作用,PHP 程序实际收到的 SERVER_NAME/SERVER_ADDR 不一定跟浏览器地址栏中一致。 // 本函数确保取到跟浏览器地址栏中一致的 url。 function getThisUrl($secure) {