"Fossies" - the Fresh Open Source Software Archive

Member "sawdog-2.4/www/index.php" (22 Sep 2006, 4981 Bytes) of package /linux/privat/old/sawdog-2.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "index.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 /* This program is free software. You can redistribute it and/or modify
    4    it under the terms of the GNU General Public License as published by
    5    the Free Software Foundation; either version 2 of the License, or
    6    (at your option) any later version. 
    7  
    8    Author: Max Kueng <maxkueng@users.sourceforge.net> */
    9 
   10 require_once './config.php';
   11 
   12 $status_path = $cfg['sawdog_status_path'];
   13 $status_mtime = filemtime($cfg['sawdog_status_path']);
   14 $status_offset = time() - $status_mtime;
   15 
   16 $handle = fopen($status_path, 'r');
   17 $contents = fread($handle, filesize($status_path));
   18 fclose($handle);
   19 
   20 $lines = preg_split('/(\r\r|\r|\n)/i', $contents);
   21 
   22 $entries = array();
   23 for ($i=0;$i<count($lines);$i++) {
   24     if (preg_match('/^([a-z0-9.-]+?)\s(\w+?)\s(\w+?)$/i', $lines[$i], $matches)) {
   25         $entries[$matches[1]][$matches[2]] = $matches[3];
   26     }
   27 }
   28 $hosts = array_keys($entries);
   29 
   30 if ($_GET['xml'] == 'true') {
   31     if ($_GET['config'] == 'true') {
   32         $conf = array_keys($cfg);
   33         $out = '<rsp stat="ok" >';
   34         for ($i=0;$i<count($conf);$i++) {
   35             $out.= '<param key="'. $conf[$i] .'" value="'. $cfg[$conf[$i]] .'" />';
   36         }
   37         $out.= '</rsp>';
   38     } else {
   39         $out = '<rsp stat="ok" timestamp="'. date('Y-m-d H:i:s', time()) .'" filemtime="'. date('Y-m-d H:i:s', $status_mtime) .'" offset="'. $status_offset .'">';
   40         for ($i=0;$i<count($hosts);$i++) {
   41             $out.= '<host id="h-'. preg_replace('/[^0-9a-z]/i', '-', $hosts[$i]) .'">';
   42             $protocols = array_keys($entries[$hosts[$i]]);
   43             for ($ii=0;$ii<count($protocols);$ii++) {
   44                 $out.= '<protocol name="'. $protocols[$ii] .'" status="'. $entries[$hosts[$i]][$protocols[$ii]] .'" />';
   45             }
   46             $out.= '</host>';
   47         }
   48         $out.= '</rsp>';
   49     }
   50 
   51     header('Content-Type: text/xml');
   52     header("Cache-Control: no-store, no-cache, must-revalidate");
   53 
   54 } else {
   55 
   56     $out = '
   57     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   58     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
   59 
   60         <head>
   61             <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
   62             <title>'.$cfg['sawdog_title'].'</title>
   63             <link rel="stylesheet" href="./css/styles.css" type="text/css" />
   64             <script src="./js/behaviour.js" type="text/javascript"></script>
   65             <script src="./js/prototype.js" type="text/javascript"></script>
   66             <script src="./js/scriptaculous.js?load=effects" type="text/javascript"></script>
   67             <script src="./js/sawdog.js" type="text/javascript"></script>
   68         </head>
   69 
   70         <body>
   71 
   72             <h1><a href="/" title="'.$cfg['sawdog_title'].'"><span>'.$cfg['sawdog_title'].'</span></a></h1>
   73             <p id="lastupdated">Last updated: <span>'. date('Y-m-d H:i:s') .'</span></p>
   74             <div id="about" style="display:'. (($_GET['about'] == 'true') ? 'block' : 'none') .';">
   75                 <a class="close" href="'. $_SERVER['SCRIPT_NAME'] .'" title="close"><span>Close</span></a>
   76                 <h2><span>Sawdog '. $cfg['sawdog_version'] .'</span></h2>
   77                 <p class="license">Licensed under the GNU General Public License (GPL).</p>
   78                 <p><strong><a href="'. $cfg['sawdog_homepage'] .'" title="">Sawdog</a></strong> (Simple Active Watch-DOG) is a suite of scripts that informs the 
   79                 system operators of mission critical servers in the case of a failure.</p>
   80                 <p>The Sawdog <em>web interface</em> uses several libraries for functionality and beautiful effects:</p>
   81                 <ul>
   82                     <li><strong><a href="http://prototype.conio.net/" title="">Prototype</a></strong> 1.5.0_rc0 (MIT-style license)</li>
   83                     <li><strong><a href="http://script.aculo.us/" title="">scritp.aculo.us</a></strong> 1.6.2 (MIT license)</li>
   84                     <li><strong><a href="http://tango.freedesktop.org/" title="">Tango Desktop Project</a></strong> (CC BY-SA 2.5 license)</li>
   85                     <li><strong><a href="http://bennolan.com/behaviour/" title="">Behaviour</a></strong> 1.1 (BSD license)</li>
   86                 </ul>
   87             </div>
   88             <p id="warning" class="warning"></p>
   89             <p id="error" class="error"></p>
   90             <div id="hosts">
   91     ';
   92     
   93     for ($i=0;$i<count($hosts);$i++) {
   94         $protocols = array_keys($entries[$hosts[$i]]);
   95 
   96         $out.= '
   97                 <div id="h-'. preg_replace('/[^0-9a-z]/i', '-', $hosts[$i]) .'" class="host">
   98                     <h2>'. $hosts[$i] .'</h2>
   99                     <ul class="protocols">
  100         ';
  101         for ($ii=0;$ii<count($protocols);$ii++) {
  102             $out.= '
  103                     <li id="h-'. preg_replace('/[^0-9a-z]/i', '-', $hosts[$i]) .'-'. $protocols[$ii] .'" 
  104                     class="'. $entries[$hosts[$i]][$protocols[$ii]] .'">'. $protocols[$ii] .' 
  105                     <span class="status"> is '. $entries[$hosts[$i]][$protocols[$ii]] .'</span></li>
  106             ';
  107         }
  108         $out.= '
  109                     </ul>
  110                 </div>
  111         ';
  112     }
  113 
  114     $out.= '
  115             </div>
  116 
  117             <div id="navigation">
  118                 <h2>Navigation</h2>
  119                 <ul>
  120                     <li><a href="'. $_SERVER['SCRIPT_NAME'] .'?xml=true" title="">XML</a></li>
  121                     <li><a id="nav-about" href="'. $_SERVER['SCRIPT_NAME'] .'?about=true" title="">About</a></li>
  122                 </ul>
  123             </div>
  124         </body>
  125 
  126     </html>
  127     ';  
  128 
  129 }
  130 
  131 echo $out;
  132 
  133 ?>