From 8410a5658d55e34c584667af4b3c5436e63af99d Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 18 Apr 2020 18:46:22 +0200 Subject: [PATCH] Import LDAP user --- .project | 6 +++ conf/generate_password_hash.py | 10 ---- hooks/post_user_create | 49 ------------------- scripts/_common.sh | 2 - scripts/install | 35 ------------- sources/patches/app-admin.html.patch | 11 +++++ sources/patches/app-main.js.patch | 12 +++++ .../patches/app-optionnal-requirements.patch | 40 +++++++++++++++ sources/patches/app-web.patch | 10 ++++ 9 files changed, 79 insertions(+), 96 deletions(-) delete mode 100644 conf/generate_password_hash.py delete mode 100644 hooks/post_user_create create mode 100644 sources/patches/app-admin.html.patch create mode 100644 sources/patches/app-main.js.patch create mode 100644 sources/patches/app-optionnal-requirements.patch create mode 100644 sources/patches/app-web.patch diff --git a/.project b/.project index 18e8b1c..0675d93 100644 --- a/.project +++ b/.project @@ -5,7 +5,13 @@ + + org.python.pydev.PyDevBuilder + + + + org.python.pydev.pythonNature diff --git a/conf/generate_password_hash.py b/conf/generate_password_hash.py deleted file mode 100644 index 4778e8c..0000000 --- a/conf/generate_password_hash.py +++ /dev/null @@ -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) diff --git a/hooks/post_user_create b/hooks/post_user_create deleted file mode 100644 index e3a7820..0000000 --- a/hooks/post_user_create +++ /dev/null @@ -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 \ No newline at end of file diff --git a/scripts/_common.sh b/scripts/_common.sh index 349ee53..9946035 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -16,8 +16,6 @@ get_db() { # TO BE DELETED WHEN RELEASED #================================================= - - #================================================= #YNH_MULTIMEDIA #================================================= diff --git a/scripts/install b/scripts/install index 1cd1332..88f1f77 100755 --- a/scripts/install +++ b/scripts/install @@ -178,41 +178,6 @@ eval sqlite3 $final_path/app.db "$conf" conf="\"UPDATE user SET $(. <(echo -E echo $(<../conf/init_calibre_db_user))) WHERE ID=1\"" 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 -#Disabled => Will be handled by LDAP -#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 #================================================= diff --git a/sources/patches/app-admin.html.patch b/sources/patches/app-admin.html.patch new file mode 100644 index 0000000..fffa7d0 --- /dev/null +++ b/sources/patches/app-admin.html.patch @@ -0,0 +1,11 @@ +--- /home/nicolas/Bureau/calibre-web-06fde4fcd00fcd067a58939e1d9eabee62a86913/cps/templates/admin.html 2020-04-18 11:48:34.000000000 +0200 ++++ ./admin.html 2020-04-18 18:21:39.272422475 +0200 +@@ -149,8 +149,6 @@ + + + +-
{{_('Check for Update')}}
+- + + + diff --git a/sources/patches/app-main.js.patch b/sources/patches/app-main.js.patch new file mode 100644 index 0000000..909cd60 --- /dev/null +++ b/sources/patches/app-main.js.patch @@ -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; diff --git a/sources/patches/app-optionnal-requirements.patch b/sources/patches/app-optionnal-requirements.patch new file mode 100644 index 0000000..02f49d2 --- /dev/null +++ b/sources/patches/app-optionnal-requirements.patch @@ -0,0 +1,40 @@ +--- a/optional-requirements.txt 2020-04-15 22:03:21.000000000 +0200 ++++ b/optional-requirements.txt 2020-04-16 20:44:43.371235411 +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,19 +6,11 @@ + 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 + rarfile>=2.7 + +-# other +-natsort>=2.2.0,<7.1.0 +-git+https://github.com/OzzieIsaacs/comicapi.git@ad8bfe5a1c31db882480433f86db2c5c57634a3f#egg=comicapi +- + #Kobo integration + jsonschema>=3.2.0,<3.3.0 + diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch new file mode 100644 index 0000000..0f1202c --- /dev/null +++ b/sources/patches/app-web.patch @@ -0,0 +1,10 @@ +--- /home/nicolas/Bureau/calibre-web-06fde4fcd00fcd067a58939e1d9eabee62a86913/cps/web.py 2020-04-18 11:48:34.000000000 +0200 ++++ ./web.py 2020-04-18 18:13:44.221590991 +0200 +@@ -1216,6 +1216,7 @@ + user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == form['username'].strip().lower()) \ + .first() + if config.config_login_type == constants.LOGIN_LDAP and services.ldap and user and form['password'] != "": ++ import_ldap_user() + login_result, error = services.ldap.bind_user(form['username'], form['password']) + if login_result: + login_user(user, remember=True)