Skip to content
Snippets Groups Projects
Commit a327bdbc authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update admin: show more hints and warnings

parent 1d616014
Branches
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@
require_once '../classes/redirect.admin.class.php';
$oR=new redirectadmin();
$sHtml='';
$sErrors='';
// ----------------------------------------------------------------------
// FUNCTIONS
......@@ -44,18 +45,13 @@ if (!$oR->isEnabled()){
// ---------- SHOW ERRORS
if(count($aHosts['_errors'])) {
$sHtml.= '<h2>🔔 Found errors</h2>'
.'<div class="content">'
.'<ol class="error">'
.'<li>' . implode('</li></li>', $aHosts['_errors']).'</li>'
.'</ol>'
.'</div>'
;
$sErrors.= '<li>' . implode('</li></li>', $aHosts['_errors']).'</li>';
}
unset($aHosts['_errors']);
// ---------- LOOP OVER ALL ENTRIES
$sMyIp=gethostbyname(gethostname());
$sHtml.='
<h2>✔️ Http head tester</h2>
<div class="content">
......@@ -82,12 +78,20 @@ if (!$oR->isEnabled()){
</thead><tbody>';
foreach($aHosts as $sHost => $aCfg){
$sTdFirst='<tr class="cfgtype-'.$aCfg['type'].'">'
.'<td>🔷 <a href="?url=http://'.$sHost.'/">'.$sHost.'</a></td>'
.'<td>🔷 <a href="?url=http://'.$sHost.'/" title="click to test http://'.$sHost.'/">'.$sHost.'</a></td>'
.'<td>'
.($aCfg['ip'] ? $aCfg['ip'] : '<span class="error">ERROR: unknown host</span>')
.($aCfg['ip']
? ($aCfg['ip']===$sMyIp
? '<span title="">🟢 '.$aCfg['ip']. '</span>'
: '<span title="Warning: this is not the ip address of the current host ('.$sMyIp.')">🟠 '.$aCfg['ip']. '</span>'
)
: '<span class="error">❗ERROR: unknown host</span>')
.'</td>'
.'<td>'.$aCfg['type'].'</td>'
;
if(!$aCfg['ip']){
$sErrors.='<li>Host was not found in DNS: '.$sHost.'</li>';
}
if (isset($aCfg['redirects'])){
$iCount=0;
foreach(['direct', 'regex'] as $sType){
......@@ -97,10 +101,10 @@ if (!$oR->isEnabled()){
$sHtml.=$sTdFirst
.'<td class="type-'.$sType.'">'.$sType.'</td>'
.'<td class="type-'.$sType.'">'
.($sType == 'direct' ? '<a href="?url=http://'.$sHost.'/'.$sFrom.'">'.$sFrom.'</a>' : $sFrom)
.($sType == 'direct' ? '<a href="?url=http://'.$sHost.'/'.$sFrom.'" title="click to test http://'.$sHost.'/'.$sFrom.'">'.$sFrom.'</a>' : $sFrom)
.'</td>'
.'<td class="http-'.$aTo['code'].'">'.$aTo['code'].'</td>'
.'<td>🌐 <a href="?url='.$aTo['target'].'">'.$aTo['target'].'</a></td>'
.'<td>🌐 <a href="?url='.$aTo['target'].'" title="click to test '.$aTo['target'].'">'.$aTo['target'].'</a></td>'
.'</tr>';
}
}
......@@ -130,6 +134,15 @@ if (!$oR->isEnabled()){
;
}
$sErrors = $sErrors
? '<h2>🔔 Found errors</h2>'
.'<div class="content">'
.'<ol class="error">'
.$sErrors
.'</ol>'
.'</div>'
: ''
;
}
......@@ -147,7 +160,7 @@ if (!$oR->isEnabled()){
<body>
<h1><a href="?">Redirects :: admin</a></h1>
<?php echo $sHtml; ?>
<?php echo $sErrors . $sHtml; ?>
<script>
$(document).ready( function () {
......
......@@ -85,6 +85,7 @@ class redirectadmin extends redirect {
.'</pre>'
;
} else {
$sReturn=preg_replace('/(HTTP.*)\\r/', '</pre><pre><strong>$1</strong>', $sReturn);
$sReturn=preg_replace('/(HTTP.*200.*)/', '<span class="status status-ok">$1</span>', $sReturn);
$sReturn=preg_replace('/(HTTP.*30.*)/', '<span class="status status-redirect">$1</span>', $sReturn);
......@@ -93,6 +94,17 @@ class redirectadmin extends redirect {
$sReturn=preg_replace('/(x-debug-.*)\\r/i', '<span class="debug">$1</span>', $sReturn);
$sReturn=preg_replace('/(location:.*)\\r/i', '<span class="location">$1</span>', $sReturn);
$sReturn.='</pre>';
preg_match_all('/(HTTP\/.*)/i', $sReturn, $aTmp);
// $sReturn.=print_r($aTmp, 1);
$iHops=(count($aTmp[0])-1);
$sReturn=($iHops>0
? 'Found hops: <strong>'.$iHops.'</strong>'
.($iHops>1 ? ' ⚠️ Verify your redirect to skip unneeded hops.' : '' ).'<br><br>'
: ''
).$sReturn
;
}
return $sReturn;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment