--- /dev/null
+<?php
+require 'config.php';
+
+function aws_sites()
+{
+ $sites = array();
+ foreach (glob($GLOBALS['confdir'] . '/awstats.*.conf') as $file) {
+ $sites[] = preg_replace('/^.*awstats.(.+).conf$/', '\\1', $file);
+ }
+ return $sites;
+}
+
+function aws_createHtml($site, $last = false)
+{
+ if (!is_dir($GLOBALS['htmldir'])) {
+ die("HTML directory " . $GLOBALS['htmldir'] . " does not exist\n");
+ }
+
+ if ($last) {
+ $month = date('m', strtotime('last month'));
+ $year = date('Y', strtotime('last month'));
+ } else {
+ $month = date('m');
+ $year = date('Y');
+ }
+
+ $dir = $GLOBALS['htmldir'] . '/' . $site . '/' . $year . '-' . $month . '/';
+ if (!is_dir($dir)) {
+ mkdir($dir, 0777, true);
+ }
+ $cmd = $GLOBALS['awsbstp']
+ . ' -config=' . escapeshellarg($site)
+ . ' -awstatsprog=' . escapeshellarg($GLOBALS['awstats'])
+ . ' -update'
+ . ' -month=' . $month
+ . ' -year=' . $year
+ . ' -dir=' . escapeshellarg($dir);
+ passthru($cmd);
+
+ if (!$last) {
+ aws_updateLink($site, $dir);
+ }
+}
+
+function aws_updateLink($site, $targetdir)
+{
+ $curdir = $GLOBALS['htmldir'] . '/' . $site . '/current';
+ unlink($curdir);
+ symlink($targetdir, $curdir);
+}
+
+function aws_createIndex($site)
+{
+ $dirs = glob($GLOBALS['htmldir'] . '/' . $site . '/*', GLOB_ONLYDIR);
+ sort($dirs);
+ $links = '';
+ foreach ($dirs as $dir) {
+ $name = basename($dir);
+ $links .= '<li><a href="' . $name . '/awstats.' . $site . '.html">'
+ . $name . '</a></li>';
+ }
+ $html = <<<XML
+<?xml version="1.0" encoding="utf-8"?>
+<html>
+ <head>
+ <title>{$site}</title>
+ </head>
+ <body>
+ <ul>
+{$links}
+ </ul>
+ </body>
+</html>
+XML;
+ file_put_contents(
+ $GLOBALS['htmldir'] . '/' . $site . '/index.htm',
+ $html
+ );
+}
+
+function aws_createGlobalIndex()
+{
+ $dirs = glob($GLOBALS['htmldir'] . '/*', GLOB_ONLYDIR);
+ sort($dirs);
+ $links = '';
+ foreach ($dirs as $dir) {
+ $name = basename($dir);
+ $links .= '<li><a href="' . $name . '/">'
+ . $name . '</a></li>';
+ }
+ $html = <<<XML
+<?xml version="1.0" encoding="utf-8"?>
+<html>
+ <head>
+ <title>awstats</title>
+ </head>
+ <body>
+ <ul>
+{$links}
+ </ul>
+ </body>
+</html>
+XML;
+ file_put_contents(
+ $GLOBALS['htmldir'] . '/index.htm',
+ $html
+ );
+}
+?>
\ No newline at end of file
/**
* Updates awstats for multiple sites
*/
-require 'config.php';
-
-function aws_sites()
-{
- $sites = array();
- foreach (glob($GLOBALS['confdir'] . '/awstats.*.conf') as $file) {
- $sites[] = preg_replace('/^.*awstats.(.+).conf$/', '\\1', $file);
- }
- return $sites;
-}
-
-function aws_createHtml($site, $last = false)
-{
- if (!is_dir($GLOBALS['htmldir'])) {
- die("HTML directory " . $GLOBALS['htmldir'] . " does not exist\n");
- }
-
- if ($last) {
- $month = date('m', strtotime('last month'));
- $year = date('Y', strtotime('last month'));
- } else {
- $month = date('m');
- $year = date('Y');
- }
-
- $dir = $GLOBALS['htmldir'] . '/' . $site . '/' . $year . '-' . $month . '/';
- if (!is_dir($dir)) {
- mkdir($dir, 0777, true);
- }
- $cmd = $GLOBALS['awsbstp']
- . ' -config=' . escapeshellarg($site)
- . ' -awstatsprog=' . escapeshellarg($GLOBALS['awstats'])
- . ' -update'
- . ' -month=' . $month
- . ' -year=' . $year
- . ' -dir=' . escapeshellarg($dir);
- passthru($cmd);var_dump($cmd);
-}
+require_once 'functions.php';
foreach (aws_sites() as $site) {
aws_createHtml($site);
+ aws_createIndex($site);
}
+aws_createGlobalIndex();
?>
\ No newline at end of file