function renderObjectMuninGraphs($object_id) { function printNewItem($options) { echo "<table cellspacing=\"0\" align=\"center\" width=\"50%\">"; echo "<tr><td> </td><th>Server</th><th>Graph</th><th>Caption</th><td> </td></tr>\n"; printOpFormIntro('add'); echo "<tr><td>"; printImageHREF('Attach', 'Link new graph', TRUE); echo '</td><td>' . getSelect($options, array('name' => 'server_id')); echo "</td><td><input type=text name=graph></td><td><input type=text name=caption></td><td>"; printImageHREF('Attach', 'Link new graph', TRUE); echo "</td></tr></form>"; echo "</table>"; echo "<br/><br/>"; } if (!extension_loaded('curl')) { showError('The PHP cURL extension is not loaded.'); return; } try { list($host, $domain) = getMuninNameAndDomain($object_id); } catch (InvalidArgException $e) { showError('This object does not have the FQDN or the common name in the host.do.ma.in format.'); return; } $servers = getMuninServers(); $options = array(); foreach ($servers as $server) { $options[$server['id']] = "{$server['id']}: {$server['base_url']}"; } startPortlet('Munin Graphs'); if (getConfigVar('ADDNEW_AT_TOP') == 'yes') { printNewItem($options); } echo "<table cellspacing=\"0\" cellpadding=\"10\" align=\"center\" width=\"50%\">"; foreach (getMuninGraphsForObject($object_id) as $graph_name => $graph) { $munin_url = $servers[$graph['server_id']]['base_url']; $text = "(graph {$graph_name} on server {$graph['server_id']})"; echo "<tr><td>"; echo "<a href='{$munin_url}/{$domain}/{$host}.{$domain}/{$graph_name}.html' target='_blank'>"; echo "<img src='index.php?module=image&img=muningraph&object_id={$object_id}&server_id={$graph['server_id']}&graph={$graph_name}' alt='{$text}' title='{$text}'></a></td>"; echo "<td>"; echo getOpLink(array('op' => 'del', 'server_id' => $graph['server_id'], 'graph' => $graph_name), '', 'Cut', 'Unlink graph', 'need-confirmation'); echo " {$graph['caption']}"; echo "</td></tr>"; } echo '</table>'; if (getConfigVar('ADDNEW_AT_TOP') != 'yes') { printNewItem($options); } finishPortlet(); }
function proxyMuninRequest($server_id, $graph) { try { list($host, $domain) = getMuninNameAndDomain(getBypassValue()); } catch (InvalidArgException $e) { throw new RTImageError('munin_graph'); } $ret = array(); $servers = getMuninServers(); if (!array_key_exists($server_id, $servers)) { throw new InvalidRequestArgException('server_id', $server_id); } $munin_url = $servers[$server_id]['base_url']; $url = "{$munin_url}/{$domain}/{$host}.{$domain}/{$graph}-day.png"; $session = curl_init(); // Initial options up here so a specific type can override them curl_setopt($session, CURLOPT_FOLLOWLOCATION, FALSE); curl_setopt($session, CURLOPT_TIMEOUT, 10); curl_setopt($session, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($session, CURLOPT_URL, $url); if (isset($_SESSION['MUNINCOOKIE'][$munin_url])) { curl_setopt($session, CURLOPT_COOKIE, $_SESSION['MUNINCOOKIE'][$munin_url]); } // Request the image $ret['contents'] = curl_exec($session); $ret['type'] = curl_getinfo($session, CURLINFO_CONTENT_TYPE); $ret['size'] = curl_getinfo($session, CURLINFO_SIZE_DOWNLOAD); curl_close($session); if ($ret['type'] != NULL) { header("Content-Type: {$ret['type']}"); } if ($ret['size'] > 0) { header("Content-Length: {$ret['size']}"); } echo $ret['contents']; }