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

Merge branch '7728-handle-http-and-https-redirects' into 'master'

fix: follow redirects

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