Simple display page for webserver RRD graphs
[infodrom.org/service.infodrom.org] / src / Infodrom / webstats / view.wml
1 <protect pass=2>
2 <?
3   # Supported variables:
4   #   type    [access]  {transfer, access}
5   #   period  [day]     {day, week, month, year, thismonth}
6   #   site    []
7   #   year    [this year]
8   if (isset($_GET["type"]) && $_GET["type"] === 'transfer')
9     $type = 'transfer';
10   else
11     $type = 'access';
12
13   $periods = array('day','week','month','year','thismonth');
14   if (isset($_GET["period"]) && in_array($_GET["period"], $periods, true) === true)
15     $period = $_GET["period"];
16   else
17     $period = 'day';
18
19   if (isset($_GET["site"]) && is_dir($_GET["site"]) && $_GET["site"][0] != '.')
20     $site = $_GET["site"];
21   else
22     $site = '';
23
24   $maxyear = 2007;
25   $maxyear = date("Y");
26   if (isset($_GET["year"]) && is_numeric($_GET["year"]) && $_GET["year"] >= $minyear && $_GET["year"] <= $maxyear)
27     $year = $_GET["year"];
28   else
29     $year = $maxyear;
30
31   $thispage = explode('/', $_SERVER['REQUEST_URI']);
32   $thispage = $thispage[count($thispage)-1];
33 ?>
34 </protect>
35
36 #include <infodrom.style>
37
38 <page func="Infodrom Oldenburg" title="Statistics">
39
40 <protect pass=2>
41 <?
42   function emit_image($site, $type, $period, $link)
43   {
44     $fname = sprintf ("%s/%s-%s.png", $site, $type, $period);
45     if (!is_file($fname)) return;
46     $size = getimagesize($fname);
47
48     echo ('<div style="padding-top: 1em"></div>');
49     echo ('<div align="center">');
50     if (!empty($link))
51       printf ('<a href="%s">', $link);
52     printf ('<img src="%s" %s border="0" />',
53       $fname, $size);
54     if (!empty($link))
55       echo ('</a>');
56     echo ('</div>');
57   }
58
59   $sites = array();
60   $dir = opendir('.');
61   while (($dent = readdir($dir)) !== false) {
62     if (!is_dir($dent) || $dent[0] == '.') continue;
63     if ($dent === 'total') continue;
64     $sites[] = $dent;
65   }
66   closedir ($dir);
67   asort ($sites);
68
69   if (empty($site)) {
70     foreach ($sites as $site) {
71       $link = sprintf("%s?type=%s&site=%s", $thispage, $type, urlencode($site));
72       emit_image ($site, $type, $period, $link);
73     }
74     $link = sprintf("%s?type=%s&site=%s", $thispage, $type, 'total');
75     emit_image ('total', $type, $period, $link);
76   } else {
77     if ($period === 'thismonth') {
78       for ($mon = 1; $mon <= 12; $mon++) {
79         emit_image($site, $type, sprintf('%04d-%02d', $year, $mon), '');
80       }
81     } else {
82       foreach ($periods as $period) {
83         if ($period == 'thismonth') {
84           $link = sprintf("%s?type=%s&period=thismonth&site=%s", $thispage, $type, urlencode($site));
85           emit_image ($site, $type, $period, $link);
86         } else
87           emit_image ($site, $type, $period, '');
88       }
89     }
90   }
91 ?>
92 </protect>
93
94 <div style="padding-top: 1em"></div>
95
96 </page>
97
98 # Local variables:
99 # mode: html
100 # mode: auto-fill
101 # end: