diff --git a/README.md b/README.md index 87bb001..41c45f4 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre ## Todo - [X] Multiinstance - [X] Better Multimedia integration : Integrate in Yunohost.multimedia -- [X] User and possibly LDAP integration, http auth +- [ ] rework LDAP integration to create user automatically - [X] Package_check integration - [X] On backup/remove/upgrade : check for database location to update settings - [ ] enable magic link diff --git a/conf/app.src b/conf/app.src index a7a76d1..355f00c 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,3 +1,3 @@ -SOURCE_URL=https://github.com/janeczku/calibre-web/archive/d81cb2927abcba3c4d198ecce9dca78550f676e1.zip -SOURCE_SUM=e9c8a9a63ceb509f8482d73ed6d044eca8e96961c485fd395e73e93b8ea09a68 -SOURCE_FORMAT=zip \ No newline at end of file +SOURCE_URL=https://github.com/janeczku/calibre-web/archive/7c89f0b5b97678c8b93a484ee7e5acf746240938.zip +SOURCE_SUM=7127c42c2573d85a56da41ea705944a724742e9059a6c138de9cfd78424cce88 +SOURCE_FORMAT=zip diff --git a/conf/init_calibre_db_ldap_settings b/conf/init_calibre_db_ldap_settings index d16c8e9..6652c9f 100644 --- a/conf/init_calibre_db_ldap_settings +++ b/conf/init_calibre_db_ldap_settings @@ -1,3 +1,9 @@ -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_login_type=1, +config_ldap_provider_url=\'localhost\', +config_ldap_port=389, +config_ldap_schema=\'ldap\', +config_ldap_serv_username=\'toto\', +config_ldap_serv_password=\'titi\', +config_ldap_dn=\'ou=users,dc=yunohost,dc=org\', +config_ldap_user_object=\'uid=%s\', +config_ldap_openldap=1 \ No newline at end of file diff --git a/manifest.json b/manifest.json index 3c0ebb7..043e31f 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "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" }, - "version": "0.96.0~ynh3", + "version": "0.96.6~ynh4", "url": "https://github.com/janeczku/calibre-web", "license": "free", "maintainer": { @@ -14,7 +14,7 @@ "email": "misterl56@hotmail.com" }, "requirements": { - "yunohost": ">= 3.0.0" + "yunohost": ">= 3.7.1" }, "multi_instance": true, "services": [ diff --git a/scripts/install b/scripts/install index 7aebc70..adbc154 100755 --- a/scripts/install +++ b/scripts/install @@ -87,6 +87,7 @@ ynh_setup_source "$final_path" ynh_print_info "Installing dependencies and pip packages" ynh_install_app_dependencies $PKG_DEPENDENCIES pip install --target $final_path/vendor -r $final_path/requirements.txt +pip install --target $final_path/vendor -r $final_path/optional-requirements.txt #================================================= # NGINX CONFIGURATION diff --git a/sources/patches/app-admin.patch b/sources/patches/app-admin.patch new file mode 100644 index 0000000..32dc2a4 --- /dev/null +++ b/sources/patches/app-admin.patch @@ -0,0 +1,11 @@ +--- a/cps/admin.py 2020-04-12 12:51:28.100811662 +0200 ++++ b/cps/admin.py 2020-02-23 09:08:01.000000000 +0100 +@@ -43,7 +43,7 @@ + from .web import admin_required, render_title_template, before_request, unconfigured, login_required_if_no_ano + + feature_support = { +- 'ldap': bool(services.ldap), ++ 'ldap': False, # bool(services.ldap), + 'goodreads': bool(services.goodreads_support) + } + \ No newline at end of file diff --git a/sources/patches/app-config.patch b/sources/patches/app-config.patch deleted file mode 100644 index c816372..0000000 --- a/sources/patches/app-config.patch +++ /dev/null @@ -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 @@ - - - {% endif %} -+
-+ -+ -+
-+
-+
-+ -+ -+
-+
-+ -+ -+
-+
-+ - - - diff --git a/sources/patches/app-ub.patch b/sources/patches/app-ub.patch deleted file mode 100644 index 16f7494..0000000 --- a/sources/patches/app-ub.patch +++ /dev/null @@ -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 '' % 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"".format(self.domain) -- -+ return u"".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 = {} diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch index c1e03e0..e529dd4 100644 --- a/sources/patches/app-web.patch +++ b/sources/patches/app-web.patch @@ -1,85 +1,11 @@ ---- 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 +--- a/cps/web.py 2020-04-12 12:52:23.940774100 +0200 ++++ b/cps/web.py 2020-02-23 09:08:01.000000000 +0100 +@@ -53,7 +53,7 @@ + from .redirect import redirect_back - 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: + feature_support = { +- 'ldap': bool(services.ldap), ++ 'ldap': False, # bool(services.ldap), + 'goodreads': bool(services.goodreads_support) + } + \ No newline at end of file