diff --git a/conf/config.php b/conf/config.php new file mode 100644 index 0000000..d888873 --- /dev/null +++ b/conf/config.php @@ -0,0 +1,22 @@ + \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..fb85c69 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,16 @@ +location YNH_WWW_PATH { + alias YNH_ALIAS ; + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } + index index.php; + try_files $uri $uri/ index.php; + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + } +} diff --git a/conf/options.php b/conf/options.php new file mode 100644 index 0000000..56b818e --- /dev/null +++ b/conf/options.php @@ -0,0 +1,23 @@ + /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') + +user_count=0 +for user in $(sudo yunohost user list | python user_list.py) +do + if [[ ! $user == yunohost.* ]]; + then + + YNH_LOGINS=$(cat << EOF +$YNH_LOGINS\\ +$user_count => $user, +EOF +) + + YNH_PASSWORDS=$(cat << EOF +$YNH_PASSWORDS\\ +$user => '', +EOF +) + + YNH_LEVELS=$(cat << EOF +$YNH_LEVELS\\ +$user => 2, +EOF +) + + YNH_EMAILS=$(cat << EOF +$YNH_EMAILS\\ +$user => '' +EOF +) + + let user_count++ + fi +done + +sudo sed -i "s@YNH_LOGINS@$YNH_LOGINS@g" ../conf/config.php +sudo sed -i "s@YNH_PASSWORDS@$YNH_PASSWORDS@g" ../conf/config.php +sudo sed -i "s@YNH_LEVELS@$YNH_LEVELS@g" ../conf/config.php +sudo sed -i "s@YNH_EMAILS@$YNH_EMAILS@g" ../conf/config.php +sudo sed -i "s@YNH_SALT@$salt@g" ../conf/config.php +sudo sed -i "s@YNH_TIMEZONE@$(cat /etc/timezone)@g" ../conf/config.php +sudo sed -i "s@YNH_TITLE@$title@g" ../conf/config.php +sudo sed -i "s@YNH_PRIVATE_LINK_BY_DEFAULT@$privatelinkbydefault@g" ../conf/config.php + +sudo cp ../conf/config.php $app_home_path/data + +sudo find $final_path -type f | xargs sudo chmod 644 +sudo find $final_path -type d | xargs sudo chmod 755 +sudo chown -R root: $final_path + +sudo find $app_home_path -type f | xargs sudo chmod 640 +sudo find $app_home_path -type d | xargs sudo chmod 750 +sudo chown -R www-data: $app_home_path + +# Modify Nginx configuration file and copy it to Nginx conf directory +sudo sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf +sudo sed -i "s@YNH_ALIAS@$final_path@g" ../conf/nginx.conf +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/shaarli.conf + +# Reload Nginx and regenerate SSOwat conf +if [ $is_public = "No" ]; then + sudo yunohost app setting shaarli unprotected_uris -v "/index.php" +fi +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..9cfecbb --- /dev/null +++ b/scripts/remove @@ -0,0 +1,5 @@ +#!/bin/bash + +sudo rm -rf /var/www/shaarli +sudo rm -f /etc/nginx/conf.d/$domain.d/shaarli.conf +sudo rm -rf /home/yunohost.app/shaarli/data \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..05a7907 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,2 @@ +#!/bin/bash + diff --git a/scripts/user_list.py b/scripts/user_list.py new file mode 100644 index 0000000..8887a02 --- /dev/null +++ b/scripts/user_list.py @@ -0,0 +1,3 @@ +import sys, json +for user in json.loads(sys.stdin.readlines()[0])["Users"]: + print user["Username"] \ No newline at end of file diff --git a/sources/index.php b/sources/index.php index 0deee42..b839d60 100644 --- a/sources/index.php +++ b/sources/index.php @@ -11,7 +11,7 @@ date_default_timezone_set('UTC'); // ----------------------------------------------------------------------------------------------- // Hardcoded parameter (These parameters can be overwritten by creating the file /config/options.php) -$GLOBALS['config']['DATADIR'] = 'data'; // Data subdirectory +$GLOBALS['config']['DATADIR'] = '/home/yunohost.app/shaarli/data'; // Data subdirectory $GLOBALS['config']['CONFIG_FILE'] = $GLOBALS['config']['DATADIR'].'/config.php'; // Configuration file (user login/password) $GLOBALS['config']['DATASTORE'] = $GLOBALS['config']['DATADIR'].'/datastore.php'; // Data storage file. $GLOBALS['config']['LINKS_PER_PAGE'] = 20; // Default links per page. @@ -28,6 +28,7 @@ $GLOBALS['config']['ENABLE_LOCALCACHE'] = true; // Enable Shaarli to store thumb $GLOBALS['config']['PUBSUBHUB_URL'] = ''; // PubSubHubbub support. Put an empty string to disable, or put your hub url here to enable. $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 +$GLOBALS['config']['RTP_TMPDIR'] = 'tmp'; // Rain template tmp directory. // Note: You must have publisher.php in the same directory as Shaarli index.php // // ----------------------------------------------------------------------------------------------- // Levels for multi users @@ -69,8 +70,10 @@ error_reporting(E_ALL^E_WARNING); // See all error except warnings. 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_tmpdir = $GLOBALS['config']['RTP_TMPDIR']; +if (substr($raintpl_tmpdir, -1) != '/') { $raintpl_tmpdir = $raintpl_tmpdir . '/'; } +if (!is_dir($raintpl_tmpdir)) { mkdir($raintpl_tmpdir,0705); chmod($raintpl_tmpdir,0705); } +raintpl::$cache_dir = $raintpl_tmpdir; // cache directory. must end with '/' ob_start(); // Output buffering for the page cache. @@ -91,16 +94,16 @@ header("Cache-Control: post-check=0, pre-check=0", false); 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_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_file($GLOBALS['config']['DATADIR'].'/.htaccess')) { file_put_contents($GLOBALS['config']['DATADIR'].'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. +if (!is_dir($GLOBALS['config']['RTP_TMPDIR'])) { mkdir($GLOBALS['config']['RTP_TMPDIR'],0705); chmod($GLOBALS['config']['RTP_TMPDIR'],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 own directory ('.realpath(dirname(__FILE__)).').'); +//if (!is_file($GLOBALS['config']['DATADIR'].'/.htaccess')) die('
ERROR: Shaarli does not have the right to write in its own directory ('.realpath(dirname(__FILE__)).').'); 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. +// 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.