create index pages, create symlinked current directory
authorChristian Weiske <cweiske@cweiske.de>
Sat, 14 Nov 2009 17:24:05 +0000 (18:24 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Sat, 14 Nov 2009 17:24:05 +0000 (18:24 +0100)
functions.php [new file with mode: 0644]
update-sites.php

diff --git a/functions.php b/functions.php
new file mode 100644 (file)
index 0000000..7649f61
--- /dev/null
@@ -0,0 +1,109 @@
+<?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
index 515954878b5a1a5e7d92a52066b6c6be14bdadc4..601ecd23f5e3b41636f99bb798d6e3cc63c0c167 100644 (file)
@@ -2,46 +2,11 @@
 /**
  * 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