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

Import LDAP user

This commit is contained in:
Krakinou 2020-04-18 18:46:22 +02:00
parent b2731a37d1
commit 8410a5658d
9 changed files with 79 additions and 96 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>

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

@ -16,8 +16,6 @@ get_db() {
# TO BE DELETED WHEN RELEASED # TO BE DELETED WHEN RELEASED
#================================================= #=================================================
#================================================= #=================================================
#YNH_MULTIMEDIA #YNH_MULTIMEDIA
#================================================= #=================================================

View file

@ -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\"" 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
#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 # SECURE FILES AND DIRECTORIES
#================================================= #=================================================

View file

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

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

View file

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