1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/calibreweb_ynh.git synced 2024-09-03 18:16:20 +02:00

Merge pull request #35 from YunoHost-Apps/Testing

Update to 0.6.7 Stable
This commit is contained in:
Krakinou 2020-05-09 11:34:24 +02:00 committed by GitHub
commit 222be3ece0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 493 additions and 582 deletions

View file

@ -5,7 +5,13 @@
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.python.pydev.pythonNature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

5
.pydevproject Normal file
View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
</pydev_project>

View file

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//conf/generate_password_hash.py=utf-8

View file

@ -15,8 +15,9 @@ Calibre-Web is a web app providing a clean interface for browsing, reading and d
Alternatively, you may use [COPS](https://github.com/YunoHost-Apps/cops_ynh) which also allows access to your Calibre Library, but in read-only mode. Alternatively, you may use [COPS](https://github.com/YunoHost-Apps/cops_ynh) which also allows access to your Calibre Library, but in read-only mode.
**Shipped version:** The shipped version 0.6.0, but as the numbering changed in the calibre-web app, it is numbered as 0.96.0 in yunohost **Shipped version:** The shipped version is 0.6.7, but as the numbering changed in the calibre-web app, it is numbered as 0.96.7 in yunohost.
Users will be synchronized with authorized Yunohost users (having the calibreweb.main authorization group) automatically. In case of issue you may force the sync in the app itself.
Library will be placed in `/home/yunohost.multimedia/share/eBook` folder except if both : Library will be placed in `/home/yunohost.multimedia/share/eBook` folder except if both :
- calibreweb is set as a private application - calibreweb is set as a private application
@ -24,25 +25,30 @@ Library will be placed in `/home/yunohost.multimedia/share/eBook` folder except
In this case the library will be set in `/home/yunohost.multimedia/[admin]/eBook` folder. Library folder can always be changed manually in the application settings by the administrator. In this case the library will be set in `/home/yunohost.multimedia/[admin]/eBook` folder. Library folder can always be changed manually in the application settings by the administrator.
This app support http authentification.
## Screenshots ## Screenshots
![screenshot](https://raw.githubusercontent.com/janeczku/docker-calibre-web/master/screenshot.png) ![screenshot](https://raw.githubusercontent.com/janeczku/docker-calibre-web/master/screenshot.png)
## Security
The default admin password of the app (admin123) is kept during the installation process. It is used as a fallback password in case of LDAP issue.
You should change it to something more secure in the app :)
## OPDS
For OPDS to work, most OPDS-readers will require the app must be set in public mode.
Also, you may have to activate the "anonym browsing" for some reader to access book covers or download books ([source](https://github.com/janeczku/calibre-web/wiki/FAQ#which-opds-readers-work-with-calibre-web)).
## Backup library ## Backup library
By default, backup process will not backup Calibre library ([backup_core_only logic](https://yunohost.org/#/backup_fr)). By default, Yunohost backup process **will backup** Calibre library.
You may activate backup of the library with You may deactivate backup of the library with
``` ```
yunohost app setting calibreweb backup_core_only -v 0 yunohost app setting calibreweb do_not_backup_data -v 1
``` ```
By default, removing the app will **never** delete the library.
By default, removing the app will **never** delete the library.
## Known Limitations ## Known Limitations
* Partial LDAP support : user existing both in Yunohost and calibreweb can use their Yunohost password to log in, but user existing previously to the application installation will not be duplicated in the database automatically
* Authorization access to library to be done manually after install if Calibre library was already existing, for example : * Authorization access to library to be done manually after install if Calibre library was already existing, for example :
``` ```
chown -R calibreweb: path/to/library chown -R calibreweb: path/to/library
@ -51,12 +57,12 @@ chmod o+rw path/to/library
``` ```
* Do not use a Nextcloud folder. It's all right if the folder is an external storage in Nextcloud but not if it's an internal one : Changing the data in the library will cause trouble with the sync * Do not use a Nextcloud folder. It's all right if the folder is an external storage in Nextcloud but not if it's an internal one : Changing the data in the library will cause trouble with the sync
* "Magic link feature is not yet available * "Magic link feature is not yet available
* Change to library made outside calibreweb are not automatically updated in calibreweb. It is required to disconnect and reconnect to see the changes * Change to library made outside calibreweb are not automatically updated in calibreweb. It is required to disconnect and reconnect to see the changes : Do not open a database both in calibre & calibreweb!
* OPDS is not yet working * Yunohost install use the Tornado server which limits the upload size of a single file to 200Mo.
## Links ## Links
* Report a bug: https://github.com/YunoHost-Apps/calibre_ynh/issues * Report a bug: https://github.com/YunoHost-Apps/calibreweb_ynh/issues
* App website: https://github.com/janeczku/calibre-web * App website: https://github.com/janeczku/calibre-web
* YunoHost website: https://yunohost.org/ * YunoHost website: https://yunohost.org/
@ -65,25 +71,32 @@ chmod o+rw path/to/library
Developers info Developers info
---------------- ----------------
Please do your pull request to the [testing branch](https://github.com/Yunohost-Apps/calibre_ynh/tree/Testing). Please do your pull request to the [testing branch](https://github.com/Yunohost-Apps/calibreweb_ynh/tree/Testing).
To try the testing branch, please proceed like that. To try the testing branch, please proceed like that.
``` ```
sudo yunohost app install https://github.com/Yunohost-Apps/calibre_ynh/tree/Testing --debug sudo yunohost app install https://github.com/Yunohost-Apps/calibreweb_ynh/tree/Testing --debug
or or
sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre_ynh/tree/Testing --debug sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibreweb_ynh/tree/Testing --debug
``` ```
## Todo ## Todo
- [X] Multiinstance - [X] Multiinstance
- [X] Better Multimedia integration : Integrate in Yunohost.multimedia - [X] Better Multimedia integration : Integrate in Yunohost.multimedia
- [X] User and possibly LDAP integration, http auth - [X] rework LDAP integration to create user automatically
- [X] Package_check integration - [X] Package_check integration
- [X] On backup/remove/upgrade : check for database location to update settings - [X] On backup/remove/upgrade : check for database location to update settings
- [ ] Update mail settings with yunohost settings
- [ ] enable magic link - [ ] enable magic link
- [ ] Add cronjob to reload database - [ ] Add cronjob to reload database (for nextcloud integration)
- [ ] OPDS activation - [X] OPDS activation
- [ ] Add config-panel option to trigger do_not_backup_data
- [ ] Add action to restart the server
- [ ] Add action to synchronize users
- [ ] Add action to deactivate LDAP et retrieve admin password
- [ ] Use internal updater to update version?
## LICENSE ## LICENSE

View file

@ -15,12 +15,10 @@
setup_root=1 setup_root=1
setup_private=1 setup_private=1
setup_public=1 setup_public=1
upgrade=1 from_commit=3b9c5041e4fa73cb965368379f2b83d076c65341 upgrade=1
upgrade=1 from_commit=03bafd5219544c5d317eaf54182e4122ba63a4ad upgrade=1 from_commit=11f5b96df7d8850beff47f9904745fa53a6f7ed9
upgrade_1 from_commit=9e5fa45df7cd840d8a26d25f953857a13d6bc5de
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
incorrect_path=1
port_already_use=1 (8083) port_already_use=1 (8083)
change_url=1 change_url=1
#;; Failed upgrade #;; Failed upgrade
@ -41,23 +39,11 @@
# setup_root=1 # setup_root=1
# upgrade=1 from_commit=3b9c5041e4fa73cb965368379f2b83d076c65341 # upgrade=1 from_commit=3b9c5041e4fa73cb965368379f2b83d076c65341
;;; Levels ;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
Level 4=1
Level 5=auto Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options ;;; Options
Email= Email=nicolas@aubonalbanais.ovh
Notification=none Notification=none
;;; Upgrade options ;;; Upgrade options
; commit=3b9c5041e4fa73cb965368379f2b83d076c65341 ; commit=11f5b96df7d8850beff47f9904745fa53a6f7ed9
name=First in progress release of the app 0.9~ynh1 name=Version 0.96.0~ynh4
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&password=pass&is_public=1&
; commit=03bafd5219544c5d317eaf54182e4122ba63a4ad
name=Release 0.91~ynh2
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&password=pass&is_public=1& manifest_arg=domain=DOMAIN&path=PATH&admin=USER&password=pass&is_public=1&

View file

@ -1,3 +1,3 @@
SOURCE_URL=https://github.com/janeczku/calibre-web/archive/d81cb2927abcba3c4d198ecce9dca78550f676e1.zip SOURCE_URL=https://github.com/janeczku/calibre-web/releases/download/0.6.7/calibre-web-0.6.7.zip
SOURCE_SUM=e9c8a9a63ceb509f8482d73ed6d044eca8e96961c485fd395e73e93b8ea09a68 SOURCE_SUM=0c803df4b49993987a7f317c47ba38e680e45712b49da3cb7eb6c66f57379f30
SOURCE_FORMAT=zip SOURCE_FORMAT=zip

3
conf/app066.src Normal file
View file

@ -0,0 +1,3 @@
SOURCE_URL=https://github.com/janeczku/calibre-web/archive/0.6.6.zip
SOURCE_SUM=87633c2817263ed2d12fce67ea292b1c6d042aa949aafb728789c15d495415cc
SOURCE_FORMAT=zip

View file

@ -1,10 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Permet de générer le hash pour le password
#Plus utilisé depuis la MAJ 0.92~ynh3 avec LDAP
import sys
path=sys.argv[2]
sys.path.append(path)
from werkzeug.security import generate_password_hash
password=sys.argv[1]
print generate_password_hash(password)

View file

@ -1,3 +1,10 @@
config_use_ldap=1, config_login_type=1,
config_ldap_provider_url=\'localhost:389\', config_ldap_provider_url=\'localhost\',
config_ldap_dn=\'uid=%s,ou=users,dc=yunohost,dc=org\' config_ldap_port=389,
config_ldap_authentication=0,
config_ldap_dn=\'dc=yunohost,dc=org\',
config_ldap_user_object=\'\(\&\(objectClass=posixAccount\)\(permission=cn=calibreweb.main,ou=permission,dc=yunohost,dc=org\)\(uid=%s\)\)\',
config_ldap_openldap=1,
config_ldap_group_object_filter=\'\(\&\(objectClass=posixGroup\)\(permission=cn=%s.main,ou=permission,dc=yunohost,dc=org\)\)\',
config_ldap_group_members_field=\'memberUid\',
config_ldap_group_name=\'calibreweb\'

View file

@ -1,11 +1,6 @@
config_calibre_dir=\'$calibre_dir\', config_calibre_dir=\'$calibre_dir\',
config_port=$port, config_port=$port,
config_certfile=\'\', config_logfile=\'$LOG_FILE\',
config_keyfile=\'\', config_access_log=1,
config_use_google_drive=0, config_access_logfile=\'$ACCESS_LOG_FILE\',
config_remote_login=0, config_uploading=\'$upload\'
config_use_goodreads=0,
config_logfile=\'\',
config_converterpath=\'\',
config_calibre=\'\',
config_uploading=\'$upload\',

View file

@ -1,5 +1,5 @@
location __PATH__ { location __PATH__ {
client_max_body_size 20M; client_max_body_size 200M;
# Force usage of https # Force usage of https
if ($scheme = http) { if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent; rewrite ^ https://$server_name$request_uri? permanent;
@ -10,8 +10,8 @@ location __PATH__ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme; proxy_set_header X-Scheme $scheme;
proxy_set_header X-Script-Name __PATH__; proxy_set_header X-Script-Name __PATH__;
proxy_set_header X-Remote-User $remote_user; # proxy_set_header X-Remote-User $remote_user;
# Include SSOWAT user panel. # Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc; include conf.d/yunohost_panel.conf.inc;
} }

View file

@ -7,7 +7,7 @@ Type=simple
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
WorkingDirectory=__FINALPATH__/ WorkingDirectory=__FINALPATH__/
ExecStart=/bin/sh -c '/usr/bin/python __FINALPATH__/cps.py >> /var/log/__APP__/__APP__.log 2>&1' ExecStart=/bin/sh -c '/usr/bin/python3.5 __FINALPATH__/cps.py'
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -1,49 +0,0 @@
#!/bin/bash
# Source YunoHost helpers
source /usr/share/yunohost/helpers
#pour récupérer l'app_id, on prend le nom du fichier puis on retire les 3 premiers caratères
app=`basename "$0"`
app=${app:3}
source /etc/yunohost/apps/$app/scripts/_common.sh
username=$1
mail=$2
pass_clear=$3
final_path=$(ynh_app_setting_get $app final_path)
public_library=$(ynh_app_setting_get "$app" public_library)
#User are duplicated in the database only if library is public
if [ $public_library -eq 1 ]; then
######################################
#1 get admin user and id from database
######################################
#we take the admin user as we're sure there is at least this one
admin=$(ynh_app_setting_get $app admin)
admin_id=$(sqlite3 $final_path/app.db "SELECT id FROM user WHERE nickname='$admin'")
######################################
#get user table structure
######################################
table_schema=$(get_db "user")
######################################
#Build new entry for user
######################################
insert_user=$table_schema
insert_user="${insert_user/id/null}" #so that a new entry is created
insert_user="${insert_user/nickname/\'$username\'}"
insert_user="${insert_user/role/0}" #standard role
pass_hash=$(python /etc/yunohost/apps/$app/conf/generate_password_hash.py "$pass_clear" $final_path/vendor)
insert_user="${insert_user/password/\'$pass_hash\'}" #we get the same pass even if it's not thanks to LDAP, ones never knows...
insert_user="${insert_user/email/\'$mail\'}"
#######################################
# Insert New entry in database
#######################################
sqlite3 $final_path/app.db "INSERT INTO user ($table_schema) SELECT $insert_user FROM user WHERE ID = $admin_id;"
fi

View file

@ -6,7 +6,7 @@
"en": "Browsing, reading and downloading eBooks using a Calibre database", "en": "Browsing, reading and downloading eBooks using a Calibre database",
"fr": "Explorer, lire et télécharger des eBooks à partir d'une base de données Calibre" "fr": "Explorer, lire et télécharger des eBooks à partir d'une base de données Calibre"
}, },
"version": "0.96.0~ynh3", "version": "0.96.7~ynh5",
"url": "https://github.com/janeczku/calibre-web", "url": "https://github.com/janeczku/calibre-web",
"license": "free", "license": "free",
"maintainer": { "maintainer": {
@ -14,7 +14,7 @@
"email": "misterl56@hotmail.com" "email": "misterl56@hotmail.com"
}, },
"requirements": { "requirements": {
"yunohost": ">= 3.0.0" "yunohost": ">= 3.7.1"
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [
@ -65,6 +65,7 @@
}, },
{ {
"name": "language", "name": "language",
"type": "string",
"optional": true, "optional": true,
"ask": { "ask": {
"en": "Select a default language", "en": "Select a default language",

View file

@ -1,105 +1,17 @@
#!/bin/bash #!/bin/bash
PKG_DEPENDENCIES="sqlite3 python-pip imagemagick" PKG_DEPENDENCIES="sqlite3 libldap2-dev libsasl2-dev python3-dev imagemagick"
#PKG_DEPENDENCIES="sqlite3 python3-pip imagemagick"
DOSSIER_MEDIA=/home/yunohost.multimedia DOSSIER_MEDIA=/home/yunohost.multimedia
create_dir=0 LOG_FILE=/var/log/$app/$app.log
ACCESS_LOG_FILE=/var/log/$app/$app-access.log
get_db() {
# $1 = nom de la table
# cette ligne de malade :
# 1/ Recupere le schém de la table user
# 2/ En extrait les noms de champs (en prenant le premier mot après la tabulation)
# 3/ en supprime les clé UNIQUE, PRIMARY et CHECK dont on ne veut pas
# 4/ remplace la liste avec retour à la ligne par une liste séparé par des virgules
# 5/ Enlève la dernière virgule
sqlite3 $final_path/app.db ".schema $1" | awk '/\t/ {print $1}' | grep -v -e "UNIQUE" -e "PRIMARY" -e "CHECK" -e "FOREIGN" | awk '{printf "%s, ", $0}' | head -c -2
}
#================================================= #=================================================
# EXPERIMENTAL HELPERS # EXPERIMENTAL HELPERS
# TO BE DELETED WHEN RELEASED # TO BE DELETED WHEN RELEASED
#================================================= #=================================================
#=================================================
#YNH_SYSTEMD_ACTION
#=================================================
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started
#
# usage: ynh_system_reload service_name [action]
# | arg: -n, --service_name= - Name of the service to reload. Default : $app
# | arg: -a, --action= - Action to perform with systemctl. Default: start
# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot.
# If not defined it don't wait until the service is completely started.
# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log
# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
# | arg: -e, --length= - Length of the error log : Default : 20
ynh_systemd_action() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= )
local service_name
local action
local line_match
local length
local log_path
local timeout
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local service_name="${service_name:-$app}"
local action=${action:-start}
local log_path="${log_path:-/var/log/$service_name/$service_name.log}"
local length=${length:-20}
local timeout=${timeout:-300}
local wait_starting=true
if [[ -z "${line_match:-}" ]]
then
wait_starting=false
fi
ynh_clean_check_starting () {
# Stop the execution of tail.
kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1
}
echo "Starting of $service_name" >&2
systemctl $action $service_name || ( journalctl --lines=$length -u $service_name >&2 && false)
if $wait_starting
then
# Following the starting of the app in its log
local templog="$(mktemp)"
tail -F -n1 "$log_path" > "$templog" &
# Get the PID of the tail command
local pid_tail=$!
local i=0
for i in $(seq 1 $timeout)
do
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
if grep --quiet "$line_match" "$templog"
then
echo "The service $service_name has correctly started." >&2
break
fi
echo -n "." >&2
sleep 1
done
if [ $i -eq $timeout ]
then
echo "The service $service_name didn't fully started before the timeout." >&2
journalctl --lines=$length -u $service_name >&2
fi
echo ""
ynh_clean_check_starting
fi
}
#================================================= #=================================================
#YNH_MULTIMEDIA #YNH_MULTIMEDIA
#================================================= #=================================================

View file

@ -5,12 +5,8 @@
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -23,12 +19,13 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get $app path)
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
#Get settings from database in case it has been changed in the app #Get settings from database in case it has been changed in the app
calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM settings WHERE ID=1") calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM settings WHERE ID=1")
@ -36,19 +33,34 @@ calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM setting
calibre_dir=${calibre_dir%/} calibre_dir=${calibre_dir%/}
ynh_app_setting_set $app calibre_dir $calibre_dir ynh_app_setting_set $app calibre_dir $calibre_dir
source ../settings/scripts/_common.sh
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Backing up the main app directory..." --weight=1
#This will backup the app.db file at the same time #This will backup the app.db file at the same time
ynh_backup "$final_path" ynh_backup --src_path="$final_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_script_progression --message="Backing up nginx web server configuration..." --weight=1
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
@ -56,26 +68,34 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP LOGROTATE # BACKUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Backing up logrotate configuration..." --weight=1
ynh_backup "/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Backing up systemd configuration..." --weight=1
ynh_backup "/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
#================================================= #=================================================
# BACKUP THE DATA DIRECTORY # BACKUP THE DATA DIRECTORY
#================================================= #=================================================
ynh_script_progression --message="Backing up data directory..."
ynh_print_info "Data directory will be backup up only if BACKUP_CORE_ONLY is unset"
ynh_backup --src_path="$calibre_dir" --is_big
backup_core_only=$(ynh_app_setting_get "$app" backup_core_only)
# If backup_core_only have any value in the settings.yml file, do not backup the data directory #=================================================
if [ ! -z $backup_core_only ] # START SYSTEMD SERVICE
then #=================================================
ynh_print_info "Backing up the library folder $calibre_dir" ynh_script_progression --message="Starting a systemd service..." --weight=5
ynh_backup "$calibre_dir"
else ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 30
ynh_print_info "Data dir will not be saved, because backup_core_only is set." >&2
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last

View file

@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -22,11 +22,29 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config" # Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get $app port)
source _common.sh
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --weight=10
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#================================================= #=================================================
# CHECK THE SYNTAX OF THE PATHS # CHECK THE SYNTAX OF THE PATHS
@ -55,9 +73,17 @@ fi
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_script_progression --message="Updating nginx web server configuration..." --weight=1
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
@ -87,16 +113,24 @@ then
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# ...
#=================================================
#================================================= #=================================================
# GENERIC FINALISATION # GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 30
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=1
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -6,16 +6,8 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#================================================= #=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST # RETRIEVE ARGUMENTS FROM THE MANIFEST
#================================================= #=================================================
@ -32,10 +24,25 @@ public_library=$7
if [ $is_public -eq 1 ]; then if [ $is_public -eq 1 ]; then
public_library=1 public_library=1
fi fi
source _common.sh
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=5
final_path=/var/www/$app final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder" test ! -e "$final_path" || ynh_die "This path already contains a folder"
@ -51,6 +58,7 @@ ynh_webpath_register $app $domain $path_url
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." --weight=5
ynh_app_setting_set $app domain $domain ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url ynh_app_setting_set $app path $path_url
@ -67,16 +75,15 @@ ynh_app_setting_set $app is_public $is_public
# Find a free port # Find a free port
port=$(ynh_find_port 8083) port=$(ynh_find_port 8083)
# Open this port # Open this port
ynh_print_info "Opening port $port" ynh_script_progression --message="Opening port $port..." --weight=5
yunohost firewall allow --no-upnp TCP $port 2>&1 yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port ynh_app_setting_set $app port $port
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Downloading sources to $final_path..." --weight=10
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set $app final_path $final_path
ynh_print_info "Downloading sources to $final_path"
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path" ynh_setup_source "$final_path"
@ -84,14 +91,26 @@ ynh_setup_source "$final_path"
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Installing dependencies and pip packages" ynh_script_progression --message="Installing package dependencies..." --weight=15
ynh_install_app_dependencies $PKG_DEPENDENCIES ynh_install_app_dependencies $PKG_DEPENDENCIES
pip install --target $final_path/vendor -r $final_path/requirements.txt
#use latest version of pip as per documentation in https://github.com/pypa/get-pip
#cannot use helper as maintaining the checksum would be a pain in the a***
curl https://bootstrap.pypa.io/get-pip.py | python3
ynh_script_progression --message="Installing pip requirements..." --weight=50
pip3 install --no-cache-dir --target $final_path/vendor -r $final_path/requirements.txt
ynh_script_progression --message="Installing pip additionnal requirements..." --weight=60
pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
#Cannot use empty string for X-script-name, causes an issue in the python prg #Cannot use empty string for X-script-name, causes an issue in the python prg
ynh_script_progression --message="Setting up system configuration..." --weight=5
if [ $path_url = "/" ] ; then if [ $path_url = "/" ] ; then
ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf
fi fi
@ -118,7 +137,7 @@ ynh_add_systemd_config
#================================================= #=================================================
# CREATE FILES AND DIRECTORIES # CREATE FILES AND DIRECTORIES
#================================================= #=================================================
ynh_print_info "Creating files and directory" ynh_script_progression --message="Creating files and directory..." --weight=5
#Logic is as follow : if app is set to be publicly accessible, we will assume that the library should be set in "Share" multimedia directory #Logic is as follow : if app is set to be publicly accessible, we will assume that the library should be set in "Share" multimedia directory
# If app is set to be private but access is requested for all user, we will assume the same # If app is set to be private but access is requested for all user, we will assume the same
# If app is set to be private but access is limited to the admin user, we will set it inside his own multimedia directory. # If app is set to be private but access is limited to the admin user, we will set it inside his own multimedia directory.
@ -158,57 +177,23 @@ chown -R $app:$app /var/log/$app
#================================================= #=================================================
# SET SQLITE DATABASE SETTINGS # SET SQLITE DATABASE SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Setting up database and settings..." --weight=5
ynh_print_info "Setting up database and settings"
#we need to start and stop the service so that initial app.db file is created and that we can set default data #we need to start and stop the service so that initial app.db file is created and that we can set default data
ynh_systemd_action -l "INFO in server: Starting Gevent server" ynh_systemd_action --service_name=$app --action="start" --line_match="server on :$port" --log_path="$final_path/calibre-web.log" -t 30
#sleep required on low spec like raspberryPi #sleep required on low spec like raspberryPi
sleep 2s sleep 2s
ynh_systemd_action -a stop #remove unwanted calibre-web.log
ynh_secure_remove --file="$final_path/calibre-web.log"
ynh_systemd_action --service_name=$app --action="stop"
#set database settings as per conf file #set database settings as per conf file
conf="\"UPDATE settings SET $(. <(echo -E echo $(<../conf/init_calibre_db_settings))) $(. <(echo -E echo $(<../conf/init_calibre_db_ldap_settings))) WHERE ID=1\"" conf="\"UPDATE settings SET $(. <(echo -E echo $(<../conf/init_calibre_db_settings))), $(. <(echo -E echo $(<../conf/init_calibre_db_ldap_settings))) WHERE ID=1\""
eval sqlite3 $final_path/app.db "$conf" eval sqlite3 $final_path/app.db "$conf"
conf="\"UPDATE user SET $(. <(echo -E echo $(<../conf/init_calibre_db_user))) WHERE ID=1\"" conf="\"UPDATE user SET $(. <(echo -E echo $(<../conf/init_calibre_db_user))) WHERE ID=1\""
eval sqlite3 $final_path/app.db "$conf" eval sqlite3 $final_path/app.db "$conf"
#mise à jour du mot de passe (je ne sais pas pourquoi, je n'arrive pas à l'intégrer dans le fichier de conf, pb de " et ')
#ynh_print_OFF
#had to set it on two lines or package_linter cries like a baby...
#pass=$(python ../conf/generate_password_hash.py "$pass" $final_path/vendor)
#sqlite3 $final_path/app.db "UPDATE user SET password='$pass' WHERE ID=1"
#ynh_print_ON
#Creation des autres utilisateurs
if [ $public_library -eq 1 ]; then
table_schema=$(get_db "user")
for i in $(ynh_user_list); do
if [ $i = $admin ]; then continue; fi
mail=$(ynh_user_get_info $i 'mail')
######################################
#Build new entry for user
######################################
insert_user=$table_schema
insert_user="${insert_user/id/null}" #so that a new entry is created
insert_user="${insert_user/nickname/\'$i\'}"
insert_user="${insert_user/role/0}" #standard role
# pass_hash=$(python /etc/yunohost/apps/$app/conf/generate_password_hash.py "$pass_clear" $final_path/vendor)
# insert_user="${insert_user/password/\'$pass_hash\'}" #we get the same pass even if it's not thanks to LDAP, ones never knows...
insert_user="${insert_user/email/\'$mail\'}"
#######################################
# Insert New entry in database
#######################################
sqlite3 $final_path/app.db "INSERT INTO user ($table_schema) SELECT $insert_user FROM user WHERE ID = 1;"
done
fi
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
@ -230,7 +215,7 @@ ynh_store_file_checksum "${final_path}/app.db"
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
#================================================= #=================================================
yunohost service add $app --log "/var/log/$app/$app.log" yunohost service add $app --description "Browse eBook in the web" --log "/var/log/$app/$app.log"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
@ -240,17 +225,22 @@ yunohost service add $app --log "/var/log/$app/$app.log"
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
# unprotected_uris allows SSO credentials to be passed anyway. # unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/" #ynh_app_setting_set $app unprotected_uris "/"
ynh_permission_update --permission "main" --add visitors
fi fi
if [ $public_library -eq 0 ]; then if [ $public_library -eq 0 ]; then
yunohost app addaccess $app -u $admin yunohost app addaccess $app -u $admin
fi fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reload nginx and start $app" ynh_script_progression --message="Reload nginx and start $app..." --weight=5
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action -l "INFO in server: Starting Gevent server" ynh_systemd_action --service_name=$app --action="start" --line_match="server on :$port" -t 30
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -6,12 +6,13 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=3
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
@ -19,14 +20,16 @@ port=$(ynh_app_setting_get $app port)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
calibre_dir=$(ynh_app_setting_get $app calibre_dir) calibre_dir=$(ynh_app_setting_get $app calibre_dir)
source _common.sh
#================================================= #=================================================
# REMOVE SERVICE FROM ADMIN PANEL # REMOVE SERVICE FROM ADMIN PANEL
#================================================= #=================================================
# Remove a service from the admin panel, added by `yunohost service add` # Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
if yunohost service status | grep -q $app if ynh_exec_warn_less yunohost service status $app >/dev/null
then then
echo "Remove $app service" ynh_script_progression --message="Removing $app service..." --weight=1
yunohost service remove $app yunohost service remove $app
fi fi
@ -37,7 +40,7 @@ fi
#================================================= #=================================================
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_print_info "Removing systemd" ynh_script_progression --message="Stopping and removing the systemd service..." --weight=2
ynh_remove_systemd_config ynh_remove_systemd_config
@ -47,7 +50,7 @@ ynh_remove_systemd_config
#================================================= #=================================================
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_print_info "Removing dependencies" ynh_script_progression --message="Removing Dependencies..." --weight=5
ynh_remove_app_dependencies ynh_remove_app_dependencies
@ -56,15 +59,15 @@ ynh_remove_app_dependencies
#================================================= #=================================================
# Remove the app directory securely # Remove the app directory securely
ynh_print_info "Removing $final_path" ynh_script_progression --message="Removing $final_path..." --weight=1
ynh_secure_remove "$final_path" ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_print_info "Removing nginx config" ynh_script_progression --message="Removing nginx web server configuration..." --weight=1
ynh_remove_nginx_config ynh_remove_nginx_config
#================================================= #=================================================
@ -72,6 +75,7 @@ ynh_remove_nginx_config
#================================================= #=================================================
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
ynh_remove_logrotate ynh_remove_logrotate
#================================================= #=================================================
@ -80,16 +84,12 @@ ynh_remove_logrotate
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
ynh_print_info "Removing open port $port" ynh_script_progression --message="Closing port $port..." --weight=10
echo "Close port $port" >&2
yunohost firewall disallow TCP $port 2>&1 yunohost firewall disallow TCP $port 2>&1
fi fi
#=================================================
# SPECIFIC REMOVE
#=================================================
# Remove the log files # Remove the log files
ynh_script_progression --message="Removing log file..." --weight=1
ynh_secure_remove "/var/log/$app/" ynh_secure_remove "/var/log/$app/"
#================================================= #=================================================
@ -97,12 +97,12 @@ ynh_secure_remove "/var/log/$app/"
#================================================= #=================================================
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
# Delete a system user # Delete a system user
ynh_system_user_delete $app ynh_script_progression --message="Removing the dedicated system user..." --weight=1
ynh_system_user_delete --username=$app
#================================================= #=================================================
# MESSAGE TO USER # MESSAGE TO USER
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_print_warn "!!!The library folder $calibre_dir was not deleted. Delete it manually if required!!!" ynh_print_warn "!!!The library folder $calibre_dir was not deleted. Delete it manually if required!!!"

View file

@ -6,12 +6,6 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -24,7 +18,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
@ -33,11 +27,12 @@ final_path=$(ynh_app_setting_get $app final_path)
calibre_dir=$(ynh_app_setting_get $app calibre_dir) calibre_dir=$(ynh_app_setting_get $app calibre_dir)
is_public=$(ynh_app_setting_get $app is_public) is_public=$(ynh_app_setting_get $app is_public)
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get $app port)
source ../settings/scripts/_common.sh
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
ynh_webpath_available $domain $path_url \ ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path \
@ -48,14 +43,14 @@ test ! -d $final_path \
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Restore nginx settings" ynh_script_progression --message="Restoring nginx configuration..." --weight=1
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# REOPEN PORT # REOPEN PORT
#================================================= #=================================================
ynh_print_info "Reopening port $port" ynh_script_progression --message="reopening port $port..." --weight=5
yunohost firewall allow --no-upnp TCP $port 2>&1 yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port ynh_app_setting_set $app port $port
@ -63,15 +58,17 @@ ynh_app_setting_set $app port $port
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Restore user $app" ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create $app ynh_system_user_create --username=$app
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Restore app directory $final_path" ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file "$final_path"
ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE USER RIGHTS
@ -87,44 +84,53 @@ chown -R $app: $final_path
#================================================= #=================================================
# Define and install dependencies # Define and install dependencies
ynh_print_info "Installing dependencies and pip packages" ynh_script_progression --message="Reinstalling dependencies..." --weight=15
ynh_install_app_dependencies $PKG_DEPENDENCIES ynh_install_app_dependencies $PKG_DEPENDENCIES
pip install --target $final_path/vendor -r $final_path/requirements.txt
#================================================= #use latest version of pip as per documentation in https://github.com/pypa/get-pip
# ADVERTISE SERVICE IN ADMIN PANEL #cannot use helper as maintaining the checksum would be a pain in the a***
#================================================= curl https://bootstrap.pypa.io/get-pip.py | python3
yunohost service add $app --log "/var/log/$app/$app.log" #pip package not required as already in app directory
#pip install --target $final_path/vendor -r $final_path/requirements.txt
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file "/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service systemctl enable $app.service
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
yunohost service add $app --description "Browse eBook in the web" --log "/var/log/$app/$app.log"
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_restore_file "/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
if [ ! -e /var/log/$app ]; then
mkdir /var/log/$app #=================================================
fi # RESTORE THE LOG FILE DIRECTORY
#=================================================
mkdir -p /var/log/$app
chown -R $app:$app /var/log/$app chown -R $app:$app /var/log/$app
#================================================= #=================================================
# RESTORE THE DATA DIRECTORY # RESTORE THE DATA DIRECTORY
#================================================= #=================================================
ynh_script_progression --message="Restoring data directory..." --weight=2
# The data directory will be restored only if it exists in the backup archive # The data directory will be restored only if it exists in the backup archive
# So only if it was backup previously. # So only if it was backup previously.
if [ -d "$YNH_BACKUP_DIR/apps/$app/backup/$calibre_dir" ] if [ -d "$YNH_BACKUP_DIR/apps/$app/backup/$calibre_dir" ]
then then
ynh_restore_file "$calibre_dir" ynh_restore_file --origin_path="$calibre_dir" --not_mandatory
else else
if [ ! -e "$calibre_dir" ]; then if [ ! -e "$calibre_dir" ]; then
ynh_print_info "Create calibre library folder $calibre_dir" ynh_print_info "Create calibre library folder $calibre_dir"
@ -148,7 +154,7 @@ ynh_app_setting_delete $app backup_core_only
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
# unprotected_uris allows SSO credentials to be passed anyway. # unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/" ynh_permission_update --permission "main" --add visitors
fi fi
#================================================= #=================================================
@ -156,10 +162,21 @@ fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reload nginx and start $app" ynh_script_progression --message="Reloading nginx web server..." --weight=1
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action -l "INFO in server: Starting Gevent server"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 30
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
#================================================= #=================================================
# WARNING FOR READ ACCESS # WARNING FOR READ ACCESS
#================================================= #=================================================

View file

@ -1,43 +1,72 @@
#!/bin/bash #!/bin/bash
version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
}
#================================================= #=================================================
# GENERIC START # GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin) admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public) is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
language=$(ynh_app_setting_get $app language) language=$(ynh_app_setting_get $app language)
#Get settings from database in case it has been changed in the app #Get settings from database in case it has been changed in the app and save it in settings so that it can be used back afterward
calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM settings WHERE ID=1") calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM settings WHERE ID=1")
#Save it in settings so that it can be used back afterward
calibre_dir=${calibre_dir%/} calibre_dir=${calibre_dir%/}
ynh_app_setting_set $app calibre_dir $calibre_dir ynh_app_setting_set $app calibre_dir $calibre_dir
port=$(ynh_app_setting_get $app port) upload=$(sqlite3 $final_path/app.db "SELECT config_uploading FROM settings WHERE ID=1")
ynh_app_setting_set $app upload $upload
source _common.sh
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
current_upstream_package_version=$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$app/manifest.json") #0.96.0
current_upstream_package_version="${current_upstream_package_version/".96"/".6"}" #0.6.0
new_upstream_package_version=$(ynh_app_upstream_version) #0.96.0
new_upstream_package_version="${new_upstream_package_version/".96"/".6"}" #0.6.0
if [ -f $final_path/cps/constants.py ]; then #on est dans une version postérieur à la 0.6.0
current_upstream_app_version=$(cat $final_path/cps/constants.py | grep STABLE_VERSION)
current_upstream_app_version="${current_upstream_app_version/STABLE_VERSION = \{\'version\': \'/""}"
current_upstream_app_version="${current_upstream_app_version/\'\}/""}"
else #on est encore en 0.6.0
current_upstream_app_version='0.6.0'
fi
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting
# restore it if the upgrade fails # restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
@ -45,7 +74,9 @@ ynh_clean_setup () {
ynh_abort_if_errors ynh_abort_if_errors
#Stop the app in case database is updated #Stop the app in case database is updated
ynh_systemd_action -a stop ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# CHECK THE PATH # CHECK THE PATH
@ -60,33 +91,64 @@ path_url=$(ynh_normalize_url_path $path_url)
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
# Download, check integrity, uncompress and patch the source from app.src #binaries version is 0.6.0, we need to go throught upgrade to 0.6.6 so that app.db is correctly updated, otherwise database is corrupted
ynh_print_info "Download and install new sources" if version_gt "0.6.6" "$current_upstream_app_version" && [ "$current_upstream_package_version" == "0.6.0" ] && [ "$upgrade_type" == "UPGRADE_APP" ]; then
ynh_setup_source "$final_path" ynh_script_progression --message="Upgrading from $current_upstream_app_version to 0.6.6..." --weight=50
ynh_setup_source --dest_dir="$final_path" --source_id="app066"
pip install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/requirements.txt
chown -R $app: $final_path
#set database settings as per conf file : restart server so that app.db is regenerated
ynh_systemd_action --service_name=$app --action="start" --line_match="Starting Gevent server" --log_path="$final_path/calibre-web.log" -t 30
#sleep required on low spec like raspberryPi
sleep 2s
ynh_systemd_action --service_name=$app --action="stop"
current_upstream_app_version="0.6.6"
#remove unwanted entry in settings db
fi
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files from $current_upstream_app_version to $new_upstream_package_version..." --weight=10
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=5
if [ $path_url = "/" ] ; then if [ $path_url = "/" ] ; then
ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf
fi fi
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
#================================================= #=================================================
# UPGRADE DEPENDENCIES # UPGRADE DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Download and install dependencies"
ynh_install_app_dependencies $PKG_DEPENDENCIES
pip install --target $final_path/vendor -r $final_path/requirements.txt
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Installing package dependencies..." --weight=15
ynh_install_app_dependencies $PKG_DEPENDENCIES
#use latest version of pip as per documentation in https://github.com/pypa/get-pip
#cannot use helper as maintaining the checksum would be a pain in the a***
curl https://bootstrap.pypa.io/get-pip.py | python3
ynh_script_progression --message="Installing pip requirements ..." --weight=30
pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/requirements.txt
ynh_script_progression --message="Installing pip additionnal requirements..." --weight=40
pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt
fi
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
# Create a dedicated user (if not existing) # Create a dedicated user (if not existing)
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
ynh_system_user_create $app ynh_system_user_create $app
# Set permissions on app files (required to be able to update database) # Set permissions on app files (required to be able to update database)
@ -97,7 +159,7 @@ chown -R $app: $final_path
#================================================= #=================================================
#build multimedia directory #build multimedia directory
#================================================= #=================================================
ynh_script_progression --message="Create Multimedia dir..." --weight=1
#Create multimedia directory but we do not change the calibre_dir : It's the user to make this choice. #Create multimedia directory but we do not change the calibre_dir : It's the user to make this choice.
ynh_multimedia_build_main_dir ynh_multimedia_build_main_dir
ynh_multimedia_addaccess $app ynh_multimedia_addaccess $app
@ -105,18 +167,24 @@ ynh_multimedia_addaccess $app
#================================================= #=================================================
#Update database structure #Update database structure
#================================================= #=================================================
ynh_script_progression --message="Update database..." --weight=1
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different "$final_path/app.db" ynh_backup_if_checksum_is_different "$final_path/app.db"
#set database settings as per conf file : restart server so that app.db is regenerated, then add new ldap settings #set database settings as per conf file : restart server so that app.db is regenerated, then add new ldap & log settings
ynh_systemd_action -l "INFO in server: Starting Gevent server" if [ "$current_upstream_app_version" == '0.6.6' ]; then
ynh_systemd_action --service_name=$app --action="start" --line_match="server on " --log_path="$final_path/calibre-web.log" -t 30
else
ynh_systemd_action --service_name=$app --action="start" --line_match="server on :$port" -t 30
fi
#sleep required on low spec like raspberryPi #sleep required on low spec like raspberryPi
sleep 2s sleep 2s
ynh_systemd_action -a stop #remove unwanted calibre-web.log
ynh_secure_remove --file="$final_path/calibre-web.log"
ynh_systemd_action --service_name=$app --action="stop"
conf="\"UPDATE settings SET $(. <(echo -E echo $(<../conf/init_calibre_db_ldap_settings))) WHERE ID=1\"" conf="\"UPDATE settings SET $(. <(echo -E echo $(<../conf/init_calibre_db_settings))), $(. <(echo -E echo $(<../conf/init_calibre_db_ldap_settings))) WHERE ID=1\""
eval sqlite3 $final_path/app.db "$conf" eval sqlite3 $final_path/app.db "$conf"
# Recalculate and store the checksum of the file for the next upgrade. # Recalculate and store the checksum of the file for the next upgrade.
@ -127,13 +195,16 @@ ynh_store_file_checksum "$final_path/app.db"
#================================================= #=================================================
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
ynh_add_systemd_config ynh_add_systemd_config
#================================================= #=================================================
@ -153,7 +224,8 @@ chown -R $app: $final_path
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
# unprotected_uris allows SSO credentials to be passed anyway # unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set $app unprotected_uris "/" #ynh_app_setting_set $app unprotected_uris "/"
ynh_permission_update --permission "main" --add visitors
fi fi
#================================================= #=================================================
@ -167,6 +239,19 @@ fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 30
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
systemctl reload nginx
ynh_systemd_action -a restart -l "INFO in server: Starting Gevent server"

View file

@ -0,0 +1,11 @@
--- a/cps/templates/admin.html 2020-04-18 11:48:34.000000000 +0200
+++ b/cps/templates/admin.html 2020-04-18 18:21:39.272422475 +0200
@@ -149,8 +149,6 @@
</table>
<div class="hidden" id="update_error"> <span>{{update_error}}</span></div>
- <div class="btn btn-default" id="check_for_update">{{_('Check for Update')}}</div>
- <div class="btn btn-default hidden" id="perform_update" data-toggle="modal" data-target="#StatusDialog">{{_('Perform Update')}}</div>
</div>
</div>
</div>

View file

@ -1,24 +0,0 @@
--- a/cps/templates/config_edit.html 2019-01-12 09:01:08.000000000 +0100
+++ b/cps/templates/config_edit.html 2019-01-13 11:21:11.000000000 +0100
@@ -162,6 +162,21 @@
</div>
</div>
{% endif %}
+ <div class="form-group">
+ <input type="checkbox" id="config_use_ldap" name="config_use_ldap" data-control="ldap-settings" {% if content.config_use_ldap %}checked{% endif %}>
+ <label for="config_use_ldap">{{_('Use')}} LDAP Authentication</label>
+ </div>
+ <div data-related="ldap-settings">
+ <div class="form-group">
+ <label for="config_ldap_provider_url">{{_('LDAP Provider URL')}}</label>
+ <input type="text" class="form-control" id="config_ldap_provider_url" name="config_ldap_provider_url" value="{% if content.config_use_ldap != None %}{{ content.config_ldap_provider_url }}{% endif %}" autocomplete="off">
+ </div>
+ <div class="form-group">
+ <label for="config_ldap_dn">{{_('LDAP Distinguished Name (DN)')}}</label>
+ <input type="text" class="form-control" id="config_ldap_dn" name="config_ldap_dn" value="{% if content.config_use_ldap != None %}{{ content.config_ldap_dn }}{% endif %}" autocomplete="off">
+ </div>
+ </div>
+ </div>
</div>
</div>
</div>

View file

@ -0,0 +1,12 @@
--- a/cps/static/js/main.js 2020-04-18 11:48:34.000000000 +0200
+++ b/cps/static/js/main.js 2020-04-18 17:39:49.405631791 +0200
@@ -308,7 +308,8 @@
$.ajax({
method:"get",
dataType: "json",
- url: path + "/../../import_ldap_users",
+ url: window.location.pathname + "/../../import_ldap_users",
+// url: path + "/../../import_ldap_users",
success: function success(data) {
$("#spinner2").hide();
ResultText = data.text;

View file

@ -0,0 +1,31 @@
--- a/optional-requirements.txt 2020-05-05 20:28:10.000000000 +0200
+++ b/optional-requirements.txt 2020-05-07 08:46:24.333467411 +0200
@@ -1,17 +1,3 @@
-# GDrive Integration
-google-api-python-client==1.7.11,<1.8.0
-gevent>=1.2.1,<1.6.0
-greenlet>=0.4.12,<0.5.0
-httplib2>=0.9.2,<0.18.0
-oauth2client>=4.0.0,<4.14.0
-uritemplate>=3.0.0,<3.1.0
-pyasn1-modules>=0.0.8,<0.3.0
-pyasn1>=0.1.9,<0.5.0
-PyDrive>=1.3.1,<1.4.0
-PyYAML>=3.12
-rsa==3.4.2,<4.1.0
-six>=1.10.0,<1.15.0
-
# goodreads
goodreads>=0.3.2,<0.4.0
python-Levenshtein>=0.12.0,<0.13.0
@@ -20,10 +6,6 @@
python-ldap>=3.0.0,<3.3.0
Flask-SimpleLDAP>=1.4.0,<1.5.0
-#oauth
-Flask-Dance>=1.4.0,<3.1.0
-SQLAlchemy-Utils>=0.33.5,<0.37.0
-
# extracting metadata
lxml>=3.8.0,<4.6.0
Pillow>=4.0.0,<7.2.0

View file

@ -1,103 +0,0 @@
--- a/cps/ub.py 2019-01-16 17:50:51.000000000 +0100
+++ b/cps/ub.py 2019-01-30 22:23:29.709075421 +0100
@@ -148,6 +148,16 @@
def __repr__(self):
return '<User %r>' % self.nickname
+#Yunohost Integration - 1
+ #Login via LDAP method
+ @staticmethod
+ def try_login(username, password):
+ conn = get_ldap_connection()
+ conn.simple_bind_s(
+ config.config_ldap_dn.replace("%s", username),
+ password
+ )
+#END Yunohost Integration - 1
# Baseclass for Users in Calibre-Web, settings which are depending on certain users are stored here. It is derived from
# User Base (all access methods are declared there)
@@ -268,8 +278,8 @@
domain = Column(String)
def __repr__(self):
- return u"<Registration('{0}')>".format(self.domain)
-
+ return u"<Registration('{0}')>".format(self.domain)
+
# Baseclass for representing settings in app.db with email server settings and Calibre database settings
# (application settings)
@@ -306,6 +316,11 @@
config_use_goodreads = Column(Boolean)
config_goodreads_api_key = Column(String)
config_goodreads_api_secret = Column(String)
+#Yunohost Integration - 2
+ config_use_ldap = Column(Boolean)
+ config_ldap_provider_url = Column(String)
+ config_ldap_dn = Column(String)
+#END Yunohost Integration - 2
config_mature_content_tags = Column(String)
config_logfile = Column(String)
config_ebookconverter = Column(Integer, default=0)
@@ -379,6 +394,11 @@
self.config_use_goodreads = data.config_use_goodreads
self.config_goodreads_api_key = data.config_goodreads_api_key
self.config_goodreads_api_secret = data.config_goodreads_api_secret
+#Yunohost Integration - 3
+ self.config_use_ldap = data.config_use_ldap
+ self.config_ldap_provider_url = data.config_ldap_provider_url
+ self.config_ldap_dn = data.config_ldap_dn
+#END Yunohost Integration - 3
if data.config_mature_content_tags:
self.config_mature_content_tags = data.config_mature_content_tags
else:
@@ -555,7 +575,7 @@
conn.execute("ALTER TABLE Settings ADD column `config_use_google_drive` INTEGER DEFAULT 0")
conn.execute("ALTER TABLE Settings ADD column `config_google_drive_folder` String DEFAULT ''")
conn.execute("ALTER TABLE Settings ADD column `config_google_drive_watch_changes_response` String DEFAULT ''")
- session.commit()
+ session.commit()
try:
session.query(exists().where(Settings.config_columns_to_ignore)).scalar()
except exc.OperationalError:
@@ -624,6 +644,16 @@
conn.execute("ALTER TABLE Settings ADD column `config_goodreads_api_key` String DEFAULT ''")
conn.execute("ALTER TABLE Settings ADD column `config_goodreads_api_secret` String DEFAULT ''")
try:
+#Yunohost Integration - 4
+ session.query(exists().where(Settings.config_use_ldap)).scalar()
+ except exc.OperationalError:
+ conn = engine.connect()
+ conn.execute("ALTER TABLE Settings ADD column `config_use_ldap` INTEGER DEFAULT 0")
+ conn.execute("ALTER TABLE Settings ADD column `config_ldap_provider_url` String DEFAULT ''")
+ conn.execute("ALTER TABLE Settings ADD column `config_ldap_dn` String DEFAULT ''")
+ session.commit()
+ try:
+#END Yunohost Integration - 4
session.query(exists().where(Settings.config_mature_content_tags)).scalar()
except exc.OperationalError:
conn = engine.connect()
@@ -668,7 +698,6 @@
conn.execute("ALTER TABLE Settings ADD column `config_theme` INTEGER DEFAULT 0")
session.commit()
-
# Remove login capability of user Guest
conn = engine.connect()
conn.execute("UPDATE user SET password='' where nickname = 'Guest' and password !=''")
@@ -778,6 +807,14 @@
migrate_Database()
clean_database()
+#Yunohost Integration - 5
+#get LDAP connection
+def get_ldap_connection():
+ import ldap
+ conn = ldap.initialize('ldap://{}'.format(config.config_ldap_provider_url))
+ return conn
+#END Yunohost Integration - 5
+
# Generate global Settings Object accessible from every file
config = Config()
searched_ids = {}

View file

@ -1,85 +0,0 @@
--- a/cps/web.py 2019-01-27 08:32:26.000000000 +0100
+++ b/cps/web.py 2019-02-02 12:38:12.364323004 +0100
@@ -78,6 +78,9 @@
import server
from reverseproxy import ReverseProxied
from updater import updater_thread
+#Yunohost LDAP integration - 1
+vlogout = 0
+#END Yunohost LDAP integration -1
try:
from googleapiclient.errors import HttpError
@@ -2256,10 +2259,36 @@
return redirect(url_for('basic_configuration'))
if current_user is not None and current_user.is_authenticated:
return redirect(url_for('index'))
+#Yunohost integration - 2
+ auth_user = request.headers.get('X-Remote-User')
+ global vlogout
+ if auth_user and config.config_use_ldap and not vlogout:
+ vlogout = 0
+ user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == auth_user.strip().lower()).first()
+ login_user(user, remember=True)
+ flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success")
+ return redirect(url_for("index"))
+#END Yunohost integration - 2
if request.method == "POST":
form = request.form.to_dict()
user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == form['username'].strip().lower()).first()
- if user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest":
+#Yunohost integration - 3
+# if user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest":
+#END Yunohost integration - 3
+#Yunohost Integration - 4
+ if config.config_use_ldap and user:
+ import ldap
+ try:
+ ub.User.try_login(form['username'], form['password'])
+ login_user(user, remember=True)
+ flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success")
+ return redirect_back(url_for("index"))
+ except ldap.INVALID_CREDENTIALS:
+ ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr)
+ app.logger.info('LDAP Login failed for user "' + form['username'] + '" IP-adress: ' + ipAdress)
+ flash(_(u"Wrong Username or Password"), category="error")
+ elif user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest":
+#End Yunohost Integration - 4
login_user(user, remember=True)
flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success")
return redirect_back(url_for("index"))
@@ -2280,6 +2309,10 @@
@login_required
def logout():
if current_user is not None and current_user.is_authenticated:
+#Yunohost Integration - 5
+ global vlogout
+ vlogout = 1
+#End Yunohost integration - 5
logout_user()
return redirect(url_for('login'))
@@ -2987,6 +3020,23 @@
if "config_ebookconverter" in to_save:
content.config_ebookconverter = int(to_save["config_ebookconverter"])
+#Yunohost Integration - 6
+ #LDAP configuration,
+ if "config_use_ldap" in to_save and to_save["config_use_ldap"] == "on":
+ if not "config_ldap_provider_url" in to_save or not "config_ldap_dn" in to_save:
+ ub.session.commit()
+ flash(_(u'Please enter a LDAP provider and a DN'), category="error")
+ return render_title_template("config_edit.html", content=config, origin=origin,
+ gdrive=gdriveutils.gdrive_support, gdriveError=gdriveError,
+ goodreads=goodreads_support, title=_(u"Basic Configuration"),
+ page="config")
+ else:
+ content.config_use_ldap = 1
+ content.config_ldap_provider_url = to_save["config_ldap_provider_url"]
+ content.config_ldap_dn = to_save["config_ldap_dn"]
+ db_change = True
+#END Yunohost integration - 6
+
# Remote login configuration
content.config_remote_login = ("config_remote_login" in to_save and to_save["config_remote_login"] == "on")
if not content.config_remote_login:

View file

@ -0,0 +1,52 @@
--- a/cps/web.py 2020-05-05 20:28:10.000000000 +0200
+++ b/cps/web.py 2020-05-07 08:52:47.151920968 +0200
@@ -294,7 +294,10 @@
if not config.db_configured and request.endpoint not in (
'admin.basic_configuration', 'login') and '/static/' not in request.path:
return redirect(url_for('admin.basic_configuration'))
-
+#Début Modif Yunohost 1/4 - Create LDAP user at login
+ if config.config_login_type == constants.LOGIN_LDAP and services.ldap:
+ import_ldap_users()
+#Fin Modif Yunohost 1/4
@app.route('/import_ldap_users')
def import_ldap_users():
@@ -326,7 +329,10 @@
log.warning("Could Not Parse LDAP User: %s", user)
continue
if ub.session.query(ub.User).filter(ub.User.nickname == user.lower()).first():
- log.warning("LDAP User: %s Already in Database", user)
+# Début Modif Yunohost 2/4 - deactivate warning for existing LDAP user (clog the log)
+# log.warning("LDAP User: %s Already in Database", user)
+ log.debug("LDAP User: %s Already in Database", user)
+#Fin Modif Yunohost 2/4
continue
user_data = services.ldap.get_object_details(user=user,
group=None,
@@ -1274,6 +1280,10 @@
if not config.db_configured:
log.debug(u"Redirect to initial configuration")
return redirect(url_for('admin.basic_configuration'))
+#Début Modif Yunohost 3/4 - Create LDAP user at Login
+ if config.config_login_type == constants.LOGIN_LDAP and services.ldap:
+ import_ldap_users()
+#Fin Modif Yunohost 3/4
if current_user is not None and current_user.is_authenticated:
return redirect(url_for('web.index'))
if config.config_login_type == constants.LOGIN_LDAP and not services.ldap:
@@ -1348,7 +1358,13 @@
if feature_support['oauth'] and (config.config_login_type == 2 or config.config_login_type == 3):
logout_oauth_user()
log.debug(u"User logged out")
- return redirect(url_for('web.login'))
+#Début Modif Yunohost 4/4 - Redirect to Yunohost at exit
+# return redirect(url_for('web.login'))
+ if config.config_login_type == constants.LOGIN_LDAP and services.ldap:
+ return redirect(request.host_url)
+ else:
+ return redirect(url_for('web.login'))
+#Fin Modif Yunohost 4/4
@web.route('/remote/login')