~ubuntu-branches/ubuntu/natty/arno-iptables-firewall/natty

« back to all changes in this revision

Viewing changes to share/arno-iptables-firewall/plugins/dyndns-host-open-helper

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2010-01-10 16:46:32 UTC
  • mfrom: (1.1.8 upstream) (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100110164632-d8e9r8svapi2qkec
Tags: 1.9.2.h-1
* New upstream release (Closes: #550222, #553036).
* Unify dependency-based boot-order and old-style update-rc.d, to be similar
  to shorewall's behavior.
* Add lintian override. The init script does handle 'stop', but it is
  shadowed by an if-clause. The 'else' branch handles 'stop' as well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
if [ -e "$CONFIG_FILE" ]; then
14
14
  . $CONFIG_FILE
15
15
else
16
 
  echo "ERROR: Could not read configuration file $CONFIG_FILE!" >&2
17
 
  echo "       Please, check the file's location and (root) rights." >&2
 
16
  echo "** ERROR: Could not read configuration file $CONFIG_FILE!" >&2
 
17
  echo "**        Please, check the file's location and (root) rights." >&2
18
18
  exit 2
19
19
fi
20
20
 
29
29
    if [ -f /usr/share/arno-iptables-firewall/environment ]; then
30
30
      . /usr/share/arno-iptables-firewall/environment
31
31
    else
32
 
      printf "\033[40m\033[1;31mERROR: The environment file (ENV_FILE) has not been specified\033[0m\n" >&2
33
 
      printf "\033[40m\033[1;31m       in the configuration file. Try upgrading your config-file!\033[0m\n" >&2
 
32
      echo "** ERROR: The environment file (ENV_FILE) has not been specified" >&2
 
33
      echo "**        in the configuration file. Try upgrading your config-file!" >&2
34
34
      exit 2
35
35
    fi
36
36
  fi
37
37
fi
38
38
 
39
39
 
40
 
# Function to first try to resolve @DynDNS else use the system default NS server
41
 
resolvehost()
42
 
{
43
 
#  local result="$(gethostbyname "$1" "@ns.dyndns.org")"
44
 
 
45
 
#  if [ -z "$result" ]; then
46
 
    result="$(gethostbyname "$1")"
47
 
#  fi
48
 
 
49
 
  echo "$result"
50
 
}
51
 
 
52
 
 
53
 
# Check sanity of ie. environment
 
40
# Check sanity of eg. environment
54
41
sanity_check()
55
42
{
56
43
  if [ -z "$DYNDNS_HOST_OPEN_CRON" ]; then
57
 
    echo "** ERROR: The plugin config file is not properly set! **" >&2
 
44
    echo "** ERROR: The plugin config file is not properly set!" >&2
58
45
    return 1
59
46
  fi
60
47
 
70
57
 
71
58
    IFS=','
72
59
    for host in $hosts; do
73
 
      if [ -z "$(resolvehost "$host")" ]; then
74
 
        echo "** ERROR: Unresolvable host \"$host\", refusing to (re)start! **" >&2
 
60
      if [ -z "$(gethostbyname "$host")" ]; then
 
61
        echo "** ERROR: Unresolvable host \"$host\", refusing to (re)start!" >&2
75
62
        return 1
76
63
      fi
77
64
    done
83
70
 
84
71
    IFS=','
85
72
    for host in $hosts; do
86
 
      if [ -z "$(resolvehost "$host")" ]; then
87
 
        echo "** ERROR: Unresolvable host \"$host\", refusing to (re)start! **" >&2
 
73
      if [ -z "$(gethostbyname "$host")" ]; then
 
74
        echo "** ERROR: Unresolvable host \"$host\", refusing to (re)start!" >&2
88
75
        return 1
89
76
      fi
90
77
    done
96
83
 
97
84
    IFS=','
98
85
    for host in $hosts; do
99
 
      if [ -z "$(resolvehost "$host")" ]; then
100
 
        echo "** ERROR: Unresolvable host \"$host\", refusing to (re)start! **" >&2
 
86
      if [ -z "$(gethostbyname "$host")" ]; then
 
87
        echo "** ERROR: Unresolvable host \"$host\", refusing to (re)start!" >&2
101
88
        return 1
102
89
      fi
103
90
    done
109
96
 
110
97
    IFS=','
111
98
    for host in $hosts; do
112
 
      if [ -z "$(resolvehost "$host")" ]; then
113
 
        echo "** ERROR: Unresolvable host \"$host\", refusing to (re)start! **" >&2
 
99
      if [ -z "$(gethostbyname "$host")" ]; then
 
100
        echo "** ERROR: Unresolvable host \"$host\", refusing to (re)start!" >&2
114
101
        return 1
115
102
      fi
116
103
    done
134
121
    hosts=`get_hosts_ihp "$rule"`
135
122
    ports=`get_ports_ihp "$rule"`
136
123
 
137
 
    echo "  $(show_if_ip "$interfaces" "$destips")Allowing $hosts for TCP port(s): $ports"
 
124
    echo "$(show_if_ip "$interfaces" "$destips")Allowing $hosts for TCP port(s): $ports"
138
125
 
139
126
    IFS=','
140
127
    for host in $hosts; do
141
128
      for port in $ports; do
142
129
        for destip in $destips; do
143
130
          for interface in $interfaces; do
144
 
            iptables -A DYNDNS_CHAIN -i $interface -s $(resolvehost "$host") -d $destip -p tcp --dport $port -j ACCEPT
 
131
            iptables -A DYNDNS_CHAIN -i $interface -s $(gethostbyname "$host") -d $destip -p tcp --dport $port -j ACCEPT
145
132
          done
146
133
        done
147
134
      done
158
145
    hosts=`get_hosts_ihp "$rule"`
159
146
    ports=`get_ports_ihp "$rule"`
160
147
 
161
 
    echo "  $(show_if_ip "$interfaces" "$destips")Allowing $hosts for UDP port(s): $ports"
 
148
    echo "$(show_if_ip "$interfaces" "$destips")Allowing $hosts for UDP port(s): $ports"
162
149
 
163
150
    IFS=','
164
151
    for host in $hosts; do
165
152
      for port in $ports; do
166
153
        for destip in $destips; do
167
154
          for interface in $interfaces; do
168
 
            iptables -A DYNDNS_CHAIN -i $interface -s $(resolvehost "$host") -d $destip -p udp --dport $port -j ACCEPT
 
155
            iptables -A DYNDNS_CHAIN -i $interface -s $(gethostbyname "$host") -d $destip -p udp --dport $port -j ACCEPT
169
156
          done
170
157
        done
171
158
      done
182
169
    hosts=`get_hosts_ihp "$rule"`
183
170
    protos=`get_ports_ihp "$rule"`
184
171
 
185
 
    echo "  $(show_if_ip "$interfaces" "$destips")Allowing $hosts for IP protocol(s): $protos"
 
172
    echo "$(show_if_ip "$interfaces" "$destips")Allowing $hosts for IP protocol(s): $protos"
186
173
 
187
174
    IFS=','
188
175
    for host in $hosts; do
190
177
      for proto in $protos; do
191
178
        for destip in $destips; do
192
179
          for interface in $interfaces; do
193
 
            iptables -A DYNDNS_CHAIN -i $interface -s $(resolvehost "$host") -d $destip -p $proto -j ACCEPT
 
180
            iptables -A DYNDNS_CHAIN -i $interface -s $(gethostbyname "$host") -d $destip -p $proto -j ACCEPT
194
181
          done
195
182
        done
196
183
      done
206
193
    destips=`get_ips "$rule"`
207
194
    hosts=`get_hosts_ih "$rule"`
208
195
 
209
 
    echo "  $(show_if_ip "$interfaces" "$destips")Allowing $hosts for ICMP-requests(ping)"
 
196
    echo "$(show_if_ip "$interfaces" "$destips")Allowing $hosts for ICMP-requests(ping)"
210
197
 
211
198
    IFS=','
212
199
    for host in $hosts; do
213
200
      for destip in $destips; do
214
201
        for interface in $interfaces; do
215
 
          iptables -A DYNDNS_CHAIN -i $interface -s $(resolvehost "$host") -d $destip -p $ICMP_PROTO $ICMP_TYPE echo-request -j ACCEPT
 
202
          iptables -A DYNDNS_CHAIN -i $interface -s $(gethostbyname "$host") -d $destip -p $ICMP_PROTO $ICMP_TYPE echo-request -j ACCEPT
216
203
        done
217
204
      done
218
205
    done
237
224
 
238
225
# Check if the config file exists
239
226
if [ ! -e "$CONF_FILE" ]; then
240
 
  printf "  ** ERROR: Config file \"$CONF_FILE\" not found! **\n" >&2
 
227
  echo "** ERROR: Config file \"$CONF_FILE\" not found!" >&2
241
228
  exit 1
242
229
else
243
230
  # Source the plugin config file