Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
efac15bf
Commit
efac15bf
authored
4 years ago
by
Tim van Dijen
Browse files
Options
Downloads
Patches
Plain Diff
Revert "Remove legacy code"
This reverts commit
f1e05f8f
.
parent
f1e05f8f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SimpleSAML/Module.php
+115
-3
115 additions, 3 deletions
lib/SimpleSAML/Module.php
with
115 additions
and
3 deletions
lib/SimpleSAML/Module.php
+
115
−
3
View file @
efac15bf
...
...
@@ -203,10 +203,122 @@ class Module
$request
->
getContent
()
);
$kernel
=
new
Kernel
(
$module
);
$response
=
$kernel
->
handle
(
$request
);
$kernel
->
terminate
(
$request
,
$response
);
try
{
$kernel
=
new
Kernel
(
$module
);
$response
=
$kernel
->
handle
(
$request
);
$kernel
->
terminate
(
$request
,
$response
);
return
$response
;
}
catch
(
FileLocatorFileNotFoundException
$e
)
{
// no routes configured for this module, fall back to the old system
}
catch
(
NotFoundHttpException
$e
)
{
// this module has been migrated, but the route wasn't found
}
$moduleDir
=
self
::
getModuleDir
(
$module
)
.
'/www/'
;
// check for '.php/' in the path, the presence of which indicates that another php-script should handle the
// request
for
(
$phpPos
=
strpos
(
$url
,
'.php/'
);
$phpPos
!==
false
;
$phpPos
=
strpos
(
$url
,
'.php/'
,
$phpPos
+
1
))
{
$newURL
=
substr
(
$url
,
0
,
$phpPos
+
4
);
$param
=
substr
(
$url
,
$phpPos
+
4
);
if
(
is_file
(
$moduleDir
.
$newURL
))
{
/* $newPath points to a normal file. Point execution to that file, and save the remainder of the path
* in PATH_INFO.
*/
$url
=
$newURL
;
$request
->
server
->
set
(
'PATH_INFO'
,
$param
);
$_SERVER
[
'PATH_INFO'
]
=
$param
;
break
;
}
}
$path
=
$moduleDir
.
$url
;
if
(
$path
[
strlen
(
$path
)
-
1
]
===
'/'
)
{
// path ends with a slash - directory reference. Attempt to find index file in directory
foreach
(
self
::
$indexFiles
as
$if
)
{
if
(
file_exists
(
$path
.
$if
))
{
$path
.
=
$if
;
break
;
}
}
}
if
(
is_dir
(
$path
))
{
/* Path is a directory - maybe no index file was found in the previous step, or maybe the path didn't end
* with a slash. Either way, we don't do directory listings.
*/
throw
new
Error\NotFound
(
'Directory listing not available.'
);
}
if
(
!
file_exists
(
$path
))
{
// file not found
Logger
::
info
(
'Could not find file \''
.
$path
.
'\'.'
);
throw
new
Error\NotFound
(
'The URL wasn\'t found in the module.'
);
}
if
(
mb_strtolower
(
substr
(
$path
,
-
4
),
'UTF-8'
)
===
'.php'
)
{
// PHP file - attempt to run it
/* In some environments, $_SERVER['SCRIPT_NAME'] is already set with $_SERVER['PATH_INFO']. Check for that
* case, and append script name only if necessary.
*
* Contributed by Travis Hegner.
*/
$script
=
"/
$module
/
$url
"
;
if
(
strpos
(
$request
->
getScriptName
(),
$script
)
===
false
)
{
$request
->
server
->
set
(
'SCRIPT_NAME'
,
$request
->
getScriptName
()
.
'/'
.
$module
.
'/'
.
$url
);
}
require
(
$path
);
exit
();
}
// some other file type - attempt to serve it
// find MIME type for file, based on extension
$contentType
=
null
;
if
(
preg_match
(
'#\.([^/\.]+)$#D'
,
$path
,
$type
))
{
$type
=
strtolower
(
$type
[
1
]);
if
(
array_key_exists
(
$type
,
self
::
$mimeTypes
))
{
$contentType
=
self
::
$mimeTypes
[
$type
];
}
}
if
(
$contentType
===
null
)
{
/* We were unable to determine the MIME type from the file extension. Fall back to mime_content_type (if it
* exists).
*/
if
(
function_exists
(
'mime_content_type'
))
{
$contentType
=
mime_content_type
(
$path
);
}
else
{
// mime_content_type doesn't exist. Return a default MIME type
Logger
::
warning
(
'Unable to determine mime content type of file: '
.
$path
);
$contentType
=
'application/octet-stream'
;
}
}
/** @psalm-var \SimpleSAML\Configuration $assetConfig */
$assetConfig
=
$config
->
getConfigItem
(
'assets'
);
/** @psalm-var \SimpleSAML\Configuration $cacheConfig */
$cacheConfig
=
$assetConfig
->
getConfigItem
(
'caching'
);
$response
=
new
BinaryFileResponse
(
$path
);
$response
->
setCache
([
// "public" allows response caching even if the request was authenticated,
// which is exactly what we want for static resources
'public'
=>
true
,
'max_age'
=>
strval
(
$cacheConfig
->
getInteger
(
'max_age'
,
86400
))
]);
$response
->
setAutoLastModified
();
if
(
$cacheConfig
->
getBoolean
(
'etag'
,
false
))
{
$response
->
setAutoEtag
();
}
$response
->
isNotModified
(
$request
);
$response
->
headers
->
set
(
'Content-Type'
,
$contentType
);
$response
->
setContentDisposition
(
ResponseHeaderBag
::
DISPOSITION_INLINE
);
$response
->
prepare
(
$request
);
return
$response
;
}
...
...
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