From 6583cb898aadf45b8966ce6f85a11eaeaf36111d Mon Sep 17 00:00:00 2001 From: Ross Duggan Date: Thu, 27 Oct 2011 00:54:18 +0100 Subject: [PATCH 1/5] Try some more standard routing options if __route__ is not set --- src/html/index.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/html/index.php b/src/html/index.php index 36284499f..98f1a162b 100644 --- a/src/html/index.php +++ b/src/html/index.php @@ -8,6 +8,25 @@ require sprintf('%s/libraries/initialize.php', dirname(dirname(__FILE__))); +// If custom route is not being used, try some more common routing cases +if (!isset($_GET['__route__'])) +{ + if (isset($_SERVER['PATH_INFO'])) + { + $_GET['__route__'] = $_SERVER['PATH_INFO']; + } + else if (isset($_SERVER['REQUEST_URI'])) + { + if ($request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)) + { + $_GET['__route__'] = $request_uri; + } + } else if (isset($_SERVER['PHP_SELF'])) + { + $_GET['__route__'] = $_SERVER['PHP_SELF']; + } +} + // if we're not running setup and the config file exists, proceed as normal // else no config file then load up the setup dependencies if(!$runSetup && file_exists($configFile)) From e382fa1cbaf09b4fd1794c7384758c76fa37a260 Mon Sep 17 00:00:00 2001 From: Ross Duggan Date: Thu, 27 Oct 2011 00:55:27 +0100 Subject: [PATCH 2/5] Allow user to manually add config after setup process --- .../themes/default/stylesheets/setup.css | 2 + src/libraries/controllers/SetupController.php | 88 +++++++++++++------ src/templates/setup.php | 7 ++ 3 files changed, 68 insertions(+), 29 deletions(-) diff --git a/src/html/assets/themes/default/stylesheets/setup.css b/src/html/assets/themes/default/stylesheets/setup.css index 0d5fd7ae5..8924f2bd2 100644 --- a/src/html/assets/themes/default/stylesheets/setup.css +++ b/src/html/assets/themes/default/stylesheets/setup.css @@ -5,6 +5,8 @@ div#setup h3{ font-size:1em; margin:15px 0 5px 0; } div#setup ul.errors, div#setup p.error{ color:#ca1616; } div#setup form em{ font-size:.75em; } div#setup label{ font-size:1.15em; color:#404040; display:block; position:relative; } +div#setup p{ font-size:1.0em; color:#404040; display:block; position:relative; margin-bottom:20px; } +div#setup p code{ font-size:1.0em; font-family: monospace, sans-serif; background-color:#ddd; border: 1px solid #eee; color:#404040; display:block; position:relative; } div#setup label em{ font-size:.6em; position:relative; top:-2px; left:3px; } div#setup label + input, div#setup label + textarea, div#setup label + select{ margin-bottom:20px; display:block; } div#setup{ width:400px; margin:auto; } diff --git a/src/libraries/controllers/SetupController.php b/src/libraries/controllers/SetupController.php index 837ae99eb..baa9722f9 100644 --- a/src/libraries/controllers/SetupController.php +++ b/src/libraries/controllers/SetupController.php @@ -42,12 +42,24 @@ public static function setup() $theme = getTheme()->getThemeName(); $themes = getTheme()->getThemes(); - $errors = self::verifyRequirements($imageLibs); + $warnings = self::verifyRequirements($imageLibs); - if(count($errors) > 0) - $step = 0; - else - $errors = ''; + $skipConfig = 0; + foreach ($warnings as $error => $message) { + switch ($error) + { + case 'config_not_writable': + $skipConfig = 1; + $step = 1; + break; + case 'cannot_create_generated': + case 'generated_not_writable': + case 'no_image_lib': + default: + $step = 0; + break; + } + } $email = ''; if(getConfig()->get('user') != null) @@ -61,7 +73,7 @@ public static function setup() $template = sprintf('%s/setup.php', getConfig()->get('paths')->templates); $body = getTemplate()->get($template, array('filesystem' => $filesystem, 'database' => $database, 'themes' => $themes, 'theme' => $theme, - 'imageLibs' => $imageLibs, 'imageLibrary' => $imageLibrary, 'appId' => $appId, 'step' => $step, 'email' => $email, 'qs' => $qs, 'errors' => $errors)); + 'imageLibs' => $imageLibs, 'imageLibrary' => $imageLibrary, 'appId' => $appId, 'step' => $step, 'email' => $email, 'qs' => $qs, 'errors' => $warnings, 'skipConfig' => $skipConfig)); getTheme()->display('template.php', array('body' => $body, 'page' => 'setup')); } @@ -167,11 +179,12 @@ public static function setupDropboxPost() */ public static function setupPost() { - $step = 1; - $appId = isset($_POST['appId']) ? $_POST['appId'] : ''; - $email = isset($_POST['email']) ? $_POST['email'] : ''; - $theme = isset($_POST['theme']) ? $_POST['theme'] : ''; - $input = array( + $step = 1; + $appId = isset($_POST['appId']) ? $_POST['appId'] : ''; + $email = isset($_POST['email']) ? $_POST['email'] : ''; + $theme = isset($_POST['theme']) ? $_POST['theme'] : ''; + $skipConfig = isset($_POST['skipConfig']) ? $_POST['skipConfig'] : ''; + $input = array( array('Email', $email, 'required') ); @@ -182,6 +195,7 @@ public static function setupPost() getSession()->set('appId', $appId); getSession()->set('ownerEmail', $email); getSession()->set('theme', $theme); + getSession()->set('skipConfig', $skipConfig); $qs = ''; if(isset($_GET['edit'])) @@ -558,7 +572,7 @@ public static function setup3Post() { $writeError = self::writeConfigFile(); if($writeErrors === false) - getRoute()->redirect('/?m=welcome'); + getRoute()->redirect('/'); else $writeErrors[] = "We were unable to save your settings file. Please make sure that the following user has proper permissions to write to src/configs ({$user})."; } @@ -640,36 +654,40 @@ private static function getDefaultConfigParams() */ private static function verifyRequirements($imageLibs) { - $errors = array(); + $warnings = array(); $configDir = Utility::getBaseDir() . '/configs'; $generatedDir = "{$configDir}/generated"; if(file_exists($generatedDir) && is_writable($generatedDir) && !empty($imageLibs)) # No errors, return empty array - return $errors; + return $warnings; $user = exec("whoami"); if(empty($user)) $user = 'Apache user'; if(!is_writable($configDir)) - $errors[] = "Insufficient privileges to complete setup."; - - if(!file_exists($generatedDir)) { - $createDir = mkdir($generatedDir, 0700); - if(!$createDir) - $errors[] = "Could not create configuration directory."; + $warnings['config_not_writable'] = "{$configDir} is not writable. "; } - elseif(!is_writable($generatedDir)) + else { - $errors[] = "Directory exist but is not writable."; - } + if(!file_exists($generatedDir)) + { + $createDir = mkdir($generatedDir, 0700); + if(!$createDir) + $warnings['cannot_create_generated'] = "Could not create configuration directory."; + } + elseif(!is_writable($generatedDir)) + { + $warnings['generated_not_writable'] = "Directory exist but is not writable."; + } - if(empty($imageLibs)) - $errors[] = 'No suitable image library exists.'; + if(empty($imageLibs)) + $warnings['no_image_lib'] = 'No suitable image library exists.'; + } - return $errors; + return $warnings; } /** @@ -737,9 +755,21 @@ private static function writeConfigFile() file_get_contents("{$configDir}/template.ini") ); - $iniWritten = file_put_contents(sprintf("%s/generated/%s.ini", $configDir, getenv('HTTP_HOST')), $generatedIni); - if(!$iniWritten) - return false; + if (getSession()->get('skipConfig') == 1) + { + $step = 4; + $iniName = sprintf("%s.ini", getenv('HTTP_HOST')); + $generatedDir = $configDir . '/generated/'; + // Output config to a text box for copying. + $template = sprintf('%s/setup.php', getConfig()->get('paths')->templates); + $body = getTemplate()->get($template, array('step' => $step, 'generatedIni' => $generatedIni, 'iniName' => $iniName, 'generatedDir' => $generatedDir)); + getTheme()->display('template.php', array('body' => $body, 'page' => 'setup')); + } + else { + $iniWritten = file_put_contents(sprintf("%s/generated/%s.ini", $configDir, getenv('HTTP_HOST')), $generatedIni); + if(!$iniWritten) + return false; + } // clean up the session foreach($session as $key => $val) diff --git a/src/templates/setup.php b/src/templates/setup.php index 1fed72711..6c2a1025a 100644 --- a/src/templates/setup.php +++ b/src/templates/setup.php @@ -30,6 +30,7 @@ value=""> + value=""> @@ -115,4 +116,10 @@ + From 045293866b8d94df68e1c5008d616e4120ef06d8 Mon Sep 17 00:00:00 2001 From: Ross Duggan Date: Thu, 27 Oct 2011 03:13:25 +0100 Subject: [PATCH 3/5] Change jpg -> jpe to prevent common web server configurations from bypassing routing --- src/libraries/controllers/ApiPhotoController.php | 2 +- src/libraries/models/Photo.php | 4 ++-- src/libraries/routes.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/controllers/ApiPhotoController.php b/src/libraries/controllers/ApiPhotoController.php index 2a28f24b6..0307d5beb 100644 --- a/src/libraries/controllers/ApiPhotoController.php +++ b/src/libraries/controllers/ApiPhotoController.php @@ -237,7 +237,7 @@ public static function upload() { unset($attributes['photo']); $localFile = tempnam(getConfig()->get('paths')->temp, 'opme'); - $name = basename($localFile).'.jpg'; + $name = basename($localFile).'.jpe'; file_put_contents($localFile, base64_decode($_POST['photo'])); $photoId = Photo::upload($localFile, $name, $attributes); } diff --git a/src/libraries/models/Photo.php b/src/libraries/models/Photo.php index 6931ef8c5..ff11a31e5 100644 --- a/src/libraries/models/Photo.php +++ b/src/libraries/models/Photo.php @@ -149,7 +149,7 @@ public static function generateUrlInternal($id, $width, $height, $options = null { $fragment = self::generateFragment($width, $height, $options); $hash = self::generateHash($id, $width, $height, $options); - return sprintf('/photo/%s/create/%s/%s.jpg', $id, $hash, $fragment); + return sprintf('/photo/%s/create/%s/%s.jpe', $id, $hash, $fragment); } /** @@ -412,7 +412,7 @@ private static function generateCustomUrl($basePath, $width, $height, $options) $fragment = self::generateFragment($width, $height, $options); $customPath = preg_replace('#^/base/#', '/custom/', $basePath); $customName = substr($customPath, 0, strrpos($customPath, '.')); - return "{$customName}_{$fragment}.jpg"; + return "{$customName}_{$fragment}.jpe"; } /** diff --git a/src/libraries/routes.php b/src/libraries/routes.php index 2499fb487..d3184fc4b 100644 --- a/src/libraries/routes.php +++ b/src/libraries/routes.php @@ -22,7 +22,7 @@ * /photo/{id}[/{additional}] */ getRoute()->get('/photo/([a-zA-Z0-9]+)/edit', array('PhotoController', 'edit')); // edit form for a photo (/photo/{id}/edit) -getRoute()->get('/photo/([a-zA-Z0-9]+)/create/([a-z0-9]+)/([0-9]+)x([0-9]+)x?(.*).jpg', array('PhotoController', 'create')); // create a version of a photo (/photo/create/{id}/{options}.jpg) +getRoute()->get('/photo/([a-zA-Z0-9]+)/create/([a-z0-9]+)/([0-9]+)x([0-9]+)x?(.*).jpe', array('PhotoController', 'create')); // create a version of a photo (/photo/create/{id}/{options}.jpg) getRoute()->get('/photo/([a-zA-Z0-9]+)/view/?(.+)?', array('PhotoController', 'view')); // view a photo (/photo/{id}/view[/{options}]) getRoute()->post('/photo/([a-zA-Z0-9]+)/update', array('PhotoController', 'update')); // update a photo (/photo/{id}/update getRoute()->post('/photo/upload', array('PhotoController', 'uploadPost')); // upload a photo From d2a8f088fd57b5621c8807bf934d21d304511183 Mon Sep 17 00:00:00 2001 From: Ross Duggan Date: Thu, 27 Oct 2011 03:53:37 +0100 Subject: [PATCH 4/5] update config examples to contain .jpe --- src/configs/openphoto-SUSE-vhost.conf | 1 + src/configs/openphoto-vhost.conf | 1 + 2 files changed, 2 insertions(+) diff --git a/src/configs/openphoto-SUSE-vhost.conf b/src/configs/openphoto-SUSE-vhost.conf index 274ea4142..a33371e48 100644 --- a/src/configs/openphoto-SUSE-vhost.conf +++ b/src/configs/openphoto-SUSE-vhost.conf @@ -35,6 +35,7 @@ ExpiresByType image/gif "A604800" ExpiresByType image/jpg "A604800" ExpiresByType image/jpeg "A604800" + ExpiresByType image/jpe "A604800" ExpiresByType image/png "A604800" Header set Cache-Control "must-revalidate" diff --git a/src/configs/openphoto-vhost.conf b/src/configs/openphoto-vhost.conf index 2e041bd0d..26253a8ce 100644 --- a/src/configs/openphoto-vhost.conf +++ b/src/configs/openphoto-vhost.conf @@ -34,6 +34,7 @@ ExpiresByType image/gif "A604800" ExpiresByType image/jpg "A604800" ExpiresByType image/jpeg "A604800" + ExpiresByType image/jpe "A604800" ExpiresByType image/png "A604800" Header set Cache-Control "must-revalidate" From 1c1232a1fead1dcd6151b5badf7a6725c973cbf7 Mon Sep 17 00:00:00 2001 From: Ross Duggan Date: Thu, 27 Oct 2011 04:23:50 +0100 Subject: [PATCH 5/5] correct minor deviation from braces style --- src/html/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/html/index.php b/src/html/index.php index 98f1a162b..23c15f282 100644 --- a/src/html/index.php +++ b/src/html/index.php @@ -21,7 +21,8 @@ { $_GET['__route__'] = $request_uri; } - } else if (isset($_SERVER['PHP_SELF'])) + } + else if (isset($_SERVER['PHP_SELF'])) { $_GET['__route__'] = $_SERVER['PHP_SELF']; }