diff --git a/debian/control b/debian/control index 5220d79c2..9736e392e 100644 --- a/debian/control +++ b/debian/control @@ -15,7 +15,7 @@ Depends: ${python3:Depends}, ${misc:Depends} , python3-miniupnpc, python3-dbus, python3-jinja2 , python3-toml, python3-packaging, python3-publicsuffix2 , python3-ldap, python3-zeroconf (>= 0.47), python3-lexicon, - , python3-cryptography, python3-jwt + , python3-cryptography, python3-jwt, python3-magic , python-is-python3, python3-pydantic, python3-email-validator , nginx, nginx-extras (>=1.22) , apt, apt-transport-https, apt-utils, dirmngr diff --git a/hooks/conf_regen/01-yunohost b/hooks/conf_regen/01-yunohost index 74331edc2..9563966f1 100755 --- a/hooks/conf_regen/01-yunohost +++ b/hooks/conf_regen/01-yunohost @@ -71,6 +71,9 @@ do_init_regen() { mkdir -p /etc/yunohost/portal chmod 500 /etc/yunohost/portal chown ynh-portal:ynh-portal /etc/yunohost/portal + mkdir -p /usr/share/yunohost/portallogos + chmod 550 /usr/share/yunohost/portallogos + chown ynh-portal:www-data /usr/share/yunohost/portallogos # YunoHost services cp yunohost-api.service /etc/systemd/system/yunohost-api.service @@ -253,6 +256,9 @@ do_post_regen() { mkdir -p /etc/yunohost/portal chmod 500 /etc/yunohost/portal chown ynh-portal:ynh-portal /etc/yunohost/portal + mkdir -p /usr/share/yunohost/portallogos + chmod 550 /usr/share/yunohost/portallogos + chown ynh-portal:www-data /usr/share/yunohost/portallogos # Domain settings mkdir -p /etc/yunohost/domains diff --git a/share/config_domain.toml b/share/config_domain.toml index e67407eaa..6fc5fc50a 100644 --- a/share/config_domain.toml +++ b/share/config_domain.toml @@ -15,8 +15,8 @@ name = "Features" type = "string" default = "YunoHost" - # [feature.portal.portal_logo] - # type = "file" + [feature.portal.portal_logo] + type = "file" [feature.portal.portal_theme] type = "select" diff --git a/src/domain.py b/src/domain.py index 2b029bd04..75fd57a6c 100644 --- a/src/domain.py +++ b/src/domain.py @@ -758,9 +758,30 @@ class DomainConfigPanel(ConfigPanel): "default_app", "show_other_domains_apps", "portal_title", - # "portal_logo", + "portal_logo", "portal_theme", ] + + if "portal_logo" in next_settings: + + import magic, hashlib + with open(next_settings["portal_logo"], "rb") as f: + file_content = f.read() + mimetype = magic.Magic(mime=True).from_buffer(file_content) + if mimetype not in ["image/png", "image/jpeg"]: + raise YunohostValidationError(f"Unsupported image type : {mimetype}", raw=True) + ext = mimetype.split("/")[-1] + m = hashlib.sha256() + m.update(file_content) + sha256sum = m.hexdigest() + filename = f"/usr/share/yunohost/portallogos/{sha256sum}.{ext}" + with open(filename, "wb") as f: + f.write(file_content) + next_settings["portal_logo"] = filename + # FIXME : the previous line doesn't actually set anything in the actual form ... + # ... and calling `form.portal_logo = filename` would actually make it sort of "re-upload" the file to another place ... + # not sure how to address this issue ... + if _get_parent_domain_of(self.entity, topest=True) is None and any( option in next_settings for option in portal_options ):