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

Update calibre-web version + comment in patch

This commit is contained in:
Krakinou 2019-01-19 12:33:21 +01:00
parent 05c15e969c
commit b4b5725182
3 changed files with 80 additions and 16 deletions

View file

@ -1,3 +1,3 @@
SOURCE_URL=https://github.com/janeczku/calibre-web/archive/c527d1f49a2213e523957fd90d814c075bacde89.zip
SOURCE_SUM=61aff733df259382ae53646e5445ac973a0c4fe70e54ec4d3ed63a7f66c4f04f
SOURCE_URL=https://github.com/janeczku/calibre-web/archive/9e5fa45df7cd840d8a26d25f953857a13d6bc5de.zip
SOURCE_SUM=be288d5caa3ccdd612b66927b0849899107941f600a58dd2e0a3dc04feb594a2
SOURCE_FORMAT=zip

View file

@ -1,9 +1,10 @@
--- a/cps/ub.py 2019-01-12 09:01:08.000000000 +0100
+++ b/cps/ub.py 2019-01-13 11:21:11.000000000 +0100
@@ -148,6 +148,14 @@
--- ./calibre-web-9e5fa45df7cd840d8a26d25f953857a13d6bc5de/cps/ub.py 2019-01-16 17:50:51.000000000 +0100
+++ "/home/nicolas/Nextcloud/06 - Technique/08 - git/calibre-web/cps/ub.py" 2019-01-19 11:03:55.799293389 +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):
@ -12,33 +13,59 @@
+ 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)
@@ -306,6 +314,9 @@
@@ -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 +390,9 @@
@@ -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:
@@ -662,13 +676,20 @@
@@ -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:
@@ -662,13 +682,22 @@
conn.execute("ALTER TABLE Settings ADD column `config_calibre` String DEFAULT ''")
session.commit()
try:
+#Yunohost Integration - 4
+ session.query(exists().where(Settings.config_use_ldap)).scalar()
+ except exc.OperationalError:
+ conn = engine.connect()
@ -47,6 +74,7 @@
+ 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_theme)).scalar()
except exc.OperationalError: # Database is not compatible, some rows are missing
conn = engine.connect()
@ -57,15 +85,17 @@
# Remove login capability of user Guest
conn = engine.connect()
conn.execute("UPDATE user SET password='' where nickname = 'Guest' and password !=''")
@@ -778,6 +799,12 @@
@@ -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()

View file

@ -1,18 +1,42 @@
--- ./ori-calibre-web/cps/web.py 2019-01-12 09:01:08.000000000 +0100
+++ ./calibre-web-Yunohost_integration/cps/web.py 2019-01-13 20:11:57.000000000 +0100
@@ -58,6 +58,8 @@
--- ./calibre-web-9e5fa45df7cd840d8a26d25f953857a13d6bc5de/cps/web.py 2019-01-16 17:50:51.000000000 +0100
+++ "/home/nicolas/Nextcloud/06 - Technique/08 - git/calibre-web/cps/web.py" 2019-01-19 10:55:51.728967203 +0100
@@ -58,6 +58,11 @@
import server
from reverseproxy import ReverseProxied
+#Yunohost LDAP integration - 1
+vlogout = 0
+#END Yunohost LDAP integration -1
+
+
try:
from googleapiclient.errors import HttpError
except ImportError:
@@ -2360,10 +2362,29 @@
@@ -1072,7 +1077,7 @@
json_dumps = json.dumps([dict(name=r.name.replace('|',',')) for r in entries])
return json_dumps
-
+
@app.route("/get_tags_json", methods=['GET', 'POST'])
@login_required_if_no_ano
def get_tags_json():
@@ -1192,8 +1197,8 @@
r = requests.get(repository_url + '/git/commits/' + commit['object']['sha'])
r.raise_for_status()
update_data = r.json()
- except requests.exceptions.HTTPError as e:
- status['error'] = _(u'HTTP Error') + ' ' + str(e)
+ except requests.exceptions.HTTPError as ex:
+ status['error'] = _(u'HTTP Error') + ' ' + str(ex)
except requests.exceptions.ConnectionError:
status['error'] = _(u'Connection error')
except requests.exceptions.Timeout:
@@ -2360,10 +2365,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:
@ -21,10 +45,15 @@
+ 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:
@ -37,23 +66,27 @@
+ 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"))
@@ -2384,6 +2405,8 @@
@@ -2384,6 +2415,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'))
@@ -3088,6 +3111,21 @@
@@ -3088,6 +3123,23 @@
if "config_ebookconverter" in to_save:
content.config_ebookconverter = int(to_save["config_ebookconverter"])
+ #LDAP configuratop,
+#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()
@ -67,6 +100,7 @@
+ 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")