1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
<?php
function parseUrl($url)
{
// parse the given URL
$url = parse_url($url);
if (!isset($url['port'])) {
if ($url['scheme'] == 'http') {
$url['port'] = 80;
}
elseif ($url['scheme'] == 'https') {
$url['port'] = 443;
}
}
if ($url['scheme'] == 'https')
$url['scheme'] = 'ssl';
elseif ($url['scheme'] == 'http')
$url['scheme'] = 'tcp';
$url['query'] = isset($url['query'])? $url['query']: '';
$url['protocol'] = $url['scheme'] . '://';
return $url;
}
function makeRequest($url, $headers) {
// parse the given URL
$content = "";
$fp = fsockopen($url['protocol'] . $url['host'], $url['port'], $errno, $errstr, 30);
if ($fp) {
if (fwrite($fp, $headers)) {
while (!feof($fp)) {
$result .= fgets($fp, 128);
}
fclose($fp);
// split the result header from the content
$result = explode("\r\n\r\n", $result, 2);
$header = isset($result[0]) ? $result[0] : '';
$content = isset($result[1]) ? $result[1] : '';
} else {
fclose($fp);
}
}
return $content;
}
function getRequest($url)
{
$url = parseUrl($url);
$eol = "\r\n";
$headers = "GET " . $url['path'] . "?" . $url['query'] . " HTTP/1.1" . $eol .
"Host: " . $url['host'].":".$url['port'] . $eol .
"Connection: close" . $eol . $eol;
return makeRequest ($url, $headers);
}
function apiURL()
{
$pageURL = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
$pageURL .= $_SERVER['SERVER_PORT'] <> '80' ? $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"] : $_SERVER['SERVER_NAME'];
return $pageURL.'/ods/api';
}
function httpURL()
{
$pageURL = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
$pageURL .= $_SERVER['SERVER_PORT'] <> '80' ? $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] : $_SERVER['SERVER_NAME'];
return $pageURL . '/ods/webid/webid_demo.php';
}
$_webid = isset ($_REQUEST['webid']) ? $_REQUEST['webid'] : '';
$_error = isset ($_REQUEST['error']) ? $_REQUEST['error'] : '';
$_action = isset ($_REQUEST['go']) ? $_REQUEST['go'] : '';
if (($_webid == '') && ($_error == ''))
{
if ($_action <> '')
{
$_url = getRequest (sprintf ("%s/getDefaultHttps", apiURL()));
$_url = sprintf ('https://%s/ods/webid_verify.vsp?callback=%s', $_url, urlencode(httpURL()));
$_expiration = isset ($_REQUEST['expiration']) ? $_REQUEST['expiration'] : '';
if ($_expiration == 'true')
$_url .= '&expiration=true';
header (sprintf ('Location: %s', $_url));
return;
}
}
?>
<html>
<head>
<title>WebID Verification Demo</title>
<style type="text/css">
body {
background-color: white;
color: black;
font-size: 10pt;
font-family: Verdana, Helvetica, sans-serif;
}
ul {
font-family: Verdana, Helvetica, sans-serif;
list-style-type: none;
}
#qrcode {
float: right;
clear: right;
margin-right: 20px;
}
</style>
</head>
<body>
<h1>WebID Verification Demo</h1>
<?php
$_QR = getRequest (sprintf ("%s/qrcode?data=%s", apiURL(), urlencode(httpURL())));
if ($_QR <> '')
{
?>
<div id="qrcode"><img alt="QRcode image" src="data:image/jpg;base64,<?php print ($_QR); ?>" /></div>
<?php
}
?>
<div>
This will check the WebID watermark in your X.509 Certificate.<br/><br/>
This service supports WebIDs based on the following URI schemes (more to come):
<ul>
<li>* <b>acct</b>, e.g: <span style="font-size: 80%; color: #1DA237;">acct:ExampleUser@id.example.com</span></li>
<li>* <b>http</b>, e.g: <span style="font-size: 80%; color: #1DA237;">http://id.example.com/person/ExampleUser#this</span></li>
<li>* <b>ldap</b>, e.g: <span style="font-size: 80%; color: #1DA237;">ldap://ldap.example.com/o=An%20Example%5C2C%20Inc.,c=US</span></li>
<li>* <b>mailto</b>, e.g: <span style="font-size: 80%; color: #1DA237;">mailto:ExampleUser@id.example.com</span></li>
</ul>
</div>
<div>
<a href="http://ods.openlinksw.com/wiki/ODS/ODSWebIDIdP">Help</a>
</div>
<br/>
<br/>
<div>
<form method="get">
<input type="checkbox" value="true" name="expiration" id="expiration" /> <label for="expiration">Check Certificate Expiration</label><br />
<input type="submit" name="go" value="Check"/>
</form>
</div>
<?php
if (($_webid <> '') || ($_error <> ''))
{
?>
<div>
The return values are:
<ul>
<?php
if ($_webid <> '')
{
$_proxyIri = getRequest (sprintf ("%s/iri2proxy?iri=%s", apiURL(), urlencode($_webid)));
?>
<li>WebID - <?php print (sprintf('<a href="%s">%s</a>', $_proxyIri, $_proxyIri)); ?></li>
<li>Timestamp in ISO 8601 format - <?php print ($_REQUEST['ts']); ?></li>
<?php
}
else if ($_error <> '')
{
?>
<li>Error - <?php print ($_error); ?></li>
<?php
}
?>
</ul>
</div>
<?php
}
?>
</body>
</html>
|