1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/shaarli_ynh.git synced 2024-09-03 20:26:10 +02:00

towards working app...

This commit is contained in:
Julien Malik 2013-12-19 03:02:51 +01:00
parent 6ea909d7ed
commit 0cf59c2135
9 changed files with 233 additions and 8 deletions

22
conf/config.php Normal file
View file

@ -0,0 +1,22 @@
<?php
$GLOBALS['login'] = array (
YNH_LOGINS
);
$GLOBALS['password'] = array (
YNH_PASSWORDS
);
$GLOBALS['level'] = array (
YNH_LEVELS
);
$GLOBALS['email'] = array (
YNH_EMAILS
);
$GLOBALS['salt'] = 'YNH_SALT';
$GLOBALS['timezone'] = 'YNH_TIMEZONE';
date_default_timezone_set('YNH_TIMEZONE');
$GLOBALS['title'] = 'YNH_TITLE';
$GLOBALS['redirector'] = '';
$GLOBALS['disablesessionprotection'] = false;
$GLOBALS['disablejquery'] = false;
$GLOBALS['privateLinkByDefault'] = YNH_PRIVATE_LINK_BY_DEFAULT;
?>

16
conf/nginx.conf Normal file
View file

@ -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;
}
}

23
conf/options.php Normal file
View file

@ -0,0 +1,23 @@
<?php
/*
* DATADIR is defined in index.php, and cannot be defined elsewhere
*
$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.
$GLOBALS['config']['IPBANS_FILENAME'] = $GLOBALS['config']['DATADIR'].'/ipbans.php'; // File storage for failures and bans.
$GLOBALS['config']['BAN_AFTER'] = 4; // Ban IP after this many failures.
$GLOBALS['config']['BAN_DURATION'] = 1800; // Ban duration for IP address after login failures (in seconds) (1800 sec. = 30 minutes)
$GLOBALS['config']['OPEN_SHAARLI'] = false; // If true, anyone can add/edit/delete links without having to login
$GLOBALS['config']['HIDE_TIMESTAMPS'] = false; // If true, the moment when links were saved are not shown to users that are not logged in.
$GLOBALS['config']['HIDE_QRCODE'] = false; // If true, qrcodes are not shown.
$GLOBALS['config']['ENABLE_THUMBNAILS'] = true; // Enable thumbnails in links.
$GLOBALS['config']['CACHEDIR'] = '/home/yunohost.app/shaarli/cache'; // Cache directory for thumbnails for SLOW services (like flickr)
$GLOBALS['config']['PAGECACHE'] = '/home/yunohost.app/shaarli/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']['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'] = '/home/yunohost.app/shaarli/tmp'; // Rain template tmp directory.

57
manifest.json Normal file
View file

@ -0,0 +1,57 @@
{
"name": "Shaarli",
"id": "shaarli",
"description": {
"en": "The personal, minimalist, super-fast, no-database delicious clone",
"fr": "Clone de delicious"
},
"developer": {
"name": "julien",
"email": "julien.malik@paraiso.me",
"url": "http://sebsauvage.net/wiki/doku.php?id=php:shaarli"
},
"multi_instance": "false",
"arguments": {
"install" : [
{
"name": "domain",
"ask": {
"en": "Choose a domain for Shaarli"
},
"example": "domain.org"
},
{
"name": "path",
"ask": {
"en": "Choose a path for Shaarli"
},
"example": "/shaarli",
"default": "/shaarli"
},
{
"name": "public",
"ask": {
"en": "Is it a public Shaarli site ?"
},
"choices": ["Yes", "No"],
"default": "Yes"
},
{
"name": "title",
"ask": {
"en": "Choose a title for Shaarli's page"
},
"example": "Shaarli",
"default": "Shaarli"
},
{
"name": "privatelinkbydefault",
"ask": {
"en": "Are new links private by default ?"
},
"choices": ["Yes", "No"],
"default": "Yes"
}
]
}
}

94
scripts/install Normal file
View file

@ -0,0 +1,94 @@
#!/bin/bash
# Retrieve arguments
domain=$1
path=$2
is_public=$3
title=$4
privatelinkbydefault=$5
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a shaarli
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Copy files to the right place
app_home_path=/home/yunohost.app/shaarli
final_path=/var/www/shaarli
sudo mkdir -p $final_path
sudo cp -r ../sources/* $final_path
for subdir in data cache pagecache tmp
do
sudo mkdir -p $app_home_path/$subdir
sudo chown -R www-data: $app_home_path/$subdir
done
salt=$(dd if=/dev/urandom bs=1 count=200 2> /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

5
scripts/remove Normal file
View file

@ -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

2
scripts/upgrade Normal file
View file

@ -0,0 +1,2 @@
#!/bin/bash

3
scripts/user_list.py Normal file
View file

@ -0,0 +1,3 @@
import sys, json
for user in json.loads(sys.stdin.readlines()[0])["Users"]:
print user["Username"]

View file

@ -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('<pre>ERROR: Shaarli does not have the right to write in its own directory ('.realpath(dirname(__FILE__)).').</pre>');
//if (!is_writable(realpath(dirname(__FILE__)))) die('<pre>ERROR: Shaarli does not have the right to write in its own directory ('.realpath(dirname(__FILE__)).').</pre>');
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('<pre>ERROR: Shaarli does not have the right to write in its own directory ('.realpath(dirname(__FILE__)).').</pre>');
//if (!is_file($GLOBALS['config']['DATADIR'].'/.htaccess')) die('<pre>ERROR: Shaarli does not have the right to write in its own directory ('.realpath(dirname(__FILE__)).').</pre>');
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.