Added a proxy for use with index.php/$1 and rewrote redirects to work with sgni.nl
This commit is contained in:
parent
1f9f6478e6
commit
cb4a743c2a
@ -13,6 +13,8 @@
|
||||
"start": "php -S 0.0.0.0:8080"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {"Inforbank\\": "src/"}
|
||||
"psr-4": {
|
||||
"Inforbank\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
composer.lock
generated
13
composer.lock
generated
@ -276,23 +276,24 @@
|
||||
},
|
||||
{
|
||||
"name": "slim/slim",
|
||||
"version": "3.7.0",
|
||||
"version": "3.8.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/slimphp/Slim.git",
|
||||
"reference": "4254e40d81559e35cdf856bcbaca5f3af468b7ef"
|
||||
"reference": "5385302707530b2bccee1769613ad769859b826d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/slimphp/Slim/zipball/4254e40d81559e35cdf856bcbaca5f3af468b7ef",
|
||||
"reference": "4254e40d81559e35cdf856bcbaca5f3af468b7ef",
|
||||
"url": "https://api.github.com/repos/slimphp/Slim/zipball/5385302707530b2bccee1769613ad769859b826d",
|
||||
"reference": "5385302707530b2bccee1769613ad769859b826d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"container-interop/container-interop": "^1.1",
|
||||
"container-interop/container-interop": "^1.2",
|
||||
"nikic/fast-route": "^1.0",
|
||||
"php": ">=5.5.0",
|
||||
"pimple/pimple": "^3.0",
|
||||
"psr/container": "^1.0",
|
||||
"psr/http-message": "^1.0"
|
||||
},
|
||||
"provide": {
|
||||
@ -342,7 +343,7 @@
|
||||
"micro",
|
||||
"router"
|
||||
],
|
||||
"time": "2016-12-20T20:30:47+00:00"
|
||||
"time": "2017-03-19T17:55:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vrana/notorm",
|
||||
|
@ -28,7 +28,7 @@ class Middleware
|
||||
return $next($request, $response);
|
||||
} else {
|
||||
// Redirect to the login page
|
||||
return Redirect::create($response, '/login');
|
||||
return Redirect::create($request, $response, '/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,20 +16,11 @@ namespace Inforbank\Application\Helper;
|
||||
|
||||
class Redirect
|
||||
{
|
||||
public static function create($response, $path)
|
||||
public static function create($request, $response, $path)
|
||||
{
|
||||
$basePath = $request->getUri()->getBaseUrl();
|
||||
$response = $response->withStatus(302);
|
||||
$response = $response->withHeader('Location', Redirect::getBasepath() . $path);
|
||||
$response = $response->withHeader('Location', $basePath . $path);
|
||||
return $response;
|
||||
}
|
||||
|
||||
private static function getBasepath()
|
||||
{
|
||||
if (isset($_SERVER['HTTPS'])) {
|
||||
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
|
||||
} else {
|
||||
$protocol = 'http';
|
||||
}
|
||||
return $protocol . "://" . $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
}
|
||||
|
@ -34,18 +34,18 @@ class Login
|
||||
$resp = $this->auth->login($post['rekeningnr'], $post['pascode']);
|
||||
|
||||
if ($resp) {
|
||||
return Redirect::create($response, '/');
|
||||
return Redirect::create($request, $response, '/');
|
||||
} else {
|
||||
return Redirect::create($response, '/login?error');
|
||||
return Redirect::create($request, $response, '/login?error');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return Redirect::create($response, '/login?error');
|
||||
return Redirect::create($request, $response, '/login?error');
|
||||
}
|
||||
});
|
||||
|
||||
$app->get('/logout', function ($request, $response, $args) {
|
||||
$this->auth->logout();
|
||||
return Redirect::create($response, '/login');
|
||||
return Redirect::create($request, $response, '/login');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
108
src/Proxy.php
Normal file
108
src/Proxy.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Informatica Eindproject D4p
|
||||
* 6in3, Stedelijk Gymnasium Nijmegen
|
||||
* Docent: Hans de Wolf
|
||||
*
|
||||
* ==================
|
||||
*
|
||||
* Daniel Boutros,
|
||||
* Christiaan Goossens,
|
||||
* Jelmer Hinssen
|
||||
*/
|
||||
|
||||
namespace Inforbank;
|
||||
|
||||
use Bat\MimeTypeTool;
|
||||
|
||||
class Proxy
|
||||
{
|
||||
public function __invoke($request, $response, $next)
|
||||
{
|
||||
$uri = $request->getUri();
|
||||
$path = $uri->getPath();
|
||||
if (strpos($path, 'assets/') !== false) {
|
||||
if (file_exists($path)) {
|
||||
$ext = pathinfo($path, PATHINFO_EXTENSION);
|
||||
$ext2Mime = array(
|
||||
|
||||
'txt' => 'text/plain',
|
||||
'htm' => 'text/html',
|
||||
'html' => 'text/html',
|
||||
'php' => 'text/html',
|
||||
'css' => 'text/css',
|
||||
'js' => 'application/javascript',
|
||||
'json' => 'application/json',
|
||||
'xml' => 'application/xml',
|
||||
'swf' => 'application/x-shockwave-flash',
|
||||
'flv' => 'video/x-flv',
|
||||
|
||||
// images
|
||||
'png' => 'image/png',
|
||||
'jpe' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'jpg' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
'bmp' => 'image/bmp',
|
||||
'ico' => 'image/vnd.microsoft.icon',
|
||||
'tiff' => 'image/tiff',
|
||||
'tif' => 'image/tiff',
|
||||
'svg' => 'image/svg+xml',
|
||||
'svgz' => 'image/svg+xml',
|
||||
|
||||
// archives
|
||||
'zip' => 'application/zip',
|
||||
'rar' => 'application/x-rar-compressed',
|
||||
'exe' => 'application/x-msdownload',
|
||||
'msi' => 'application/x-msdownload',
|
||||
'cab' => 'application/vnd.ms-cab-compressed',
|
||||
|
||||
// audio/video
|
||||
'mp3' => 'audio/mpeg',
|
||||
'qt' => 'video/quicktime',
|
||||
'mov' => 'video/quicktime',
|
||||
|
||||
// adobe
|
||||
'pdf' => 'application/pdf',
|
||||
'psd' => 'image/vnd.adobe.photoshop',
|
||||
'ai' => 'application/postscript',
|
||||
'eps' => 'application/postscript',
|
||||
'ps' => 'application/postscript',
|
||||
|
||||
// ms office
|
||||
'doc' => 'application/msword',
|
||||
'rtf' => 'application/rtf',
|
||||
'xls' => 'application/vnd.ms-excel',
|
||||
'ppt' => 'application/vnd.ms-powerpoint',
|
||||
|
||||
// open office
|
||||
'odt' => 'application/vnd.oasis.opendocument.text',
|
||||
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
||||
);
|
||||
|
||||
if (array_key_exists($ext, $ext2Mime)) {
|
||||
$mime = $ext2Mime[$ext];
|
||||
} else {
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
if (false !== ($_mime = finfo_file($finfo, $path))) {
|
||||
$mime = $_mime;
|
||||
}
|
||||
finfo_close($finfo);
|
||||
}
|
||||
|
||||
header('Content-Type: ' . $mime);
|
||||
header('Content-Length: ' . filesize($path));
|
||||
|
||||
ob_clean();
|
||||
flush();
|
||||
readfile($path);
|
||||
exit;
|
||||
} else {
|
||||
return $next($request, $response);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request, $response);
|
||||
}
|
||||
}
|
@ -130,5 +130,8 @@ new Inforbank\Application\API\Handler($app);
|
||||
* - http://php.net/manual/en/language.oop5.basic.php (over de class)
|
||||
*/
|
||||
|
||||
// Add the asset Proxy
|
||||
$app->add(new Inforbank\Proxy());
|
||||
|
||||
// Run app
|
||||
$app->run();
|
||||
|
@ -17,14 +17,14 @@
|
||||
echo " " . $klant['tussenvoegsel'];
|
||||
}
|
||||
?> <?= $klant['achternaam'] ?><br/>
|
||||
<a href="/logout">Uitloggen</a>
|
||||
<a href="logout">Uitloggen</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="menu">
|
||||
<div class="container">
|
||||
<ul class="nv">
|
||||
<li><a href="/">Rekeningen</a></li>
|
||||
<li><a href="rekeningen">Rekeningen</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user