Customize SOGo theme from Web UI
This commit is contained in:
@@ -273,7 +273,50 @@ class DockerUtils:
|
||||
# todo: check each exit code
|
||||
res = { 'type': 'success', 'msg': 'Scheduled immediate delivery'}
|
||||
return Response(content=json.dumps(res, indent=4), media_type="application/json")
|
||||
|
||||
|
||||
# api call: container_post - post_action: exec - cmd: sogo - task: customize_enable
|
||||
def container_post__exec__sogo__customize_enable(self, container_id, request_json):
|
||||
for container in self.docker_client.containers.list(filters={"id": container_id}):
|
||||
cmd = ["/bin/bash", "-c", "/customize.sh enable"]
|
||||
sogo_return = container.exec_run(cmd)
|
||||
return exec_run_handler('utf8_text_only', sogo_return)
|
||||
# api call: container_post - post_action: exec - cmd: sogo - task: customize_disable
|
||||
def container_post__exec__sogo__customize_disable(self, container_id, request_json):
|
||||
for container in self.docker_client.containers.list(filters={"id": container_id}):
|
||||
cmd = ["/bin/bash", "-c", "/customize.sh disable"]
|
||||
sogo_return = container.exec_run(cmd)
|
||||
return exec_run_handler('utf8_text_only', sogo_return)
|
||||
# api call: container_post - post_action: exec - cmd: sogo - task: set_logo
|
||||
def container_post__exec__sogo__set_logo(self, container_id, request_json):
|
||||
for container in self.docker_client.containers.list(filters={"id": container_id}):
|
||||
cmd = ["/bin/bash", "-c", "/customize.sh set_logo"]
|
||||
sogo_return = container.exec_run(cmd)
|
||||
return exec_run_handler('utf8_text_only', sogo_return)
|
||||
# api call: container_post - post_action: exec - cmd: sogo - task: remove_logo
|
||||
def container_post__exec__sogo__remove_logo(self, container_id, request_json):
|
||||
for container in self.docker_client.containers.list(filters={"id": container_id}):
|
||||
cmd = ["/bin/bash", "-c", "rm -f /usr/lib/GNUstep/SOGo/WebServerResources/img/sogo-full.svg"]
|
||||
sogo_return = container.exec_run(cmd)
|
||||
return exec_run_handler('utf8_text_only', sogo_return)
|
||||
# api call: container_post - post_action: exec - cmd: sogo - task: set_favicon
|
||||
def container_post__exec__sogo__set_favicon(self, container_id, request_json):
|
||||
for container in self.docker_client.containers.list(filters={"id": container_id}):
|
||||
cmd = ["/bin/bash", "-c", "/customize.sh set_favicon"]
|
||||
sogo_return = container.exec_run(cmd)
|
||||
return exec_run_handler('utf8_text_only', sogo_return)
|
||||
# api call: container_post - post_action: exec - cmd: sogo - task: remove_favicon
|
||||
def container_post__exec__sogo__remove_favicon(self, container_id, request_json):
|
||||
for container in self.docker_client.containers.list(filters={"id": container_id}):
|
||||
cmd = ["/bin/bash", "-c", "cp /sogo.ico /usr/lib/GNUstep/SOGo/WebServerResources/img/sogo.ico"]
|
||||
sogo_return = container.exec_run(cmd)
|
||||
return exec_run_handler('utf8_text_only', sogo_return)
|
||||
# api call: container_post - post_action: exec - cmd: sogo - task: set_theme
|
||||
def container_post__exec__sogo__set_theme(self, container_id, request_json):
|
||||
for container in self.docker_client.containers.list(filters={"id": container_id}):
|
||||
cmd = ["/bin/bash", "-c", "/customize.sh set_theme"]
|
||||
sogo_return = container.exec_run(cmd)
|
||||
return exec_run_handler('utf8_text_only', sogo_return)
|
||||
|
||||
# api call: container_post - post_action: exec - cmd: mailq - task: list
|
||||
def container_post__exec__mailq__list(self, container_id, request_json):
|
||||
for container in self.docker_client.containers.list(filters={"id": container_id}):
|
||||
|
@@ -25,6 +25,7 @@ RUN echo "Building from repository $SOGO_DEBIAN_REPOSITORY" \
|
||||
psmisc \
|
||||
wget \
|
||||
patch \
|
||||
redis-tools \
|
||||
&& dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \
|
||||
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" \
|
||||
&& chmod +x /usr/local/bin/gosu \
|
||||
@@ -46,10 +47,14 @@ COPY syslog-ng-redis_slave.conf /etc/syslog-ng/syslog-ng-redis_slave.conf
|
||||
COPY supervisord.conf /etc/supervisor/supervisord.conf
|
||||
COPY acl.diff /acl.diff
|
||||
COPY stop-supervisor.sh /usr/local/sbin/stop-supervisor.sh
|
||||
COPY customize.sh /
|
||||
COPY docker-entrypoint.sh /
|
||||
|
||||
RUN rm -rf /usr/lib/GNUstep/SOGo/WebServerResources/img/sogo-full.svg
|
||||
RUN mv /usr/lib/GNUstep/SOGo/WebServerResources/img/sogo.ico /sogo.ico
|
||||
RUN chmod +x /bootstrap-sogo.sh \
|
||||
/usr/local/sbin/stop-supervisor.sh
|
||||
/usr/local/sbin/stop-supervisor.sh \
|
||||
/customize.sh
|
||||
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
|
||||
|
@@ -240,6 +240,8 @@ chmod 600 /var/lib/sogo/GNUstep/Defaults/sogod.plist
|
||||
|
||||
# Copy logo, if any
|
||||
[[ -f /etc/sogo/sogo-full.svg ]] && cp /etc/sogo/sogo-full.svg /usr/lib/GNUstep/SOGo/WebServerResources/img/sogo-full.svg
|
||||
# Use the mailcow logo if no sogo-full.svg file does exist
|
||||
! [[ -f /usr/lib/GNUstep/SOGo/WebServerResources/img/sogo-full.svg ]] && cp /etc/sogo/cow_mailcow.svg /usr/lib/GNUstep/SOGo/WebServerResources/img/sogo-full.svg
|
||||
|
||||
# Rsync web content
|
||||
echo "Syncing web content with named volume"
|
||||
|
112
data/Dockerfiles/sogo/customize.sh
Normal file
112
data/Dockerfiles/sogo/customize.sh
Normal file
@@ -0,0 +1,112 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$1" == "enable" ]]; then
|
||||
# enable debug mode
|
||||
if grep -q "SOGoUIxDebugEnabled = YES;" "/etc/sogo/sogo.conf"; then
|
||||
sed -i "s|//SOGoUIxDebugEnabled = YES;|SOGoUIxDebugEnabled = YES;|" "/etc/sogo/sogo.conf"
|
||||
else
|
||||
echo "SOGoUIxDebugEnabled = YES;" >> "/etc/sogo/sogo.conf"
|
||||
fi
|
||||
|
||||
echo "Success: SOGoUIxDebugEnabled has been enabled"
|
||||
elif [[ "$1" == "disable" ]]; then
|
||||
# disable debug mode
|
||||
if grep -q "SOGoUIxDebugEnabled = YES;" "/etc/sogo/sogo.conf"; then
|
||||
if ! grep -q "//SOGoUIxDebugEnabled = YES;" "/etc/sogo/sogo.conf"; then
|
||||
sed -i "s|SOGoUIxDebugEnabled = YES;|//SOGoUIxDebugEnabled = YES;|" "/etc/sogo/sogo.conf"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Success: SOGoUIxDebugEnabled has been disabled"
|
||||
elif [[ "$1" == "set_theme" ]]; then
|
||||
# Get the sogo palettes from Redis
|
||||
PRIMARY=$(redis-cli -h redis HGET SOGO_THEME primary)
|
||||
if [ $? -ne 0 ]; then
|
||||
PRIMARY="green"
|
||||
fi
|
||||
ACCENT=$(redis-cli -h redis HGET SOGO_THEME accent)
|
||||
if [ $? -ne 0 ]; then
|
||||
ACCENT="green"
|
||||
fi
|
||||
BACKGROUND=$(redis-cli -h redis HGET SOGO_THEME background)
|
||||
if [ $? -ne 0 ]; then
|
||||
BACKGROUND="grey"
|
||||
fi
|
||||
|
||||
# Read custom palettes
|
||||
if [ -f /etc/sogo/custom-palettes.js ]; then
|
||||
COLORS=$(cat /etc/sogo/custom-palettes.js)
|
||||
else
|
||||
COLORS=""
|
||||
fi
|
||||
|
||||
# Write theme to /usr/lib/GNUstep/SOGo/WebServerResources/js/theme.js
|
||||
cat > /usr/lib/GNUstep/SOGo/WebServerResources/js/theme.js <<EOL
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular.module('SOGo.Common')
|
||||
.config(configure)
|
||||
|
||||
configure.\$inject = ['\$mdThemingProvider'];
|
||||
function configure(\$mdThemingProvider) {
|
||||
|
||||
$COLORS
|
||||
|
||||
var primary = \$mdThemingProvider.extendPalette('$PRIMARY', {});
|
||||
var accent = \$mdThemingProvider.extendPalette('$ACCENT', {
|
||||
'A100': 'ffffff'
|
||||
});
|
||||
var background = \$mdThemingProvider.extendPalette('$BACKGROUND', {});
|
||||
|
||||
\$mdThemingProvider.definePalette('primary-cow', primary);
|
||||
\$mdThemingProvider.definePalette('accent-cow', accent);
|
||||
\$mdThemingProvider.definePalette('background-cow', background);
|
||||
|
||||
\$mdThemingProvider.theme('default')
|
||||
.primaryPalette('primary-cow', primarySettings)
|
||||
.accentPalette('accent-cow', accentSettings)
|
||||
.backgroundPalette('background-cow', backgroundSettings);
|
||||
\$mdThemingProvider.generateThemesOnDemand(false);
|
||||
}
|
||||
})();
|
||||
EOL
|
||||
|
||||
echo "Success: Theme configuration written"
|
||||
elif [[ "$1" == "set_logo" ]]; then
|
||||
# Get the image data from Redis and save it to a tmp file
|
||||
redis-cli -h redis GET MAIN_LOGO > /tmp/logo_base64.txt
|
||||
|
||||
# Check if mime type is svg+xml
|
||||
mime_type=$(awk -F'[:;]' '{print $2}' /tmp/logo_base64.txt | sed 's/.*\///')
|
||||
if [ "$mime_type" != "svg+xml" ]; then
|
||||
echo "Error: Image format must be of type svg"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Decode base64 and save to file
|
||||
payload=$(cat /tmp/logo_base64.txt | sed 's/^data:[^;]*;//' | awk '{ sub(/^base64,/, ""); print $0 }')
|
||||
echo $payload | base64 -d | tee /usr/lib/GNUstep/SOGo/WebServerResources/img/sogo-full.svg > /dev/null
|
||||
|
||||
# Remove temp file
|
||||
rm /tmp/logo_base64.txt
|
||||
echo "Success: Image has been set"
|
||||
elif [[ "$1" == "set_favicon" ]]; then
|
||||
# Get the image data from Redis and save it to a tmp file
|
||||
redis-cli -h redis GET FAVICON > /tmp/favicon_base64.txt
|
||||
|
||||
# Check if mime type is png or ico
|
||||
mime_type=$(awk -F'[:;]' '{print $2}' /tmp/favicon_base64.txt | sed 's/.*\///')
|
||||
if [[ "$mime_type" != "png" && "$mime_type" != "ico" ]]; then
|
||||
echo "Error: Image format must be of type png or ico"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Decode base64 and save to file
|
||||
payload=$(cat /tmp/favicon_base64.txt | sed 's/^data:[^;]*;//' | awk '{ sub(/^base64,/, ""); print $0 }')
|
||||
echo $payload | base64 -d | tee /usr/lib/GNUstep/SOGo/WebServerResources/img/sogo.ico > /dev/null
|
||||
|
||||
# Remove temp file
|
||||
rm /tmp/favicon_base64.txt
|
||||
echo "Success: Image has been set"
|
||||
fi
|
Reference in New Issue
Block a user