2015-11-02 09:13:11 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
|
|
|
|
# Removes a SIP phone user from the system
|
|
|
|
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
2016-01-02 22:58:27 +01:00
|
|
|
# Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
|
2015-11-02 09:13:11 +01:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2016-02-13 23:09:27 +01:00
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
2015-11-02 09:13:11 +01:00
|
|
|
# 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
|
2016-02-13 23:09:27 +01:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
2015-11-02 09:13:11 +01:00
|
|
|
#
|
2016-02-13 23:09:27 +01:00
|
|
|
# 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/>.
|
2015-11-02 09:13:11 +01:00
|
|
|
|
2015-11-27 12:42:16 +01:00
|
|
|
PROJECT_NAME='freedombone'
|
|
|
|
|
2015-11-27 17:52:23 +01:00
|
|
|
export TEXTDOMAIN=${PROJECT_NAME}-rmsipuser
|
2015-11-27 12:42:16 +01:00
|
|
|
export TEXTDOMAINDIR="/usr/share/locale"
|
|
|
|
|
2015-11-02 11:12:49 +01:00
|
|
|
MY_USERNAME=$1
|
|
|
|
CONFIG_FILE=/etc/sipwitch.conf
|
|
|
|
USER_EXISTS="no"
|
|
|
|
|
|
|
|
function show_help {
|
|
|
|
echo ''
|
2015-12-08 17:22:48 +01:00
|
|
|
echo $"${PROJECT_NAME}-rmsipuser [username]"
|
2015-11-02 11:12:49 +01:00
|
|
|
echo ''
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function sip_user_exists {
|
2015-11-02 13:11:49 +01:00
|
|
|
IFS=''
|
|
|
|
while read line; do
|
2015-11-02 13:16:21 +01:00
|
|
|
if [[ "$line" == *"<user id=\"$MY_USERNAME\">" ]]; then
|
2015-11-02 11:12:49 +01:00
|
|
|
USER_EXISTS="yes"
|
|
|
|
return
|
|
|
|
fi
|
2015-11-02 13:11:49 +01:00
|
|
|
done < $CONFIG_FILE
|
2015-11-02 11:12:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove_sip_user {
|
|
|
|
USER_FOUND=
|
|
|
|
NEW_CONFIG_FILE="${CONFIG_FILE}.new"
|
|
|
|
if [ -f $NEW_CONFIG_FILE ]; then
|
|
|
|
rm -f $NEW_CONFIG_FILE
|
|
|
|
fi
|
|
|
|
touch $NEW_CONFIG_FILE
|
2015-11-02 13:11:49 +01:00
|
|
|
IFS=''
|
|
|
|
while read line; do
|
2015-11-02 11:12:49 +01:00
|
|
|
if [ ! $USER_FOUND ]; then
|
2015-11-02 13:16:21 +01:00
|
|
|
if [[ "$line" == *"<user id=\"$MY_USERNAME\">" ]]; then
|
2015-11-02 11:12:49 +01:00
|
|
|
USER_FOUND="yes"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ ! $USER_FOUND ]; then
|
2015-11-02 13:11:49 +01:00
|
|
|
echo "$line" >> $NEW_CONFIG_FILE
|
2015-11-02 11:12:49 +01:00
|
|
|
else
|
2015-11-02 13:16:21 +01:00
|
|
|
if [[ "$line" == *'</user>' ]]; then
|
2015-11-02 11:12:49 +01:00
|
|
|
USER_FOUND=
|
|
|
|
fi
|
|
|
|
fi
|
2015-11-02 13:11:49 +01:00
|
|
|
done < $CONFIG_FILE
|
2015-11-02 11:12:49 +01:00
|
|
|
mv $NEW_CONFIG_FILE $CONFIG_FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ ! $MY_USERNAME ]; then
|
|
|
|
show_help
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $CONFIG_FILE ]; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"SIP configuration file not found"
|
2015-11-02 11:12:49 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# the user must already exist on the system
|
|
|
|
if [ ! -d /home/$MY_USERNAME ]; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"User $MY_USERNAME not found"
|
2015-11-02 11:12:49 +01:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
sip_user_exists
|
|
|
|
|
|
|
|
if [[ $USER_EXISTS != "yes" ]]; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $'User not found within SIP configuration file'
|
2015-11-02 11:12:49 +01:00
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
2015-11-02 16:13:42 +01:00
|
|
|
systemctl stop sipwitch
|
|
|
|
|
2015-11-02 11:12:49 +01:00
|
|
|
remove_sip_user
|
|
|
|
|
2015-11-02 16:13:42 +01:00
|
|
|
systemctl start sipwitch
|
2015-11-02 11:12:49 +01:00
|
|
|
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"SIP user $MY_USERNAME removed"
|
2015-11-02 09:13:11 +01:00
|
|
|
exit 0
|