FreedomBox/actions/xmpp-setup
2015-06-12 15:49:41 +05:30

94 lines
3.0 KiB
Bash
Executable File

#!/bin/sh
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
if grep --quiet "ip_access: all" /etc/ejabberd/ejabberd.yml; then
xmpp_inband_enable=true
else
xmpp_inband_enable=false
fi
xmpp_inband_enable_cur=$xmpp_inband_enable
export xmpp_inband_enable
if grep --quiet "^auth_method: ldap" /etc/ejabberd/ejabberd.yml; then
ldap_enable=true
else
ldap_enable=false
fi
ldap_enable_cur=$ldap_enable
export ldap_enable
while [ "$1" ] ; do
arg="$1"
shift
case "$arg" in
inband_enable|noinband_enable) # Not using disable for consistency with other options
if [ 'inband_enable' = "$arg" ] ; then
xmpp_inband_enable=true
else
xmpp_inband_enable=false
fi
export xmpp_inband_enable
;;
ldap_enable|noldap_enable)
if [ 'ldap_enable' = "$arg" ] ; then
ldap_enable=true
else
ldap_enable=false
fi
export ldap_enable
;;
status)
printstatus() {
if "$2" ; then
echo "$1"
else
echo no"$1"
fi
}
printstatus inband_enable $xmpp_inband_enable_cur
printstatus ldap_enable $ldap_enable_cur
exit 0
;;
*)
;;
esac
done
if [ "$xmpp_inband_enable" != "$xmpp_inband_enable_cur" ] ; then
if $xmpp_inband_enable ; then
sed -i s/"ip_access: trusted_network"/"ip_access: all"/ /etc/ejabberd/ejabberd.yml
else
sed -i s/"ip_access: all"/"ip_access: trusted_network"/ /etc/ejabberd/ejabberd.yml
fi
ejabberdctl restart || echo "Failed to restart ejabberd with new configuration."
fi
if [ "$ldap_enable" != "$ldap_enable_cur" ] ; then
if $ldap_enable ; then
sed -i 's/^auth_method: internal/## auth_method: internal/' /etc/ejabberd/ejabberd.yml
sed -i 's/^## auth_method: ldap/auth_method: ldap/' /etc/ejabberd/ejabberd.yml
sed -i 's/^## ldap_servers:/ldap_servers:\
- "localhost"/' /etc/ejabberd/ejabberd.yml
sed -i 's/^## ldap_base: .*/ldap_base: "ou=users,dc=thisbox"/' /etc/ejabberd/ejabberd.yml
else
sed -i 's/^## auth_method: internal/auth_method: internal/' /etc/ejabberd/ejabberd.yml
sed -i 's/^auth_method: ldap/## auth_method: ldap/' /etc/ejabberd/ejabberd.yml
fi
ejabberdctl restart || echo "Failed to restart ejabberd with new configuration."
fi