# Setup vm from 64 bit centos6.5 iso, take all the defaults, desktop # install # Set the hostname to a fully qualified globally resolvable name, # something like oc.example.com; we assume the mail domain is then # example.com after removing the leading component # Set a fixed ip address - not dhcp. below we need to point # /etc/resolv.conf to the internal samba dns server running on this # machine, and that would be overwritten by the dhcp client. # Set the time zone to something that does NOT include a # space. America/Los Angeles does not work, but America/Chicago works. # Possibly Ubuntu uses underscore instead of spaces. # http://www.openchange.org/cookbook/configuring.html # there are three hard-coded users here; # sogo is specified in some of the rpms # openchange-user is used for the msql account # johndoe is a test mail account function logme() { echo "" echo "" echo '****' "$(date) $@" } function makesemodule() { modulename="$1" checkmodule -M -m -o $modulename.mod $modulename.te semodule_package -o $modulename.pp -m $modulename.mod rm -f $modulename.mod semodule -i $modulename.pp } function makeauser() { user="$1" pass="$2" logme "create $user in samba" samba-tool user add "$user" "$pass" logme "extend $user in openchange" openchange_newuser --create "$user" logme "setup mail directories for $user" ( REALM=$(hostname) MAILDOMAIN=$(echo $REALM | cut -d. -f2-) cd /var/spool/mail mkdir "$user" mkdir -p "$user"/Drafts "$user"/Sent "$user"/Trash chown -R vmail:vmail "$user" cd /etc/mail echo "$user@$MAILDOMAIN $user@DOVECOT" >>virtusertable echo "$user@$REALM $user@DOVECOT" >>virtusertable make ) } function setupenv() { DOMAIN="$1" ADMINPASS="$2" REALM=$(hostname) HOST=$(echo $REALM | cut -d. -f1) MAILDOMAIN=$(echo $REALM | cut -d. -f2-) AUTODISC=autodiscover.$MAILDOMAIN REALMDN=$(echo .$REALM | sed -e 'sx\.x,DC=xg' | cut -c2-) IP=$(ip -4 addr list eth0 primary | tail -1 | awk '{print $2}' | cut -d/ -f1) REALMUC=$(echo $REALM | tr 'a-z' 'A-Z') } function phase0() { logme 'add epel repository' yum -y install http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm logme 'disable gnustep from epel' # http://www.sogo.nu/english/support/faq/article/how-to-install-sogo-and-sope-through-yum.html fn=/etc/yum.repos.d/epel.repo sed -i -e 's,enabled=.*,\0\nexclude=gnustep-*,g' $fn logme 'install updates' yum -y update } function phase1() { logme 'starting phase 1, does most of the work' setupenv "$1" "$2" logme 'add openchange repository' cat >/etc/yum.repos.d/SOGo.repo <amavisdpatch.te <dnsbl.te <sendmail.te <>/etc/krb5.conf <>/etc/samba/smb.conf </etc/resolv.conf <= 1.0.8,libmemcached >= 0.49,g' configure.ac ./autogen.sh ./configure --prefix=/usr --enable-pyopenchange make logme $(pwd) 'find mapistore and openchange directories' cp python/openchange/mapistore.so /usr/lib64/python2.6/site-packages/openchange/ ) logme 'fixup boot time config for eth0' sed -i -r -e "s/(DNS.=).*$/\1$IP/g" /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i -r -e "s/(DOMAIN=).*$/\1$REALM/g" /etc/sysconfig/network-scripts/ifcfg-eth0 logme 'add user account for backend' # this default could be changed in # /etc/sysconfig/sogo but the rpm has already created the local # account, so we use that default samba-tool user add sogo "$ADMINPASS" # there are many errors in the cookbook at # http://www.openchange.org/cookbook/backends/sogo/index.html # # key=value; lines missing the = and trailing ; # remove other conf file, as claimed below, but the format of # ~sogo/GNUstep/Defaults/.GNUstepDefaults does not look anything # like this one. That one is xml, this one plist. mv ~sogo/GNUstep/Defaults ~sogo/GNUstep/Defaults.save # and that movement does not seem to do any good, since the file # is recreated when sogod restarts. logme 'replace entire sogo conf file here' mv /etc/sogo/sogo.conf /etc/sogo/sogo.conf.save cat >/etc/sogo/sogo.conf <>/etc/sysconfig/memcached </dev/null sleep 1 done service httpd start logme 'start sogo' service sogod restart sleep 10 curl -L http://$REALM/SOGo | grep -q 'loginScreen' if [ $? -eq 1 ]; then echo "sogo not running properly" echo "try http://$REALM/SOGo" exit fi logme 'create the user account for dovecot' # system account since centos selinux tries to relable all user home directories # and we want to keep /var/spool/mail as mail_spool_t useradd -r -s /bin/bash -d /var/spool/mail -G mail vmail chown -R vmail:vmail /var/spool/mail logme 'configure and start dovecot' # http://www.openchange.org/cookbook/backends/sogo/dovecot.html sed -i -e 's/^..include_try/\!include_try/g' /etc/dovecot/dovecot.conf sed -i -e 's/^\!include auth-system.conf/#\!include auth-system.conf/g' /etc/dovecot/conf.d/10-auth.conf vmailuid=$(id -u vmail) vmailgid=$(id -g vmail) cat >/etc/dovecot/local.conf </etc/dovecot/dovecot-ldap-passdb.conf.ext </etc/dovecot/dovecot-ldap-userdb.conf.ext <$modulename.te </usr/share/sendmail-cf/mailer/dovecot.m4 < # License: GNU GPL version 3 or later # _DEFIFNOT(\`DOVECOT_MAILER_MAX', \`ifdef(\`SMTP_MAILER_MAX', \`SMTP_MAILER_MAX', \`10240000')') _DEFIFNOT(\`DOVECOT_MAILER_PATH', \`/usr/libexec/dovecot/dovecot-lda') _DEFIFNOT(\`DOVECOT_MAILER_FLAGS', \`l59DFMPhnu') _DEFIFNOT(\`DOVECOT_MAILER_ARGS', \`/usr/libexec/dovecot/dovecot-lda -d \$u') _DEFIFNOT(\`DOVECOT_MAILER_USER', \`keeper:mail') POPDIVERT ###################################################################### ### Dovecot-lda Mailer specification ### ###################################################################### Mdovecot, P=DOVECOT_MAILER_PATH, F=DOVECOT_MAILER_FLAGS, S=EnvFromL/HdrFromL, R=EnvToL/HdrToL, _OPTINS(\`DOVECOT_MAILER_MAX', \`M=', \`, ') _OPTINS(\`DOVECOT_MAILER_USER', \`U=', \`, ') T=DNS/RFC822/X-Unix, A=DOVECOT_MAILER_ARGS EOF # http://jmaimon.com/sendmail/anfi.homeunix.net/sendmail/localNalias.html cat >/etc/mail/mailertable </etc/mail/access </etc/mail/local-host-names </etc/mail/genericstable </etc/mail/virtusertable </etc/mail/sendmail.ct < /etc/mail/virtual-host-domains </etc/mail/submit.mc </etc/mail/sendmail.mc < /etc/mail/sendmail.cf dnl include(\`/usr/share/sendmail-cf/m4/cf.m4') VERSIONID(\`linux setup for Red Hat Linux') OSTYPE(\`linux') undefine(\`UUCP_RELAY') undefine(\`BITNET_RELAY') define(\`ALIAS_FILE', /etc/mail/aliases) define(\`confAUTH_MECHANISMS', \`LOGIN PLAIN') define(\`confAUTH_OPTIONS', \`A') define(\`confBAD_RCPT_THROTTLE', 2) define(\`confCONNECTION_RATE_THROTTLE', 1) define(\`confCR_FILE', \`/etc/mail/relay-domains') define(\`confCT_FILE', \`/etc/mail/sendmail.ct') define(\`confCW_FILE', \`/etc/mail/local-host-names') define(\`confDEF_USER_ID',\`\`8:12'') define(\`confDONT_PROBE_INTERFACES',true) define(\`confDOUBLE_BOUNCE_ADDRESS', \`') define(\`confLOG_LEVEL', \`20') define(\`confMAX_DAEMON_CHILDREN', \`30') define(\`confMAX_MESSAGE_SIZE', 30000000) define(\`confMAX_RCPTS_PER_MESSAGE',500) define(\`confME_TOO', true) define(\`confPRIVACY_FLAGS', \`goaway,nobodyreturn,noreceipts') define(\`confQUEUE_LA', 25) define(\`confREFUSE_LA', 20) define(\`confTO_COMMAND', \`2m') define(\`confTO_CONNECT', \`1m') define(\`confTO_DATABLOCK', \`3m') define(\`confTO_IDENT', \`0') define(\`confTO_QUEUERETURN', \`5d')dnl define(\`confTO_QUEUEWARN', \`10d')dnl define(\`confTO_STARTTLS', \`3m') define(\`DOVECOT_MAILER_USER', \`vmail:vmail') define(\`MAIL_SETTINGS_DIR', \`/etc/mail/') define(\`MILTER', 1) define(\`PROCMAIL_MAILER_PATH',\`/usr/bin/procmail') define(\`STATUS_FILE', /var/log/mail/statistics) define(\`confSMTP_LOGIN_MSG',\`\$?{if_name}\${if_name}\$|\$j\$. Sendmail \$v/\$Z; \$b') FEATURE(\`no_default_msa',\`dnl') DAEMON_OPTIONS(\`Port=smtp, Name=MTA, M=h') DAEMON_OPTIONS(\`Port=587, Name=MSA, M=E') FEATURE(always_add_domain) FEATURE(local_procmail,\`',\`procmail -t -Y -a \$h -d \$u')dnl The '-t' option will retry delivery if e.g. the user runs over his quota. FEATURE(redirect) FEATURE(use_ct_file) FEATURE(use_cw_file) FEATURE(\`access_db',\`hash -T /etc/mail/access.db') FEATURE(\`greet_pause',\`250') FEATURE(\`delay_checks', \`friend') FEATURE(\`relay_hosts_only') FEATURE(\`mailertable',\`hash /etc/mail/mailertable.db') FEATURE(\`virtusertable',\`hash /etc/mail/virtusertable.db') FEATURE(\`genericstable',\`hash /etc/mail/genericstable.db') FEATURE(\`masquerade_envelope')dnl MASQUERADE_AS(\`$MAILDOMAIN')dnl MASQUERADE_DOMAIN(\`$REALM')dnl MASQUERADE_DOMAIN(\`$HOST.$REALM')dnl VIRTUSER_DOMAIN_FILE(\`/etc/mail/virtual-host-domains') TRUST_AUTH_MECH(\`LOGIN PLAIN')dnl INPUT_MAIL_FILTER(\`dnsbl', \`S=local:/var/run/dnsbl/dnsbl.sock, F=T, T=C:30s;S:5m;R:5m;E:5m') INPUT_MAIL_FILTER(\`milter-amavisd', \`S=local:/var/run/amavisd/amavisd-milter.sock, F=T, T=S:10m;R:10m;E:10m') MAILER(smtp) MAILER(procmail) MAILER(dovecot)dnl define(\`confCACERT_PATH',\`/etc/pki/tls/certs') define(\`confCACERT',\`/etc/pki/tls/certs/ca-bundle.crt') define(\`confSERVER_CERT',\`/etc/pki/tls/certs/sendmail.pem') define(\`confSERVER_KEY',\`/etc/pki/tls/certs/sendmail.pem') LOCAL_CONFIG CPDOVECOT EOF logme 'move the alias file in with the other mail files' mv /etc/aliases /etc/mail logme 'setup saslauthd to do ldap authentication into the samba ldap server' # https://github.com/DigitalOcean-User-Projects/Articles-and-Tutorials/blob/master/sogo_an_MS_exchange_alt.md # http://www.su4me.de/soft_gw_so.html # http://comments.gmane.org/gmane.mail.imap.cyrus/11782 cat >/etc/saslauthd.conf <>/etc/sysconfig/saslauthd </etc/ocsmanager/ocsmanager.ini </dev/null | md5sum | cut -c-32) app_instance_uuid = {$(uuidgen)} NTLMAUTHHANDLER_WORKDIR = /var/cache/ntlmauthhandler SAMBA_HOST = 127.0.0.1 [rpcproxy:ldap] host = localhost port = 389 basedn = CN=Users,$REALMDN # If you'd like to fine-tune the individual locations of the cache data dirs # for the Cache data, or the Session saves, un-comment the desired settings # here: #beaker.cache.data_dir = %(here)s/data/cache #beaker.session.data_dir = %(here)s/data/sessions # WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* # Debug mode will enable the interactive debugging tool, allowing ANYONE to # execute malicious code after an exception is raised. set debug = false [autodiscover:rpcproxy] # We assume the autodiscover host and the EWS (Free/Busy) are in the same host # external_hostname = hostname # Require SSL to logon. Default value is false # ssl = true [outofoffice] # Path of the sieve script for the user # Expansion variables (example user.name@example.com): # \$domain = example.com # \$user = user.name # \$fulluser = user.name@example.com sieve_script_path = /var/spool/mail/\$user/sieve-script # If the sieve script directory hierarchy does not exists it will be created sieve_script_path_mkdir = false # Logging configuration [loggers] keys = root [handlers] keys = console [formatters] keys = generic [logger_root] level = INFO handlers = console [handler_console] class = StreamHandler args = (sys.stderr,) level = NOTSET formatter = generic [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s] [%(threadName)s] %(message)s EOF chmod 640 /etc/ocsmanager/ocsmanager.ini chkconfig --add openchange-ocsmanager service openchange-ocsmanager start logme 'create directories needed for ssl keys' mkdir /etc/httpd/certs logme 'End of phase 1: manually generate the sendmail, dovecot and' echo 'web server ssl keys, get them signed and installed.' echo 'you might script that, then continue with phase2' echo '' echo 'install keys into:' echo ' /etc/pki/tls/certs/sendmail.pem' echo ' /etc/pki/dovecot/certs/dovecot.pem' echo ' /etc/pki/dovecot/private/dovecot.pem' echo " /etc/httpd/certs/$REALM.cert" echo " /etc/httpd/certs/$REALM.key" echo " /etc/httpd/certs/$AUTODISC.cert" echo " /etc/httpd/certs/$AUTODISC.key" echo '' echo 'place the CA certificate in /tmp/*.pem if you have your own' echo 'certificate authority. Otherwise, we assume the certificates' echo 'above are signed by a public CA.' } ## end of phase 1 function phase2() { logme 'starting phase 2, ssl configuration' setupenv unused unused logme 'restart dovecot/sendmail to pickup new ssl keys' service dovecot restart service sendmail restart logme 'configure apache ssl' # https://wiki.mozilla.org/Security/Server_Side_TLS#Apache cat >>/etc/httpd/conf.d/$REALM.conf < ServerName $REALM DocumentRoot /var/www/html ServerAdmin administrator@$MAILDOMAIN CustomLog /var/log/httpd/access_log combined SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK SSLHonorCipherOrder on #SSLCompression off Header add Strict-Transport-Security "max-age=15768000" SSLCertificateFile /etc/httpd/certs/$REALM.cert SSLCertificateKeyFile /etc/httpd/certs/$REALM.key ServerName $AUTODISC DocumentRoot /var/www/html ServerAdmin administrator@$MAILDOMAIN CustomLog /var/log/httpd/access_log combined SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK SSLHonorCipherOrder on #SSLCompression off Header add Strict-Transport-Security "max-age=15768000" SSLCertificateFile /etc/httpd/certs/$AUTODISC.cert SSLCertificateKeyFile /etc/httpd/certs/$AUTODISC.key EOF logme 'restart apache for new config' service httpd restart ca=$(ls -1 /tmp/*.pem 2>/dev/null | head -1) if [ -n "$ca" ]; then curl -L --cacert "$ca" https://$REALM/SOGo | grep -q 'loginScreen' else curl -L https://$REALM/SOGo | grep -q 'loginScreen' fi if [ $? -eq 1 ]; then echo "sogo not running properly, perhaps the ssl key is not properly signed" echo "try https://$REALM/SOGo" exit fi } # run the specified phase with arguments $1 "$2" "$3" # openchange.bash phase1 'DOMAINCHANGEME' 'adminpasschangeme!' # -- generate and install ssl keys # openchange.bash phase2 # openchange.bash makeauser 'username' 'password'