compact awstats overview HTML page

raw

1-screenshot.png

1-screenshot.png
raw

index.php

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
<?php
/**
 * Compact overview for awstats multi-domain HTML web statistics
 *
 * Lists all years + months for each domain.
 * Put it as index.php in the base output directory of "buildstatic.sh",
 * "/var/cache/awstats/".
 * Can also be symlinked into the domain subdirectories.
 *
 * @author Christian Weiske <cweiske+awstats-overview@cweiske.de>
 */
$hiddenDomains = [
    'old-ahso4',
];
 
$domains = glob('*', GLOB_ONLYDIR);
$domains = array_filter(
    $domains,
    function ($domain) use ($hiddenDomains) {
        return !in_array($domain, $hiddenDomains);
    }
);
 
$singleDomainView = array_reduce(
    $domains,
    function ($carry, $domain) {
        return $carry &&  strlen($domain) == 4 && ctype_digit($domain);
    },
    true
);
if ($singleDomainView) {
    //we are in a domain directory
    $domains = [basename(getcwd())];
    chdir('..');
}
 
$struct = [];
foreach ($domains as $domain) {
    $dyears = glob($domain . '/*', GLOB_ONLYDIR);
    foreach ($dyears as $dyear) {
        $year = basename($dyear);
        $dymonths = glob($dyear . '/*', GLOB_ONLYDIR | GLOB_MARK);
        foreach ($dymonths as $num => $dymonth) {
            $month = basename($dymonth);
            if ($num == 0 && $month != '01') {
                foreach (range(1, $month - 1) as $dummy) {
                    $struct[$domain][$year][str_pad($dummy, 2, '0', STR_PAD_LEFT)] = null;
                }
            }
            $struct[$domain][$year][$month] = $dymonth;
        }
    }
}
 
$title = 'awstats overview';
if ($singleDomainView) {
    $title .= ': ' . array_key_first($struct);
}
?>
<!DOCTYPE html>
<html>
    <head>
        <title><?= $title ?></title>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <?php if ($singleDomainView): ?>
            <base href="../"/>
        <?php endif; ?>
        <style type="text/css">
         div.domains {
             display: flex;
             flex-wrap: wrap;
             gap: 1em;
         }
         
         dl {
             display: grid;
             grid-template-columns: max-content auto;
         }
         dt {
             grid-column-start: 1;
         }
         dd {
             grid-column-start: 2;
             margin-left: 1em;
         }
 
         ul {
             padding-left: 0;
         }
         ul > li {
             display: inline;
         }
         li.disabled {
             color: #DDD;
         }
        </style>
    </head>
    <body>
        <h1><?= $title ?></h1>
 
        <div class="domains">
            <?php foreach ($struct as $domain => $years): ?>
                <div class="domain" id="<?= $domain ?>">
                    <?php if (!$singleDomainView): ?>
                        <h2><a href="<?= $domain ?>"><?= $domain ?></a></h2>
                    <?php endif; ?>
                    <dl>
                        <?php foreach ($years as $year => $months): ?>
                            <dt><?= $year ?></dt>
                            <dd>
                                <ul>
                                    <?php foreach ($months as $month => $path): ?>
                                        <?php if ($path === null): ?>
                                            <li class="disabled"><?= $month ?></li>
                                        <?php else: ?>
                                            <li><a href="<?= $path ?>"><?= $month ?></a></li>
                                        <?php endif; ?>
                                    <?php endforeach; ?>
                                </ul>
                            </dd>
                        <?php endforeach; ?>
                    </dl>
                </div>
            <?php endforeach; ?>
        </div>
    </body>
</html>
 
Christian Weiske Christian Weiske
owner

History