%s | %s |
---|
' . $message . '
+ + +'; + error_log($html); + echo $html; + exit(0); +} + + +/** + * Return a key-value pair in plain text + * @global string $charset + * @param array $keys + */ +function wrap_kv ( $keys ) { + global $charset; + + debug($keys, 'Wrapped key/vals'); + header('Content-Type: text/plain; charset=' . $charset); + foreach ($keys as $key => $value) + printf("%s:%s\n", $key, $value); + + exit(0); +} + + +/** + * Redirect, with OpenID keys + * @param string $url + * @param array @keys + */ +function wrap_keyed_redirect ($url, $keys) { + $keys = append_openid($keys); + debug($keys, 'Location keys'); + + $q = strpos($url, '?') ? '&' : '?'; + wrap_redirect($url . $q . http_build_query($keys)); +} + + +/** + * Redirect the browser + * @global string $charset + * @param string $url + */ +function wrap_redirect ($url) { + header('HTTP/1.1 302 Found'); + header('Location: ' . $url); + debug('Location: ' . $url); + exit(0); +} + +/** + * Return an HTML refresh + * @global string $charset + * @param string $url + */ +function wrap_refresh ($url) { + global $charset; + + header('Content-Type: text/html; charset=' . $charset); + echo ' + + +Redirecting to ' . $url . '
+ + +'; + + debug('Refresh: ' . $url); + exit(0); +} + + +/** + * Implement binary x_or + * @param string $a + * @param string $b + * @return string + */ +function x_or ($a, $b) { + $r = ""; + + for ($i = 0; $i < strlen($b); $i++) + $r .= $a[$i] ^ $b[$i]; + debug("Xor size: " . strlen($r)); + return $r; +} + + + +/* + * App Initialization + */ +// Determine the charset to use +$GLOBALS['charset'] = 'iso-8859-1'; + +// Set the internal encoding +if (function_exists('mb_internal_encoding')) + mb_internal_encoding($charset); + +// Avoid problems with non-default arg_separator.output settings +// Credit for this goes to user 'prelog' on the forums +ini_set('arg_separator.output', '&'); + +// Do a check to be sure everything is set up correctly +self_check(); + + +/** + * Determine the HTTP request port + * @name $port + * @global integer $GLOBALS['port'] + */ +$GLOBALS['port'] = ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on' && $_SERVER['SERVER_PORT'] == 443) + || $_SERVER['SERVER_PORT'] == 80) + ? '' + : ':' . $_SERVER['SERVER_PORT']; + + +error_log($_SERVER['HTTP_HOST']); +/** + * Determine the HTTP request protocol + * @name $proto + * @global string $GLOBALS['proto'] + */ +$GLOBALS['proto'] = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') ? 'https' : 'http'; + +// Set the authorization state - DO NOT OVERRIDE +$profile['authorized'] = false; + +// Set a default IDP URL +if (! array_key_exists('idp_url', $profile)) + $profile['idp_url'] = sprintf("%s://%s%s%s", + $proto, + $_SERVER['SERVER_NAME'], + $port, + $_SERVER['PHP_SELF']); + +// Determine the requested URL - DO NOT OVERRIDE +$profile['req_url'] = sprintf("%s://%s%s", + $proto, + $_SERVER['HTTP_HOST'], +// $port,//host already includes the path + $_SERVER["REQUEST_URI"]); + +error_log($profile['req_url']); + +// Set the default allowance for testing +if (! array_key_exists('allow_test', $profile)) + $profile['allow_test'] = false; + +// Set the default allowance for gmp +if (! array_key_exists('allow_gmp', $profile)) + $profile['allow_gmp'] = false; + +// Set the default force bigmath - BAD IDEA to override this +if (! array_key_exists('force_bigmath', $profile)) + $profile['force_bigmath'] = false; + +// Determine if GMP is usable +$profile['use_gmp'] = (extension_loaded('gmp') && $profile['allow_gmp']) ? true : false; + +// Determine if I can perform big math functions +$profile['use_bigmath'] = (extension_loaded('bcmath') || $profile['use_gmp'] || $profile['force_bigmath']) ? true : false; + +// Set a default authentication domain +if (! array_key_exists('auth_domain', $profile)) + $profile['auth_domain'] = $profile['req_url'] . ' ' . $profile['idp_url']; + +// Set a default authentication realm +if (! array_key_exists('auth_realm', $profile)) + $profile['auth_realm'] = 'phpMyID'; + +// Determine the realm for digest authentication - DO NOT OVERRIDE +$profile['php_realm'] = $profile['auth_realm'] . (ini_get('safe_mode') ? '-' . getmyuid() : ''); + +// Set a default lifetime - the lesser of GC and cache time +if (! array_key_exists('lifetime', $profile)) { + $sce = session_cache_expire() * 60; + $gcm = ini_get('session.gc_maxlifetime'); + $profile['lifetime'] = $sce < $gcm ? $sce : $gcm; +} + +// Set a default log file +if (! array_key_exists('logfile', $profile)) + $profile['logfile'] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $profile['auth_realm'] . '.debug.log'; + + +/* + * Optional Initialization + */ +// Setup optional headers +$profile['opt_headers'] = array(); + +// Determine if I should add microid stuff +if (array_key_exists('microid', $profile)) { + $hash = sha1($profile['idp_url']); + $values = is_array($profile['microid']) ? $profile['microid'] : array($profile['microid']); + + foreach ($values as $microid) { + preg_match('/^([a-z]+)/i', $microid, $mtx); + $profile['opt_headers'][] = sprintf('', $mtx[1], $proto, sha1(sha1($microid) . $hash)); + } +} + +// Determine if I should add pavatar stuff +if (array_key_exists('pavatar', $profile)) + $profile['opt_headers'][] = sprintf('', $profile['pavatar']); + + +/* + * Do it + */ +// Decide which runmode, based on user request or default +$run_mode = (isset($_REQUEST['openid_mode']) + && in_array($_REQUEST['openid_mode'], $known['openid_modes'])) + ? $_REQUEST['openid_mode'] + : 'no'; + +// Run in the determined runmode +debug("Run mode: $run_mode at: " . time()); +debug($_REQUEST, 'Request params'); +call_user_func($run_mode . '_mode'); +?> diff --git a/apps/user_openid/settings.php b/apps/user_openid/settings.php new file mode 100644 index 0000000000..76316de100 --- /dev/null +++ b/apps/user_openid/settings.php @@ -0,0 +1,24 @@ +assign('identity',$identity); +$tmpl->assign('user',OC_USER::getUser()); + +$tmpl->printPage(); + +?> diff --git a/apps/user_openid/templates/settings.php b/apps/user_openid/templates/settings.php new file mode 100644 index 0000000000..7a1b530fbc --- /dev/null +++ b/apps/user_openid/templates/settings.php @@ -0,0 +1,7 @@ + diff --git a/apps/user_openid/user.php b/apps/user_openid/user.php new file mode 100644 index 0000000000..9ca1fd47c9 --- /dev/null +++ b/apps/user_openid/user.php @@ -0,0 +1,34 @@ +. +* +*/ + +$USERNAME=substr($_SERVER["REQUEST_URI"],strpos($_SERVER["REQUEST_URI"],'.php/')+5); +if(strpos($USERNAME,'?')){ + $USERNAME=substr($USERNAME,0,strpos($USERNAME,'?')); +} + +require_once '../../lib/base.php'; + +require_once 'phpmyid.php'; + + +?> \ No newline at end of file diff --git a/apps/user_openid/user_openid.php b/apps/user_openid/user_openid.php new file mode 100644 index 0000000000..d4bcefeb26 --- /dev/null +++ b/apps/user_openid/user_openid.php @@ -0,0 +1,73 @@ +. + * + */ + +require_once('User/backend.php'); +require_once('class.openid.v3.php'); + +/** + * Class for user management in a SQL Database (e.g. MySQL, SQLite) + */ +class OC_USER_OPENID extends OC_USER_BACKEND { + /** + * @brief Check if the password is correct + * @param $uid The username + * @param $password The password + * @returns true/false + * + * Check if the password is correct without logging in the user + */ + public function checkPassword( $uid, $password ){ + global $WEBROOT; + // Get identity from user and redirect browser to OpenID Server + $openid = new SimpleOpenID; + $openid->SetIdentity($uid); + $openid->SetTrustRoot('http://' . $_SERVER["HTTP_HOST"]); + if ($openid->GetOpenIDServer()){ + $openid->SetApprovedURL('http://' . $_SERVER["HTTP_HOST"] . $WEBROOT); // Send Response from OpenID server to this script + $openid->Redirect(); // This will redirect user to OpenID Server + exit; + }else{ + $error = $openid->GetError(); + echo "ERROR CODE: " . $error['code'] . "