add packages_10.03.2 in preparation for the 10.03.2 interim release
[10.03/packages.git] / net / siproxd / files / siproxd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 Alina Friedrichsen
3
4 START=50
5
6 start() {
7         local ifname
8         local cfgt
9
10         option_cb() {
11                 local varname="$1"
12                 local value="$2"
13                 local cfg="$CONFIG_SECTION"
14                 local cfgt
15                 local item
16                 local c
17
18                 config_get cfgt "$cfg" TYPE
19
20                 if [ "$cfgt" == siproxd ]; then
21                         if [ "$varname" == config_file ]; then
22                                 CONFIG_FILE="$value"
23                         elif [ "$varname" == if_inbound ]; then
24                                 IF_INBOUND="$value"
25                         elif [ "$varname" == if_outbound ]; then
26                                 IF_OUTBOUND="$value"
27                         elif [ "$varname" == mask_host ]; then
28                                 c=0
29                                 for item in $value
30                                 do
31                                         if [ "$((c % 2))" -eq 0 ]; then
32                                                 printf '%s\n' "mask_host = $item" >> /var/etc/siproxd.conf
33                                         else
34                                                 printf '%s\n' "masked_host = $item" >> /var/etc/siproxd.conf
35                                         fi
36                                         c=$((c + 1))
37                                 done
38                         elif [ "$varname" == outbound_domain ]; then
39                                 c=0
40                                 for item in $value
41                                 do
42                                         if [ "$((c % 3))" -eq 0 ]; then
43                                                 printf '%s\n' "outbound_domain_name = $item" >> /var/etc/siproxd.conf
44                                         elif [ "$((c % 3))" -eq 1 ]; then
45                                                 printf '%s\n' "outbound_domain_host = $item" >> /var/etc/siproxd.conf
46                                         else
47                                                 printf '%s\n' "outbound_domain_port = $item" >> /var/etc/siproxd.conf
48                                         fi
49                                         c=$((c + 1))
50                                 done
51                         elif [ "$varname" == pi_shortdial_entry ]; then
52                                 for item in $value
53                                 do
54                                         printf '%s\n' "pi_shortdial_entry = $item" >> /var/etc/siproxd.conf
55                                 done
56                         else
57                                 if [ "$varname" == hosts_allow_reg -o "$varname" == hosts_allow_sip -o "$varname" == hosts_deny_sip ]; then
58                                         value=$(printf '%s' "$value" | tr -s '\t ' ',')
59                                 fi
60                                 [ "$varname" == sip_listen_port ] && SIP_LISTEN_PORT=""
61                                 [ "$varname" == daemonize ] && DAEMONIZE=""
62                                 [ "$varname" == silence_log ] && SILENCE_LOG=""
63                                 [ "$varname" == log_calls ] && LOG_CALLS=""
64                                 [ "$varname" == user ] && USER=""
65                                 [ "$varname" == registration_file ] && REGISTRATION_FILE=""
66                                 [ "$varname" == pid_file ] && PID_FILE=""
67                                 [ "$varname" == rtp_proxy_enable ] && RTP_PROXY_ENABLE=""
68                                 [ "$varname" == rtp_port_low ] && RTP_PORT_LOW=""
69                                 [ "$varname" == rtp_port_high ] && RTP_PORT_HIGH=""
70                                 [ "$varname" == rtp_timeout ] && RTP_TIMEOUT=""
71                                 [ "$varname" == default_expires ] && DEFAULT_EXPIRES=""
72                                 [ "$varname" == debug_level ] && DEBUG_LEVEL=""
73                                 [ "$varname" == debug_port ] && DEBUG_PORT=""
74                                 printf '%s\n' "$varname = $value" >> /var/etc/siproxd.conf
75                         fi
76                 fi
77         }
78
79         mkdir -p /var/etc
80         > /var/etc/siproxd.conf
81         mkdir -p /var/lib/siproxd
82         chmod 777 /var/lib/siproxd
83         mkdir -p /var/run/siproxd
84         chmod 777 /var/run/siproxd
85         CONFIG_FILE=/var/etc/siproxd.conf
86         SIP_LISTEN_PORT=5060
87         DAEMONIZE=1
88         SILENCE_LOG=0
89         LOG_CALLS=1
90         USER=nobody
91         REGISTRATION_FILE=/var/lib/siproxd/siproxd_registrations
92         PID_FILE=/var/run/siproxd/siproxd.pid
93         RTP_PROXY_ENABLE=1
94         RTP_PORT_LOW=7070
95         RTP_PORT_HIGH=7089
96         RTP_TIMEOUT=300
97         DEFAULT_EXPIRES=600
98         DEBUG_LEVEL=0x00000000
99         DEBUG_PORT=0
100         config_load siproxd
101         [ -n "$SIP_LISTEN_PORT" ] && printf '%s\n' "sip_listen_port = $SIP_LISTEN_PORT" >> /var/etc/siproxd.conf
102         [ -n "$DAEMONIZE" ] && printf '%s\n' "daemonize = $DAEMONIZE" >> /var/etc/siproxd.conf
103         [ -n "$SILENCE_LOG" ] && printf '%s\n' "silence_log = $SILENCE_LOG" >> /var/etc/siproxd.conf
104         [ -n "$LOG_CALLS" ] && printf '%s\n' "log_calls = $LOG_CALLS" >> /var/etc/siproxd.conf
105         [ -n "$USER" ] && printf '%s\n' "user = $USER" >> /var/etc/siproxd.conf
106         [ -n "$REGISTRATION_FILE" ] && printf '%s\n' "registration_file = $REGISTRATION_FILE" >> /var/etc/siproxd.conf
107         [ -n "$PID_FILE" ] && printf '%s\n' "pid_file = $PID_FILE" >> /var/etc/siproxd.conf
108         [ -n "$RTP_PROXY_ENABLE" ] && printf '%s\n' "rtp_proxy_enable = $RTP_PROXY_ENABLE" >> /var/etc/siproxd.conf
109         [ -n "$RTP_PORT_LOW" ] && printf '%s\n' "rtp_port_low = $RTP_PORT_LOW" >> /var/etc/siproxd.conf
110         [ -n "$RTP_PORT_HIGH" ] && printf '%s\n' "rtp_port_high = $RTP_PORT_HIGH" >> /var/etc/siproxd.conf
111         [ -n "$RTP_TIMEOUT" ] && printf '%s\n' "rtp_timeout = $RTP_TIMEOUT" >> /var/etc/siproxd.conf
112         [ -n "$DEFAULT_EXPIRES" ] && printf '%s\n' "default_expires = $DEFAULT_EXPIRES" >> /var/etc/siproxd.conf
113         [ -n "$DEBUG_LEVEL" ] && printf '%s\n' "debug_level = $DEBUG_LEVEL" >> /var/etc/siproxd.conf
114         [ -n "$DEBUG_PORT" ] && printf '%s\n' "debug_port = $DEBUG_PORT" >> /var/etc/siproxd.conf
115         reset_cb
116         include /lib/network
117         scan_interfaces
118         config_load /var/state/network
119         if [ -n "$IF_INBOUND" ]; then
120                 config_get IF_INBOUND "$IF_INBOUND" ifname
121                 printf '%s\n' "if_inbound = $IF_INBOUND" >> /var/etc/siproxd.conf
122         fi
123         if [ -n "$IF_OUTBOUND" ]; then
124                 config_get IF_OUTBOUND "$IF_OUTBOUND" ifname
125                 printf '%s\n' "if_outbound = $IF_OUTBOUND" >> /var/etc/siproxd.conf
126         fi
127         /usr/sbin/siproxd --config "$CONFIG_FILE"
128 }
129
130 stop() {
131         killall siproxd
132 }