-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissabel-change-language
executable file
·191 lines (166 loc) · 4.33 KB
/
issabel-change-language
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
function check_dialog()
{
if ! dialog &> /dev/null
then
echo "ERROR: dialog binary not found."
exit 1
fi
}
function check_database()
{
if ! mysql -uroot $MYSQLAUTH asterisk -e "show tables" &> /dev/null
then
echo "ERROR: Cannot connect to Datbase."
exit 1
fi
}
function logo()
{
dialog --stdout --sleep 1 --backtitle "$BACKTITLE" \
--infobox " O @ @\n @ @ O\n @ O O\n O\nIssabel" \
7 11
}
function set_lang_variables() {
#Set *non standard* GUI languages
case $selLang in
pt_BR)
webLang="br"
fopLang="pt_BR"
ipbxLang="pt_BR"
;;
pr)
webLang="fa"
fopLang="en"
ipbxLang="en_US"
;;
fr)
fopLang="fr_FR"
webLang=$selLang
ipbxLang="fr_FR"
;;
en)
webLang="en"
fopLang="en"
ipbxLang="en_US"
;;
es)
webLang="es"
fopLang="es"
ipbxLang="es_ES"
;;
*)
webLang=$selLang
fopLang=$selLang
ipbxLang=$selLang
;;
esac
}
function set_language()
{
if [ -f /var/www/db/settings.db ]; then
(
sqlite3 /var/www/db/settings.db "update settings set value='$webLang' where key='language'"
if [ -f /usr/local/fop2/fop2settings.db ]
then
sqlite3 /usr/local/fop2/fop2settings.db "update setup set value=\"'$fopLang'\" WHERE extension='SETTINGS' and context='GENERAL' and parameter='language'";
fi
mysql -uroot $MYSQLAUTH asterisk -e "REPLACE INTO sipsettings(keyword,data) VALUES('sip_language','$selLang');" &> /dev/null
mysql -uroot $MYSQLAUTH asterisk -e "REPLACE INTO iaxsettings(keyword,data) VALUES('iax_language','$selLang');" &> /dev/null
mysql -uroot $MYSQLAUTH asterisk -e "REPLACE INTO pjsipsettings(keyword,data) VALUES('sip_language','$selLang');" &> /dev/null
mysql -uroot $MYSQLAUTH asterisk -e "REPLACE INTO issabelpbx_settings(keyword,value,type,defaultval,category,name,description) VALUES('LANGUAGE','$ipbxLang','text','en_EN','GUI Behavior','Language','General Language Setting for IssabelPBX');" &> /dev/null
#DAHDI
DAHDI_CFG="/etc/asterisk/chan_dahdi.conf"
if grep -q "language=" $DAHDI_CFG
then
sed -i "s/^language=.*/language=$selLang/g" $DAHDI_CFG
else
sed -i "/^\[channels\]/a language=$selLang" $DAHDI_CFG
fi
sed -i "s/.*defaultlanguage.*/defaultlanguage=$selLang/" /etc/asterisk/asterisk.conf
) &> /dev/null
else
write_selection
fi
}
function reload_amportal() {
which amportal &>/dev/null
if [ $? -eq 0 ]; then
logo
if ! amportal a r &> /dev/null
then
clear
echo "ERROR: Cannot apply changes."
exit 3
else
clear
fi
fi
}
function write_selection() {
echo "webLang=$webLang" >/tmp/ipbx.lang
echo "fopLang=$fopLang" >>/tmp/ipbx.lang
echo "ipbxLang=$ipbxLang" >>/tmp/ipbx.lang
echo "selLang=$selLang" >>/tmp/ipbx.lang
}
# Loads mysql root password
source /etc/issabel.conf
if [ -z $mysqlrootpwd ]
then
MYSQLAUTH=""
else
MYSQLAUTH="-p$mysqlrootpwd"
fi
# Start MAIN section
if [ $# -eq 0 ];
then
# No argument supplied, check for /tmp/ipbx.lang
if [ ! -f /tmp/ipbx.lang ]; then
check_dialog
if [ -f /var/www/db/settings.db ]; then
check_database
currentLang=$(sqlite3 /var/www/db/settings.db "select value from settings where key='language'")
else
currentLang=""
fi
langselected_en=on
langselected_es=off
langselected_br=off
langselected_fr=off
langselected_fa=off
if [ "x$currentLang" != "x" ]; then
langselected_en=off
declare langselected_${currentLang}=on
fi
selLang=$((dialog --backtitle "Issabel" --no-tags \
--radiolist "Select PBX language:" 15 40 10 \
en "English" $langselected_en \
es "Spanish" $langselected_es \
pt_BR "Portuguese(BR)" $langselected_br \
fr "French" $langselected_fr \
pr "Persian" $langselected_fa \
> /dev/tty) 2>&1)
if [ -z $selLang ]
then
#No language selected
exit 2
fi
set_lang_variables
else
# this sets languages as set_lang_variables based on selection, but from saved lang file
set -o allexport && source /tmp/ipbx.lang && set +o allexport
rm -f /tmp/ipbx.lang
fi
else
# language argument passed, if valid just apply changes
valid_lang="es en fr pt_BR pr"
selLang=$1
if [[ $valid_lang =~ (^|[[:space:]])$selLang($|[[:space:]]) ]]; then
set_lang_variables
else
exit 1
fi
fi
# actually set the language and reloads
set_language
reload_amportal