From 790bf4e871b1a1555dc32287ab222b6694d402a2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 22 Sep 2010 21:35:49 -0700 Subject: Prioritize using the value in graphics_toolkit_path over the standard path so that if you change that value in Admin > Settings > Advanced we prefer it over other paths (which may be restricted by open_basedir). Fixes #1395. --- modules/gallery/helpers/gallery.php | 13 +++++++++++++ modules/gallery/helpers/graphics.php | 9 ++++----- modules/gallery/helpers/movie.php | 9 ++++----- 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index ca8c92c9..3cf0eacd 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -140,4 +140,17 @@ class gallery_Core { return $file_name; } + /** + * Set the PATH environment variable to the paths specified. + * @param array Array of paths. Each array entry can contain a colon separated list of paths. + */ + static function set_path_env($paths) { + $path_env = array(); + foreach ($paths as $path) { + if ($path) { + array_push($path_env, $path); + } + } + putenv("PATH=" . implode(":", $path_env)); + } } \ No newline at end of file diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 2868a28d..dd521d84 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -313,11 +313,10 @@ class graphics_Core { $toolkits->graphicsmagick->installed = false; $toolkits->graphicsmagick->error = t("GraphicsMagick requires the exec function"); } else { - $graphics_path = module::get_var("gallery", "graphics_toolkit_path", null); - $extra_binary_paths = module::get_var("gallery", "extra_binary_paths", null); - - putenv("PATH=" . getenv("PATH") . (empty($graphics_path) ? "" : ":$graphics_path") . - ":" . $extra_binary_paths); + gallery::set_path_env( + array(module::get_var("gallery", "graphics_toolkit_path"), + getenv("PATH"), + module::get_var("gallery", "extra_binary_paths"))); // @todo: consider refactoring the two segments below into a loop since they are so // similar. diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 50339541..78358b6b 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -85,11 +85,10 @@ class movie_Core { static function find_ffmpeg() { if (!($ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) || !file_exists($ffmpeg_path)) { - $graphics_path = module::get_var("gallery", "graphics_toolkit_path", null); - $extra_binary_paths = module::get_var("gallery", "extra_binary_paths", null); - - putenv("PATH=" . getenv("PATH") . (empty($graphics_path) ? "" : ":$graphics_path") . - ":" . $extra_binary_paths); + gallery::set_path_env( + array(module::get_var("gallery", "graphics_toolkit_path"), + getenv("PATH"), + module::get_var("gallery", "extra_binary_paths"))); if (function_exists("exec")) { $ffmpeg_path = exec("which ffmpeg"); } -- cgit v1.2.3 From ef8751468b998baddbc6d5827a392ed6e12e5548 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 25 Sep 2010 13:27:35 -0700 Subject: Base64 encode the data result if the encoding param is set to "base64". Fixes #1400. --- modules/gallery/helpers/data_rest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/data_rest.php b/modules/gallery/helpers/data_rest.php index 98c98894..791de9c0 100644 --- a/modules/gallery/helpers/data_rest.php +++ b/modules/gallery/helpers/data_rest.php @@ -72,7 +72,12 @@ class data_rest_Core { header("Content-Type: {$item->mime_type}"); } Kohana::close_buffers(false); - readfile($file); + + if (isset($p->encoding) && $p->encoding == "base64") { + print base64_encode(file_get_contents($file)); + } else { + readfile($file); + } // We must exit here to keep the regular REST framework reply code from adding more bytes on // at the end or tinkering with headers. -- cgit v1.2.3 From f84782d6200efb424731c93bd029c7cbeb9f3dad Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 29 Sep 2010 20:47:43 -0700 Subject: Stop caching all module variables in the vars table using the name=_cache row. If that overflows, it will cause us to be unable to load variables, and we can't recover from that. Instead, use the Cache table. Bump the gallery module to v40. Fixes ticket #1405. --- modules/gallery/controllers/packager.php | 5 -- modules/gallery/helpers/gallery_installer.php | 7 ++- modules/gallery/helpers/module.php | 55 ++++------------------ modules/gallery/module.info | 2 +- .../gallery/views/admin_advanced_settings.html.php | 1 - 5 files changed, 15 insertions(+), 55 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php index f463d0de..bd51b93c 100644 --- a/modules/gallery/controllers/packager.php +++ b/modules/gallery/controllers/packager.php @@ -81,11 +81,6 @@ class Packager_Controller extends Controller { Database::instance()->query("TRUNCATE {caches}"); Database::instance()->query("TRUNCATE {sessions}"); Database::instance()->query("TRUNCATE {logs}"); - db::build() - ->delete("vars") - ->where("module_name", "=", "gallery") - ->where("name", "=", "_cache") - ->execute(); db::build()->update("users") ->set(array("password" => "")) ->where("id", "in", array(1, 2)) diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 83961d6b..3d82bc69 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -309,7 +309,7 @@ class gallery_installer { module::set_var("gallery", "show_user_profiles_to", "registered_users"); module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin"); - module::set_version("gallery", 40); + module::set_version("gallery", 41); } static function upgrade($version) { @@ -637,6 +637,11 @@ class gallery_installer { module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin"); module::set_version("gallery", $version = 40); } + + if ($version == 40) { + module::clear_var("gallery", "_cache"); + module::set_version("gallery", $version = 41); + } } static function uninstall() { diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 7863520e..64d0d1d6 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -425,48 +425,21 @@ class module_Core { * @return the value */ static function get_var($module_name, $name, $default_value=null) { - // We cache all vars in gallery._cache so that we can load all vars at once for - // performance. + // We cache vars so we can load them all at once for performance. if (empty(self::$var_cache)) { - $row = db::build() - ->select("value") - ->from("vars") - ->where("module_name", "=", "gallery") - ->where("name", "=", "_cache") - ->execute() - ->current(); - if ($row) { - self::$var_cache = unserialize($row->value); - } else { - // gallery._cache doesn't exist. Create it now. + self::$var_cache = Cache::instance()->get("var_cache"); + if (empty(self::$var_cache)) { + // Cache doesn't exist, create it now. foreach (db::build() ->select("module_name", "name", "value") ->from("vars") ->order_by("module_name") ->order_by("name") ->execute() as $row) { - if ($row->module_name == "gallery" && $row->name == "_cache") { - // This could happen if there's a race condition - continue; - } // Mute the "Creating default object from empty value" warning below @self::$var_cache->{$row->module_name}->{$row->name} = $row->value; } - $cache = ORM::factory("var"); - $cache->module_name = "gallery"; - $cache->name = "_cache"; - $cache->value = serialize(self::$var_cache); - try { - $cache->save(); - } catch (Database_Exception $e) { - // There's a potential race condition here. Don't fail if that happens because it's - // bound to be transient and not a huge deal, but at least put something in the logs. - if (stristr($e->getMessage(), "duplicate entry")) { - Kohana_Log::add("error", "Failed to cache vars"); - } else { - throw $e; - } - } + Cache::instance()->set("var_cache", self::$var_cache, array("vars")); } } @@ -495,11 +468,7 @@ class module_Core { $var->value = $value; $var->save(); - db::build() - ->delete("vars") - ->where("module_name", "=", "gallery") - ->where("name", "=", "_cache") - ->execute(); + Cache::instance()->delete("var_cache"); self::$var_cache = null; } @@ -524,11 +493,7 @@ class module_Core { ->where("name", "=", $name) ->execute(); - db::build() - ->delete("vars") - ->where("module_name", "=", "gallery") - ->where("name", "=", "_cache") - ->execute(); + Cache::instance()->delete("var_cache"); self::$var_cache = null; } @@ -546,11 +511,7 @@ class module_Core { $var->delete(); } - db::build() - ->delete("vars") - ->where("module_name", "=", "gallery") - ->where("name", "=", "_cache") - ->execute(); + Cache::instance()->delete("var_cache"); self::$var_cache = null; } diff --git a/modules/gallery/module.info b/modules/gallery/module.info index 1155ddf7..2b684e5e 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 40 +version = 41 diff --git a/modules/gallery/views/admin_advanced_settings.html.php b/modules/gallery/views/admin_advanced_settings.html.php index 1f7d2f64..edaeecaf 100644 --- a/modules/gallery/views/admin_advanced_settings.html.php +++ b/modules/gallery/views/admin_advanced_settings.html.php @@ -17,7 +17,6 @@ - module_name == "gallery" && $var->name == "_cache") continue ?> "> module_name ?> name) ?> -- cgit v1.2.3 From c0022dc3c35024ecfc101171bdccfc3b07227ebb Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 1 Oct 2010 21:17:08 -0700 Subject: Fix a bug in the way we set the mime type for protected image renders. Also whitelist the digibug controller so that it's accessible when the gallery is private, and don't expire old proxies right away since Digibug may request the full size multiple times for different preview operations. Fixes ticket #1410. --- modules/digibug/controllers/digibug.php | 7 +------ modules/gallery/helpers/gallery.php | 8 ++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index 3c2bb115..88d1ace0 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -95,16 +95,11 @@ class Digibug_Controller extends Controller { if (!TEST_MODE) { // Dump out the image - header("Content-Type: $proxy->item->mime_type"); + header("Content-Type: {$proxy->item->mime_type}"); Kohana::close_buffers(false); $fd = fopen($file, "rb"); fpassthru($fd); fclose($fd); - - // If the request was for the image and not the thumb, then delete the proxy. - if ($type == "full") { - $proxy->delete(); - } } $this->_clean_expired(); diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 3cf0eacd..d7d3d9ad 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -25,6 +25,10 @@ class gallery_Core { * down for maintenance" page. */ static function maintenance_mode() { + // @todo: we need a mechanism here to identify controllers that are still legally accessible + // when the entire Gallery is in maintenance mode. Perhaps a controller class function or + // method? + // https://sourceforge.net/apps/trac/gallery/ticket/1411 if (Router::$controller != "login" && Router::$controller != "combined" && module::get_var("gallery", "maintenance_mode", 0) && @@ -41,8 +45,12 @@ class gallery_Core { * the login page. */ static function private_gallery() { + // @todo: we need a mechanism here to identify controllers that are still legally accessible + // when the entire Gallery is private. Perhaps a controller class function or method? + // https://sourceforge.net/apps/trac/gallery/ticket/1411 if (Router::$controller != "login" && Router::$controller != "combined" && + Router::$controller != "digibug" && identity::active_user()->guest && !access::user_can(identity::guest(), "view", item::root()) && php_sapi_name() != "cli") { -- cgit v1.2.3 From 62f1bb06a21c3b07acf8005c30a5d856199d7424 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 2 Oct 2010 13:46:47 -0700 Subject: Set the User-Agent field to "Gallery3" by default. Fixes #1408. --- modules/gallery/helpers/MY_remote.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/MY_remote.php b/modules/gallery/helpers/MY_remote.php index 3e13ba8d..05341330 100644 --- a/modules/gallery/helpers/MY_remote.php +++ b/modules/gallery/helpers/MY_remote.php @@ -63,6 +63,9 @@ class remote extends remote_Core { * WebHelper_simple::_parseLocation logic. */ static function do_request($url, $method='GET', $headers=array(), $body='') { + if (!array_key_exists("User-Agent", $headers)) { + $headers["User-Agent"] = "Gallery3"; + } /* Convert illegal characters */ $url = str_replace(' ', '%20', $url); -- cgit v1.2.3 From 161bbb9ba3fbc10cada28e4ce384a426cabc02d8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 2 Oct 2010 16:44:31 -0700 Subject: Proxy the BasicAuth authentication header in htaccess_works() so that if the entire Gallery is behind BasicAuth we share the same credentials as the browser. Fixes #1413. --- modules/gallery/helpers/access.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index 52a36298..1a448e4a 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -727,8 +727,18 @@ class access_Core { fclose($fp); } - list ($response) = remote::do_request(url::abs_file("var/security_test/verify")); - $works = $response == "HTTP/1.1 200 OK"; + // Proxy our authorization headers so that if the entire Gallery is covered by Basic Auth + // this callback will still work. + $headers = array(); + if (function_exists("apache_request_headers")) { + $arh = apache_request_headers(); + if (!empty($arh["Authorization"])) { + $headers["Authorization"] = $arh["Authorization"]; + } + } + list ($status, $headers, $body) = + remote::do_request(url::abs_file("var/security_test/verify"), "GET", $headers); + $works = ($status == "HTTP/1.1 200 OK") && ($body == "success"); } catch (Exception $e) { @dir::unlink(VARPATH . "security_test"); throw $e; -- cgit v1.2.3 From a153ca082971e1eb454aa66199ee0380a9794a6e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 2 Oct 2010 17:04:37 -0700 Subject: Detect the case where there are no more broken images and skip to the end. Fixes #1414. --- modules/gallery/helpers/gallery_task.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 3b173928..d56edabb 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -84,6 +84,13 @@ class gallery_task_Core { $ignored = $task->get("ignored", array()); $i = 0; + + // If there's no work left to do, skip to the end. This can happen if we resume a task long + // after the work got done in some other task. + if (!$result->count()) { + $completed = $total_count; + } + foreach ($result as $row) { if (array_key_exists($row->id, $ignored)) { continue; -- cgit v1.2.3 From 4b4a2f8d8d170e2c42b202865bc4050ac92694cd Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 4 Oct 2010 23:55:19 -0700 Subject: Set the version to 3.0 final (woot!). --- modules/gallery/helpers/gallery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index d7d3d9ad..b016f436 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class gallery_Core { - const VERSION = "3.0 RC2 (Santa Fe)"; + const VERSION = "3.0 (Santa Fe)"; /** * If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is -- cgit v1.2.3