function renderCactiServersEditor() { function printNewItemTR() { printOpFormIntro('add'); echo '<tr>'; echo '<td>' . getImageHREF('create', 'add a new server', TRUE, 112) . '</td>'; echo '<td><input type=text size=48 name=base_url tabindex=101></td>'; echo '<td><input type=text size=24 name=username tabindex=102></td>'; echo '<td><input type=password size=24 name=password tabindex=103></td>'; echo '<td> </td>'; echo '<td>' . getImageHREF('create', 'add a new server', TRUE, 111) . '</td>'; echo '</tr></form>'; } echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>'; echo '<tr><th> </th><th>base URL</th><th>username</th><th>password</th><th>graph(s)</th><th> </th></tr>'; if (getConfigVar('ADDNEW_AT_TOP') == 'yes') { printNewItemTR(); } foreach (getCactiServers() as $server) { printOpFormIntro('upd', array('id' => $server['id'])); echo '<tr><td>'; if ($server['num_graphs']) { printImageHREF('nodestroy', 'cannot delete, graphs exist'); } else { echo getOpLink(array('op' => 'del', 'id' => $server['id']), '', 'destroy', 'delete this server'); } echo '</td>'; echo '<td><input type=text size=48 name=base_url value="' . htmlspecialchars($server['base_url'], ENT_QUOTES, 'UTF-8') . '"></td>'; echo '<td><input type=text size=24 name=username value="' . htmlspecialchars($server['username'], ENT_QUOTES, 'UTF-8') . '"></td>'; echo '<td><input type=password size=24 name=password value="' . htmlspecialchars($server['password'], ENT_QUOTES, 'UTF-8') . '"></td>'; echo "<td class=tdright>{$server['num_graphs']}</td>"; echo '<td>' . getImageHREF('save', 'update this server', TRUE) . '</td>'; echo '</tr></form>'; } if (getConfigVar('ADDNEW_AT_TOP') != 'yes') { printNewItemTR(); } echo '</table>'; }
function renderObjectCactiGraphs($object_id) { function printNewItemTR($options) { echo "<table cellspacing=\"0\" align=\"center\" width=\"50%\">"; echo "<tr><td> </td><th>Server</th><th>Graph ID</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_id></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')) { throw new RackTablesError("The PHP cURL extension is not loaded.", RackTablesError::MISCONFIGURED); } $servers = getCactiServers(); $options = array(); foreach ($servers as $server) { $options[$server['id']] = "{$server['id']}: {$server['base_url']}"; } startPortlet('Cacti Graphs'); if (getConfigVar('ADDNEW_AT_TOP') == 'yes' && permitted('object', 'cacti', 'add')) { printNewItemTR($options); } echo "<table cellspacing=\"0\" cellpadding=\"10\" align=\"center\" width=\"50%\">"; foreach (getCactiGraphsForObject($object_id) as $graph_id => $graph) { $cacti_url = $servers[$graph['server_id']]['base_url']; $text = "(graph {$graph_id} on server {$graph['server_id']})"; echo "<tr><td>"; echo "<a href='{$cacti_url}/graph.php?action=view&local_graph_id={$graph_id}&rra_id=all' target='_blank'>"; echo "<img src='index.php?module=image&img=cactigraph&object_id={$object_id}&server_id={$graph['server_id']}&graph_id={$graph_id}' alt='{$text}' title='{$text}'></a></td><td>"; if (permitted('object', 'cacti', 'del')) { echo getOpLink(array('op' => 'del', 'server_id' => $graph['server_id'], 'graph_id' => $graph_id), '', 'Cut', 'Unlink graph', 'need-confirmation'); } echo " {$graph['caption']}"; echo "</td></tr>"; } echo '</table>'; if (getConfigVar('ADDNEW_AT_TOP') != 'yes' && permitted('object', 'cacti', 'add')) { printNewItemTR($options); } finishPortlet(); }
function proxyCactiRequest($server_id, $graph_id) { $ret = array(); $servers = getCactiServers(); if (!array_key_exists($server_id, $servers)) { throw new InvalidRequestArgException('server_id', $server_id); } $cacti_url = $servers[$server_id]['base_url']; $url = "{$cacti_url}/graph_image.php?action=view&local_graph_id={$graph_id}&rra_id=1"; $postvars = 'action=login&login_username='******'username']; $postvars .= '&login_password='******'password']; $session = curl_init(); // curl_setopt ($session, CURLOPT_VERBOSE, TRUE); // 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['CACTICOOKIE'][$cacti_url])) { curl_setopt($session, CURLOPT_COOKIE, $_SESSION['CACTICOOKIE'][$cacti_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); // Not an image, probably the login page if (preg_match('/^text\\/html.*/i', $ret['type'])) { // Request to set the cookies curl_setopt($session, CURLOPT_HEADER, TRUE); curl_setopt($session, CURLOPT_COOKIE, ""); // clear the old cookie $headers = curl_exec($session); // Get the cookies from the headers preg_match('/Set-Cookie: ([^;]*)/i', $headers, $cookies); array_shift($cookies); // Remove 'Set-Cookie: ...' value $cookie_header = implode(";", $cookies); $_SESSION['CACTICOOKIE'][$cacti_url] = $cookie_header; // store for later use by this user // POST Login curl_setopt($session, CURLOPT_COOKIE, $cookie_header); curl_setopt($session, CURLOPT_HEADER, FALSE); curl_setopt($session, CURLOPT_POST, TRUE); curl_setopt($session, CURLOPT_POSTFIELDS, $postvars); curl_exec($session); // Request the image curl_setopt($session, CURLOPT_HTTPGET, TRUE); $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']; }
function triggerCactiGraphs() { if (!count(getCactiServers())) { return ''; } if (count(getCactiGraphsForObject(getBypassValue())) or considerConfiguredConstraint(spotEntity('object', getBypassValue()), 'CACTI_LISTSRC')) { return 'std'; } else { return ''; } }