aboutsummaryrefslogtreecommitdiffstats
path: root/storage-backend/index.php
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-01-04 21:48:17 +0100
committersteckbrief <steckbrief@chefmail.de>2016-01-04 21:48:17 +0100
commitfbba3876b537e84699b854e098936a5cd4fe0c8b (patch)
tree25ab681f333b83dc7b6859aa7b9504d158a497ec /storage-backend/index.php
parent45cd34e42b9a980b76b66310c823fc8d2f5b55cb (diff)
Reduced manual configuration, folder structure created
Determination of storage paths now relative to script directory and programmatically Determination of get and put URLs now based on the slot request request Basic access restriction to default directories
Diffstat (limited to 'storage-backend/index.php')
-rw-r--r--storage-backend/index.php42
1 files changed, 41 insertions, 1 deletions
diff --git a/storage-backend/index.php b/storage-backend/index.php
index 1753055..d9c82d5 100644
--- a/storage-backend/index.php
+++ b/storage-backend/index.php
@@ -31,7 +31,12 @@
$method = $_SERVER['REQUEST_METHOD'];
// Load configuration
-$config = require('config.php');
+$config = require(__DIR__.'/config/config.php');
+// Initialize directory config
+$config['storage_base_path'] = __DIR__.'/files/';
+$config['slot_registry_dir'] = __DIR__.'/slots/';
+$config['base_url_put'] = getServerProtocol()."://".getRequestHostname().getRequestUriWithoutFilename().'files/';
+$config['base_url_get'] = $config['base_url_put'];
switch ($method) {
case 'POST':
@@ -173,6 +178,41 @@ function getUploadFilePath($slotUUID, $config, $filename = NULL) {
}
/**
+ * Inspired by https://github.com/owncloud/core/blob/master/lib/private/appframework/http/request.php#L523
+ */
+function getServerProtocol() {
+ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
+ if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], ',') !== false) {
+ $parts = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO']);
+ $proto = strtolower(trim($parts[0]));
+ } else {
+ $proto = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']);
+ }
+ // Verify that the protocol is always HTTP or HTTPS
+ // default to http if an invalid value is provided
+ return $proto === 'https' ? 'https' : 'http';
+ }
+ if (isset($_SERVER['HTTPS'])
+ && $_SERVER['HTTPS'] !== null
+ && $_SERVER['HTTPS'] !== 'off'
+ && $_SERVER['HTTPS'] !== '') {
+ return 'https';
+ }
+ return 'http';
+}
+
+function getRequestHostname() {
+ if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
+ return strtolower($_SERVER['HTTP_X_FORWARDED_HOST']);
+ }
+ return strtolower($_SERVER['HTTP_HOST']);
+}
+
+function getRequestUriWithoutFilename() {
+ return strtolower(substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1));
+}
+
+/**
* Copied from http://rogerstringer.com/2013/11/15/generate-uuids-php/
*/
function generate_uuid() {