Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch for PaaS providers (Orchestra in particular) #277

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/configs/openphoto-SUSE-vhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/configs/openphoto-vhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/html/assets/themes/default/stylesheets/setup.css
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
20 changes: 20 additions & 0 deletions src/html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@

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))
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/controllers/ApiPhotoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
88 changes: 59 additions & 29 deletions src/libraries/controllers/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'));
}

Expand Down Expand Up @@ -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')
);

Expand All @@ -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']))
Expand Down Expand Up @@ -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}).";
}
Expand Down Expand Up @@ -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.<ul><li>Make sure the user <em>{$user}</em> can write to <em>{$configDir}</em>.</li></ul>";

if(!file_exists($generatedDir))
{
$createDir = mkdir($generatedDir, 0700);
if(!$createDir)
$errors[] = "Could not create configuration directory.<ul><li>Make sure the user <em>{$user}</em> can write to <em>{$generatedDir}</em>.</li></ul>";
$warnings['config_not_writable'] = "<em>{$configDir}</em> is not writable. <ul><li>You can either make the directory writable by <em>{$user}</em> or,</li><li>manually upload the config at the end of the setup.</li></ul>";
}
elseif(!is_writable($generatedDir))
else
{
$errors[] = "Directory exist but is not writable.<ul><li>Make sure the user <em>{$user}</em> can write to <em>{$generatedDir}</em>.</li></ul>";
}
if(!file_exists($generatedDir))
{
$createDir = mkdir($generatedDir, 0700);
if(!$createDir)
$warnings['cannot_create_generated'] = "Could not create configuration directory.<ul><li>Make sure the user <em>{$user}</em> can write to <em>{$generatedDir}</em>.</li></ul>";
}
elseif(!is_writable($generatedDir))
{
$warnings['generated_not_writable'] = "Directory exist but is not writable.<ul><li>Make sure the user <em>{$user}</em> can write to <em>{$generatedDir}</em>.</li></ul>";
}

if(empty($imageLibs))
$errors[] = 'No suitable image library exists.<ul><li>Make sure that one of the following are installed: <em><a href="http://php.net/imagick">Imagick</a></em>, <em><a href="http://php.net/gmagick">Gmagick</a></em>, or <em><a href="http://php.net/gd">GD</a></em>.</li></ul>';
if(empty($imageLibs))
$warnings['no_image_lib'] = 'No suitable image library exists.<ul><li>Make sure that one of the following are installed: <em><a href="http://php.net/imagick">Imagick</a></em>, <em><a href="http://php.net/gmagick">Gmagick</a></em>, or <em><a href="http://php.net/gd">GD</a></em>.</li></ul>';
}

return $errors;
return $warnings;
}

/**
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/models/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/templates/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</select>

<input type="hidden" name="appId" id="appId" <?php if(isset($appId)) { ?>value="<?php Utility::safe($appId); ?>"<?php } ?>>
<input type="hidden" name="skipConfig" id="skipConfig" <?php if($skipConfig == 1) { ?>value="<?php Utility::safe($skipConfig); ?>"<?php } ?>>
<button type="submit">Continue to Step 2</button>
</form>
</div>
Expand Down Expand Up @@ -115,4 +116,10 @@
<button type="submit">Complete setup</button>
</form>
</div>
<div id="setup-step-4"<?php echo ($step != 4) ? ' class="hidden"' : ''?>>
<h2>Configuration</h2>
<p>Copy and paste the details below into a file named <code><?php Utility::safe($iniName); ?></code> in the folder <code><?php Utility::safe($generatedDir); ?></code> (you may have to create this folder)</p>
<textarea cols="80" rows="65"><?php Utility::safe($generatedIni) ?></textarea>
<p>Once the configuration is in place, <a href="/">you're done!</a>.</p>
</div>
</div>