SOGo multi-domain setup
parent
e0dc88cf7e
commit
85b243a15b
|
@ -5,7 +5,7 @@ ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
ENV GOSU_VERSION 1.9
|
ENV GOSU_VERSION 1.9
|
||||||
RUN set -x \
|
RUN set -x \
|
||||||
&& apt-get update && apt-get install -y --no-install-recommends apt-transport-https ca-certificates wget rsyslog supervisor && rm -rf /var/lib/apt/lists/* \
|
&& apt-get update && apt-get install -y --no-install-recommends apt-transport-https ca-certificates wget rsyslog supervisor mysql-client && rm -rf /var/lib/apt/lists/* \
|
||||||
&& dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \
|
&& 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" \
|
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" \
|
||||||
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc" \
|
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc" \
|
||||||
|
|
|
@ -1,16 +1,93 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
AS_SOGO="gosu sogo"
|
mkdir -p /var/lib/sogo/GNUstep/Defaults/
|
||||||
|
|
||||||
${AS_SOGO} defaults write sogod SOGoUserSources "({type = sql;id = directory;viewURL = mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_view;canAuthenticate = YES;isAddressBook = YES;displayName = \"GAL\";MailFieldNames = (aliases, ad_aliases, senderacl);userPasswordAlgorithm = ssha256;})"
|
# Generate plist header with timezone data
|
||||||
${AS_SOGO} defaults write sogod SOGoProfileURL "mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_user_profile"
|
cat <<EOF > /var/lib/sogo/GNUstep/Defaults/sogod.plist
|
||||||
${AS_SOGO} defaults write sogod OCSFolderInfoURL "mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_folder_info"
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
${AS_SOGO} defaults write sogod OCSEMailAlarmsFolderURL "mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_alarms_folder"
|
<!DOCTYPE plist PUBLIC "-//GNUstep//DTD plist 0.9//EN" "http://www.gnustep.org/plist-0_9.xml">
|
||||||
${AS_SOGO} defaults write sogod OCSSessionsFolderURL "mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_sessions_folder"
|
<plist version="0.9">
|
||||||
${AS_SOGO} defaults write sogod OCSCacheFolderURL "mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_cache_folder"
|
<dict>
|
||||||
${AS_SOGO} defaults write sogod OCSStoreURL "mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_store"
|
<key>OCSAclURL</key>
|
||||||
${AS_SOGO} defaults write sogod OCSAclURL "mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_acl"
|
<string>mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_acl</string>
|
||||||
${AS_SOGO} defaults write sogod SOGoTimeZone "${TZ}"
|
<key>OCSCacheFolderURL</key>
|
||||||
|
<string>mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_cache_folder</string>
|
||||||
|
<key>OCSEMailAlarmsFolderURL</key>
|
||||||
|
<string>mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_alarms_folder</string>
|
||||||
|
<key>OCSFolderInfoURL</key>
|
||||||
|
<string>mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_folder_info</string>
|
||||||
|
<key>OCSSessionsFolderURL</key>
|
||||||
|
<string>mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_sessions_folder</string>
|
||||||
|
<key>OCSStoreURL</key>
|
||||||
|
<string>mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_store</string>
|
||||||
|
<key>SOGoProfileURL</key>
|
||||||
|
<string>mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_user_profile</string>
|
||||||
|
<key>SOGoTimeZone</key>
|
||||||
|
<string>${TZ}</string>
|
||||||
|
<key>domains</key>
|
||||||
|
<dict>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Generate multi-domain setup
|
||||||
|
while read line
|
||||||
|
do
|
||||||
|
DOMAIN_SANE=$(echo ${line} | tr '-' 'b' | tr '.' 'p' | tr -cd '[[:alnum:]]')
|
||||||
|
echo " <key>${line}</key>
|
||||||
|
<dict>
|
||||||
|
<key>SOGoMailDomain</key>
|
||||||
|
<string>$(echo ${line} | tr '-' 'b' | tr '.' 'p')</string>
|
||||||
|
<key>SOGoUserSources</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>MailFieldNames</key>
|
||||||
|
<array>
|
||||||
|
<string>aliases</string>
|
||||||
|
<string>ad_aliases</string>
|
||||||
|
<string>senderacl</string>
|
||||||
|
</array>
|
||||||
|
<key>KindFieldName</key>
|
||||||
|
<string>kind</string>
|
||||||
|
<key>MultipleBookingsFieldName</key>
|
||||||
|
<string>multiple_bookings</string>
|
||||||
|
<key>IMAPLoginFieldName</key>
|
||||||
|
<string>c_uid</string>
|
||||||
|
<key>canAuthenticate</key>
|
||||||
|
<string>YES</string>
|
||||||
|
<key>displayName</key>
|
||||||
|
<string>GAL</string>
|
||||||
|
<key>id</key>
|
||||||
|
<string>${line}</string>
|
||||||
|
<key>isAddressBook</key>
|
||||||
|
<string>YES</string>
|
||||||
|
<key>type</key>
|
||||||
|
<string>sql</string>
|
||||||
|
<key>userPasswordAlgorithm</key>
|
||||||
|
<string>ssha256</string>
|
||||||
|
<key>viewURL</key>
|
||||||
|
<string>mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_view_${DOMAIN_SANE}</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
</dict>" >> /var/lib/sogo/GNUstep/Defaults/sogod.plist
|
||||||
|
mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "DROP VIEW IF EXISTS sogo_view_${DOMAIN_SANE}"
|
||||||
|
mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} << EOF
|
||||||
|
CREATE VIEW sogo_view_${DOMAIN_SANE} (c_uid, c_name, c_password, c_cn, mail, aliases, ad_aliases, senderacl, home) AS
|
||||||
|
SELECT mailbox.username, mailbox.username, mailbox.password, mailbox.name, mailbox.username, IFNULL(ga.aliases, ''), IFNULL(gda.ad_alias, ''), IFNULL(gs.send_as, ''), CONCAT('/var/vmail/', maildir) FROM mailbox
|
||||||
|
LEFT OUTER JOIN grouped_mail_aliases ga ON ga.username = mailbox.username
|
||||||
|
LEFT OUTER JOIN grouped_sender_acl gs ON gs.username = mailbox.username
|
||||||
|
LEFT OUTER JOIN grouped_domain_alias_address gda ON gda.username = mailbox.username
|
||||||
|
WHERE mailbox.active = '1' AND domain = '${line}';
|
||||||
|
EOF
|
||||||
|
done < <(mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT domain FROM domain;" -B -N)
|
||||||
|
|
||||||
|
# Generate footer
|
||||||
|
echo ' </dict>
|
||||||
|
</dict>
|
||||||
|
</plist>' >> /var/lib/sogo/GNUstep/Defaults/sogod.plist
|
||||||
|
|
||||||
|
|
||||||
|
# Fix permissions
|
||||||
|
chown sogo:sogo -R /var/lib/sogo/
|
||||||
|
chmod 600 /var/lib/sogo/GNUstep/Defaults/sogod.plist
|
||||||
|
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
|
|
@ -21,3 +21,7 @@ stdout_logfile_maxbytes=0
|
||||||
command=/sogo-cron.sh
|
command=/sogo-cron.sh
|
||||||
user=sogo
|
user=sogo
|
||||||
autorestart=true
|
autorestart=true
|
||||||
|
|
||||||
|
#[unix_http_server]
|
||||||
|
#file=/var/run/controller/supervisord.sock
|
||||||
|
#chown=www-data:nogroup
|
||||||
|
|
|
@ -15,6 +15,15 @@
|
||||||
SOGoFoldersSendEMailNotifications = YES;
|
SOGoFoldersSendEMailNotifications = YES;
|
||||||
SOGoForwardEnabled = YES;
|
SOGoForwardEnabled = YES;
|
||||||
|
|
||||||
|
// Multi-domain setup
|
||||||
|
// Domains are isolated, you can define visibility options here.
|
||||||
|
// Example:
|
||||||
|
|
||||||
|
// SOGoDomainsVisibility = (
|
||||||
|
// (domain1.tld, domain5.tld),
|
||||||
|
// (domain3.tld, domain2.tld)
|
||||||
|
// );
|
||||||
|
|
||||||
SOGoIMAPServer = "imap://dovecot:143/?tls=YES";
|
SOGoIMAPServer = "imap://dovecot:143/?tls=YES";
|
||||||
SOGoSieveServer = "sieve://dovecot:4190/?tls=YES";
|
SOGoSieveServer = "sieve://dovecot:4190/?tls=YES";
|
||||||
SOGoSMTPServer = "postfix:588";
|
SOGoSMTPServer = "postfix:588";
|
||||||
|
|
|
@ -328,6 +328,12 @@ function mailbox_add_domain($postarray) {
|
||||||
':modified' => date('Y-m-d H:i:s'),
|
':modified' => date('Y-m-d H:i:s'),
|
||||||
':relay_all_recipients' => $relay_all_recipients
|
':relay_all_recipients' => $relay_all_recipients
|
||||||
));
|
));
|
||||||
|
/*
|
||||||
|
PoC for a restart with supervisord unix socket
|
||||||
|
* $sock = stream_socket_client("unix:///var/run/controller/supervisord.sock", $errno, $errstr, 30);
|
||||||
|
* fwrite($sock, "GET ?processname=sogo&action=restart HTTP/1.0\r\nAccept: */*\r\n\r\n");
|
||||||
|
* fclose($sock);
|
||||||
|
*/
|
||||||
$_SESSION['return'] = array(
|
$_SESSION['return'] = array(
|
||||||
'type' => 'success',
|
'type' => 'success',
|
||||||
'msg' => sprintf($lang['success']['domain_added'], htmlspecialchars($domain))
|
'msg' => sprintf($lang['success']['domain_added'], htmlspecialchars($domain))
|
||||||
|
|
|
@ -102,7 +102,6 @@ CREATE TABLE IF NOT EXISTS `filterconf` (
|
||||||
DROP VIEW IF EXISTS grouped_mail_aliases;
|
DROP VIEW IF EXISTS grouped_mail_aliases;
|
||||||
DROP VIEW IF EXISTS grouped_sender_acl;
|
DROP VIEW IF EXISTS grouped_sender_acl;
|
||||||
DROP VIEW IF EXISTS grouped_domain_alias_address;
|
DROP VIEW IF EXISTS grouped_domain_alias_address;
|
||||||
DROP VIEW IF EXISTS sogo_view;
|
|
||||||
|
|
||||||
CREATE VIEW grouped_mail_aliases (username, aliases) AS
|
CREATE VIEW grouped_mail_aliases (username, aliases) AS
|
||||||
SELECT goto, IFNULL(GROUP_CONCAT(address SEPARATOR ' '), '') AS address FROM alias
|
SELECT goto, IFNULL(GROUP_CONCAT(address SEPARATOR ' '), '') AS address FROM alias
|
||||||
|
@ -120,14 +119,6 @@ CREATE VIEW grouped_domain_alias_address (username, ad_alias) AS
|
||||||
SELECT username, IFNULL(GROUP_CONCAT(local_part, '@', alias_domain SEPARATOR ' '), '') AS ad_alias FROM mailbox
|
SELECT username, IFNULL(GROUP_CONCAT(local_part, '@', alias_domain SEPARATOR ' '), '') AS ad_alias FROM mailbox
|
||||||
LEFT OUTER JOIN alias_domain on target_domain=domain GROUP BY username;
|
LEFT OUTER JOIN alias_domain on target_domain=domain GROUP BY username;
|
||||||
|
|
||||||
CREATE VIEW sogo_view (c_uid, c_name, c_password, c_cn, mail, aliases, ad_aliases, senderacl, home) AS
|
|
||||||
SELECT mailbox.username, mailbox.username, mailbox.password, mailbox.name, mailbox.username, IFNULL(ga.aliases, ''), IFNULL(gda.ad_alias, ''), IFNULL(gs.send_as, ''), CONCAT('/var/vmail/', maildir)
|
|
||||||
FROM mailbox
|
|
||||||
LEFT OUTER JOIN grouped_mail_aliases ga ON ga.username = mailbox.username
|
|
||||||
LEFT OUTER JOIN grouped_sender_acl gs ON gs.username = mailbox.username
|
|
||||||
LEFT OUTER JOIN grouped_domain_alias_address gda ON gda.username = mailbox.username
|
|
||||||
WHERE mailbox.active = '1';
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS sogo_acl (
|
CREATE TABLE IF NOT EXISTS sogo_acl (
|
||||||
c_folder_id integer NOT NULL,
|
c_folder_id integer NOT NULL,
|
||||||
c_object character varying(255) NOT NULL,
|
c_object character varying(255) NOT NULL,
|
||||||
|
|
Loading…
Reference in New Issue