php-collection: New graph toolbox
[collectd.git] / contrib / php-collection / index.php
index 93f1fcf..837d261 100644 (file)
@@ -58,6 +58,7 @@ function build_page() {
                print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n");
                print('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'."\n");
        }
+       $url_base = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
 ?>
        <head>
                <title>Collectd graph viewer</title>
@@ -65,7 +66,8 @@ function build_page() {
                <style type="text/css">
                        body, html { background-color: #EEEEEE; color: #000000; }
                        h1 { text-align: center; }
-                       div.body { margin: auto; width: <?php echo 125+$config['rrd_width'] ?>px; background: #FFFFFF; border: 1px solid #DDDDDD; }
+                       div.body { margin: auto; width: <?php echo isset($config['rrd_width']) ? 110+(int)$config['rrd_width'] : 600; ?>px; background: #FFFFFF; border: 1px solid #DDDDDD; }
+                       p.error { color: #CC0000; margin: 0em; }
                        div.selector { margin: 0.5em 2em; }
                        div.selectorbox { padding: 5px; border: 1px solid #CCCCCC; background-color: #F8F8F8; }
                        div.selectorbox table { border: none; }
@@ -75,20 +77,21 @@ function build_page() {
                        div.selectorbox table td.sc { padding: 0.5em 2em; text-align: center; }
                        a img { border: none; }
                        div.graphs { border-top: 1px solid #DDDDDD; padding: 5px; overflow: auto; }
-                       div.graphs_t { display: table; }
-                       div.graph { display: table-row; }
-                       div.graph_img { display: table-cell; vertical-align: middle; text-align: right; }
-                       div.graph_opts { display: table-cell; vertical-align: middle; text-align: center; line-height: 2em; }
-                       select { width: 100%; }
+                       div.graphs_t { position: relative; }
+                       div.graph { text-align: right; }
+                       div.selector select { width: 100%; }
+                       table.toolbox { border: 1px solid #5500dd; padding: 0px; margin: 0px; background: #ffffff;}
+                       table.toolbox td.c1 { vertical-align: middle; text-align: left; padding-left: 0.3em; padding-right: 1em; border-right: 1px solid #5500dd; }
+                       table.toolbox td.c2 { vertical-align: middle; text-align: center; padding-left: 5px; padding-right: 5px; }
                </style>
                <script type="text/javascript">// <![CDATA[
-var dhtml_url = '<?php echo addslashes('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']); ?>';
-var graph_url = '<?php echo addslashes('http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/graph.php'); ?>';
+var dhtml_url = '<?php echo addslashes($url_base.basename($_SERVER['PHP_SELF'])); ?>';
+var graph_url = '<?php echo addslashes($url_base.'graph.php'); ?>';
 //             ]]></script>
-               <script type="text/javascript" src="browser.js"></script>
+               <script type="text/javascript" src="<?php echo htmlspecialchars($url_base.'browser.js'); ?>"></script>
        </head>
 
-       <body onload="ListRefreshHost()"><div class="body">
+       <body onload="ListRefreshHost(); GraphListRefresh(); "><div class="body">
                <h1><img src="collectd-logo.png" align="bottom" alt="" /> Collectd browser for system statistics graphs</h1>
                <div class="selector"><a href="javascript:toggleDiv('selector')"><span id="selector_sw">Hide</span> graph selection tool</a><div id="selector" class="selectorbox">
                        <table>
@@ -135,13 +138,80 @@ var graph_url = '<?php echo addslashes('http://'.$_SERVER['HTTP_HOST'].dirname($
                                <tr>
                                        <td class="sc" colspan="3"><input id="btnAdd"     name="btnAdd"     type="button" disabled="disabled" onclick="GraphAppend()" value="Add graph" />
                                        <input id="btnClear"   name="btnClear"   type="button" disabled="disabled" onclick="GraphDropAll()" value="Remove all graphs" />
-                                       <input id="btnRefresh" name="btnRefresh" type="button" disabled="disabled" onclick="GraphRefresh(null)" value="Refresh all graphs" /></td>
+                                       <input id="btnRefresh" name="btnRefresh" type="button" disabled="disabled" onclick="GraphRefreshAll()" value="Refresh all graphs" /></td>
+                               </tr>
+                               <tr>
+                                       <td class="s1" rowspan="2">Graph list favorites:</td>
+                                       <td class="s3"><input type="text" style="width: 100%" maxlength="30" id="GraphListName" name="GraphListName" value="default" onchange="GraphListCheckName(false)" /></td>
+                                       <td class="s3"><a href="javascript:GraphSave()"><img src="save.png" width="16" height="16" alt="S" title="Save graph list to cookie" /></a></td>
+                               </tr>
+                               <tr>
+                                       <td class="s2"><select id="GraphList" name="GraphList" onfocus="GraphListRefresh()">
+                                               <option value="default">default</option>
+                                       </select></td>
+                                       <td class="s3"><a href="javascript:GraphLoad()"><img src="load.png" width="16" height="16" alt="L" title="Load graph list from cookie" /></a><a href="javascript:GraphDrop()"><img src="delete.png" width="16" height="16" alt="D" title="Delete graph list from cookie" /></a></td>
                                </tr>
                        </table>
                </div></div>
                <div class="graphs"><div id="graphs" class="graphs_t">
-                       <div id="nograph">Please use above graph selection tool to add graphs to this area.</div>
+                       <div id="nograph">Please use above graph selection tool to add graphs to this area.<?php
+                       // Config checking
+                       if (!isset($config['datadirs']))
+                               echo '<p class="error">Config error: $config["datadirs"] is not set</p>';
+                       else if (!is_array($config['datadirs']))
+                               echo '<p class="error">Config error: $config["datadirs"] is not an array</p>';
+                       else if (count($config['datadirs']) == 0)
+                               echo '<p class="error">Config error: $config["datadirs"] is empty</p>';
+                       else foreach ($config['datadirs'] as $datadir)
+                               if (!is_dir($datadir))
+                                       echo '<p class="error">Config error: $config["datadirs"], '.htmlspecialchars($datadir).' does not exist</p>';
+                       if (!isset($config['rrd_width']))
+                               echo '<p class="error">Config error: $config["rrd_width"] is not set</p>';
+                       else if (10 > (int)$config['rrd_width'])
+                               echo '<p class="error">Config error: $config["rrd_width"] is invalid. Integer >= 10 expected</p>';
+                       if (!isset($config['rrd_height']))
+                               echo '<p class="error">Config error: $config["rrd_height"] is not set</p>';
+                       else if (10 > (int)$config['rrd_height'])
+                               echo '<p class="error">Config error: $config["rrd_height"] is invalid. Integer >= 10 expected</p>';
+                       if (!isset($config['rrd_opts']))
+                               echo '<p class="error">Config error: $config["rrd_opts"] is not set</p>';
+                       else if (!is_array($config['rrd_opts']))
+                               echo '<p class="error">Config error: $config["rrd_opts"] is not an array</p>';
+                       if (!isset($config['timespan']))
+                               echo '<p class="error">Config error: $config["timespan"] is not set</p>';
+                       else if (!is_array($config['timespan']))
+                               echo '<p class="error">Config error: $config["timespan"] is not an array</p>';
+                       else if (count($config['timespan']) == 0)
+                               echo '<p class="error">Config error: $config["timespan"] is empty</p>';
+                       else foreach ($config['timespan'] as &$timespan)
+                               if (!is_array($timespan) || !isset($timespan['name']) || !isset($timespan['label']) || !isset($timespan['seconds']) || 10 > (int)$timespan['seconds'])
+                                       echo '<p class="error">Config error: $config["timespan"], invalid entry found</p>';
+                       if (!is_null($config['collectd_sock']) && strncmp('unix://', $config['collectd_sock'], 7) != 0)
+                               echo '<p class="error">Config error: $config["collectd_sock"] is not valid</p>';
+                       if (!defined('RRDTOOL'))
+                               echo '<p class="error">Config error: RRDTOOL is not defined</p>';
+                       else if (!is_executable(RRDTOOL))
+                               echo '<p class="error">Config error: RRDTOOL ('.htmlspecialchars(RRDTOOL).') is not executable</p>';
+                       ?></div>
                </div></div>
+               <input type="hidden" name="ge_graphid" id="ge_graphid" value="" />
+               <table id="ge" class="toolbox" style="position: absolute; display: none; " cellspacing="1" cellpadding="0">
+                       <tr>
+                               <td class="c1" rowspan="3"><select id="ge_timespan" name="ge_timespan" onchange="GraphAdjust(null)"><?php
+                               foreach ($config['timespan'] as &$timespan)
+                                       printf("\t\t\t\t\t\t<option value=\"%s\">%s</option>\n", htmlspecialchars($timespan['name']), htmlspecialchars($timespan['label']));
+                               ?></select><br />
+                               <label><input id="ge_logarithmic"  name="ge_logarithmic" type="checkbox" value="1" onchange="GraphAdjust(null)" /> Logarithmic scale</label><br />
+                               <label><input id="ge_tinylegend"  name="ge_tinylegend" type="checkbox" value="1" onchange="GraphAdjust(null)" /> Minimal legend</label></td>
+                               <td class="c2"><a href="javascript:GraphMoveUp(null)"><img src="move-up.png" alt="UP" title="Move graph up"/></a></td>
+                       </tr>
+                       <tr>
+                               <td class="c2"><a href="javascript:GraphRefresh(null)"><img src="refresh.png" alt="R" title="Refresh graph"/></a>&nbsp;<a href="javascript:GraphRemove(null)"><img src="delete.png" alt="RM" title="Remove graph"/></a></td>
+                       </tr>
+                       <tr>
+                               <td class="c2"><a href="javascript:GraphMoveDown(null)"><img src="move-down.png" alt="DN" title="Move graph down"/></a></td>
+                       </tr>
+               </table>
        </div></body>
 </html><?php
 }