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

fix: follow redirects

parent cb0795cf
No related branches found
No related tags found
1 merge request!7fix: follow redirects
......@@ -5,6 +5,7 @@
*
* ----------------------------------------------------------------------
* 2022-05-23 ah v0.1 initial version
* 2025-01-13 ah v1.0 colorize clicked testlink in dependency of the result
* ======================================================================
*/
......@@ -46,10 +47,13 @@ async function showInOverlay(oLink){
show(body);
// colorize clicked link
var myspan=document.getElementsByClassName("status")[0];
var myclass=myspan.className.replace("status ","");
oLink.className=myclass;
oLink.title=myspan.innerText;
var spans=document.getElementsByClassName("status");
if(spans){
var myspan=spans[spans.length-1];
var myclass=myspan.className.replace("status ","");
oLink.className=myclass;
oLink.title=myspan.innerText;
}
} else {
show("HTTP-Error: " + response.status);
}
......
......@@ -115,11 +115,11 @@ if (!$oR->isEnabled()) {
$sTdFirst = '<tr class="cfgtype-' . $aCfg['type'] . '">'
. '<td>'
. '<span style="display: none">' . $sHost . '</span>'
. '<nobr>'.$aIco['type_' . $aCfg['type']] . " $sHost</nobr>"
. '<span style="float: right;">'
. ' <a href="?url=http' . $sUrlpart . '" title="click to test http://' . $sHost . '/" onclick="showInOverlay(this); return false;">http</a> '
. ($bHttpOnly ? '' : '<a href="?url=https' . $sUrlpart . '" title="click to test https://' . $sHost . '/" onclick="showInOverlay(this); return false;">https</a>')
. '</span>'
. $aIco['type_' . $aCfg['type']] . " $sHost"
. '</td>'
. '<td>'
. ($aCfg['ip']
......@@ -138,17 +138,19 @@ if (!$oR->isEnabled()) {
;
if (isset($aCfg['redirects'])) {
$iCount = 0;
foreach (['direct', 'regex'] as $sType) {
if (count($aCfg['redirects'][$sType])) {
foreach ($aCfg['redirects'][$sType] as $sFrom => $aTo) {
$iCount++;
$sRelFrom = $sType == 'direct' ? $sFrom : ($aTo['link'] ?? false );
$sTable .= $sTdFirst
. '<td class="type-' . $sType . '">' . $sType . '</td>'
. '<td class="type-' . $sType . '">'
. ($sType == 'direct'
. ($sRelFrom
? '<span style="float: right;">'
. '<a href="?url=http://' . $sHost . $sFrom . '" title="click to test http://' . $sHost . '/' . $sFrom . '" onclick="showInOverlay(this); return false;">http</a> '
. '<a href="?url=https://' . $sHost . $sFrom . '" title="click to test http://' . $sHost . '/' . $sFrom . '" onclick="showInOverlay(this); return false;">https</a> '
. '<a href="?url=http://' . $sHost . $sRelFrom . '" title="click to test http://' . $sHost . '/' . $sRelFrom . '" onclick="showInOverlay(this); return false;">http</a> '
. ($bHttpOnly ? '' : '<a href="?url=https://' . $sHost . $sRelFrom . '" title="click to test http://' . $sHost . '/' . $sRelFrom . '" onclick="showInOverlay(this); return false;">https</a> ')
. '</span>'
: ''
)
......
......@@ -61,7 +61,7 @@ a{color: var(--link-color);}
body {
background: var(--body-bg);
color: var(--body-color);
font-size: 1.2em;
font-size: 1.0em;
font-family: arial;
margin: 0;
padding: 0;
......
......@@ -50,8 +50,8 @@ class redirectadmin extends redirect
],
// TODO: this is unsafe .. better: let the user configure it
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
// CURLOPT_SSL_VERIFYHOST => true,
// CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_TIMEOUT => 5,
];
return $aReturn;
......@@ -79,16 +79,22 @@ class redirectadmin extends redirect
$sHeader = '';
$sBody = '';
$aResponse = explode("\r\n\r\n", $res, 2);
list($sHeader, $sBody) = count($aResponse) > 1
if($bHeaderOnly){
$sHeader = $res;
$sBody = '';
} else {
$aResponse = explode("\r\n\r\n", $res, 2);
list($sHeader, $sBody) = count($aResponse) > 1
? $aResponse
: [$aResponse[0], ''];
}
$aResult = [
'url' => $url,
'response_header' => $sHeader,
'response_body' => $sBody,
'curlinfo' => curl_getinfo($ch),
// 'curlinfo' => curl_getinfo($ch),
'curlerrorcode' => curl_errno($ch),
'curlerrormsg' => curl_error($ch),
];
......@@ -105,7 +111,7 @@ class redirectadmin extends redirect
*/
public function renderHttpResponseHeader(array $aResponse): string
{
$sHeader=$aResponse['response_header'];
$sHeader=$aResponse['response_header']."\r\n\r\n".$aResponse['response_body'];
$sReturn = $sHeader;
// $sReturn.="<pre>".print_r($aResponse, 1)."</pre>";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment