From 94b785f7c6cb274e5e167f921d12071b8f1e50bb Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 29 Dec 2018 10:45:15 +0100 Subject: [PATCH 01/16] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index abaa53d..1cc2eb8 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre ## Todo - [X] Multiinstance - [ ] Better Multimedia integration : Integrate in Yunohost.multimedia +- [ ] User and possibly LDAP integration - [X] Package_check integration - [X] On backup/remove/upgrade : check for database location to update settings From cdae5f6c311498fb075a9d943549d5ac115ecf95 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Tue, 8 Jan 2019 21:45:25 +0100 Subject: [PATCH 02/16] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 1cc2eb8..7f24b66 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ or 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 +* "Magic link feature is not yet available + ## Links * Report a bug: https://github.com/YunoHost-Apps/calibre_ynh/issues @@ -68,6 +70,7 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre - [ ] User and possibly LDAP integration - [X] Package_check integration - [X] On backup/remove/upgrade : check for database location to update settings +- [ ] enable magic link ## LICENSE From d2a717fec0daebcd9e8c80621aec845870fb2e96 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 12 Jan 2019 20:04:35 +0100 Subject: [PATCH 03/16] Change to LDAP supported version --- conf/app.src | 4 ++-- conf/init_calibre_db_settings | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/conf/app.src b/conf/app.src index c765e11..5b5b484 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,4 +1,4 @@ #useless as long as V1.0 not issued -SOURCE_URL=https://github.com/janeczku/calibre-web/archive/d0fd1a46014006138977398ee65f48c98df937e7.zip -SOURCE_SUM=0d297719f32670840fb1fcee52d3e73fa6213127709809d9a232f862d037af03 +SOURCE_URL=https://github.com/Krakinou/calibre-web/archive/calibre-web-masterzip +SOURCE_SUM=3cef8d95f2543cc07f5b2a9975f8633d614d2f02e404e1538353a6bd18f3f405 SOURCE_FORMAT=zip diff --git a/conf/init_calibre_db_settings b/conf/init_calibre_db_settings index 8dacf91..e84ebce 100644 --- a/conf/init_calibre_db_settings +++ b/conf/init_calibre_db_settings @@ -8,4 +8,7 @@ config_use_goodreads=0, config_logfile=\'\', config_converterpath=\'\', config_calibre=\'\', -config_uploading=\'$upload\' \ No newline at end of file +config_uploading=\'$upload\' +config_use_ldap=1 +config_ldap_provider_url=\'localhost:389\' +config_ldap_dn=\'uid=%s,ou=users,dc=yunohost,dc=org\' \ No newline at end of file From d30380a4f8e42eb7d5134475c1fb29529c218b4a Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 12 Jan 2019 20:09:28 +0100 Subject: [PATCH 04/16] typo --- conf/app.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/app.src b/conf/app.src index 5b5b484..f7088b4 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,4 +1,4 @@ #useless as long as V1.0 not issued -SOURCE_URL=https://github.com/Krakinou/calibre-web/archive/calibre-web-masterzip +SOURCE_URL=https://github.com/Krakinou/calibre-web/archive/calibre-web-master.zip SOURCE_SUM=3cef8d95f2543cc07f5b2a9975f8633d614d2f02e404e1538353a6bd18f3f405 SOURCE_FORMAT=zip From dc279c8e468209f55092516f8d25a77dc156e753 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 12 Jan 2019 20:12:17 +0100 Subject: [PATCH 05/16] typo --- conf/app.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/app.src b/conf/app.src index f7088b4..9c71a22 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,4 +1,4 @@ #useless as long as V1.0 not issued -SOURCE_URL=https://github.com/Krakinou/calibre-web/archive/calibre-web-master.zip +SOURCE_URL=https://github.com/YunoHost-Apps/calibre_ynh/archive/master.zip SOURCE_SUM=3cef8d95f2543cc07f5b2a9975f8633d614d2f02e404e1538353a6bd18f3f405 SOURCE_FORMAT=zip From c959b0a90b0bff7f5bbb009ce346e987ea9bd0de Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 12 Jan 2019 20:16:15 +0100 Subject: [PATCH 06/16] source update --- conf/app.src | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/app.src b/conf/app.src index 9c71a22..9eecae9 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,4 +1,4 @@ #useless as long as V1.0 not issued -SOURCE_URL=https://github.com/YunoHost-Apps/calibre_ynh/archive/master.zip -SOURCE_SUM=3cef8d95f2543cc07f5b2a9975f8633d614d2f02e404e1538353a6bd18f3f405 +SOURCE_URL=https://github.com/Krakinou/calibre-web/archive/82e4f11334444f8650fbf5e0b16a4e8eb70253da.zip +SOURCE_SUM=29f68e6ef88cce19f0f6a2006517c43d93167ad80f13cbe16cdc78b4ea8d52be SOURCE_FORMAT=zip From c5143ba88890ed475a0b4a6597f302dfbfa9c392 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 12 Jan 2019 23:02:02 +0100 Subject: [PATCH 07/16] correct db_settings for ldap --- conf/init_calibre_db_settings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/init_calibre_db_settings b/conf/init_calibre_db_settings index e84ebce..cf39aca 100644 --- a/conf/init_calibre_db_settings +++ b/conf/init_calibre_db_settings @@ -9,6 +9,6 @@ config_logfile=\'\', config_converterpath=\'\', config_calibre=\'\', config_uploading=\'$upload\' -config_use_ldap=1 +config_use_ldap=\'1\' config_ldap_provider_url=\'localhost:389\' config_ldap_dn=\'uid=%s,ou=users,dc=yunohost,dc=org\' \ No newline at end of file From b1973cd56bfbd436a947f881c55bca2608bc7d90 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 12 Jan 2019 23:10:36 +0100 Subject: [PATCH 08/16] revert config_use_ldap --- conf/init_calibre_db_settings | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conf/init_calibre_db_settings b/conf/init_calibre_db_settings index cf39aca..ee54396 100644 --- a/conf/init_calibre_db_settings +++ b/conf/init_calibre_db_settings @@ -8,7 +8,7 @@ config_use_goodreads=0, config_logfile=\'\', config_converterpath=\'\', config_calibre=\'\', -config_uploading=\'$upload\' -config_use_ldap=\'1\' +config_use_ldap=1 config_ldap_provider_url=\'localhost:389\' -config_ldap_dn=\'uid=%s,ou=users,dc=yunohost,dc=org\' \ No newline at end of file +config_ldap_dn=\'uid=%s,ou=users,dc=yunohost,dc=org\' +config_uploading=\'$upload\' From bba261cf4385cbd0323714203c0d072270a11c84 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 12 Jan 2019 23:13:22 +0100 Subject: [PATCH 09/16] la virgule, mais la virgule! --- conf/init_calibre_db_settings | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conf/init_calibre_db_settings b/conf/init_calibre_db_settings index ee54396..f600faa 100644 --- a/conf/init_calibre_db_settings +++ b/conf/init_calibre_db_settings @@ -8,7 +8,7 @@ config_use_goodreads=0, config_logfile=\'\', config_converterpath=\'\', config_calibre=\'\', -config_use_ldap=1 -config_ldap_provider_url=\'localhost:389\' -config_ldap_dn=\'uid=%s,ou=users,dc=yunohost,dc=org\' +config_use_ldap=1, +config_ldap_provider_url=\'localhost:389\', +config_ldap_dn=\'uid=%s,ou=users,dc=yunohost,dc=org\', config_uploading=\'$upload\' From 0b15e9c9fecf12fe19d7c65403f23494f4b5d6b2 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 13 Jan 2019 11:57:47 +0100 Subject: [PATCH 10/16] Move to last version --- conf/app.src | 5 ++--- conf/nginx.conf | 13 +++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/conf/app.src b/conf/app.src index 9eecae9..33e5909 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,4 +1,3 @@ -#useless as long as V1.0 not issued -SOURCE_URL=https://github.com/Krakinou/calibre-web/archive/82e4f11334444f8650fbf5e0b16a4e8eb70253da.zip -SOURCE_SUM=29f68e6ef88cce19f0f6a2006517c43d93167ad80f13cbe16cdc78b4ea8d52be +SOURCE_URL=https://github.com/janeczku/calibre-web/archive/c527d1f49a2213e523957fd90d814c075bacde89.zip +SOURCE_SUM=61aff733df259382ae53646e5445ac973a0c4fe70e54ec4d3ed63a7f66c4f04f SOURCE_FORMAT=zip diff --git a/conf/nginx.conf b/conf/nginx.conf index 75e244a..64bc976 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -4,12 +4,13 @@ location __PATH__ { if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } - proxy_pass http://localhost:__PORT__; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header Host $http_host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; - proxy_set_header X-Script-Name __PATH__; + proxy_pass http://localhost:__PORT__; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Scheme $scheme; + proxy_set_header X-Script-Name __PATH__; + proxy_set_header X-Remote-User $remote_user; # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; From 72530669dbc76768c0f6c2c681b663b07ee9a773 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 13 Jan 2019 12:33:17 +0100 Subject: [PATCH 11/16] Patch sources --- sources/patches/app-config.patch | 24 +++++++++++ sources/patches/app-ub.patch | 72 ++++++++++++++++++++++++++++++++ sources/patches/app-web.patch | 44 +++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 sources/patches/app-config.patch create mode 100644 sources/patches/app-ub.patch create mode 100644 sources/patches/app-web.patch diff --git a/sources/patches/app-config.patch b/sources/patches/app-config.patch new file mode 100644 index 0000000..c816372 --- /dev/null +++ b/sources/patches/app-config.patch @@ -0,0 +1,24 @@ +--- 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 @@ + + + {% endif %} ++
++ ++ ++
++
++
++ ++ ++
++
++ ++ ++
++
++ + + + diff --git a/sources/patches/app-ub.patch b/sources/patches/app-ub.patch new file mode 100644 index 0000000..5da0e64 --- /dev/null +++ b/sources/patches/app-ub.patch @@ -0,0 +1,72 @@ +--- 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 @@ + def __repr__(self): + return '' % self.nickname + ++ #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 ++ ) + + # 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 @@ + config_use_goodreads = Column(Boolean) + config_goodreads_api_key = Column(String) + config_goodreads_api_secret = Column(String) ++ config_use_ldap = Column(Boolean) ++ config_ldap_provider_url = Column(String) ++ config_ldap_dn = Column(String) + config_mature_content_tags = Column(String) + config_logfile = Column(String) + config_ebookconverter = Column(Integer, default=0) +@@ -379,6 +390,9 @@ + 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 ++ 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 + if data.config_mature_content_tags: + self.config_mature_content_tags = data.config_mature_content_tags + else: +@@ -662,13 +676,20 @@ + conn.execute("ALTER TABLE Settings ADD column `config_calibre` String DEFAULT ''") + session.commit() + try: ++ 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: + session.query(exists().where(Settings.config_theme)).scalar() + except exc.OperationalError: # Database is not compatible, some rows are missing + conn = engine.connect() + 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 +799,12 @@ + migrate_Database() + clean_database() + ++#get LDAP connection ++def get_ldap_connection(): ++ import ldap ++ conn = ldap.initialize('ldap://{}'.format(config.config_ldap_provider_url)) ++ return conn ++ + # Generate global Settings Object accessible from every file + config = Config() + searched_ids = {} diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch new file mode 100644 index 0000000..f8536d9 --- /dev/null +++ b/sources/patches/app-web.patch @@ -0,0 +1,44 @@ +--- a/cps/web.py 2019-01-12 09:01:08.000000000 +0100 ++++ b/cps/web.py 2019-01-13 11:21:11.000000000 +0100 +@@ -2363,7 +2363,18 @@ + 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": ++ 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": + 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")) +@@ -3088,6 +3099,21 @@ + if "config_ebookconverter" in to_save: + content.config_ebookconverter = int(to_save["config_ebookconverter"]) + ++ #LDAP configuratop, ++ 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 ++ + # 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: From 5f553d72ccc01654a509af5000be1b5aea5a4501 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 13 Jan 2019 15:39:06 +0100 Subject: [PATCH 12/16] Apply new patch for logout --- sources/patches/app-web.patch | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch index f8536d9..a941437 100644 --- a/sources/patches/app-web.patch +++ b/sources/patches/app-web.patch @@ -1,6 +1,15 @@ --- a/cps/web.py 2019-01-12 09:01:08.000000000 +0100 -+++ b/cps/web.py 2019-01-13 11:21:11.000000000 +0100 -@@ -2363,7 +2363,18 @@ ++++ b/cps/web.py 2019-01-13 15:29:45.000000000 +0100 +@@ -2360,10 +2360,27 @@ + return redirect(url_for('basic_configuration')) + if current_user is not None and current_user.is_authenticated: + return redirect(url_for('index')) ++ auth_user = request.headers.get('X-Remote-User') ++ if auth_user and config.config_use_ldap: ++ 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")) 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() @@ -20,7 +29,18 @@ 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")) -@@ -3088,6 +3099,21 @@ +@@ -2384,8 +2401,9 @@ + @login_required + def logout(): + if current_user is not None and current_user.is_authenticated: ++ logout_host = request.headers.get('Host') + logout_user() +- return redirect(url_for('login')) ++ return redirect("https://%servername/yunohost/sso/".replace("%servername", logout_host)) + + + @app.route('/remote/login') +@@ -3088,6 +3106,21 @@ if "config_ebookconverter" in to_save: content.config_ebookconverter = int(to_save["config_ebookconverter"]) From 2760dea36f8219dd43dab92abca311561420a02c Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 13 Jan 2019 16:16:36 +0100 Subject: [PATCH 13/16] Correct patches w/ vlogout correct install script for tab add new todo --- README.md | 1 + scripts/install | 2 +- sources/patches/app-web.patch | 95 +++++++++++++++++++---------------- 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 7f24b66..dc4f95a 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre - [X] Package_check integration - [X] On backup/remove/upgrade : check for database location to update settings - [ ] enable magic link +- [ ] Add cronjob to reload database ## LICENSE diff --git a/scripts/install b/scripts/install index b235d84..182a99d 100755 --- a/scripts/install +++ b/scripts/install @@ -94,7 +94,7 @@ pip install --target $final_path/vendor -r $final_path/requirements.txt #================================================= #Cannot use empty string for X-script-name, causes an issue in the python prg if [ $path_url = "/" ] ; then - ynh_replace_string "X-Script-Name __PATH__;" "X-Script-Name /$app;" ../conf/nginx.conf + ynh_replace_string "X-Script-Name __PATH__;" "X-Script-Name $app;" ../conf/nginx.conf fi # Create a dedicated nginx config diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch index a941437..51bd470 100644 --- a/sources/patches/app-web.patch +++ b/sources/patches/app-web.patch @@ -1,64 +1,71 @@ ---- a/cps/web.py 2019-01-12 09:01:08.000000000 +0100 -+++ b/cps/web.py 2019-01-13 15:29:45.000000000 +0100 -@@ -2360,10 +2360,27 @@ +--- ./calibre-web-Yunohost_integration/cps/web.py 2019-01-13 16:13:23.000000000 +0100 ++++ ./ori-calibre-web-master/cps/web.py 2019-01-12 09:01:08.000000000 +0100 +@@ -58,8 +58,6 @@ + import server + from reverseproxy import ReverseProxied + +-global vlogout +- + try: + from googleapiclient.errors import HttpError + except ImportError: +@@ -2362,28 +2360,10 @@ return redirect(url_for('basic_configuration')) if current_user is not None and current_user.is_authenticated: return redirect(url_for('index')) -+ auth_user = request.headers.get('X-Remote-User') -+ if auth_user and config.config_use_ldap: -+ 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")) +- auth_user = request.headers.get('X-Remote-User') +- 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")) 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": -+ 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": +- 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": ++ if user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest": 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,8 +2401,9 @@ +@@ -2404,7 +2384,6 @@ @login_required def logout(): if current_user is not None and current_user.is_authenticated: -+ logout_host = request.headers.get('Host') +- vlogout = 1 logout_user() -- return redirect(url_for('login')) -+ return redirect("https://%servername/yunohost/sso/".replace("%servername", logout_host)) + return redirect(url_for('login')) - - @app.route('/remote/login') -@@ -3088,6 +3106,21 @@ +@@ -3109,21 +3088,6 @@ if "config_ebookconverter" in to_save: content.config_ebookconverter = int(to_save["config_ebookconverter"]) -+ #LDAP configuratop, -+ 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 -+ +- #LDAP configuratop, +- 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 +- # 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: From f2a8067c93327d8126ca957ec4220da41a2a9176 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 13 Jan 2019 16:19:08 +0100 Subject: [PATCH 14/16] path correction --- sources/patches/app-web.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch index 51bd470..7913803 100644 --- a/sources/patches/app-web.patch +++ b/sources/patches/app-web.patch @@ -1,5 +1,5 @@ ---- ./calibre-web-Yunohost_integration/cps/web.py 2019-01-13 16:13:23.000000000 +0100 -+++ ./ori-calibre-web-master/cps/web.py 2019-01-12 09:01:08.000000000 +0100 +--- a/cps/web.py 2019-01-13 16:13:23.000000000 +0100 ++++ b/cps/web.py 2019-01-12 09:01:08.000000000 +0100 @@ -58,8 +58,6 @@ import server from reverseproxy import ReverseProxied From 4e40df22a69c1c10fab5cd320129109ad0c58058 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 13 Jan 2019 19:13:34 +0100 Subject: [PATCH 15/16] Reupload web.patch --- sources/patches/app-web.patch | 88 +++++++++++++++++------------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch index 7913803..8be0b4e 100644 --- a/sources/patches/app-web.patch +++ b/sources/patches/app-web.patch @@ -1,71 +1,71 @@ ---- a/cps/web.py 2019-01-13 16:13:23.000000000 +0100 -+++ b/cps/web.py 2019-01-12 09:01:08.000000000 +0100 -@@ -58,8 +58,6 @@ +--- a/cps/web.py 2019-01-12 09:01:08.000000000 +0100 ++++ b/cps/web.py 2019-01-13 16:13:23.000000000 +0100 +@@ -58,6 +58,8 @@ import server from reverseproxy import ReverseProxied --global vlogout -- ++global vlogout ++ try: from googleapiclient.errors import HttpError except ImportError: -@@ -2362,28 +2360,10 @@ +@@ -2360,10 +2362,28 @@ return redirect(url_for('basic_configuration')) if current_user is not None and current_user.is_authenticated: return redirect(url_for('index')) -- auth_user = request.headers.get('X-Remote-User') -- 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")) ++ auth_user = request.headers.get('X-Remote-User') ++ 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")) 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 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": -+ if user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest": +- if user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest": ++ 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": 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")) -@@ -2404,7 +2384,6 @@ +@@ -2384,6 +2404,7 @@ @login_required def logout(): if current_user is not None and current_user.is_authenticated: -- vlogout = 1 ++ vlogout = 1 logout_user() return redirect(url_for('login')) -@@ -3109,21 +3088,6 @@ +@@ -3088,6 +3109,21 @@ if "config_ebookconverter" in to_save: content.config_ebookconverter = int(to_save["config_ebookconverter"]) -- #LDAP configuratop, -- 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 -- ++ #LDAP configuratop, ++ 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 ++ # 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: From cbdef9bda77b8603953f094ae3f6c125b5969bd2 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 13 Jan 2019 20:57:54 +0100 Subject: [PATCH 16/16] udpate global patches --- sources/patches/app-web.patch | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch index 8be0b4e..1145a8d 100644 --- a/sources/patches/app-web.patch +++ b/sources/patches/app-web.patch @@ -1,19 +1,20 @@ ---- a/cps/web.py 2019-01-12 09:01:08.000000000 +0100 -+++ b/cps/web.py 2019-01-13 16:13:23.000000000 +0100 +--- ./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 @@ import server from reverseproxy import ReverseProxied -+global vlogout ++vlogout = 0 + try: from googleapiclient.errors import HttpError except ImportError: -@@ -2360,10 +2362,28 @@ +@@ -2360,10 +2362,29 @@ return redirect(url_for('basic_configuration')) if current_user is not None and current_user.is_authenticated: return redirect(url_for('index')) + 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() @@ -39,15 +40,16 @@ 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 +2404,7 @@ +@@ -2384,6 +2405,8 @@ @login_required def logout(): if current_user is not None and current_user.is_authenticated: ++ global vlogout + vlogout = 1 logout_user() return redirect(url_for('login')) -@@ -3088,6 +3109,21 @@ +@@ -3088,6 +3111,21 @@ if "config_ebookconverter" in to_save: content.config_ebookconverter = int(to_save["config_ebookconverter"])