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

« back to all changes in this revision

Viewing changes to share/arno-iptables-firewall/plugins/traffic-accounting-helper

  • Committer: Package Import Robot
  • Author(s): Michael Hanke
  • Date: 2014-05-08 16:07:04 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20140508160704-uu2gozrk4sw9d72x
Tags: 2.0.1.e-1
* New upstream release.
  - Removed TRACE option.
* Updated debian/copyright.
* Bumped Standards-Version to 3.9.5; no changes necessary.
* Bumped debhelper compatibility level to 9.
* Adjust update-rc.d call to replace unsupported use of 'start' and 'stop'
  commands with 'defaults' and rely on LSB header information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
# Returns   : Resolved host's IP in "$host_ip"
97
97
traffic_accounting_get_host()
98
98
{
 
99
  host_ip=""      # Reset result
99
100
  local host="$1"
100
 
  host_ip=""
101
 
  
 
101
  local retval=0
 
102
 
102
103
  if is_numeric_ip "$host"; then
103
104
    host_ip="$host"
 
105
    return 0
 
106
  fi
 
107
 
 
108
  printf "${INDENT}Resolving \"$host\" -> "
 
109
 
 
110
  # First try to get host from host-cache
 
111
  if [ "$TRAFFIC_ACCOUNTING_USE_HOST_CACHE" != "0" ] && \
 
112
     [ -n "$TA_HOST_CACHE" ] && [ -e "$TA_HOST_CACHE" ]; then
 
113
 
 
114
    local find_host=`grep "^$host " -m1 "$TA_HOST_CACHE"`
 
115
    if [ -n "$find_host" ]; then
 
116
      host_ip=`echo "$find_host" |cut -s -f2 -d' '`
 
117
 
 
118
      echo "$host_ip (cached)"
 
119
      return 0
 
120
    fi
 
121
  fi
 
122
 
 
123
  # Perform normal lookup
 
124
  DNS_FAST_FAIL_ONCE="$DYNDNS_DNS_FAST_FAIL"
 
125
  host_ip=`gethostbyname "$host"`
 
126
  retval=$?
 
127
 
 
128
  if [ -z "$host_ip" -o $retval -ne 0 ]; then
 
129
    printf "\033[40m\033[1;31mFAILED!\n\033[0m"
 
130
    echo "** ERROR($retval): Unresolvable host \"$host\"! **" >&2
104
131
  else
105
 
    printf "${INDENT}Resolving \"$host\" -> "
106
 
    if [ "$TRAFFIC_ACCOUNTING_USE_HOST_CACHE" != "0" ] && \
107
 
       [ -n "$TA_HOST_CACHE" ] && [ -e "$TA_HOST_CACHE" ]; then
108
 
      host_ip=`grep "^$host " -m1 "$TA_HOST_CACHE" |cut -s -f2 -d' '`
109
 
 
110
 
      if [ -n "$host_ip" ]; then
111
 
        echo "$host_ip (cached)"
112
 
      fi
113
 
    fi
114
 
 
115
 
    if [ -z "$host_ip" ]; then
116
 
      # Perform normal lookup
117
 
      host_ip=`gethostbyname "$host"`
118
 
      if [ -n "$host_ip" ]; then
119
 
        echo "$host_ip"
120
 
      else
121
 
        printf "\033[40m\033[1;31mFAILED!\n\033[0m"
122
 
      fi
123
 
    fi
 
132
    echo "$host_ip"
124
133
  fi
 
134
 
 
135
  return $retval
125
136
}
126
137
 
127
138
 
166
177
      old_out_value=0
167
178
    fi
168
179
 
169
 
    # Get host_ip
170
 
    traffic_accounting_get_host "$host"
171
 
 
172
 
    # If it fails use old IP
173
 
    if [ -z "$host_ip" ]; then
 
180
    # Get host_ip, if it fails, skip rule
 
181
    if ! traffic_accounting_get_host "$host"; then
 
182
      echo "** WARNING: Skipping rule for \"$host\"! **" >&2
174
183
      continue;
175
184
    fi
176
185