Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
marcus-lodspeakr
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
uib-ub
Spesialsamlingene
marcus-lodspeakr
Merge requests
!5
add check for static dir and static/img
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
add check for static dir and static/img
lodspeakr-issue-6
into
master
Overview
2
Commits
5
Pipelines
0
Changes
1
Merged
Oyvind.Gjesdal
requested to merge
lodspeakr-issue-6
into
master
3 years ago
Overview
2
Commits
5
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
master
version 4
d5fe2b0b
3 years ago
version 3
e7588ceb
3 years ago
version 2
6216e485
3 years ago
version 1
4d3e23b7
3 years ago
master (base)
and
latest version
latest version
6e00b2c7
5 commits,
3 years ago
version 4
d5fe2b0b
4 commits,
3 years ago
version 3
e7588ceb
3 commits,
3 years ago
version 2
6216e485
2 commits,
3 years ago
version 1
4d3e23b7
1 commit,
3 years ago
1 file
+
112
−
85
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
classes/modules/staticModule.php
+
112
−
85
Options
<?php
require_once
(
'abstractModule.php'
);
class
StaticModule
extends
abstractModule
{
//Static module
public
function
match
(
$uri
){
global
$conf
;
global
$localUri
;
global
$uri
;
global
$acceptContentType
;
global
$endpoints
;
global
$lodspk
;
$q
=
preg_replace
(
'|^'
.
$conf
[
'basedir'
]
.
'|'
,
''
,
$localUri
);
if
(
strlen
(
$q
)
>
0
&&
file_exists
(
$conf
[
'home'
]
.
$conf
[
'static'
][
'directory'
]
.
$q
)){
return
$q
;
}
return
FALSE
;
public
function
match
(
$uri
)
{
global
$conf
;
global
$localUri
;
global
$uri
;
global
$acceptContentType
;
global
$endpoints
;
global
$lodspk
;
$q
=
preg_replace
(
'|^'
.
$conf
[
'basedir'
]
.
'|'
,
''
,
$localUri
);
if
(
strlen
(
$q
)
>
0
&&
file_exists
(
$conf
[
'home'
]
.
$conf
[
'static'
][
'directory'
]
.
$q
))
{
return
$q
;
}
return
FALSE
;
}
public
function
execute
(
$file
){
global
$conf
;
global
$localUri
;
global
$uri
;
global
$acceptContentType
;
global
$endpoints
;
global
$lodspk
;
$filenamearray
=
explode
(
"."
,
$file
);
$extension
=
end
(
$filenamearray
);
$ct
=
$this
->
getContentType
(
$extension
);
header
(
"Content-type: "
.
$ct
);
$uri
=
$localUri
;
if
(
$conf
[
'debug'
]){
Logging
::
log
(
"In "
.
$conf
[
'static'
][
'directory'
]
.
" static file
$file
"
);
}
$htmlExtension
=
'html'
;
if
(
$conf
[
'static'
][
'haanga'
]
&&
substr_compare
(
$file
,
$htmlExtension
,
-
strlen
(
$htmlExtension
),
strlen
(
$htmlExtension
))
===
0
){
$lodspk
[
'home'
]
=
$conf
[
'basedir'
];
$lodspk
[
'baseUrl'
]
=
$conf
[
'basedir'
];
$lodspk
[
'module'
]
=
'static'
;
$lodspk
[
'root'
]
=
$conf
[
'root'
];
$lodspk
[
'contentType'
]
=
$acceptContentType
;
$lodspk
[
'ns'
]
=
$conf
[
'ns'
];
$lodspk
[
'this'
][
'value'
]
=
$localUri
;
$lodspk
[
'this'
][
'curie'
]
=
Utils
::
uri2curie
(
$localUri
);
$lodspk
[
'local'
][
'value'
]
=
$localUri
;
$lodspk
[
'local'
][
'curie'
]
=
Utils
::
uri2curie
(
$localUri
);
$lodspk
[
'contentType'
]
=
$acceptContentType
;
$lodspk
[
'endpoint'
]
=
$conf
[
'endpoint'
];
$lodspk
[
'type'
]
=
$modelFile
;
$lodspk
[
'header'
]
=
$prefixHeader
;
$lodspk
[
'baseUrl'
]
=
$conf
[
'basedir'
];
Utils
::
processDocument
(
$conf
[
'static'
][
'directory'
]
.
$file
,
$lodspk
,
null
);
}
else
{
echo
file_get_contents
(
$conf
[
'static'
][
'directory'
]
.
$file
);
}
public
function
execute
(
$file
)
{
global
$conf
;
global
$localUri
;
global
$uri
;
global
$acceptContentType
;
global
$endpoints
;
global
$lodspk
;
$this
->
validateDirectory
(
$conf
,
$file
);
$filenamearray
=
explode
(
"."
,
$file
);
$extension
=
end
(
$filenamearray
);
$ct
=
$this
->
getContentType
(
$extension
);
header
(
"Content-type: "
.
$ct
);
$uri
=
$localUri
;
if
(
$conf
[
'debug'
])
{
Logging
::
log
(
"In "
.
$conf
[
'static'
][
'directory'
]
.
" static file
$file
"
);
}
$htmlExtension
=
'html'
;
if
(
$conf
[
'static'
][
'haanga'
]
&&
substr_compare
(
$file
,
$htmlExtension
,
-
strlen
(
$htmlExtension
),
strlen
(
$htmlExtension
))
===
0
)
{
$lodspk
[
'home'
]
=
$conf
[
'basedir'
];
$lodspk
[
'baseUrl'
]
=
$conf
[
'basedir'
];
$lodspk
[
'module'
]
=
'static'
;
$lodspk
[
'root'
]
=
$conf
[
'root'
];
$lodspk
[
'contentType'
]
=
$acceptContentType
;
$lodspk
[
'ns'
]
=
$conf
[
'ns'
];
$lodspk
[
'this'
][
'value'
]
=
$localUri
;
$lodspk
[
'this'
][
'curie'
]
=
Utils
::
uri2curie
(
$localUri
);
$lodspk
[
'local'
][
'value'
]
=
$localUri
;
$lodspk
[
'local'
][
'curie'
]
=
Utils
::
uri2curie
(
$localUri
);
$lodspk
[
'contentType'
]
=
$acceptContentType
;
$lodspk
[
'endpoint'
]
=
$conf
[
'endpoint'
];
$lodspk
[
'baseUrl'
]
=
$conf
[
'basedir'
];
Utils
::
processDocument
(
$conf
[
'static'
][
'directory'
]
.
$file
,
$lodspk
,
null
);
}
else
{
echo
file_get_contents
(
$conf
[
'static'
][
'directory'
]
.
$file
);
}
}
private
function
getContentType
(
$e
){
$contentTypes
=
array
(
'html'
=>
'text/html'
,
'css'
=>
'text/css'
,
'js'
=>
'application/javascript'
,
'json'
=>
'application/json'
,
'jsonp'
=>
'application/javascript'
,
'nt'
=>
'text/plain'
,
'ttl'
=>
'text/turtle'
,
'png'
=>
'image/png'
,
'jpg'
=>
'image/jpeg'
,
'gif'
=>
'image/gif'
,
'bmp'
=>
'image/bmp'
,
'pdf'
=>
'application/pdf'
,
'zip'
=>
'application/zip'
,
'gz'
=>
'application/gzip'
,
'svg'
=>
'image/svg+xml'
);
//Add new/override existing mime types defined by user
if
(
isset
(
$conf
[
'static'
][
'mimetypes'
])){
foreach
(
$conf
[
'static'
][
'mimetypes'
]
as
$k
=>
$v
){
$contentTypes
[
$k
]
=
$v
;
}
}
if
(
isset
(
$contentTypes
[
$e
])){
return
$contentTypes
[
$e
];
}
return
""
;
//empty string seems to work fine with browsers
private
function
getContentType
(
$e
)
{
$contentTypes
=
[
'html'
=>
'text/html'
,
'css'
=>
'text/css'
,
'js'
=>
'application/javascript'
,
'json'
=>
'application/json'
,
'jsonp'
=>
'application/javascript'
,
'nt'
=>
'text/plain'
,
'ttl'
=>
'text/turtle'
,
'png'
=>
'image/png'
,
'jpg'
=>
'image/jpeg'
,
'gif'
=>
'image/gif'
,
'bmp'
=>
'image/bmp'
,
'pdf'
=>
'application/pdf'
,
'zip'
=>
'application/zip'
,
'gz'
=>
'application/gzip'
,
'svg'
=>
'image/svg+xml'
,
];
//Add new/override existing mime types defined by user.
if
(
isset
(
$conf
[
'static'
][
'mimetypes'
]))
{
foreach
(
$conf
[
'static'
][
'mimetypes'
]
as
$k
=>
$v
)
{
$contentTypes
[
$k
]
=
$v
;
}
}
if
(
isset
(
$contentTypes
[
$e
]))
{
return
$contentTypes
[
$e
];
}
return
""
;
}
/**
* Validate that resource directory is valid and safe to use.
*
* @param array $conf
* Global configuration.
* @param $file
*
* @return void
*/
private
function
validateDirectory
(
array
$conf
,
$file
):
void
{
$staticDirectory
=
realpath
(
$conf
[
'static'
][
'directory'
]);
$imgDirectory
=
realpath
(
$conf
[
'static'
][
'directory'
]
.
"img"
);
$resourcePath
=
realpath
(
$conf
[
'static'
][
'directory'
]
.
$file
);
if
(
strpos
(
$resourcePath
,
$staticDirectory
)
!==
0
&&
strpos
(
$resourcePath
,
$imgDirectory
)
!==
0
)
{
HTTPStatus
::
send404
(
$file
);
}
}
}
?>
Loading