make tests/router.php more like .htaccess
This commit is contained in:
parent
69cb67fe24
commit
1d389f0156
3 changed files with 26 additions and 21 deletions
|
@ -17,8 +17,7 @@
|
||||||
# rather than link to images/ha/hash and have an ugly filename,
|
# rather than link to images/ha/hash and have an ugly filename,
|
||||||
# we link to images/hash/tags.ext; mod_rewrite splits things so
|
# we link to images/hash/tags.ext; mod_rewrite splits things so
|
||||||
# that shimmie sees hash and the user sees tags.ext
|
# that shimmie sees hash and the user sees tags.ext
|
||||||
RewriteRule ^_images/([0-9a-f]{2})([0-9a-f]{30}).*$ data/images/$1/$1$2 [L]
|
RewriteRule ^_(images|thumbs)/([0-9a-f]{2})([0-9a-f]{30}).*$ data/$1/$2/$2$3 [L]
|
||||||
RewriteRule ^_thumbs/([0-9a-f]{2})([0-9a-f]{30}).*$ data/thumbs/$1/$1$2 [L]
|
|
||||||
|
|
||||||
# any requests for files which don't physically exist should be handled by index.php
|
# any requests for files which don't physically exist should be handled by index.php
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
|
|
@ -3,4 +3,10 @@ groupadd -g $GID shimmie
|
||||||
useradd -ms /bin/bash -u $UID -g $GID shimmie
|
useradd -ms /bin/bash -u $UID -g $GID shimmie
|
||||||
mkdir /app/data
|
mkdir /app/data
|
||||||
chown shimmie:shimmie /app/data
|
chown shimmie:shimmie /app/data
|
||||||
exec /usr/local/bin/su-exec shimmie:shimmie /usr/bin/php -d upload_max_filesize=50M -d post_max_size=50M -S 0.0.0.0:8000 tests/router.php
|
export PHP_CLI_SERVER_WORKERS=8
|
||||||
|
exec /usr/local/bin/su-exec shimmie:shimmie \
|
||||||
|
/usr/bin/php \
|
||||||
|
-d upload_max_filesize=50M \
|
||||||
|
-d post_max_size=50M \
|
||||||
|
-S 0.0.0.0:8000 \
|
||||||
|
tests/router.php
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
// custom routing for stand-alone mode
|
// custom routing for stand-alone mode, basically
|
||||||
|
// .htaccess for the built-in php web server
|
||||||
if (PHP_SAPI !== 'cli-server') {
|
if (PHP_SAPI !== 'cli-server') {
|
||||||
die('cli only');
|
die('cli only');
|
||||||
}
|
}
|
||||||
|
|
||||||
// warehouse files
|
// warehouse files
|
||||||
@include_once "data/config/shimmie.conf.php";
|
|
||||||
@include_once "data/config/extensions.conf.php";
|
|
||||||
require_once "core/sys_config.php";
|
|
||||||
require_once "core/polyfills.php";
|
|
||||||
require_once "core/util.php";
|
|
||||||
|
|
||||||
$matches = [];
|
$matches = [];
|
||||||
if (preg_match('/\/_(images|thumbs)\/([0-9a-f]{32}).*$/', $_SERVER["REQUEST_URI"], $matches)) {
|
if (preg_match('/\/_(images|thumbs)\/([0-9a-f]{2})([0-9a-f]{30}).*$/', $_SERVER["REQUEST_URI"], $matches)) {
|
||||||
header('Content-Type: image/jpeg');
|
header('Content-Type: image/jpeg');
|
||||||
header("Cache-control: public, max-age=86400");
|
header("Cache-control: public, max-age=86400");
|
||||||
print(file_get_contents(warehouse_path($matches[1], $matches[2])));
|
print(file_get_contents("data/$matches[1]/$matches[2]/$matches[2]$matches[3]"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the default handler (serve static files, interpret php files)
|
// if file exists, serve it as normal
|
||||||
elseif (preg_match('/\.(?:png|jpg|jpeg|gif|css|js|php)(\?.*)?$/', $_SERVER["REQUEST_URI"])) {
|
elseif (is_file("." . explode("?", $_SERVER["REQUEST_URI"])[0])) {
|
||||||
if (!preg_match('/register\.php(\?.*)?$/', $_SERVER["REQUEST_URI"])) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
unset($matches);
|
|
||||||
|
|
||||||
// all other requests (use shimmie routing based on URL)
|
// all other requests (use shimmie routing based on URL)
|
||||||
$_GET['q'] = explode("?", $_SERVER["REQUEST_URI"])[0];
|
else {
|
||||||
error_log($_GET['q']); // if we use a custom handler, we need to do our own access log
|
unset($matches);
|
||||||
require_once "index.php";
|
// PHP_SELF is very unreliable, but there's no(?) better way to know what
|
||||||
|
// website subdirectory we're installed in - if we're using router.php, then
|
||||||
|
// let's blindly assume that we're in the root directory.
|
||||||
|
$_SERVER["PHP_SELF"] = "/index.php";
|
||||||
|
$_GET['q'] = explode("?", $_SERVER["REQUEST_URI"])[0];
|
||||||
|
// if we use a custom handler, we need to do our own access log
|
||||||
|
error_log("{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} [???]: {$_GET['q']}");
|
||||||
|
require_once "index.php";
|
||||||
|
}
|
||||||
|
|
Reference in a new issue