diff options
Diffstat (limited to 'index.php')
| -rw-r--r-- | index.php | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/index.php b/index.php new file mode 100644 index 0000000..756e086 --- /dev/null +++ b/index.php @@ -0,0 +1,127 @@ +<?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> |
