-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawstats-update
executable file
·1070 lines (916 loc) · 40.7 KB
/
awstats-update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# AWStats Updater 2.4 (build 20171020)
# https://github.com/PhrozenByte/awstats-update
#
# Copyright (C) 2011-2017 Daniel Rudolf <www.daniel-rudolf.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# See <http://www.gnu.org/licenses/> to receive a full-text-copy of
# the GNU General Public License.
APP_NAME="$(basename "$0")"
EXIT_CODE=0
BUILD="20171020"
VERSION="2.4"
# usage
function showUsage() {
echo "Usage:"
echo " $APP_NAME [OPTION]..."
echo " $APP_NAME [OPTION]... CONFIG..."
echo " CONFIG can either be:"
echo " - a absolute path to a config file"
echo " - a relative path to a config file, starting from /etc/awstats/"
echo " - a config spec in the form [ HOST_TYPE \"/\" ] HOST"
}
# include Debian config
AWSTATS_NICE=""
AWSTATS_LANG="en"
AWSTATS_FORMAT="plain"
AWSTATS_DATA_DIR=""
AWSTATS_WWW_DIR=""
if [ -r "/etc/default/awstats" ]; then
. "/etc/default/awstats"
fi
# use getopt to parse parameters
if ! OPTIONS="$(
getopt -n "$APP_NAME" -o aovqh \
-l "no-update" -l "update" -l "no-rebuild" -l "rebuild" -l "rebuild-all" -l "overwrite" \
-l "no-config::" -l "format:" -l "lang:" -l "data-dir:" -l "www-dir:" -l "standalone:" \
-l "verbose" -l "quiet" -l "help" -l "version" -- "$@"
)"; then
showUsage
exit 1
fi
eval set -- "$OPTIONS"
# parse options
UPDATE="yes"
REBUILD="current"
OVERWRITE="no"
NO_CONFIG=""
CONFIG_DIR=""
STANDALONE=""
VERBOSE=1
while true; do
case "$1" in
"--update")
UPDATE="yes"
shift
;;
"--no-update")
UPDATE="no"
shift
;;
"--rebuild")
REBUILD="current"
shift
;;
"--no-rebuild")
REBUILD="no"
shift
;;
"-a"|"--rebuild-all")
REBUILD="all"
shift
;;
"-o"|"--overwrite")
OVERWRITE="yes"
shift
;;
"--no-config")
if [ -n "$2" ]; then
NO_CONFIG="$2"
else
NO_CONFIG="awstats.conf"
fi
shift 2
;;
"--format")
AWSTATS_FORMAT=""
IFS=','; for ADD_FORMAT in $2; do
if [ "$ADD_FORMAT" == "plain" ] || [ "$ADD_FORMAT" == "gzip" ]; then
[ -z "$AWSTATS_FORMAT" ] && AWSTATS_FORMAT="$ADD_FORMAT" || AWSTATS_FORMAT+=",$ADD_FORMAT"
else
echo "$APP_NAME: Invalid argument '$2' for '--format'" >&2
exit 1
fi
done
shift 2
;;
"--lang")
AWSTATS_LANG="$2"
shift 2
;;
"--data-dir")
AWSTATS_DATA_DIR="$2"
shift 2
;;
"--www-dir")
AWSTATS_WWW_DIR="$2"
shift 2
;;
"--standalone")
STANDALONE="$2"
shift 2
;;
"-v"|"--verbose")
((VERBOSE++))
shift
;;
"-q"|"--quiet")
((VERBOSE--))
shift
;;
"-h"|"--help")
showUsage
echo
echo "Update AWStats database and/or generate static HTML pages, either of the"
echo "specified or all known hosts. By default, $APP_NAME updates the database"
echo "(\`--update') and creates HTML pages (\`--rebuild') for the current month."
echo "You can create HTML pages for all historic data using \`--rebuild-all'."
echo
echo "Application options:"
echo " --[no-]update [don't] update AWStats database"
echo " --[no-]rebuild [don't] generate static HTML pages"
echo " (current month only)"
echo " -a, --rebuild-all generate static HTML pages (all historic data)"
echo " -o, --overwrite re-create existing HTML pages (with --rebuild-all)"
echo " --no-config[=CONFIG] don't skip domains without a config; use CONFIG,"
echo " otherwise use default config (with --rebuild-all)"
echo " --format=FORMAT output HTML pages according to FORMAT: plain, or"
echo " gzip. You also pass both comma separated."
echo " default: plain"
echo " --lang=LANG output HTML pages using language LANG."
echo " default: en"
echo " --data-dir=PATH path to AWStats data directory."
echo " default: /var/lib/awstats"
echo " --www-dir=PATH path to AWStats www directory."
echo " default: /var/cache/awstats/www"
echo " --standalone=PATH path to a standalone \`awstats.pl'"
echo " -v, --verbose increase verbosity"
echo " -q, --quiet decrease verbosity"
echo
echo "Help options:"
echo " -h, --help display this help and exit"
echo " --version output version information and exit"
echo
echo "Please report bugs using GitHub <https://github.com/PhrozenByte/awstats-update>"
exit 0
;;
"--version")
echo "awstats-update $VERSION ($BUILD)"
echo "Copyright (C) 2011-2016 Daniel Rudolf"
echo "License GPLv3: GNU GPL version 3 only <http://gnu.org/licenses/gpl.html>."
echo "This is free software: you are free to change and redistribute it."
echo "There is NO WARRANTY, to the extent permitted by law."
echo
echo "Written by Daniel Rudolf <http://www.daniel-rudolf.de/>"
exit 0
;;
"--")
shift
break
;;
default)
echo "$APP_NAME: execution of getopt failed" >&2
showUsage
exit 1
;;
esac
done
if [ -n "$STANDALONE" ]; then
AWSTATS="$STANDALONE"
[ "${AWSTATS:0:1}" == "/" ] || AWSTATS="$PWD/$AWSTATS"
CONFIG_DIR="$(dirname "$AWSTATS")"
[ -z "$AWSTATS_DATA_DIR" ] && AWSTATS_DATA_DIR="$CONFIG_DIR/data"
[ -z "$AWSTATS_WWW_DIR" ] && AWSTATS_WWW_DIR="$CONFIG_DIR/www"
else
AWSTATS="$(which "awstats")"
CONFIG_DIR="/etc/awstats"
[ -z "$AWSTATS_DATA_DIR" ] && AWSTATS_DATA_DIR="/var/lib/awstats"
[ -z "$AWSTATS_WWW_DIR" ] && AWSTATS_WWW_DIR="/var/cache/awstats/www"
fi
# check AWStats executable
if [ -z "$AWSTATS" ]; then
echo "$APP_NAME: AWStats executable not found" >&2
exit 1
elif [ ! -e "$AWSTATS" ]; then
echo "$APP_NAME: Invalid AWStats executable \`$AWSTATS': No such file or directory" >&2
exit 1
elif [ ! -f "$AWSTATS" ] || [ ! -x "$AWSTATS" ]; then
echo "$APP_NAME: Invalid AWStats executable \`$AWSTATS': Not an executable" >&2
exit 1
fi
# nothing to do?
if [ "$UPDATE" == "no" ] && [ "$REBUILD" == "no" ]; then
echo "$APP_NAME: You specified \`--no-update' and \`--no-rebuild'; do you really want to do nothing?" >&2
exit 0
fi
if [ -z "$AWSTATS_FORMAT" ] && [ "$REBUILD" != "no" ]; then
echo "$APP_NAME: You specified \'--rebuild' or \'--rebuild-all', but no output format; use \`--format'" >&2
exit 1
fi
# validate --data-dir
[ "${AWSTATS_DATA_DIR:0:1}" == "/" ] || AWSTATS_DATA_DIR="$PWD/$AWSTATS_DATA_DIR"
if [ ! -e "$AWSTATS_DATA_DIR" ]; then
echo "$APP_NAME: Invalid \`--data-dir': $AWSTATS_DATA_DIR: No such file or directory" >&2
exit 1
elif [ ! -d "$AWSTATS_DATA_DIR" ]; then
echo "$APP_NAME: Invalid \`--data-dir': $AWSTATS_DATA_DIR: Not a directory" >&2
exit 1
fi
# validate --www-dir
[ "${AWSTATS_WWW_DIR:0:1}" == "/" ] || AWSTATS_WWW_DIR="$PWD/$AWSTATS_WWW_DIR"
if [ ! -e "$AWSTATS_WWW_DIR" ]; then
echo "$APP_NAME: Invalid \`--www-dir': $AWSTATS_WWW_DIR: No such file or directory" >&2
exit 1
elif [ ! -d "$AWSTATS_WWW_DIR" ]; then
echo "$APP_NAME: Invalid \`--www-dir': $AWSTATS_WWW_DIR: Not a directory" >&2
exit 1
fi
# resolve CONFIG
function resolveConfig() {
local __NO_CONFIG_PARAM="--no-config"
[ "$1" == "--no-config" ] && shift || __NO_CONFIG_PARAM=""
local __RESULTVAR="$1"
shift
local __RETURN=0
eval "$__RESULTVAR=\"\""
while [ $# -gt 0 ]; do
# step 1: check for a config path
__DATA="$(resolveConfigPath --soft-fail "$1")"
__EXIT_CODE=$?
if [ "$__EXIT_CODE" -ne 0 ]; then
if [ "$__EXIT_CODE" -eq 3 ]; then
# step 2: check for a config spec
__DATA="$(resolveConfigSpec --soft-fail $__NO_CONFIG_PARAM "$1")"
__EXIT_CODE=$?
if [ "$__EXIT_CODE" -ne 0 ]; then
[ "$__EXIT_CODE" -eq 3 ] && echo "$APP_NAME: Invalid parameter \`$1': No such config" >&2
__RETURN=1
shift
continue
fi
else
__RETURN=1
shift
continue
fi
fi
eval "$__RESULTVAR=\"\$(echo \"\$$__RESULTVAR\" ; echo \"\$__DATA\")\""
shift
done
# result format: HOST_TYPE/HOST, /HOST or /
eval "$__RESULTVAR=\"\$(echo \"\$$__RESULTVAR\" | LC_ALL=C sort -u)\""
return $__RETURN
}
function resolveConfigPath() {
local SOFT_FAIL="yes"
[ "$1" == "--soft-fail" ] && shift || SOFT_FAIL="no"
local CHECK_FILE="$1"
local CHECK_FILENAME="$(basename "$1")"
local FILE=""
local FILENAME=""
if [ -z "$CHECK_FILE" ] || [ "$CHECK_FILE" == "[default]" ]; then
# default config file
FILE="$CONFIG_DIR/awstats.conf"
FILENAME="awstats.conf"
elif [ "$CHECK_FILE" == "$CHECK_FILENAME" ]; then
# filename
if [ "$CHECK_FILENAME" == "awstats.conf" ] || [[ "$CHECK_FILENAME" =~ ^awstats\.(.+)\.conf$ ]]; then
FILE="$CONFIG_DIR/$CHECK_FILENAME"
FILENAME="$CHECK_FILENAME"
fi
elif [ "$CHECK_FILENAME" == "awstats.conf" ] || [[ "$CHECK_FILENAME" =~ ^awstats\.(.+)\.conf$ ]]; then
# absolute/relative path
FILE="$CONFIG_DIR/$CHECK_FILENAME"
FILENAME="$CHECK_FILENAME"
# get real directory of config file
local CHECK_DIR="$(dirname "$CHECK_FILE")"
[ "${CHECK_DIR:0:1}" != "/" ] && CHECK_DIR="$CONFIG_DIR/$CHECK_DIR"
CHECK_DIR="$(readlink -f "$CHECK_DIR")"
if [ -z "$CHECK_DIR" ]; then
# readlink wasn't able to resolve the path (the path doesn't exist)
echo "$APP_NAME: Invalid config path \`$CHECK_FILE': Unable to resolve path" >&2
return 1
fi
# file must be in $CONFIG_DIR (can be a symlink)
# we explicitly don't support any other config dirs,
# awstats handling of them is unbelievable stupid...
# if $CONFIG_DIR/awstats.conf exists, it's impossible
# to use any other directory... wtf?
local VALID_DIR="$(readlink -f "$CONFIG_DIR")"
if [ "$CHECK_DIR" != "$VALID_DIR" ]; then
echo "$APP_NAME: Invalid config path \`$CHECK_FILE': Config file must be in \`$CONFIG_DIR'" >&2
return 1
fi
fi
# invalid file; maybe it's a config spec?
if [ -z "$FILE" ]; then
[ "$SOFT_FAIL" == "yes" ] || echo "$APP_NAME: Invalid config path \`$CHECK_FILE'" >&2
return 3
fi
# check file
if [ ! -e "$FILE" ]; then
echo "$APP_NAME: Invalid config path \`$CHECK_FILE': Resolved to invalid path \`$FILE': No such file or directory" >&2
return 2
elif [ ! -f "$FILE" ]; then
echo "$APP_NAME: Invalid config path \`$CHECK_FILE': Resolved to invalid path \`$FILE': Not a file" >&2
return 1
fi
if [[ "$FILENAME" =~ ^awstats\.(([^\.]+)\.)?(.+)\.conf$ ]]; then
echo "${BASH_REMATCH[2]}/${BASH_REMATCH[3]}"
else
echo "/"
fi
return 0
}
function resolveConfigSpec() {
local SOFT_FAIL="no"
local SINGLE_MATCH="no"
local NO_CONFIG_MATCH="no"
while [ $# -gt 1 ]; do
if [ "$1" == "--soft-fail" ]; then
SOFT_FAIL="yes"
elif [ "$1" == "--single" ]; then
SINGLE_MATCH="yes"
elif [ "$1" == "--no-config" ]; then
NO_CONFIG_MATCH="yes"
fi
shift
done
local SPEC="$1"
if ! [[ "$SPEC" =~ ^(([^\./]*)/)?([^/]*)$ ]]; then
[ "$SOFT_FAIL" == "yes" ] || echo "$APP_NAME: Invalid config spec \`$SPEC'" >&2
return 3
fi
local HOST_TYPE=""
local HOST=""
local CONFIG_FILE=""
local CONFIG_NAME=""
if [ "$SPEC" == "/" ]; then
# default config file
CONFIG_FILE="$CONFIG_DIR/awstats.conf"
else
# split HOST_TYPE and HOST
[[ "$SPEC" == */* ]] && HOST_TYPE="$(echo "$SPEC" | cut -d '/' -f 1)" || HOST_TYPE="*"
HOST="$(echo "$SPEC" | cut -d '/' -f 2)"
# HOST_TYPE given, but HOST is empty - invalid input
if [ -z "$HOST" ]; then
echo "$APP_NAME: Invalid config spec \`$SPEC'" >&2
return 1
fi
# prepare CONFIG_NAME
[ -n "$HOST_TYPE" ] && local CONFIG_NAME=".$HOST_TYPE.$HOST" || local CONFIG_NAME=".$HOST"
if [[ "$HOST_TYPE" != *\** ]] && [[ "$HOST" != *\** ]]; then
# no wildcards, should match a single file
CONFIG_FILE="$CONFIG_DIR/awstats$CONFIG_NAME.conf"
else
# resolve wildcards, probably multiple files
[ -n "$HOST_TYPE" ] && HOST_TYPE_REGEX="\($(echo "$HOST_TYPE" | sed -e 's/[]\/$*.^|[]/\\&/g' -e 's/\\\*/[^\\.]*/g' -e 's/?/[^\\.]/g')\)\." || HOST_TYPE_REGEX="\(\)"
local HOST_REGEX="\($(echo "$HOST" | sed -e 's/[]\/$*.^|[]/\\&/g' -e 's/\\\*/.*/g' -e 's/?/./g')\)\."
local CONFIGS="$(
(
find "$CONFIG_DIR" -mindepth 1 -maxdepth 1 -type f -name "awstats$CONFIG_NAME.conf" -printf '%f\n'
[ "$NO_CONFIG_MATCH" == "yes" ] && find "$AWSTATS_DATA_DIR" -mindepth 1 -maxdepth 1 -name "awstats??????$CONFIG_NAME.txt" -printf '%f\n'
) | sed -n -e "s/^awstats\.${HOST_TYPE_REGEX}${HOST_REGEX}conf$/\1\/\2/p" \
-e "s/^awstats[0-9]\{6\}\.${HOST_TYPE_REGEX}${HOST_REGEX}txt$/\1\/\2/p" \
| LC_ALL=C sort -u
)"
if [ -z "$CONFIGS" ]; then
echo "$APP_NAME: Invalid config spec \`$SPEC': No matching config files found" >&2
return 2
elif [ "$SINGLE_MATCH" == "yes" ] && [ "$(echo "$CONFIGS" | wc -l)" -gt 1 ]; then
echo "$APP_NAME: Invalid config spec \`$SPEC': Matches multiple config files" >&2
return 1
fi
# return multiple files
# no need for further checks, find already returns existing files only
echo "$CONFIGS"
return 0
fi
fi
# check single file
if [ ! -e "$CONFIG_FILE" ]; then
if [ "$NO_CONFIG_MATCH" == "no" ] || [ -z "$(find "$AWSTATS_DATA_DIR" -mindepth 1 -maxdepth 1 -name "awstats??????$CONFIG_NAME.txt" -printf "." -quit)" ]; then
echo "$APP_NAME: Invalid config spec \`$SPEC': Resolved to invalid path \`$CONFIG_FILE': No such file or directory" >&2
return 2
fi
elif [ ! -f "$CONFIG_FILE" ]; then
echo "$APP_NAME: Invalid config spec \`$SPEC': Resolved to invalid path \`$CONFIG_FILE': Not a file" >&2
return 1
fi
echo "$HOST_TYPE/$HOST"
return 0
}
# validate and resolve --no-config
# nearly the same as resolveConfig(), but with a preliminary check for arbitrary existing files
if [ -n "$NO_CONFIG" ]; then
[ "${NO_CONFIG:0:1}" == "/" ] && NO_CONFIG_FILE="$NO_CONFIG" || NO_CONFIG_FILE="$CONFIG_DIR/$NO_CONFIG"
if [ -e "$NO_CONFIG_FILE" ]; then
# step 1: any existing file is sufficient
if [ ! -f "$NO_CONFIG_FILE" ]; then
echo "$APP_NAME: Invalid --no-config spec \`$NO_CONFIG': Resolved to invalid path \`$NO_CONFIG_FILE': Not a file" >&2
exit 1
fi
else
# step 2: check for a config path
NO_CONFIG_DATA="$(resolveConfigPath --soft-fail "$NO_CONFIG")"
NO_CONFIG_RESULT=$?
if [ "$NO_CONFIG_RESULT" -ne 0 ]; then
if [ "$NO_CONFIG_RESULT" -eq 3 ]; then
# step 3: check for a config spec
NO_CONFIG_DATA="$(resolveConfigSpec --soft-fail --single "$NO_CONFIG")"
NO_CONFIG_RESULT=$?
if [ "$NO_CONFIG_RESULT" -ne 0 ]; then
[ "$NO_CONFIG_RESULT" -eq 3 ] || echo "$APP_NAME: Invalid --no-config spec \`$NO_CONFIG'" >&2
exit 1
fi
else
exit 1
fi
fi
if [ "$NO_CONFIG_DATA" == "/" ]; then
NO_CONFIG="$CONFIG_DIR/awstats.conf"
elif [ "${NO_CONFIG_DATA:0:1}" == "/" ]; then
NO_CONFIG="$CONFIG_DIR/awstats.$(echo "$NO_CONFIG_DATA" | cut -d '/' -f 2).conf"
else
NO_CONFIG="$CONFIG_DIR/awstats.$(echo "$NO_CONFIG_DATA" | cut -d '/' -f 1).$(echo "$NO_CONFIG_DATA" | cut -d '/' -f 2).conf"
fi
fi
fi
# prepare fds according to verbosity
# verbosity -1: hide stdout and stderr
# verbosity 0: print stderr, hide stdout
[ "$VERBOSE" -le -1 ] && exec 2> /dev/null
[ "$VERBOSE" -le 0 ] && exec 1> /dev/null
[ "$VERBOSE" -gt 1 ] && exec 3>&1 || exec 3> /dev/null
[ "$VERBOSE" -gt 2 ] && exec 4>&1 || exec 4> /dev/null
# add wildcard parameter if no parameters were supplied
[ $# -eq 0 ] && eval set -- "'*'"
# perform --update
if [ "$UPDATE" == "yes" ]; then
echo "Performing update..."
resolveConfig UPDATE_CONFIGS "$@"
IFS=$'\n'; for CONFIG in $UPDATE_CONFIGS; do
HOST_TYPE="$(echo "$CONFIG" | cut -d '/' -f 1)"
HOST="$(echo "$CONFIG" | cut -d '/' -f 2)"
if [ -n "$HOST_TYPE" ]; then
IDENT="$HOST ($HOST_TYPE)"
CONFIG_NAME="$HOST_TYPE.$HOST"
elif [ -n "$HOST" ]; then
IDENT="$HOST"
CONFIG_NAME="$HOST"
else
IDENT="[default]"
CONFIG_NAME="awstats.conf"
fi
echo " - $IDENT"
if [ -n "$AWSTATS_NICE" ]; then
nice -n "$AWSTATS_NICE" \
"$AWSTATS" -config="$CONFIG_NAME" -update \
| sed -e 's/^ / /' | sed -e 's/^/ /' >&4
UPDATE_EXIT_CODE=$?
else
"$AWSTATS" -config="$CONFIG_NAME" -update \
| sed -e 's/^ / /' | sed -e 's/^/ /' >&4
UPDATE_EXIT_CODE=$?
fi
if [ "$UPDATE_EXIT_CODE" -ne 0 ]; then
echo " ! $IDENT FAILED with exit code $UPDATE_EXIT_CODE"
EXIT_CODE=1
fi
done
fi
# check exit code
if [ "$EXIT_CODE" -ne 0 ]; then
exit "$EXIT_CODE"
fi
# perform --rebuild
if [ "$REBUILD" == "current" ]; then
echo "Collecting rebuild data..."
resolveConfig REBUILD_CONFIGS "$@"
REBUILD_DATA=""
IFS=$'\n'; for CONFIG in $REBUILD_CONFIGS; do
HOST_TYPE="$(echo "$CONFIG" | cut -d '/' -f 1)"
HOST="$(echo "$CONFIG" | cut -d '/' -f 2)"
# the config for this month doesn't exist yet
# maybe we're at the beginning of a new month... rebuild the previous month
# if there is no previous month yet, it will be automatically skipped
if [ -n "$HOST_TYPE" ]; then
CONFIG_WWW_DIR="$HOST_TYPE/$HOST"
elif [ -n "$HOST" ]; then
CONFIG_WWW_DIR="[none]/$HOST"
else
CONFIG_WWW_DIR="[none]/[default]"
fi
if [ ! -e "$AWSTATS_WWW_DIR/$CONFIG_WWW_DIR/$(date +%Y)/$(date +%m)" ]; then
YEAR="$(date +%Y)"
MONTH="$(date +%-m)"
((MONTH--))
[ "${#MONTH}" -eq 1 ] && MONTH="0$MONTH"
if [ "$MONTH" == "00" ]; then
MONTH=12
((YEAR--))
fi
REBUILD_DATA="$(echo "$REBUILD_DATA" ; echo "$HOST_TYPE/$HOST/$YEAR/$MONTH")"
fi
# add current month
REBUILD_DATA="$(echo "$REBUILD_DATA" ; echo "$HOST_TYPE/$HOST/$(date +%Y)/$(date +%m)")"
# add year sum
REBUILD_DATA="$(echo "$REBUILD_DATA" ; echo "$HOST_TYPE/$HOST/$(date +%Y)/all")"
done
# --rebuild implies --overwrite
OVERWRITE="yes"
# perform --rebuild-all
elif [ "$REBUILD" == "all" ]; then
function createTempConfig() {
if [ $# -eq 2 ]; then
local FILE="$CONFIG_DIR/awstats.$1.$2.conf"
local DOMAIN="$2"
local DOMAIN_ALIASES="$2 www.$2"
elif [ $# -eq 1 ]; then
local FILE="$CONFIG_DIR/awstats.$1.conf"
local DOMAIN="$1"
local DOMAIN_ALIASES="$1 www.$1"
else
local FILE="$CONFIG_DIR/awstats.conf"
local DOMAIN="localhost"
local DOMAIN_ALIASES="localhost 127.0.0.1 ::1"
fi
if [ -e "$FILE" ]; then
echo "$APP_NAME: Unable to create temp config file \`$FILE': File exists" >&2
return 1
fi
if [ "$(readlink -f "$FILE")" == "$(readlink -f "$NO_CONFIG")" ]; then
echo "$APP_NAME: Unable to create temp config file \`$FILE': Temp config file includes itself as --no-config file ($NO_CONFIG)" >&2
return 1
fi
echo -n "" > $FILE
echo "Include \"$NO_CONFIG\"" >> "$FILE"
echo "LogFile=\"/dev/null\"" >> "$FILE"
echo "SiteDomain=\"$DOMAIN\"" >> "$FILE"
echo "HostAliases=\"$DOMAIN_ALIASES\"" >> "$FILE"
CLEANUP_TEMP_CONFIG="$(echo "$CLEANUP_TEMP_CONFIG" ; echo "$FILE")"
return 0
}
function cleanupTempConfig() {
IFS=$'\n'; for FILE in $CLEANUP_TEMP_CONFIG; do
rm -f "$FILE"
done
exit
}
CLEANUP_TEMP_CONFIG=""
trap cleanupTempConfig INT TERM EXIT
echo "Collecting rebuild data..."
[ -n "$NO_CONFIG" ] && NO_CONFIG_PARAM="--no-config" || NO_CONFIG_PARAM=""
resolveConfig $NO_CONFIG_PARAM REBUILD_CONFIGS "$@"
REBUILD_DATA=""
IFS=$'\n'; for CONFIG in $REBUILD_CONFIGS; do
HOST_TYPE="$(echo "$CONFIG" | cut -d '/' -f 1)"
HOST="$(echo "$CONFIG" | cut -d '/' -f 2)"
if [ -n "$HOST_TYPE" ]; then
DATA_PATTERN="awstats??????.$HOST_TYPE.$HOST.txt"
if [ ! -f "$CONFIG_DIR/awstats.$HOST_TYPE.$HOST.conf" ]; then
createTempConfig "$HOST_TYPE" "$HOST"
[ $? -ne 0 ] && EXIT_CODE=1 && continue
fi
elif [ -n "$HOST" ]; then
DATA_PATTERN="awstats??????.$HOST.txt"
if [ ! -f "$CONFIG_DIR/awstats.$HOST.conf" ]; then
createTempConfig "$HOST"
[ $? -ne 0 ] && EXIT_CODE=1 && continue
fi
else
DATA_PATTERN="awstats??????.txt"
if [ ! -f "$CONFIG_DIR/awstats.conf" ]; then
createTempConfig
[ $? -ne 0 ] && EXIT_CODE=1 && continue
fi
fi
readarray -t DATA_FILES <<< "$(find "$AWSTATS_DATA_DIR" -mindepth 1 -maxdepth 1 -name "$DATA_PATTERN")"
[ ${#DATA_FILES[@]} -ne 1 ] || [ -n "${DATA_FILES[0]}" ] || DATA_FILES=()
DATA_EXISTS="no"
for FILE in "${DATA_FILES[@]}"; do
FILENAME="$(basename "$FILE")"
REGEX="^awstats([0-9]{2})([0-9]{4})(\.(.+))?\.txt$"
if ! [[ "$FILENAME" =~ $REGEX ]]; then
echo "$APP_NAME: Unable to collect rebuild data: Invalid database file \`$FILE'" >&2
exit 1
fi
YEAR="$(echo "$FILENAME" | sed -r "s/$REGEX/\2/")"
MONTH="$(echo "$FILENAME" | sed -r "s/$REGEX/\1/")"
REBUILD_DATA="$(echo "$REBUILD_DATA" ; echo "$HOST_TYPE/$HOST/$YEAR/$MONTH")"
DATA_EXISTS="yes"
# add year sum
echo "$REBUILD_DATA" | grep --fixed-strings --line-regexp -q "$HOST_TYPE/$HOST/$YEAR/all"
[ $? -eq 0 ] || REBUILD_DATA="$(echo "$REBUILD_DATA" ; echo "$HOST_TYPE/$HOST/$YEAR/all")"
done
if [ "$DATA_EXISTS" == "no" ]; then
# if no data files were found, add at least the current month
# obviously no HTML page will be built, but the user gets a clue what's happening
# hosts without a config file have at least a single data file, so they can't get to this point
REBUILD_DATA="$(echo "$REBUILD_DATA" ; echo "$HOST_TYPE/$HOST/$(date +%Y)/$(date +%m)")"
fi
done
# sort rebuild data
REBUILD_DATA="$(echo "$REBUILD_DATA" | LC_ALL=C sort)"
fi
if [ "$REBUILD" != "no" ]; then
# read AWStats pages from config
declare -A CONFIG_FILES
function getPages() {
local __RESULTVAR="$1"
local __FILE="$2"
# evaluate config files
local __INNER_RESULT=""
readPageConfig __INNER_RESULT "$__FILE"
[ $? -eq 0 ] || return 1
# append default pages (= lowest severity)
__INNER_RESULT+="alldomains=1\n"
__INNER_RESULT+="allhosts=1\nlasthosts=1\nunknownip=1\n"
__INNER_RESULT+="alllogins=0\nlastlogins=0\n"
__INNER_RESULT+="allrobots=1\nlastrobots=1\n"
__INNER_RESULT+="allemails=0\nlastemails=0\n"
__INNER_RESULT+="allemailr=0\nlastemailr=0\n"
__INNER_RESULT+="session=1\n"
__INNER_RESULT+="urldetail=1\nurlentry=1\nurlexit=1\n"
__INNER_RESULT+="downloads=1\n"
__INNER_RESULT+="osdetail=1\nunknownos=1\n"
__INNER_RESULT+="browserdetail=1\nunknownbrowser=1\n"
__INNER_RESULT+="screensize=0\n"
__INNER_RESULT+="refererse=1\nrefererpages=1\n"
__INNER_RESULT+="keyphrases=1\n"
__INNER_RESULT+="keywords=1\n"
__INNER_RESULT+="errors404=1\n"
# remove duplicates (keep the first row = keep last specified config)
eval "$__RESULTVAR=\"\$(echo 'main=1' ; printf \"$__INNER_RESULT\" | LC_ALL=C sort -u -t '=' -k 1,1)\""
# remove invisible pages
eval "$__RESULTVAR=\"\$(echo \"\$$__RESULTVAR\" | sed -ne 's/^\(.*\)=1$/\1/p')\""
return 0
}
function readPageConfig() {
local __RESULTVAR="$1"
local __FILE="$2"
# don't evaluate the same config file multiple times...
if [ -n "${CONFIG_FILES[$__FILE]+isset}" ]; then
eval "$__RESULTVAR=\"${CONFIG_FILES[$__FILE]}\$$__RESULTVAR\"";
else
while IFS= read -r __LINE || [ -n "$__LINE" ]; do
__LINE="${__LINE%%#*}"
__LINE="${__LINE#"${__LINE%%[![:space:]]*}"}"
__LINE="${__LINE%"${__LINE##*[![:space:]]}"}"
# skip empty lines
[ -n "$__LINE" ] || continue
# perform includes
if [[ "$__LINE" =~ ^Include\ \"([^\"]+)\"$ ]] || [[ "$__LINE" =~ ^#include\ \"[^\"]+\"$ ]]; then
local INCLUDE="${BASH_REMATCH[1]}"
[ "${INCLUDE:0:1}" != "/" ] && INCLUDE="$(dirname "$__FILE")/$INCLUDE"
((INCLUDE_DEPTH++))
if [ "$INCLUDE_DEPTH" -gt 100 ]; then
echo "$APP_NAME: Reached maximum include depth in config file \`$__FILE' (infinite loop?)" >&2
return 1
fi
readPageConfig "$__RESULTVAR" "$INCLUDE"
[ $? -eq 0 ] || return 1
((INCLUDE_DEPTH--))
continue
fi
# get parameter
# no need to validate the line, we're matching known configs only anyway
local __PARAM="$(echo "$__LINE" | cut -d '=' -f 1)"
__PARAM="${__PARAM%"${__PARAM##*[![:space:]]}"}"
# get value
local __VALUE="$(echo "$__LINE" | cut -d '=' -f 2 -s)"
__VALUE="${__VALUE#"${__VALUE%%[![:space:]]*}"}"
[[ "$__VALUE" == *\; ]] && __VALUE="${__VALUE:0: -1}"
if [[ "$__VALUE" == \"*\" ]] || [[ "$__VALUE" == \'*\' ]]; then __VALUE="${__VALUE:1: -1}"; fi
# replace __ENV__
while [[ "$__VALUE" =~ __([^[:space:]_]+(_[^[:space:]_]+)*)__ ]]; do
local __ENV_NAME="__${BASH_REMATCH[1]}__"
local __ENV_VALUE="$(eval "echo \"\$${BASH_REMATCH[1]}\"")"
__VALUE="${__VALUE//${__ENV_NAME}/$__ENV_VALUE}"
done
# require value = < 0 | 1 >
if [ -n "$__VALUE" ] && [ "$__VALUE" != "0" ]; then __VALUE="1"; else __VALUE="0"; fi
# search for known configs...
if [ "$__PARAM" == "ShowDomainsStats" ]; then eval "$__RESULTVAR=\"alldomains=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowHostsStats" ]; then eval "$__RESULTVAR=\"allhosts=$__VALUE\nlasthosts=$__VALUE\nunknownip=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowAuthenticatedUsers" ]; then eval "$__RESULTVAR=\"alllogins=$__VALUE\nlastlogins=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowRobotsStats" ]; then eval "$__RESULTVAR=\"allrobots=$__VALUE\nlastrobots=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowEMailSenders" ]; then eval "$__RESULTVAR=\"allemails=$__VALUE\nlastemails=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowEMailReceivers" ]; then eval "$__RESULTVAR=\"allemailr=__$__VALUE\nlastemailr=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowSessionsStats" ]; then eval "$__RESULTVAR=\"session=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowPagesStats" ]; then eval "$__RESULTVAR=\"urldetail=$__VALUE\nurlentry=$__VALUE\nurlexit=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowDownloadsStats" ]; then eval "$__RESULTVAR=\"downloads=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowOSStats" ]; then eval "$__RESULTVAR=\"osdetail=$__VALUE\nunknownos=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowBrowsersStats" ]; then eval "$__RESULTVAR=\"browserdetail=$__VALUE\nunknownbrowser=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowScreenSizeStats" ]; then eval "$__RESULTVAR=\"screensize=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowOriginStats" ]; then eval "$__RESULTVAR=\"refererse=$__VALUE\nrefererpages=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowKeyphrasesStats" ]; then eval "$__RESULTVAR=\"keyphrases=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowKeywordsStats" ]; then eval "$__RESULTVAR=\"keywords=$__VALUE\n\$$__RESULTVAR\""; fi
if [ "$__PARAM" == "ShowHTTPErrorsStats" ]; then eval "$__RESULTVAR=\"errors404=$__VALUE\n\$$__RESULTVAR\""; fi
# no distinct pages for ShowWormsStats, ShowFileTypesStats, ShowMiscStats, ShowHTTPErrorsStats, ShowSMTPErrorsStats, ShowClusterStats
# ShowFileSizesStats is "not yet available" as of AWStats 7.2
if [ "$__PARAM" == "LoadPlugin" ] && [[ "$__VALUE" == geoip* ]]; then eval "$__RESULTVAR=\"plugin_$(echo "$__VALUE" | cut -d ' ' -f 1)=1\n\$$__RESULTVAR\""; fi
if [[ "$__PARAM" =~ ^ExtraSectionName([0-9]+)$ ]]; then eval "$__RESULTVAR=\"allextra${BASH_REMATCH[1]}=1\n\$$__RESULTVAR\""; fi
done < "$__FILE"
# remember result
eval "CONFIG_FILES[\$__FILE]=\"\$$__RESULTVAR\""
fi
return 0
}
# perform rebuild...
echo "Generating static HTML pages..."
REBUILD_EXIT_CODE=0
REBUILD_GZIP_EXIT_CODE=0
PREVIOUS_IDENT=""
PREVIOUS_HOST_TYPE=""
PREVIOUS_HOST=""
IGNORE_HOST_TYPE=""
IGNORE_HOST=""
IFS=$'\n'; for DATA in $REBUILD_DATA; do
HOST_TYPE="$(echo "$DATA" | cut -d '/' -f 1)"
HOST="$(echo "$DATA" | cut -d '/' -f 2)"
YEAR="$(echo "$DATA" | cut -d '/' -f 3)"
MONTH="$(echo "$DATA" | cut -d '/' -f 4)"
if [ -n "$HOST_TYPE" ]; then
IDENT="$HOST ($HOST_TYPE)"
CONFIG_NAME="$HOST_TYPE.$HOST"
CONFIG_FILE="$CONFIG_DIR/awstats.$HOST_TYPE.$HOST.conf"
DATA_FILE="$AWSTATS_DATA_DIR/awstats$([ "$MONTH" != "all" ] && echo "$MONTH" || echo "??")$YEAR.$HOST_TYPE.$HOST.txt"
elif [ -n "$HOST" ]; then
IDENT="$HOST"
CONFIG_NAME="$HOST"
CONFIG_FILE="$CONFIG_DIR/awstats.$HOST.conf"
DATA_FILE="$AWSTATS_DATA_DIR/awstats$([ "$MONTH" != "all" ] && echo "$MONTH" || echo "??")$YEAR.$HOST.txt"
HOST_TYPE="[none]"
else
IDENT="[default]"
CONFIG_NAME="awstats.conf"
CONFIG_FILE="$CONFIG_DIR/awstats.conf"
DATA_FILE="$AWSTATS_DATA_DIR/awstats$([ "$MONTH" != "all" ] && echo "$MONTH" || echo "??")$YEAR.txt"
HOST_TYPE="[none]"
HOST="[default]"
fi
# something is wrong with this host; ignore it!
[ "$IGNORE_HOST_TYPE" == "$HOST_TYPE" ] && [ "$IGNORE_HOST" == "$HOST" ] && continue
# new host
if [ "$PREVIOUS_HOST_TYPE" != "$HOST_TYPE" ] || [ "$PREVIOUS_HOST" != "$HOST" ]; then
if [ -n "$PREVIOUS_HOST" ] && [ "$VERBOSE" -eq 2 ]; then
if [ "$PREVIOUS_HOST_TYPE" != "$IGNORE_HOST_TYPE" ] || [ "$PREVIOUS_HOST" != "$IGNORE_HOST" ]; then
echo "" >&3
fi
fi
if [ "$REBUILD_EXIT_CODE" -ne 0 ]; then
echo " ! $PREVIOUS_IDENT FAILED"
elif [ "$REBUILD_GZIP_EXIT_CODE" -ne 0 ]; then
echo " ~ $PREVIOUS_IDENT COMPRESSION FAILED"
fi
REBUILD_EXIT_CODE=0
REBUILD_GZIP_EXIT_CODE=0
PREVIOUS_IDENT="$IDENT"
PREVIOUS_HOST_TYPE="$HOST_TYPE"
PREVIOUS_HOST="$HOST"
# check for AWStats config file
if [ ! -f "$CONFIG_FILE" ]; then
echo " - $IDENT: config file not found; skipping..."
IGNORE_HOST_TYPE="$HOST_TYPE"
IGNORE_HOST="$HOST"
continue
fi
# read pages from config
getPages PAGES "$CONFIG_FILE"
if [ $? -ne 0 ]; then
echo " - $IDENT: unable to read pages from config file; skipping..."
IGNORE_HOST_TYPE="$HOST_TYPE"
IGNORE_HOST="$HOST"
continue
fi
# print current host
if [ "$VERBOSE" -eq 2 ]; then
echo -n " - $IDENT: " >&3
else
echo " - $IDENT"
fi
fi
# check for AWStats data file
if [ "$MONTH" != "all" ]; then
if [ ! -f "$DATA_FILE" ]; then
echo " - $YEAR-$MONTH: no data; skipping..." >&4
[ "$VERBOSE" -eq 2 ] && echo -n "$YEAR-$MONTH [no data] " >&3
continue
fi
elif [ -z "$(find "$(dirname "$DATA_FILE")" -maxdepth 1 -name "$(basename "$DATA_FILE")" -print -quit)" ]; then
echo " - $YEAR-$MONTH: no data; skipping..." >&4
[ "$VERBOSE" -eq 2 ] && echo -n "$YEAR-$MONTH [no data] " >&3
continue
fi
# create directories, if necessary
[ -d "$AWSTATS_WWW_DIR/$HOST_TYPE" ] || mkdir "$AWSTATS_WWW_DIR/$HOST_TYPE"
[ -d "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST" ] || mkdir "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST"
[ -d "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST/$YEAR" ] || mkdir "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST/$YEAR"
# delete and re-create destination directory (either --rebuild or --overwrite specified)
if [ -e "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST/$YEAR/$MONTH" ]; then
if [ "$OVERWRITE" == "yes" ]; then
rm -r "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST/$YEAR/$MONTH"
else
echo -n " ~ $YEAR-$MONTH: exists; skipping..." >&4
[ "$VERBOSE" -eq 2 ] && echo -n "$YEAR-$MONTH [exists] " >&3
continue
fi
fi
mkdir "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST/$YEAR/$MONTH"
# let the user know what happens
echo -n " - $YEAR-$MONTH: " >&4
[ "$VERBOSE" -eq 2 ] && echo -n "$YEAR-$MONTH " >&3
# generate static HTML pages
ROUND_EXIT_CODE=0
ROUND_GZIP_EXIT_CODE=0
for PAGE in $PAGES; do
echo -n "$PAGE " >&4
if [ -n "$AWSTATS_NICE" ]; then
nice -n "$AWSTATS_NICE" \
"$AWSTATS" -config="$CONFIG_NAME" \
-output="$PAGE" -year="$YEAR" -month="$MONTH" \
-staticlinks -lang="$AWSTATS_LANG" \
> "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST/$YEAR/$MONTH/awstats.$HOST_TYPE.$HOST.$PAGE.html"
PAGE_EXIT_CODE=$?
else
"$AWSTATS" -config="$CONFIG_NAME" \
-output="$PAGE" -year="$YEAR" -month="$MONTH" \
-staticlinks -lang="$AWSTATS_LANG" \
> "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST/$YEAR/$MONTH/awstats.$HOST_TYPE.$HOST.$PAGE.html"
PAGE_EXIT_CODE=$?
fi
if [ "$PAGE_EXIT_CODE" -eq 0 ]; then
# create compressed HTML page
if [[ ",$AWSTATS_FORMAT," == *,gzip,* ]]; then
gzip -c "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST/$YEAR/$MONTH/awstats.$HOST_TYPE.$HOST.$PAGE.html" \
> "$AWSTATS_WWW_DIR/$HOST_TYPE/$HOST/$YEAR/$MONTH/awstats.$HOST_TYPE.$HOST.$PAGE.html.gz"
PAGE_GZIP_EXIT_CODE=$?