[packages]: net/freeswitch: Fixed sed expression for escaping replaced string in...
[openwrt/svn-archive/archive.git] / net / freeswitch / files / uci / extensions.sh
1 #!/bin/sh
2 # Copyright (C) 2010 Vertical Communications
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
5
6 fs_escape_slash() {
7 local inval="$1"
8 [ -z "$inval" ] && return 0
9 echo "$inval" | sed -e 's/\([/\\]\)/\\\1/g'
10 }
11
12 fs_ext_entry() {
13 local cfg="$1"
14 local number
15 local userid
16 local password
17 local vm_password
18 local toll_allow
19 local account_code
20 local effective_callerid_name
21 local effective_callerid_number
22 local outbound_callerid_name
23 local outbound_callerid_number
24 local did
25 local callgroup
26
27 config_get number "$cfg" number
28 [ "$number" = "default" ] && return 1
29 config_get userid "$cfg" userid "$number"
30 config_get password "$cfg" password '$${default_password}'
31 config_get vm_password "$cfg" vm_password "$number"
32 config_get toll_allow "$cfg" toll_allow 'domestic,international,local'
33 config_get account_code "$cfg" account_code "$number"
34 config_get effective_callerid_name "$cfg" effective_callerid_name "Extension $number"
35 config_get effective_callerid_number "$cfg" effective_callerid_number "$number"
36 config_get outbound_callerid_name "$cfg" outbound_callerid_name '$${outbound_caller_name}'
37 config_get outbound_callerid_number "$cfg" outbound_callerid_number '$${outbound_caller_id}'
38 config_get did "$cfg" did
39 config_get callgroup "$cfg" callgroup "everyone"
40
41 sed -e "s/\[{FS_EXTENSION_ID}\]/$(fs_escape_slash $userid)/
42 s/\[{FS_EXTENSION_PASSWORD}\]/$(fs_escape_slash $password)/
43 s/\[{FS_EXTENSION_VM_PASSWORD}\]/$(fs_escape_slash $vm_password)/
44 s/\[{FS_EXTENSION_TOLL_ALLOW}\]/$(fs_escape_slash $toll_allow)/
45 s/\[{FS_EXTENSION_ACCOUNT_CODE}\]/$(fs_escape_slash $account_code)/
46 s/\[{FS_EXTENSION_EFFECTIVE_CALLERID_NAME}\]/$(fs_escape_slash $effective_callerid_name)/
47 s/\[{FS_EXTENSION_EFFECTIVE_CALLERID_NUMBER}\]/$(fs_escape_slash $effective_callerid_number)/
48 s/\[{FS_EXTENSION_OUTBOUND_CALLERID_NAME}\]/$(fs_escape_slash $outbound_callerid_name)/
49 s/\[{FS_EXTENSION_OUTBOUND_CALLERID_NUMBER}\]/$(fs_escape_slash $outbound_callerid_number)/
50 s/\[{FS_EXTENSION_CALLGROUP}\]/$(fs_escape_slash $callgroup)/
51 " /etc/freeswitch/directory/default/extension.xml.template >/etc/freeswitch/directory/default/ext-"$number".xml
52
53 [ -n "$did" ] && {
54 sed -e "s/\[{FS_INCOMING_DID}\]/$did/
55 s/\[{FS_EXTENSION_NUMBER}\]/$number/
56 " /etc/freeswitch/dialplan/public/did.xml.template >/etc/freeswitch/dialplan/public/20-did-"$did".xml
57 }
58
59 append ext_number_list "$number" '|'
60 }
61
62 fs_extensions_all() {
63 local ext_number_list=""
64 rm -f /etc/freeswitch/directory/default/ext-*.xml
65 rm -f /etc/freeswitch/dialplan/public/20-did-*.xml
66 config_foreach fs_ext_entry "extension"
67 sed -e "s/\[{FS_DIALPLAN_PHONES}\]/$ext_number_list/" /etc/freeswitch/dialplan/public.xml.template >/etc/freeswitch/dialplan/public.xml
68 sed -e "s/\[{FS_DIALPLAN_PHONES}\]/$ext_number_list/" /etc/freeswitch/dialplan/default.xml.template >/etc/freeswitch/dialplan/default.xml
69 }