| 1 |
#! @SCRIPT_SH@ |
| 2 |
# $Id$ |
| 3 |
# |
| 4 |
# HylaFAX Facsimile Software |
| 5 |
# |
| 6 |
# Copyright (c) 1990-1996 Sam Leffler |
| 7 |
# Copyright (c) 1991-1996 Silicon Graphics, Inc. |
| 8 |
# HylaFAX is a trademark of Silicon Graphics |
| 9 |
# |
| 10 |
# Permission to use, copy, modify, distribute, and sell this software and |
| 11 |
# its documentation for any purpose is hereby granted without fee, provided |
| 12 |
# that (i) the above copyright notices and this permission notice appear in |
| 13 |
# all copies of the software and related documentation, and (ii) the names of |
| 14 |
# Sam Leffler and Silicon Graphics may not be used in any advertising or |
| 15 |
# publicity relating to the software without the specific, prior written |
| 16 |
# permission of Sam Leffler and Silicon Graphics. |
| 17 |
# |
| 18 |
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, |
| 19 |
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY |
| 20 |
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
| 21 |
# |
| 22 |
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR |
| 23 |
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, |
| 24 |
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
| 25 |
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF |
| 26 |
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 27 |
# OF THIS SOFTWARE. |
| 28 |
# |
| 29 |
|
| 30 |
# |
| 31 |
# Print Statistics about Transmitted Facsimile. |
| 32 |
# |
| 33 |
SPOOL=@SPOOL@ |
| 34 |
. $SPOOL/bin/common-functions |
| 35 |
|
| 36 |
test -f $SPOOL/etc/setup.cache || { |
| 37 |
cat<<EOF |
| 38 |
|
| 39 |
FATAL ERROR: $SPOOL/etc/setup.cache is missing! |
| 40 |
|
| 41 |
The file $SPOOL/etc/setup.cache is not present. This |
| 42 |
probably means the machine has not been setup using the faxsetup(@MANNUM1_8@) |
| 43 |
command. Read the documentation on setting up HylaFAX before you |
| 44 |
startup a server system. |
| 45 |
|
| 46 |
EOF |
| 47 |
hfExit 1 |
| 48 |
} |
| 49 |
. $SPOOL/etc/setup.cache |
| 50 |
|
| 51 |
FILES= |
| 52 |
SORTKEY=-sender # default is to sort by sender |
| 53 |
MAPNAMES=no # default is to not map email addresses (NIS) |
| 54 |
TODAY="`date +'%D %H:%M'`" |
| 55 |
AGE="360" # report statistics for last year |
| 56 |
SINCEDT= |
| 57 |
ENDDT= |
| 58 |
|
| 59 |
while [ x"$1" != x"" ] ; do |
| 60 |
case $1 in |
| 61 |
-send*|-csi|-dest*|-speed|-rate|-format|-job*|-dev*) |
| 62 |
SORTKEY=$1;; |
| 63 |
-nomap) MAPNAMES=no;; |
| 64 |
-map) MAPNAMES=yes;; |
| 65 |
-age) shift; AGE=$1;; |
| 66 |
-since) shift; SINCEDT=$1;; |
| 67 |
-end) shift; ENDDT=$1;; |
| 68 |
-*) echo "Usage: $0 [-sortkey] [-age days] [-since date] [-end date] [-nomap] [files]"; hfExit 1;; |
| 69 |
*) FILES="$FILES $1";; |
| 70 |
esac |
| 71 |
shift |
| 72 |
done |
| 73 |
if [ -z "$FILES" ]; then |
| 74 |
FILES=$SPOOL/etc/xferfaxlog |
| 75 |
fi |
| 76 |
|
| 77 |
# |
| 78 |
# Construct awk rules to collect information according |
| 79 |
# to the desired sort key. There are multiple rules for |
| 80 |
# each; to deal with the different formats that have |
| 81 |
# existed over time. |
| 82 |
# |
| 83 |
case $SORTKEY in |
| 84 |
-send*) |
| 85 |
AWKRULES=' |
| 86 |
$2 == "SEND" && NF == 9 { acct($3, $4, $7, $8, $5, $6, $9); } |
| 87 |
$2 == "SEND" && NF == 11 { acct($4, $5, $9, $10, $7, $8, $11); } |
| 88 |
$2 == "SEND" && NF == 12 { acct($5, $6, $10, $11, $8, $9, $12); } |
| 89 |
$2 == "SEND" && NF == 13 { acct($7, $8, $11, $12, getBR($10), getDF($10), $13); } |
| 90 |
$2 == "SEND" && NF == 14 { acct($7, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 91 |
$2 == "SEND" && NF == 16 { acct($7, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 92 |
$2 == "SEND" && NF == 17 { acct($7 " (" $17 ")", $8, $11, $13, getBR($10), getDF($10), $14); } |
| 93 |
$2 == "SEND" && NF == 18 { acct($7 " (" $18 ")", $8, $11, $13, getBR($10), getDF($10), $14); } |
| 94 |
$2 == "SEND" && NF == 19 { acct($7 " (" $18 ")", $8, $11, $13, getBR($10), getDFfromDCS($19), $14); } |
| 95 |
' |
| 96 |
KEYTITLE="Sender" |
| 97 |
;; |
| 98 |
-csi) |
| 99 |
AWKRULES=' |
| 100 |
$2 == "SEND" && NF == 9 { acct($4, $4, $7, $8, $5, $6, $9); } |
| 101 |
$2 == "SEND" && NF == 11 { acct($6, $5, $9, $10, $7, $8, $11); } |
| 102 |
$2 == "SEND" && NF == 12 { acct($7, $6, $10, $11, $8, $9, $12); } |
| 103 |
$2 == "SEND" && NF == 13 { acct($9, $8, $11, $12, getBR($10), getDF($10), $13); } |
| 104 |
$2 == "SEND" && NF == 14 { acct($9, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 105 |
$2 == "SEND" && NF == 16 { acct($9, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 106 |
$2 == "SEND" && NF == 17 { acct($9, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 107 |
$2 == "SEND" && NF == 18 { acct($9, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 108 |
$2 == "SEND" && NF == 19 { acct($9, $8, $11, $13, getBR($10), getDFfromDCS($19), $14); } |
| 109 |
' |
| 110 |
KEYTITLE="CSI" |
| 111 |
MAPNAMES=no |
| 112 |
;; |
| 113 |
-dest*) |
| 114 |
AWKRULES=' |
| 115 |
$2 == "SEND" && NF == 9 { acct($4, $4, $7, $8, $5, $6, $9); } |
| 116 |
$2 == "SEND" && NF == 11 { acct($5, $5, $9, $10, $7, $8, $11); } |
| 117 |
$2 == "SEND" && NF == 12 { acct($6, $6, $10, $11, $8, $9, $12); } |
| 118 |
$2 == "SEND" && NF == 13 { acct($8, $8, $11, $12, getBR($10), getDF($10), $13); } |
| 119 |
$2 == "SEND" && NF == 14 { acct($8, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 120 |
$2 == "SEND" && NF == 16 { acct($8, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 121 |
$2 == "SEND" && NF == 17 { acct($8, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 122 |
$2 == "SEND" && NF == 18 { acct($8, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 123 |
$2 == "SEND" && NF == 19 { acct($8, $8, $11, $13, getBR($10), getDFfromDCS($19), $14); } |
| 124 |
' |
| 125 |
KEYTITLE="Destination" |
| 126 |
MAPNAMES=no |
| 127 |
;; |
| 128 |
-speed|-rate) |
| 129 |
AWKRULES=' |
| 130 |
$2 == "SEND" && NF == 9 { acct($5, $4, $7, $8, $5, $6, $9); } |
| 131 |
$2 == "SEND" && NF == 11 { acct($7, $5, $9, $10, $7, $8, $11); } |
| 132 |
$2 == "SEND" && NF == 12 { acct($8, $6, $10, $11, $8, $9, $12); } |
| 133 |
$2 == "SEND" && NF == 13 { acct(getBR($10), $8, $11, $12, getBR($10), getDF($10), $13); } |
| 134 |
$2 == "SEND" && NF == 14 { acct(getBR($10), $8, $11, $13, getBR($10), getDF($10), $14); } |
| 135 |
$2 == "SEND" && NF == 16 { acct(getBR($10), $8, $11, $13, getBR($10), getDF($10), $14); } |
| 136 |
$2 == "SEND" && NF == 17 { acct(getBR($10), $8, $11, $13, getBR($10), getDF($10), $14); } |
| 137 |
$2 == "SEND" && NF == 18 { acct(getBR($10), $8, $11, $13, getBR($10), getDF($10), $14); } |
| 138 |
$2 == "SEND" && NF == 19 { acct(getBR($10), $8, $11, $13, getBR($10), getDFfromDCS($19), $14); } |
| 139 |
' |
| 140 |
KEYTITLE="Speed" |
| 141 |
MAPNAMES=no |
| 142 |
;; |
| 143 |
-format) |
| 144 |
AWKRULES=' |
| 145 |
$2 == "SEND" && NF == 9 { acct($6, $4, $7, $8, $5, $6, $9); } |
| 146 |
$2 == "SEND" && NF == 11 { acct($8, $5, $9, $10, $7, $8, $11); } |
| 147 |
$2 == "SEND" && NF == 12 { acct($9, $6, $10, $11, $8, $9, $12); } |
| 148 |
$2 == "SEND" && NF == 13 { acct(getDF($10), $8, $11, $12, getBR($10), getDF($10), $13); } |
| 149 |
$2 == "SEND" && NF == 14 { acct(getDF($10), $8, $11, $13, getBR($10), getDF($10), $14); } |
| 150 |
$2 == "SEND" && NF == 16 { acct(getDF($10), $8, $11, $13, getBR($10), getDF($10), $14); } |
| 151 |
$2 == "SEND" && NF == 17 { acct(getDF($10), $8, $11, $13, getBR($10), getDF($10), $14); } |
| 152 |
$2 == "SEND" && NF == 18 { acct(getDF($10), $8, $11, $13, getBR($10), getDF($10), $14); } |
| 153 |
$2 == "SEND" && NF == 19 { acct(getDF($10), $8, $11, $13, getBR($10), getDFfromDCS($19), $14); } |
| 154 |
' |
| 155 |
KEYTITLE="Format" |
| 156 |
MAPNAMES=no |
| 157 |
;; |
| 158 |
-job*) |
| 159 |
AWKRULES=' |
| 160 |
$2 == "SEND" && NF == 13 { acct($6, $8, $11, $12, getBR($10), getDF($10), $13); } |
| 161 |
$2 == "SEND" && NF == 14 { acct($6, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 162 |
$2 == "SEND" && NF == 16 { acct($6, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 163 |
$2 == "SEND" && NF == 17 { acct($6, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 164 |
$2 == "SEND" && NF == 18 { acct($6, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 165 |
$2 == "SEND" && NF == 19 { acct($6, $8, $11, $13, getBR($10), getDFfromDCS($19), $14); } |
| 166 |
' |
| 167 |
KEYTITLE="JobTag" |
| 168 |
MAPNAMES=no |
| 169 |
;; |
| 170 |
-dev*) |
| 171 |
AWKRULES=' |
| 172 |
$2 == "SEND" && NF == 13 { acct($4, $8, $11, $12, getBR($10), getDF($10), $13); } |
| 173 |
$2 == "SEND" && NF == 14 { acct($4, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 174 |
$2 == "SEND" && NF == 16 { acct($4, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 175 |
$2 == "SEND" && NF == 17 { acct($4, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 176 |
$2 == "SEND" && NF == 18 { acct($4, $8, $11, $13, getBR($10), getDF($10), $14); } |
| 177 |
$2 == "SEND" && NF == 19 { acct($4, $8, $11, $13, getBR($10), getDFfromDCS($19), $14); } |
| 178 |
' |
| 179 |
KEYTITLE="Device" |
| 180 |
MAPNAMES=no |
| 181 |
;; |
| 182 |
esac |
| 183 |
|
| 184 |
# |
| 185 |
# Generate an awk program to process the statistics file. |
| 186 |
# |
| 187 |
SetupPrivateTmp |
| 188 |
tmpAwk=$TMPDIR/xferfax$$ |
| 189 |
|
| 190 |
($CAT<<'EOF' |
| 191 |
# |
| 192 |
# Setup date conversion data structures. |
| 193 |
# |
| 194 |
function setupDateTimeStuff() |
| 195 |
{ |
| 196 |
daysInMonth[ 0] = 31; daysInMonth[ 1] = 28; daysInMonth[ 2] = 31; |
| 197 |
daysInMonth[ 3] = 30; daysInMonth[ 4] = 31; daysInMonth[ 5] = 30; |
| 198 |
daysInMonth[ 6] = 31; daysInMonth[ 7] = 31; daysInMonth[ 8] = 30; |
| 199 |
daysInMonth[ 9] = 31; daysInMonth[10] = 30; daysInMonth[11] = 31; |
| 200 |
|
| 201 |
FULLDAY = 24 * 60 * 60; |
| 202 |
} |
| 203 |
|
| 204 |
# |
| 205 |
# Convert hh:mm:ss to seconds. |
| 206 |
# |
| 207 |
function cvtTime(s) |
| 208 |
{ |
| 209 |
t = i = 0; |
| 210 |
for (n = split(s, a, ":"); i++ < n; ) |
| 211 |
t = t*60 + a[i]; |
| 212 |
return t; |
| 213 |
} |
| 214 |
|
| 215 |
# |
| 216 |
# Convert MM/DD/YY hh:mm to seconds. |
| 217 |
# NB: this does not deal with leap years. |
| 218 |
# |
| 219 |
function cvtDateTime(s) |
| 220 |
{ |
| 221 |
yday = substr(s,7,2) |
| 222 |
if (yday < 70) |
| 223 |
yday += 30; |
| 224 |
else |
| 225 |
yday -= 70; |
| 226 |
yday = yday*365 + substr(s,4,2) - 1; |
| 227 |
mon = substr(s,1,2) - 1; |
| 228 |
for (i = 0; i < mon; i++) |
| 229 |
yday += daysInMonth[i]; |
| 230 |
return yday*FULLDAY + cvtTime(substr(s,10) ":00"); |
| 231 |
} |
| 232 |
|
| 233 |
function setupDigits() |
| 234 |
{ |
| 235 |
digits[0] = "0"; digits[1] = "1"; digits[2] = "2"; |
| 236 |
digits[3] = "3"; digits[4] = "4"; digits[5] = "5"; |
| 237 |
digits[6] = "6"; digits[7] = "7"; digits[8] = "8"; |
| 238 |
digits[9] = "9"; |
| 239 |
} |
| 240 |
|
| 241 |
# |
| 242 |
# Format seconds as hh:mm:ss. |
| 243 |
# |
| 244 |
function fmtTime(t) |
| 245 |
{ |
| 246 |
v = int(t/3600); |
| 247 |
result = ""; |
| 248 |
if (v > 0) { |
| 249 |
t -= v*3600; |
| 250 |
result = v ":" |
| 251 |
} |
| 252 |
v = int(t/60); |
| 253 |
if (v >= 10 || result != "") |
| 254 |
result = result digits[int(v/10)]; |
| 255 |
result = result digits[int(v%10)]; |
| 256 |
t -= v*60; |
| 257 |
return (result ":" digits[int(t/10)] digits[int(t%10)]); |
| 258 |
} |
| 259 |
|
| 260 |
# |
| 261 |
# Setup map for histogram calculations |
| 262 |
# and indexed table for decoding params. |
| 263 |
# |
| 264 |
function setupMaps(s, map, names) |
| 265 |
{ |
| 266 |
n = split(s, a, ":"); |
| 267 |
for (i = 1; i <= n; i++) { |
| 268 |
map[a[i]] = i; |
| 269 |
names[i-1] = a[i]; |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
# |
| 274 |
# Add pages to a histogram. |
| 275 |
# |
| 276 |
function addToMap(key, ix, pages, map) |
| 277 |
{ |
| 278 |
if (key == "") { |
| 279 |
for (i in map) |
| 280 |
key = key ":"; |
| 281 |
} |
| 282 |
n = split(key, a, ":"); |
| 283 |
a[map[ix]] += pages; |
| 284 |
t = a[1]; |
| 285 |
for (i = 2; i <= n; i++) |
| 286 |
t = t ":" a[i]; |
| 287 |
return t; |
| 288 |
} |
| 289 |
|
| 290 |
# |
| 291 |
# Merge two histogram maps. |
| 292 |
# |
| 293 |
function mergeMap(map2, map1) |
| 294 |
{ |
| 295 |
if (map2 == "") |
| 296 |
return map1; |
| 297 |
else if (map1 == "") |
| 298 |
return map2; |
| 299 |
# map1 & map2 are populated |
| 300 |
n1 = split(map1, a1, ":"); |
| 301 |
n2 = split(map2, a2, ":"); |
| 302 |
for (i = 1; i <= n1; i++) |
| 303 |
a2[i] += a1[i]; |
| 304 |
t = a2[1]; |
| 305 |
for (i = 2; i <= n; i++) |
| 306 |
t = t ":" a2[i]; |
| 307 |
return t; |
| 308 |
} |
| 309 |
|
| 310 |
# |
| 311 |
# Return the name of the item with the |
| 312 |
# largest number of accumulated pages. |
| 313 |
# |
| 314 |
function bestInMap(totals, map) |
| 315 |
{ |
| 316 |
n = split(totals, a, ":"); |
| 317 |
imax = 1; max = -1; |
| 318 |
for (j = 1; j <= n; j++) |
| 319 |
if (a[j] > max) { |
| 320 |
max = a[j]; |
| 321 |
imax = j; |
| 322 |
} |
| 323 |
split(map, a, ":"); |
| 324 |
return a[imax]; |
| 325 |
} |
| 326 |
|
| 327 |
# |
| 328 |
# Sort array a[l..r] |
| 329 |
# |
| 330 |
function qsort(a, l, r) { |
| 331 |
i = l; |
| 332 |
k = r+1; |
| 333 |
item = a[l]; |
| 334 |
for (;;) { |
| 335 |
while (i < r) { |
| 336 |
i++; |
| 337 |
if (a[i] >= item) |
| 338 |
break; |
| 339 |
} |
| 340 |
while (k > l) { |
| 341 |
k--; |
| 342 |
if (a[k] <= item) |
| 343 |
break; |
| 344 |
} |
| 345 |
if (i >= k) |
| 346 |
break; |
| 347 |
t = a[i]; a[i] = a[k]; a[k] = t; |
| 348 |
} |
| 349 |
t = a[l]; a[l] = a[k]; a[k] = t; |
| 350 |
if (k != 0 && l < k-1) |
| 351 |
qsort(a, l, k-1); |
| 352 |
if (k+1 < r) |
| 353 |
qsort(a, k+1, r); |
| 354 |
} |
| 355 |
|
| 356 |
function cleanup(s) |
| 357 |
# remove special characters from the string s and return the results |
| 358 |
# the first arg of gsub is a regex to be substituted (removed in this |
| 359 |
# case) from the string s |
| 360 |
# remove double quotes, leading spaces at the beginning |
| 361 |
# of the string any spaces followed at the end of the string |
| 362 |
{ |
| 363 |
gsub("\"", "", s); |
| 364 |
gsub("^ +", "", s); |
| 365 |
gsub(" +$", "", s); |
| 366 |
return s; |
| 367 |
} |
| 368 |
|
| 369 |
function setupToLower() |
| 370 |
{ |
| 371 |
upperRE = "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]"; |
| 372 |
upper["A"] = "a"; upper["B"] = "b"; upper["C"] = "c"; |
| 373 |
upper["D"] = "d"; upper["E"] = "e"; upper["F"] = "f"; |
| 374 |
upper["G"] = "g"; upper["H"] = "h"; upper["I"] = "i"; |
| 375 |
upper["J"] = "j"; upper["K"] = "k"; upper["L"] = "l"; |
| 376 |
upper["M"] = "m"; upper["N"] = "n"; upper["O"] = "o"; |
| 377 |
upper["P"] = "p"; upper["Q"] = "q"; upper["R"] = "r"; |
| 378 |
upper["S"] = "s"; upper["T"] = "t"; upper["U"] = "u"; |
| 379 |
upper["V"] = "v"; upper["W"] = "w"; upper["X"] = "x"; |
| 380 |
upper["Y"] = "y"; upper["Z"] = "z"; |
| 381 |
} |
| 382 |
|
| 383 |
function toLower(s) |
| 384 |
{ |
| 385 |
if (match(s, upperRE) != 0) { |
| 386 |
do { |
| 387 |
c = substr(s, RSTART, 1); |
| 388 |
gsub(c, upper[c], s); |
| 389 |
} while (match(s, upperRE)); |
| 390 |
} |
| 391 |
return s; |
| 392 |
} |
| 393 |
|
| 394 |
function getBR(params) |
| 395 |
{ |
| 396 |
if ((int(int(params) / 2097152) % 2) == 1) { |
| 397 |
return brNames[int(int(params) / 8) % 16]; |
| 398 |
} else { |
| 399 |
return brNames[int(int(params) / 2) % 8]; |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
function getDF(params) |
| 404 |
{ |
| 405 |
if ((int(int(params) / 2097152) % 2) == 1) { |
| 406 |
return dfNames[int(int(params) / 16384) % 4]; |
| 407 |
} else { |
| 408 |
return dfNames[int(int(params) / 512) % 4]; |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
function hex(n) { |
| 413 |
# GNU Awk 3.1.3 has a type conversion error from hex strings, |
| 414 |
# so we have to do it the hard way |
| 415 |
val = 0; |
| 416 |
for (position = 1; position <= length(n); position++) { |
| 417 |
val = val * 16; |
| 418 |
char = tolower(substr(n, position, 1)); |
| 419 |
if (char == "a") val = val + 10; |
| 420 |
else if (char == "b") val = val + 11; |
| 421 |
else if (char == "c") val = val + 12; |
| 422 |
else if (char == "d") val = val + 13; |
| 423 |
else if (char == "e") val = val + 14; |
| 424 |
else if (char == "f") val = val + 15; |
| 425 |
else val = val + int(char); |
| 426 |
} |
| 427 |
return val; |
| 428 |
} |
| 429 |
|
| 430 |
function isBitSet(bit, dcs) { |
| 431 |
byte = int((bit - 1) / 8); |
| 432 |
pos = 7 - ((bit - 1) % 8); |
| 433 |
dcsbyte = hex(substr(dcs, (byte*3+1), 2)); |
| 434 |
return int(int(dcsbyte / (2 ^ pos)) % 2); |
| 435 |
} |
| 436 |
|
| 437 |
function getDFfromDCS(dcs) |
| 438 |
{ |
| 439 |
if (substr(dcs, 1, 1) == "\"") |
| 440 |
dcs = substr(dcs, 2); |
| 441 |
if (substr(dcs, length(dcs), 1) == "\"") |
| 442 |
dcs = substr(dcs, 1, length(dcs)-1); |
| 443 |
if (isBitSet(68, dcs)) { |
| 444 |
if (isBitSet(69, dcs)) |
| 445 |
return dfNames[6]; |
| 446 |
return dfNames[5]; |
| 447 |
} |
| 448 |
if (isBitSet(78, dcs) || isBitSet(79, dcs)) |
| 449 |
return dfNames[4]; |
| 450 |
if (isBitSet(31, dcs)) |
| 451 |
return dfNames[3]; |
| 452 |
if (isBitSet(26, dcs)) |
| 453 |
return dfNames[2]; |
| 454 |
if (isBitSet(16, dcs)) |
| 455 |
return dfNames[1]; |
| 456 |
return dfNames[0]; |
| 457 |
} |
| 458 |
|
| 459 |
# |
| 460 |
# Accumulate a statistics record. |
| 461 |
# |
| 462 |
|
| 463 |
function acct(key, dest, pages, time, br, df, status) |
| 464 |
{ |
| 465 |
status = cleanup(status); |
| 466 |
if (length(status) > 11) { |
| 467 |
msg = toLower(substr(status, 1, 11)); |
| 468 |
if (callFailed[msg]) |
| 469 |
return; |
| 470 |
} |
| 471 |
if (cvtDateTime($1) < KEEPSINCE || cvtDateTime($1) > KEEPEND) |
| 472 |
return; |
| 473 |
key = cleanup(key); |
| 474 |
EOF |
| 475 |
test "$MAPNAMES" = "yes" && $CAT<<'EOF' |
| 476 |
# |
| 477 |
# Try to merge unqualified names w/ fully qualified names |
| 478 |
# by stripping the host part of the domain address and |
| 479 |
# mapping unqualified names to a stripped qualified name. |
| 480 |
# |
| 481 |
n = split(key, parts, "@"); |
| 482 |
if (n == 2) { # user@addr |
| 483 |
user = parts[1]; |
| 484 |
if (user != "root" && user != "guest") { |
| 485 |
addr = parts[2]; |
| 486 |
# |
| 487 |
# Strip hostname from multi-part domain name. |
| 488 |
# |
| 489 |
EOF |
| 490 |
test "$MAPNAMES" = "yes" && echo 'p = split("'`hostname`'", hostname, ".");' |
| 491 |
test "$MAPNAMES" = "yes" && $CAT<<'EOF' |
| 492 |
n = split(addr, domains, "."); |
| 493 |
if (p > 1 && n > p) { # e.g. flake.asd.sgi.com |
| 494 |
l = length(domains[1])+1; |
| 495 |
addr = substr(addr, l+1, length(addr)-l); |
| 496 |
key = user "@" addr; |
| 497 |
} |
| 498 |
if (addrs[user] == "") { # record mapped name |
| 499 |
addrs[user] = addr; |
| 500 |
} else if (addrs[user] != addr) { |
| 501 |
if (!warned[user "@" addr]) { |
| 502 |
warned[user "@" addr] = 1; |
| 503 |
printf "Warning, address clash, \"%s\" and \"%s\".\n", \ |
| 504 |
user "@" addrs[user], user "@" addr |
| 505 |
} |
| 506 |
} |
| 507 |
} |
| 508 |
} else if (n != 1) { |
| 509 |
printf "Warning, weird user address/name \"%s\".\n", key |
| 510 |
} |
| 511 |
EOF |
| 512 |
$CAT<<'EOF' |
| 513 |
dest = cleanup(dest); |
| 514 |
sendpages[key] += pages; |
| 515 |
time = cleanup(time); |
| 516 |
if (pages == 0 && time > 60) |
| 517 |
time = 0; |
| 518 |
sendtime[key] += cvtTime(time); |
| 519 |
if (status != "") |
| 520 |
senderrs[key]++; |
| 521 |
br = cleanup(br); |
| 522 |
sendrate[key] = addToMap(sendrate[key], br, pages, rateMap); |
| 523 |
df = cleanup(df); |
| 524 |
senddata[key] = addToMap(senddata[key], df, pages, dataMap); |
| 525 |
} |
| 526 |
|
| 527 |
# |
| 528 |
# Print a rule between the stats and the totals line. |
| 529 |
# |
| 530 |
function printRule(n, s) |
| 531 |
{ |
| 532 |
r = ""; |
| 533 |
while (n-- >= 0) |
| 534 |
r = r s; |
| 535 |
printf "%s\n", r; |
| 536 |
} |
| 537 |
|
| 538 |
BEGIN { FS="\t"; |
| 539 |
rates = "2400:4800:7200:9600:12000:14400:16800:19200:21600:24000:26400:28800:31200:33600"; |
| 540 |
setupMaps(rates, rateMap, brNames); |
| 541 |
datas = "1-D MH:2-D MR:2-D Uncompressed Mode:2-D MMR:JBIG:JPEG Greyscale:JPEG Full-color"; |
| 542 |
setupMaps(datas, dataMap, dfNames); |
| 543 |
callFailed["busy signal"] = 1; |
| 544 |
callFailed["unknown pro"] = 1; |
| 545 |
callFailed["no carrier "] = 1; |
| 546 |
callFailed["no local di"] = 1; |
| 547 |
callFailed["no answer f"] = 1; |
| 548 |
callFailed["ringback de"] = 1; |
| 549 |
callFailed["job aborted"] = 1; |
| 550 |
setupToLower(); |
| 551 |
setupDateTimeStuff(); |
| 552 |
if (SINCEDT == "") |
| 553 |
KEEPSINCE = cvtDateTime(TODAY) - AGE*FULLDAY; |
| 554 |
else |
| 555 |
KEEPSINCE = cvtDateTime(SINCEDT); |
| 556 |
if (ENDDT == "") |
| 557 |
KEEPEND = cvtDateTime(TODAY); |
| 558 |
else |
| 559 |
KEEPEND = cvtDateTime(ENDDT); |
| 560 |
EOF |
| 561 |
echo "KeyTitle = \"$KEYTITLE\"" |
| 562 |
$CAT<<'EOF' |
| 563 |
} |
| 564 |
END { OFS="\t"; setupDigits(); |
| 565 |
maxlen = 15; |
| 566 |
# merge unqualified and qualified names |
| 567 |
for (key in sendpages) { |
| 568 |
if (addrs[key] != "") { |
| 569 |
fullkey = key "@" addrs[key]; |
| 570 |
sendpages[fullkey] += sendpages[key]; |
| 571 |
sendtime[fullkey] += sendtime[key]; |
| 572 |
senderrs[fullkey] += senderrs[key]; |
| 573 |
sendrate[fullkey] = \ |
| 574 |
mergeMap(sendrate[fullkey], sendrate[key]); |
| 575 |
senddata[fullkey] = \ |
| 576 |
mergeMap(senddata[fullkey], senddata[key]); |
| 577 |
} |
| 578 |
} |
| 579 |
nsorted = 0; |
| 580 |
for (key in sendpages) { |
| 581 |
if (addrs[key] != "") # unqualified name |
| 582 |
continue; |
| 583 |
l = length(key); |
| 584 |
if (l > maxlen) |
| 585 |
maxlen = l; |
| 586 |
sorted[nsorted++] = key; |
| 587 |
} |
| 588 |
qsort(sorted, 0, nsorted-1); |
| 589 |
fmt = "%-" maxlen "." maxlen "s"; # e.g. %-24.24s |
| 590 |
printf fmt " %6s %9s %6s %5s %7s %7s\n", |
| 591 |
KeyTitle, "Pages", "Time", "Pg/min", |
| 592 |
"Errs", "TypRate", "TypData"; |
| 593 |
tpages = 0; |
| 594 |
ttime = 0; |
| 595 |
terrs = 0; |
| 596 |
for (k = 0; k < nsorted; k++) { |
| 597 |
i = sorted[k]; |
| 598 |
t = sendtime[i]/60; if (t == 0) t = 1; |
| 599 |
n = sendpages[i]; if (n == 0) n = 1; |
| 600 |
brate = best |
| 601 |
printf fmt " %6d %9s %6.1f %5d %7d %7.7s\n", |
| 602 |
i, sendpages[i], fmtTime(sendtime[i]), |
| 603 |
sendpages[i] / t, senderrs[i], |
| 604 |
bestInMap(sendrate[i], rates), |
| 605 |
bestInMap(senddata[i], datas); |
| 606 |
tpages += sendpages[i]; |
| 607 |
ttime += sendtime[i]; |
| 608 |
terrs += senderrs[i]; |
| 609 |
} |
| 610 |
printRule(maxlen+1+6+1+9+6+1+5+1+7+1+7, "-"); |
| 611 |
t = ttime/60; if (t == 0) t = 1; |
| 612 |
printf fmt " %6d %9s %6.1f %5d\n", |
| 613 |
"Total", tpages, fmtTime(ttime), tpages/t, terrs; |
| 614 |
} |
| 615 |
EOF |
| 616 |
echo "$AWKRULES" |
| 617 |
)>$tmpAwk |
| 618 |
$AWK -f $tmpAwk -v TODAY="$TODAY" -v AGE="$AGE" -v SINCEDT="$SINCEDT" -v ENDDT="$ENDDT" $FILES |
| 619 |
|
| 620 |
# cleanup |
| 621 |
hfExit 0 |