Adds beginning of status code handling, better status code reporting
This commit is contained in:
parent
db57919ade
commit
7f6c4a6d77
@ -84,9 +84,17 @@ class Follow
|
|||||||
{
|
{
|
||||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
$this->code = ($code) ? $code : 0;
|
$this->code = ($code) ? $code : 0;
|
||||||
if ($code == 200) {
|
|
||||||
$this->updatePath($this->step, 'code', $this->code);
|
// handle certain codes specifically
|
||||||
return true;
|
switch ($code)
|
||||||
|
{
|
||||||
|
case 200:
|
||||||
|
$this->updatePath($this->step, 'code', $this->code);
|
||||||
|
return true;
|
||||||
|
case 404:
|
||||||
|
$this->updatePath($this->step, 'code', $this->code);
|
||||||
|
$this->setError(['type' => 'code', 'message' => 'URL returned a 404 error response.']);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -24,6 +24,7 @@ if (isset($_POST['url']))
|
|||||||
// end on an error
|
// end on an error
|
||||||
if ($request->error)
|
if ($request->error)
|
||||||
{
|
{
|
||||||
|
$error = $request->error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ if (isset($_POST['url']))
|
|||||||
// update our code
|
// update our code
|
||||||
$code = ($request->code) ? $request->code : false;
|
$code = ($request->code) ? $request->code : false;
|
||||||
|
|
||||||
} while ($code != 200);
|
} while (substr($code, 0, 1) != 2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -116,6 +116,16 @@ button[type="submit"]:hover {
|
|||||||
background-color: #f0eded;
|
background-color: #f0eded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
address {
|
||||||
|
display: flex;
|
||||||
|
align-self: stretch;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-style: normal;
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
background: #ffdee3;
|
||||||
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
align-self: stretch;
|
align-self: stretch;
|
||||||
@ -252,13 +262,21 @@ td {
|
|||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
word-wrap: anywhere;
|
word-wrap: anywhere;
|
||||||
}
|
}
|
||||||
|
td:first-child {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
td:nth-child(2) {
|
td:nth-child(2) {
|
||||||
line-height: 1.5rem;
|
line-height: 1.5rem;
|
||||||
padding: 0.8rem 1rem;
|
padding: 0.8rem 1rem;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
td:nth-child(2) a:hover {
|
td:nth-child(2) a:hover {
|
||||||
text-decoration-color: transparent;
|
text-decoration-color: transparent;
|
||||||
}
|
}
|
||||||
|
td:nth-child(4) {
|
||||||
|
text-align: center;
|
||||||
|
padding-right: 1.5rem;
|
||||||
|
}
|
||||||
td b {
|
td b {
|
||||||
border: 1px solid #aaa;
|
border: 1px solid #aaa;
|
||||||
border-right-width: 2px;
|
border-right-width: 2px;
|
||||||
@ -271,10 +289,17 @@ td b {
|
|||||||
padding: 0 0.25rem;
|
padding: 0 0.25rem;
|
||||||
transition: border-color 150ms ease-in-out, color 150ms ease-in-out;
|
transition: border-color 150ms ease-in-out, color 150ms ease-in-out;
|
||||||
}
|
}
|
||||||
|
td b i {
|
||||||
|
display: inline-block;
|
||||||
|
transition: transform 150ms ease-in-out;
|
||||||
|
}
|
||||||
td:nth-child(2) a:hover b {
|
td:nth-child(2) a:hover b {
|
||||||
border-color: #1a1a1a;
|
border-color: #1a1a1a;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
}
|
}
|
||||||
|
td:nth-child(2) a:hover b i {
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
tbody tr:nth-child(odd) td {
|
tbody tr:nth-child(odd) td {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
}
|
}
|
||||||
|
160
index.php
160
index.php
@ -19,126 +19,130 @@ include('inc/codes.php');
|
|||||||
</nav>
|
</nav>
|
||||||
</menu>
|
</menu>
|
||||||
<form method="post" action="/" type="application/x-www-form-urlencoded">
|
<form method="post" action="/" type="application/x-www-form-urlencoded">
|
||||||
<input type="url" value="" placeholder="URL to check..." name="url">
|
<input type="url" value="<?php echo $url; ?>" placeholder="URL to check..." name="url">
|
||||||
<button type="submit">Check</button>
|
<button type="submit">Check</button>
|
||||||
</form>
|
</form>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// error message display
|
// error message display
|
||||||
if (isset($error))
|
if (isset($error))
|
||||||
{
|
{
|
||||||
|
echo "
|
||||||
|
<address>
|
||||||
|
".$error['message']."
|
||||||
|
</address>";
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<?php
|
||||||
// if we have a valid request object
|
// if we have a valid request object
|
||||||
if (isset($request) && count($request->path) > 0)
|
if (isset($request) && count($request->path) > 0)
|
||||||
{
|
{
|
||||||
$steps = count($request->path) - 1;
|
$steps = count($request->path) - 1;
|
||||||
$count = ($steps == 1) ? '1 redirect' : $steps.' redirects';
|
$count = ($steps == 1) ? 'once' : $steps.' times';
|
||||||
echo "
|
echo "
|
||||||
<article>
|
<article>
|
||||||
<h2>Final destination</h2>
|
<h2>Final destination</h2>
|
||||||
<p>The URL you traced had ".$count." and ended here:</p>
|
<p>Your URL returned a <code><strong>".$request->code."</strong></code> status code and redirected ".$count.":</p>
|
||||||
<p class=\"final\">
|
<p class=\"final\">
|
||||||
<a href=\"".$request->getFinalRedirect()."\" target=\"blank\">
|
<a href=\"".$request->getFinalRedirect()."\" target=\"blank\">
|
||||||
".$request->getFinalRedirect()."
|
".$request->getFinalRedirect()."
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
<h3>Redirect trace</h3>
|
<h3>Redirect trace</h3>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Step</th>
|
<th>Step</th>
|
||||||
<th>Request</th>
|
<th>Request</th>
|
||||||
<th colspan=\"2\">Code</th>
|
<th colspan=\"2\">Code</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>";
|
<tbody>";
|
||||||
foreach ($request->path as $step)
|
foreach ($request->path as $step)
|
||||||
{
|
{
|
||||||
$item = $step['step'];
|
$item = $step['step'];
|
||||||
$url = $step['url'];
|
$url = $step['url'];
|
||||||
$code = $step['code'];
|
$code = $step['code'];
|
||||||
$next = ($step['next']) ? '⥂⇄↩︎' : '✓';
|
$next = ($step['next']) ? '↩︎' : ((isset($error)) ? 'x' : '✓');
|
||||||
echo "
|
echo "
|
||||||
<tr>
|
<tr>
|
||||||
<td>".$item."</td>
|
<td>".$item."</td>
|
||||||
<td>".$url." <a href=\"".$url."\" target=\"blank\"><b>↗︎</b></a></td>
|
<td>".$url." <a href=\"".$url."\" target=\"blank\"><b><i>↗︎</i></b></a></td>
|
||||||
<td><code>".$code."</code></td>
|
<td><code>".$code."</code></td>
|
||||||
<td>".$next."</td>
|
<td>".$next."</td>
|
||||||
</tr>";
|
</tr>";
|
||||||
}
|
}
|
||||||
echo "
|
echo "
|
||||||
</tbody>
|
</tbody>
|
||||||
<caption>
|
<caption>
|
||||||
User agent: ".$request::USER_AGENT."
|
User agent: ".$request::USER_AGENT."
|
||||||
</caption>
|
</caption>
|
||||||
</table>
|
</table>
|
||||||
</article>";
|
</article>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo "
|
echo "
|
||||||
<article>
|
<article>
|
||||||
<h2>
|
<h2>
|
||||||
Trace a URL's redirects
|
Trace a URL's redirects
|
||||||
</h2>
|
</h2>
|
||||||
<p>
|
<p>
|
||||||
Enter a URL in the search box above to derive the final resolved URL after all redirects. The script runs recursive curl requests until we get a <code>200</code> status code. This is helpful to get around link tracking or original URLs that Pi-hole outright blocks (like email links).
|
Enter a URL in the search box above to derive the final resolved URL after all redirects. The script runs recursive curl requests until we get a <code>200</code> status code. This is helpful to get around link tracking or original URLs that Pi-hole outright blocks (like email links).
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
I used to use <a href=\"https://wheregoes.com\">wheregoes.com</a> which is a good, reliable service, but decided to roll my own for privacy reasons. Absolutely nothing is logged as all URL searches are via POST and that's not currently included in my nginx logs.
|
I used to use <a href=\"https://wheregoes.com\">wheregoes.com</a> which is a good, reliable service, but decided to roll my own for privacy reasons. Absolutely nothing is logged as all URL searches are via POST and that's not currently included in my nginx logs.
|
||||||
</p>
|
</p>
|
||||||
<h3>
|
<h3>
|
||||||
Technical details
|
Technical details
|
||||||
</h3>
|
</h3>
|
||||||
<p>
|
<p>
|
||||||
User agent
|
User agent
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Other curl settings
|
Other curl settings
|
||||||
</p>
|
</p>
|
||||||
</article>
|
</article>";
|
||||||
";
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<aside>
|
<aside>
|
||||||
<h3>
|
<h3>
|
||||||
HTTP response status codes
|
HTTP response status codes
|
||||||
</h3>
|
</h3>
|
||||||
<?php
|
<?php
|
||||||
if (isset($codes) && is_array($codes) && !empty($codes))
|
if (isset($codes) && is_array($codes) && !empty($codes))
|
||||||
{
|
{
|
||||||
foreach ($codes as $group)
|
foreach ($codes as $group)
|
||||||
{
|
{
|
||||||
echo "
|
echo "
|
||||||
<details>
|
<details>
|
||||||
<summary>
|
<summary>
|
||||||
".$group['label']." (<code>".$group['start']."</code>–<code>".$group['range']."</code>)
|
".$group['label']." (<code>".$group['start']."</code>–<code>".$group['range']."</code>)
|
||||||
</summary>
|
</summary>
|
||||||
<dl>";
|
<dl>";
|
||||||
foreach ($group['codes'] as $code => $prop)
|
foreach ($group['codes'] as $code => $prop)
|
||||||
{
|
{
|
||||||
echo "
|
echo "
|
||||||
<!-- ".$code." -->
|
<!-- ".$code." -->
|
||||||
<dt>
|
<dt>
|
||||||
<label for=\"".$code."\"><code>".$code."</code> ".$prop['name']."</label>
|
<label for=\"".$code."\"><code>".$code."</code> ".$prop['name']."</label>
|
||||||
</dt>
|
</dt>
|
||||||
<input type=\"checkbox\" id=\"".$code."\">
|
<input type=\"checkbox\" id=\"".$code."\">
|
||||||
<dd>".$prop['desc']."</dd>";
|
<dd>".$prop['desc']."</dd>";
|
||||||
}
|
}
|
||||||
echo "
|
echo "
|
||||||
</dl>
|
</dl>
|
||||||
</details>";
|
</details>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<p>
|
<p>
|
||||||
See <a href="https://httpwg.org/specs/rfc9110.html#overview.of.status.codes">RFC 9110</a> for official documentation on each status code.
|
See <a href="https://httpwg.org/specs/rfc9110.html#overview.of.status.codes">RFC 9110</a> for official documentation on each status code.
|
||||||
</p>
|
</p>
|
||||||
</aside>
|
</aside>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user