Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
redirect-handler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
redirect-handler
Commits
9e3d933b
Commit
9e3d933b
authored
4 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
admin: add boxes for hops
parent
6e67b1f4
Branches
Branches containing commit
No related tags found
1 merge request
!9
7728 handle http and https redirects
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
public_html/admin/main.css
+6
-2
6 additions, 2 deletions
public_html/admin/main.css
public_html/classes/redirect.admin.class.php
+69
-26
69 additions, 26 deletions
public_html/classes/redirect.admin.class.php
public_html/classes/redirect.class.php
+8
-2
8 additions, 2 deletions
public_html/classes/redirect.class.php
with
83 additions
and
30 deletions
public_html/admin/main.css
+
6
−
2
View file @
9e3d933b
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
--top-bg
:
linear-gradient
(
0deg
,
#000
,
#234
,
#222
);
--top-bg
:
linear-gradient
(
0deg
,
#000
,
#234
,
#222
);
--top-color
:
#e55
;
--top-color
:
#e55
;
--top-version-color
:
#488
;
--top-bottom
:
var
(
--col-border-1
);
--top-bottom
:
var
(
--col-border-1
);
--link-color
:
#46d
;
--link-color
:
#46d
;
...
@@ -70,11 +71,12 @@ body {
...
@@ -70,11 +71,12 @@ body {
h1
{
margin
:
0
0
0.5em
;
;
padding
:
0
;}
h1
{
margin
:
0
0
0.5em
;
;
padding
:
0
;}
h1
a
{
background
:
var
(
--top-bg
);
color
:
var
(
--top-color
);
text-decoration
:
none
;
border-bottom
:
5px
solid
var
(
--top-bottom
);
display
:
block
;
padding
:
0.5em
;}
h1
a
{
background
:
var
(
--top-bg
);
color
:
var
(
--top-color
);
text-decoration
:
none
;
border-bottom
:
5px
solid
var
(
--top-bottom
);
display
:
block
;
padding
:
0.5em
;}
h1
a
small
{
color
:
var
(
--top-version-color
);}
h2
{
background
:
var
(
--h2-bg
);
color
:
var
(
'--h2-color'
);
margin
:
1em
0
0.5em
;
border-top
:
2px
solid
var
(
--h2-border
);
border-left
:
5px
solid
var
(
--h2-border
);
border-top-left-radius
:
0.5em
;
padding
:
0.5em
;
margin
:
0
;}
h2
{
background
:
var
(
--h2-bg
);
color
:
var
(
'--h2-color'
);
margin
:
1em
0
0.5em
;
border-top
:
2px
solid
var
(
--h2-border
);
border-left
:
5px
solid
var
(
--h2-border
);
border-top-left-radius
:
0.5em
;
padding
:
0.5em
;
margin
:
0
;}
h3
{
color
:
var
(
'--h3-color'
);
font-size
:
250%
}
h3
{
color
:
var
(
'--h3-color'
);
font-size
:
250%
}
pre
{
background
:
rgba
(
0
,
0
,
0
,
0.02
);
padding
:
0.3em
1em
;
border
:
1px
solid
rgba
(
0
,
0
,
0
,
0.1
);
margin
:
2
em
0
3em
;
;
border-bottom
:
2px
solid
rgba
(
0
,
0
,
0
,
0.2
);
border-bottom-right-radius
:
1em
;}
pre
{
background
:
rgba
(
0
,
0
,
0
,
0.02
);
padding
:
0.3em
1em
;
border
:
1px
solid
rgba
(
0
,
0
,
0
,
0.1
);
margin
:
1
em
0
3em
;
;
border-bottom
:
2px
solid
rgba
(
0
,
0
,
0
,
0.2
);
border-bottom-right-radius
:
1em
;}
.dataTable
tr
:hover
{
background
:
#f4f0f8
!important
;}
.dataTable
tr
:hover
{
background
:
#f4f0f8
!important
;}
footer
{
background
:
var
(
--footer-bg
);
margin-top
:
4em
;
text-align
:
right
;
padding
:
1em
;}
footer
{
background
:
var
(
--footer-bg
);
margin-top
:
4em
;
text-align
:
right
;
padding
:
1em
;}
...
@@ -96,7 +98,7 @@ ol.error{padding-left: 2em;}
...
@@ -96,7 +98,7 @@ ol.error{padding-left: 2em;}
.type-direct
{
color
:
var
(
--type-direct-color
);
}
.type-direct
{
color
:
var
(
--type-direct-color
);
}
.type-regex
{
color
:
var
(
--type-regex-color
);
}
.type-regex
{
color
:
var
(
--type-regex-color
);
}
.status
{
padding
:
0.5em
1em
;
position
:
relative
;
top
:
-1.4em
;
left
:
-0.9em
;
border-left
:
5px
solid
;
font-size
:
125%
;
border-
bot
to
m
-right-radius
:
0.7em
;}
.status
{
padding
:
0.5em
1em
;
border-left
:
5px
solid
;
font-size
:
125%
;
border-to
p
-right-radius
:
0.7em
;}
.status-ok
{
background
:
var
(
--txt-ok-bg
);
color
:
var
(
--txt-ok-color
);}
.status-ok
{
background
:
var
(
--txt-ok-bg
);
color
:
var
(
--txt-ok-color
);}
.status-redirect
{
background
:
var
(
--txt-warning-bg
);
color
:
var
(
--txt-warning-color
);}
.status-redirect
{
background
:
var
(
--txt-warning-bg
);
color
:
var
(
--txt-warning-color
);}
.status-error
{
background
:
var
(
--txt-error-bg
);
color
:
var
(
--txt-error-color
);}
.status-error
{
background
:
var
(
--txt-error-bg
);
color
:
var
(
--txt-error-color
);}
...
@@ -106,6 +108,8 @@ ol.error{padding-left: 2em;}
...
@@ -106,6 +108,8 @@ ol.error{padding-left: 2em;}
.location
::before
{
content
:
' 🌐 '
;
background-color
:
var
(
--txt-location-before-bg
);}
.location
::before
{
content
:
' 🌐 '
;
background-color
:
var
(
--txt-location-before-bg
);}
.debug
{
color
:
var
(
--txt-debug-color
);}
.debug
{
color
:
var
(
--txt-debug-color
);}
.box
{
display
:
inline-block
;
border
:
1px
solid
rgba
(
0
,
0
,
0
,
0.1
);
padding
:
0.3em
;
margin
:
0em
;
text-align
:
center
;
border-radius
:
0.25em
;}
.overlay
{
position
:
fixed
;
margin
:
0
;
width
:
100%
;
height
:
100%
;
top
:
0
;
left
:
0
;
background
:
var
(
--overlay-bg
);
overflow
:
scroll
;
display
:
none
;}
.overlay
{
position
:
fixed
;
margin
:
0
;
width
:
100%
;
height
:
100%
;
top
:
0
;
left
:
0
;
background
:
var
(
--overlay-bg
);
overflow
:
scroll
;
display
:
none
;}
.overlay
>
div
{
margin
:
3%
10%
;
background
:
var
(
--overlay-box-bg
);
padding
:
1em
;
box-shadow
:
var
(
--overlay-box-shadow
);
}
.overlay
>
div
{
margin
:
3%
10%
;
background
:
var
(
--overlay-box-bg
);
padding
:
1em
;
box-shadow
:
var
(
--overlay-box-shadow
);
}
...
...
This diff is collapsed.
Click to expand it.
public_html/classes/redirect.admin.class.php
+
69
−
26
View file @
9e3d933b
...
@@ -40,7 +40,7 @@ class redirectadmin extends redirect
...
@@ -40,7 +40,7 @@ class redirectadmin extends redirect
CURLOPT_HEADER
=>
true
,
CURLOPT_HEADER
=>
true
,
CURLOPT_FOLLOWLOCATION
=>
true
,
CURLOPT_FOLLOWLOCATION
=>
true
,
CURLOPT_RETURNTRANSFER
=>
true
,
CURLOPT_RETURNTRANSFER
=>
true
,
CURLOPT_USERAGENT
=>
strip_tags
(
$this
->
sAbout
),
CURLOPT_USERAGENT
=>
strip_tags
(
$this
->
_app
.
' '
.
$this
->
_version
),
CURLOPT_VERBOSE
=>
false
,
CURLOPT_VERBOSE
=>
false
,
CURLOPT_ENCODING
=>
'gzip, deflate'
,
// to fetch encoding
CURLOPT_ENCODING
=>
'gzip, deflate'
,
// to fetch encoding
CURLOPT_HTTPHEADER
=>
[
CURLOPT_HTTPHEADER
=>
[
...
@@ -112,41 +112,80 @@ class redirectadmin extends redirect
...
@@ -112,41 +112,80 @@ class redirectadmin extends redirect
public
function
renderHttpResponseHeader
(
array
$aResponse
):
string
public
function
renderHttpResponseHeader
(
array
$aResponse
):
string
{
{
$sHeader
=
$aResponse
[
'response_header'
]
.
"
\r\n\r\n
"
.
$aResponse
[
'response_body'
];
$sHeader
=
$aResponse
[
'response_header'
]
.
"
\r\n\r\n
"
.
$aResponse
[
'response_body'
];
$sReturn
=
$sHeader
;
// $sReturn.="<pre>".print_r($aResponse, 1)."</pre>";
// $sReturn.="<pre>".print_r($aResponse, 1)."</pre>";
$iJump
=
0
;
$sBox
=
''
;
$sReturn
=
''
;
if
(
$aResponse
[
'curlerrorcode'
])
{
if
(
$aResponse
[
'curlerrorcode'
])
{
$sReturn
=
'<pre><br>'
$sReturn
.
=
'<br>'
.
'<span class="status status-error">Request failed.<br></span>'
.
'<span class="status status-error">Request failed.</span>'
.
'<pre>'
.
'Curl error #'
.
$aResponse
[
'curlerrorcode'
]
.
':<br>'
.
'Curl error #'
.
$aResponse
[
'curlerrorcode'
]
.
':<br>'
.
'<strong>'
.
$aResponse
[
'curlerrormsg'
]
.
'</strong><br><br>'
.
'<strong>'
.
$aResponse
[
'curlerrormsg'
]
.
'</strong><br><br>'
.
'</pre>'
.
'</pre>'
.
'🌐 <a href="https://curl.se/libcurl/c/libcurl-errors.html" target="_blank">Curl error codes</a>'
.
'🌐 <a href="https://curl.se/libcurl/c/libcurl-errors.html" target="_blank">Curl error codes</a>'
;
;
}
else
{
}
$sReturn
=
preg_replace
(
'/(HTTP.*)\\r/'
,
'</pre><pre><strong>$1</strong>'
,
$sReturn
);
$sUrl
=
$aResponse
[
'url'
];
$sReturn
=
preg_replace
(
'/(HTTP.*200.*)/'
,
'<span class="status status-ok">$1</span>'
,
$sReturn
);
foreach
(
explode
(
"
\r\n\r\n
"
,
$aResponse
[
'response_header'
]
.
"
\r\n\r\n
"
.
$aResponse
[
'response_body'
]
)
as
$sBlock
){
$sReturn
=
preg_replace
(
'/(HTTP.*30.*)/'
,
'<span class="status status-redirect">$1</span>'
,
$sReturn
);
if
(
strlen
(
$sBlock
)){
$sReturn
=
preg_replace
(
'/(HTTP.*40.*)/'
,
'<span class="status status-error">$1</span>'
,
$sReturn
);
$iJump
++
;
$sReturn
=
preg_replace
(
'/(HTTP.*50.*)/'
,
'<span class="status status-error">$1</span>'
,
$sReturn
);
$sReturn
=
preg_replace
(
'/\ ([1-5][0-9][0-9])\ /'
,
' <span class="statuscode">$1</span> '
,
$sReturn
);
// find http status
preg_match
(
'/HTTP\/.* ([0-9]*) /'
,
$sBlock
,
$aTmp
);
$sReturn
=
preg_replace
(
'/(x-debug-.*)\\r/i'
,
'<span class="debug">$1</span>'
,
$sReturn
);
// $sReturn.='<pre>'.print_r($aTmp, 1).'</pre>';
$sReturn
=
preg_replace
(
'/(location:.*)\\r/i'
,
'<span class="location">$1</span>'
,
$sReturn
);
$iStatus
=
$aTmp
[
1
]
??
'0'
;
$sReturn
.
=
'</pre>'
;
$sStatus
=
''
;
preg_match_all
(
'/(HTTP\/.*)/i'
,
$sReturn
,
$aTmp
);
if
(
$iStatus
>=
200
&&
$iStatus
<
300
){
// $sReturn.=print_r($aTmp, 1);
$sStatus
=
'status-ok'
;
$iHops
=
(
count
(
$aTmp
[
0
])
-
1
);
}
elseif
(
$iStatus
>=
300
&&
$iStatus
<
400
){
$sStatus
=
'status-redirect'
;
$sReturn
=
(
$iHops
>
0
}
elseif
(
$iStatus
>=
400
&&
$iStatus
<
500
){
?
'<br>Found hops: <strong>'
.
$iHops
.
'</strong>'
$sStatus
=
'status-error'
;
.
(
$iHops
>
1
?
' <br><span class="warning"> ⚠️ Verify your redirect to skip unneeded hops.</span>'
:
''
)
.
'<br><br>'
}
elseif
(
$iStatus
>=
500
&&
$iStatus
<
600
){
:
''
$sStatus
=
'status-error'
;
)
.
$sReturn
}
;
// find location
preg_match
(
'/Location: (.*)/i'
,
$sBlock
,
$aTmp
);
$sNextUrl
=
$aTmp
[
1
]
??
''
;
// modify lines in block
$sBlock
=
preg_replace
(
'/(x-debug-.*)\\r/i'
,
'<span class="debug">$1</span>'
,
$sBlock
);
$sBlock
=
preg_replace
(
'/(location:.*)\\r/i'
,
'<span class="location">$1</span>'
,
$sBlock
);
$sReturn
.
=
"<span class=
\"
status
$sStatus
\"
>
$sUrl
(
$iStatus
) </span><pre>
$sBlock
</pre>"
;
// $sReturn .= '<strong>'.$iJump.') HTTP status: '.$iStatus.' - '.$sUrl.'</strong><pre>'.$sBlock.'</pre>';
$sWebhost
=
parse_url
(
$sUrl
,
PHP_URL_HOST
);
$sBox
.
=
"<div class=
\"
box
$sStatus
\"
>"
.
$sWebhost
.
'<br>'
.
$this
->
_getIp
(
$sWebhost
)
.
'</div>'
;
if
(
$sNextUrl
){
$sBox
.
=
" ---
$iStatus
---> "
;
$sUrl
=
$sNextUrl
;
}
}
}
}
$iHops
=
$iJump
-
1
;
$sReturn
=
'<br>'
.
(
$iHops
>
0
?
'Found hops: <strong>'
.
$iHops
.
'</strong>'
.
(
$iHops
>
1
?
'<span class="warning"> ⚠️ Verify your redirect to skip unneeded hops.</span>'
:
''
)
.
'<br><br>'
.
'<div>'
.
$sBox
.
'</div><br><br><br>'
:
''
)
.
$sReturn
;
return
$sReturn
;
return
$sReturn
;
}
}
...
@@ -222,5 +261,9 @@ class redirectadmin extends redirect
...
@@ -222,5 +261,9 @@ class redirectadmin extends redirect
return
$aReturn
;
return
$aReturn
;
}
}
function
getTitle
():
string
{
return
'Redirect :: admin <small>'
.
$this
->
_version
.
'</small>'
;
}
}
}
This diff is collapsed.
Click to expand it.
public_html/classes/redirect.class.php
+
8
−
2
View file @
9e3d933b
...
@@ -39,6 +39,12 @@ class redirect
...
@@ -39,6 +39,12 @@ class redirect
// CONFIG
// CONFIG
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
/**
* About message
* @var string
*/
protected
string
$_version
=
'1.7'
;
/**
/**
* Flag: debug is enabled?
* Flag: debug is enabled?
* @var bool
* @var bool
...
@@ -55,7 +61,7 @@ class redirect
...
@@ -55,7 +61,7 @@ class redirect
* About message
* About message
* @var string
* @var string
*/
*/
protected
string
$
sAbout
=
'IML redirect
<small>v1.6</small>
'
;
protected
string
$
_app
=
'IML redirect'
;
/**
/**
* Hostname
* Hostname
...
@@ -417,7 +423,7 @@ class redirect
...
@@ -417,7 +423,7 @@ class redirect
.
'</head>'
.
'</head>'
.
'<body>'
.
'<body>'
.
$sBody
.
$sBody
.
'<h2>'
.
$this
->
sAbout
.
'
</h2>'
.
'<h2>'
.
$this
->
_app
.
' <small>'
.
$this
->
_version
.
'</small>
</h2>'
.
'<footer>© '
.
date
(
'Y'
)
.
' '
.
$this
->
sHostname
.
'</footer>'
.
'<footer>© '
.
date
(
'Y'
)
.
' '
.
$this
->
sHostname
.
'</footer>'
.
'</body></html>'
.
'</body></html>'
);
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment