diff --git a/src/configs/openphoto-SUSE-vhost.conf b/src/configs/openphoto-SUSE-vhost.conf index 7b66b0c69..4f082061d 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 1c06ad125..2551c446a 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" 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/ApiPhotoController.php b/src/libraries/controllers/ApiPhotoController.php index 259daedcf..208079b2a 100644 --- a/src/libraries/controllers/ApiPhotoController.php +++ b/src/libraries/controllers/ApiPhotoController.php @@ -262,7 +262,7 @@ public function upload() { unset($attributes['photo']); $localFile = tempnam($this->config->paths->temp, 'opme'); - $name = basename($localFile).'.jpg'; + $name = basename($localFile).'.jpe'; file_put_contents($localFile, base64_decode($_POST['photo'])); $photoId = $this->photo->upload($localFile, $name, $attributes); } diff --git a/src/libraries/controllers/SetupController.php b/src/libraries/controllers/SetupController.php index 05af2dcdb..ac2cdd613 100644 --- a/src/libraries/controllers/SetupController.php +++ b/src/libraries/controllers/SetupController.php @@ -1,12 +1,12 @@ - * @author Kevin Hornschemeier - */ +* Setup controller for HTML endpoints +* This controls the setup flow when the software is first installed. +* The main purpose of this flow is to generate settings.ini. +* +* @author Jaisen Mathai +* @author Kevin Hornschemeier +*/ class SetupController extends BaseController { /** @@ -55,10 +55,23 @@ public function setup() $errors = $this->verifyRequirements($imageLibs); - if(count($errors) > 0) - $step = 0; - else - $errors = ''; + $skipConfig = 0; + foreach ($errors 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) @@ -178,11 +191,12 @@ public function setupDropboxPost() */ public 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') ); @@ -193,6 +207,7 @@ public function setupPost() getSession()->set('appId', $appId); getSession()->set('ownerEmail', $email); getSession()->set('theme', $theme); + getSession()->set('skipConfig', $skipConfig); $qs = ''; if(isset($_GET['edit'])) @@ -553,7 +568,9 @@ public function setup3Post() $fsObj = getFs(); $dbObj = getDb(); - $serverUser = exec("whoami"); + $serverUser = @exec("whoami"); + if(empty($serverUser)) + $serverUser = 'unknown'; if(!$fsObj->initialize($isEditMode)) { if($usesAws) @@ -577,8 +594,9 @@ public function setup3Post() if($fsErrors === false && $dbErrors === false) { - $writeError = $this->writeConfigFile(); - if($writeErrors === false) + // we negate this because writeConfigFile returns status + $writeStatus = ($this->writeConfigFile() === false); + if($writeStatus === true) { if(isset($_GET['edit'])) { @@ -617,6 +635,9 @@ public function setup3Post() if(isset($_GET['edit'])) $qs = '?edit'; + if(isset($writeStatus) && $writeStatus === false) + $step = 4; + $template = sprintf('%s/setup.php', getConfig()->get('paths')->templates); // copied to/from setup3() $body = $this->template->get($template, array('step' => $step, 'themes' => $themes, 'usesAws' => $usesAws, 'usesMySql' => $usesMySql, @@ -674,36 +695,40 @@ private function getDefaultConfigParams() */ private function verifyRequirements($imageLibs) { - $errors = array(); + $warnings = array(); $configDir = $this->utility->getBaseDir() . '/userdata'; $generatedDir = "{$configDir}/configs"; if(file_exists($generatedDir) && is_writable($generatedDir) && !empty($imageLibs)) # No errors, return empty array - return $errors; + return $warnings; - $user = exec("whoami"); + $user = @exec("whoami"); if(empty($user)) $user = 'Apache user'; if(!is_writable($configDir)) - $errors[] = "Insufficient privileges to complete setup.
  • Make sure the user {$user} can write to {$configDir}.
"; - - if(!file_exists($generatedDir)) { - $createDir = mkdir($generatedDir, 0700); - if(!$createDir) - $errors[] = "Could not create configuration directory.
  • Make sure the user {$user} can write to {$generatedDir}.
"; + $warnings['config_not_writable'] = "{$configDir} is not writable.
  • You can either make the directory writable by {$user} or,
  • manually upload the config at the end of the setup.
"; } - elseif(!is_writable($generatedDir)) + else { - $errors[] = "Directory exist but is not writable.
  • Make sure the user {$user} can write to {$generatedDir}.
"; - } + if(!file_exists($generatedDir)) + { + $createDir = mkdir($generatedDir, 0700); + if(!$createDir) + $warnings['cannot_create_generated'] = "Could not create configuration directory.
  • Make sure the user {$user} can write to {$generatedDir}.
"; + } + elseif(!is_writable($generatedDir)) + { + $warnings['generated_not_writable'] = "Directory exist but is not writable.
  • Make sure the user {$user} can write to {$generatedDir}.
"; + } - 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; } /** @@ -775,9 +800,21 @@ private function writeConfigFile() file_get_contents("{$configDir}/template.ini") ); - $iniWritten = file_put_contents(sprintf("%s/userdata/configs/%s.ini", $baseDir, 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/userdata/configs/%s.ini", $baseDir, getenv('HTTP_HOST')), $generatedIni); + if(!$iniWritten) + return false; + } // clean up the session foreach($session as $key => $val) diff --git a/src/libraries/initialize.php b/src/libraries/initialize.php index 5a97aeb52..d42f11082 100644 --- a/src/libraries/initialize.php +++ b/src/libraries/initialize.php @@ -2,6 +2,27 @@ // TODO, remove these date_default_timezone_set('America/Los_Angeles'); +// If custom route is not being used, try some more common routing cases +// See pull request #277 and issue #293 +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(isset($_GET['__route__']) && strstr($_GET['__route__'], '.json')) header('Content-type: application/json'); diff --git a/src/libraries/models/Photo.php b/src/libraries/models/Photo.php index a443d8e41..c78a0f8ed 100644 --- a/src/libraries/models/Photo.php +++ b/src/libraries/models/Photo.php @@ -520,7 +520,7 @@ private function generateCustomUrl($basePath, $width, $height, $options) $fragment = $this->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/plugins/FacebookConnectPlugin.php b/src/libraries/plugins/FacebookConnectPlugin.php index eb0d0055e..a0e42f3bf 100644 --- a/src/libraries/plugins/FacebookConnectPlugin.php +++ b/src/libraries/plugins/FacebookConnectPlugin.php @@ -47,4 +47,3 @@ public function onBodyEnd() MKP; } } - diff --git a/src/libraries/routes.php b/src/libraries/routes.php index 701303f0a..a9bf2a60c 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 diff --git a/src/templates/setup.php b/src/templates/setup.php index 9a5927013..7335f8070 100644 --- a/src/templates/setup.php +++ b/src/templates/setup.php @@ -40,6 +40,7 @@ value="utility->safe($appId); ?>"> + value="utility->safe($skipConfig); ?>"> + + +