From 25f5c59db6ac482ae2dd7996c9dd6794680c2a5b Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Thu, 31 Jul 2014 23:12:29 +0200 Subject: [PATCH 1/4] Adds configuration variables, TPL and TMP, for RainTPL The path for templates and temporary files are now part of the configuration. For a custom install, it's possible to put these writable directories elsewhere than in the read-only source code. --- index.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 5dd0353..fedad2b 100644 --- a/index.php +++ b/index.php @@ -26,6 +26,8 @@ $GLOBALS['config']['CACHEDIR'] = 'cache'; // Cache directory for thumbnails for $GLOBALS['config']['PAGECACHE'] = 'pagecache'; // Page cache directory. $GLOBALS['config']['ENABLE_LOCALCACHE'] = true; // Enable Shaarli to store thumbnail in a local cache. Disable to reduce webspace usage. $GLOBALS['config']['PUBSUBHUB_URL'] = ''; // PubSubHubbub support. Put an empty string to disable, or put your hub url here to enable. +$GLOBALS['config']['RAINTPL_TMP'] = 'tmp' ; // Raintpl cache directory +$GLOBALS['config']['RAINTPL_TPL'] = 'tpl/' ; // Raintpl template directory (keep the trailling slash!) $GLOBALS['config']['UPDATECHECK_FILENAME'] = $GLOBALS['config']['DATADIR'].'/lastupdatecheck.txt'; // For updates check of Shaarli. $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400 ; // Updates check frequency for Shaarli. 86400 seconds=24 hours // Note: You must have publisher.php in the same directory as Shaarli index.php @@ -63,9 +65,9 @@ error_reporting(E_ALL^E_WARNING); // See all error except warnings. //error_reporting(-1); // See all errors (for debugging only) include "inc/rain.tpl.class.php"; //include Rain TPL -raintpl::$tpl_dir = "tpl/"; // template directory -if (!is_dir('tmp')) { mkdir('tmp',0705); chmod('tmp',0705); } -raintpl::$cache_dir = "tmp/"; // cache directory +raintpl::$tpl_dir = $GLOBALS['config']['RAINTPL_TPL']; // template directory +if (!is_dir($GLOBALS['config']['RAINTPL_TMP'])) { mkdir($GLOBALS['config']['RAINTPL_TMP'],0705); chmod($GLOBALS['config']['RAINTPL_TMP'],0705); } +raintpl::$cache_dir = $GLOBALS['config']['RAINTPL_TMP']; // cache directory ob_start(); // Output buffering for the page cache. @@ -88,7 +90,7 @@ header("Pragma: no-cache"); // Directories creations (Note that your web host may require differents rights than 705.) if (!is_writable(realpath(dirname(__FILE__)))) die('
ERROR: Shaarli does not have the right to write in its own directory ('.realpath(dirname(__FILE__)).').
'); if (!is_dir($GLOBALS['config']['DATADIR'])) { mkdir($GLOBALS['config']['DATADIR'],0705); chmod($GLOBALS['config']['DATADIR'],0705); } -if (!is_dir('tmp')) { mkdir('tmp',0705); chmod('tmp',0705); } // For RainTPL temporary files. +if (!is_dir($GLOBALS['config']['RAINTPL_TMP'])) { mkdir($GLOBALS['config']['RAINTPL_TMP'],0705);chmod($GLOBALS['config']['RAINTPL_TMP'],0705); } // For RainTPL temporary files. if (!is_file($GLOBALS['config']['DATADIR'].'/.htaccess')) { file_put_contents($GLOBALS['config']['DATADIR'].'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. // Second check to see if Shaarli can write in its directory, because on some hosts is_writable() is not reliable. if (!is_file($GLOBALS['config']['DATADIR'].'/.htaccess')) die('
ERROR: Shaarli does not have the right to write in its data directory ('.realpath($GLOBALS['config']['DATADIR']).').
'); From c614a35db8c49bc953c6fcd83161def61a76d945 Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Thu, 31 Jul 2014 23:17:30 +0200 Subject: [PATCH 2/4] Removed redundant check on RAINTPL_TMP directory The same test is already on line 93 --- index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/index.php b/index.php index fedad2b..3301b13 100644 --- a/index.php +++ b/index.php @@ -66,7 +66,6 @@ error_reporting(E_ALL^E_WARNING); // See all error except warnings. include "inc/rain.tpl.class.php"; //include Rain TPL raintpl::$tpl_dir = $GLOBALS['config']['RAINTPL_TPL']; // template directory -if (!is_dir($GLOBALS['config']['RAINTPL_TMP'])) { mkdir($GLOBALS['config']['RAINTPL_TMP'],0705); chmod($GLOBALS['config']['RAINTPL_TMP'],0705); } raintpl::$cache_dir = $GLOBALS['config']['RAINTPL_TMP']; // cache directory ob_start(); // Output buffering for the page cache. From e7416aba2c7a06fc96e37700f555c2b70a5ac859 Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Mon, 4 Aug 2014 00:13:30 +0200 Subject: [PATCH 3/4] Adds empty directories: cache, data, pagecache and tmp. Removes mkdirs. They are still in .gitignore because their future content will still be ignored. --- cache/.placeholder | 0 data/.placeholder | 0 index.php | 4 ---- pagecache/.placeholder | 0 tmp/.placeholder | 0 5 files changed, 4 deletions(-) create mode 100644 cache/.placeholder create mode 100644 data/.placeholder create mode 100644 pagecache/.placeholder create mode 100644 tmp/.placeholder diff --git a/cache/.placeholder b/cache/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/data/.placeholder b/data/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/index.php b/index.php index 3301b13..747f113 100644 --- a/index.php +++ b/index.php @@ -88,14 +88,11 @@ header("Pragma: no-cache"); // Directories creations (Note that your web host may require differents rights than 705.) if (!is_writable(realpath(dirname(__FILE__)))) die('
ERROR: Shaarli does not have the right to write in its own directory ('.realpath(dirname(__FILE__)).').
'); -if (!is_dir($GLOBALS['config']['DATADIR'])) { mkdir($GLOBALS['config']['DATADIR'],0705); chmod($GLOBALS['config']['DATADIR'],0705); } -if (!is_dir($GLOBALS['config']['RAINTPL_TMP'])) { mkdir($GLOBALS['config']['RAINTPL_TMP'],0705);chmod($GLOBALS['config']['RAINTPL_TMP'],0705); } // For RainTPL temporary files. if (!is_file($GLOBALS['config']['DATADIR'].'/.htaccess')) { file_put_contents($GLOBALS['config']['DATADIR'].'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. // Second check to see if Shaarli can write in its directory, because on some hosts is_writable() is not reliable. if (!is_file($GLOBALS['config']['DATADIR'].'/.htaccess')) die('
ERROR: Shaarli does not have the right to write in its data directory ('.realpath($GLOBALS['config']['DATADIR']).').
'); if ($GLOBALS['config']['ENABLE_LOCALCACHE']) { - if (!is_dir($GLOBALS['config']['CACHEDIR'])) { mkdir($GLOBALS['config']['CACHEDIR'],0705); chmod($GLOBALS['config']['CACHEDIR'],0705); } if (!is_file($GLOBALS['config']['CACHEDIR'].'/.htaccess')) { file_put_contents($GLOBALS['config']['CACHEDIR'].'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. } @@ -188,7 +185,6 @@ class pageCache public function cache($page) { if (!$this->shouldBeCached) return; - if (!is_dir($GLOBALS['config']['PAGECACHE'])) { mkdir($GLOBALS['config']['PAGECACHE'],0705); chmod($GLOBALS['config']['PAGECACHE'],0705); } file_put_contents($this->filename,$page); } diff --git a/pagecache/.placeholder b/pagecache/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/tmp/.placeholder b/tmp/.placeholder new file mode 100644 index 0000000..e69de29 From 3bb684f59f04511ed157833d3d9552ee0e65d980 Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Mon, 4 Aug 2014 00:38:37 +0200 Subject: [PATCH 4/4] Removes htaccess file creation and adds them in the repository I also removed the previously created placeholders, which after all, have no more utility. --- cache/.htaccess | 2 ++ cache/.placeholder | 0 data/.htaccess | 2 ++ data/.placeholder | 0 index.php | 7 ------- pagecache/.htaccess | 2 ++ pagecache/.placeholder | 0 tmp/.htaccess | 2 ++ tmp/.placeholder | 0 9 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 cache/.htaccess delete mode 100644 cache/.placeholder create mode 100644 data/.htaccess delete mode 100644 data/.placeholder create mode 100644 pagecache/.htaccess delete mode 100644 pagecache/.placeholder create mode 100644 tmp/.htaccess delete mode 100644 tmp/.placeholder diff --git a/cache/.htaccess b/cache/.htaccess new file mode 100644 index 0000000..b584d98 --- /dev/null +++ b/cache/.htaccess @@ -0,0 +1,2 @@ +Allow from none +Deny from all diff --git a/cache/.placeholder b/cache/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/data/.htaccess b/data/.htaccess new file mode 100644 index 0000000..b584d98 --- /dev/null +++ b/data/.htaccess @@ -0,0 +1,2 @@ +Allow from none +Deny from all diff --git a/data/.placeholder b/data/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/index.php b/index.php index 747f113..3136193 100644 --- a/index.php +++ b/index.php @@ -88,13 +88,6 @@ header("Pragma: no-cache"); // Directories creations (Note that your web host may require differents rights than 705.) if (!is_writable(realpath(dirname(__FILE__)))) die('
ERROR: Shaarli does not have the right to write in its own directory ('.realpath(dirname(__FILE__)).').
'); -if (!is_file($GLOBALS['config']['DATADIR'].'/.htaccess')) { file_put_contents($GLOBALS['config']['DATADIR'].'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. -// Second check to see if Shaarli can write in its directory, because on some hosts is_writable() is not reliable. -if (!is_file($GLOBALS['config']['DATADIR'].'/.htaccess')) die('
ERROR: Shaarli does not have the right to write in its data directory ('.realpath($GLOBALS['config']['DATADIR']).').
'); -if ($GLOBALS['config']['ENABLE_LOCALCACHE']) -{ - if (!is_file($GLOBALS['config']['CACHEDIR'].'/.htaccess')) { file_put_contents($GLOBALS['config']['CACHEDIR'].'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. -} // Handling of old config file which do not have the new parameters. if (empty($GLOBALS['title'])) $GLOBALS['title']='Shared links on '.htmlspecialchars(indexUrl()); diff --git a/pagecache/.htaccess b/pagecache/.htaccess new file mode 100644 index 0000000..b584d98 --- /dev/null +++ b/pagecache/.htaccess @@ -0,0 +1,2 @@ +Allow from none +Deny from all diff --git a/pagecache/.placeholder b/pagecache/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/tmp/.htaccess b/tmp/.htaccess new file mode 100644 index 0000000..b584d98 --- /dev/null +++ b/tmp/.htaccess @@ -0,0 +1,2 @@ +Allow from none +Deny from all diff --git a/tmp/.placeholder b/tmp/.placeholder deleted file mode 100644 index e69de29..0000000