function send_mail($to, $from, $subject, $message, $filename = '', $headers = '') { global $config; include_once $config["base_path"] . "/plugins/settings/include/mailer.php"; $message = str_replace('<SUBJECT>', $subject, $message); $message = str_replace('<TO>', $to, $message); $message = str_replace('<FROM>', $from, $message); $how = read_config_option("settings_how"); if ($how < 0 || $how > 2) { $how = 0; } if ($how == 0) { $Mailer = new Mailer(array('Type' => 'PHP')); } else { if ($how == 1) { $sendmail = read_config_option('settings_sendmail_path'); $Mailer = new Mailer(array('Type' => 'DirectInject', 'DirectInject_Path' => $sendmail)); } else { if ($how == 2) { $smtp_host = read_config_option("settings_smtp_host"); $smtp_port = read_config_option("settings_smtp_port"); $smtp_username = read_config_option("settings_smtp_username"); $smtp_password = read_config_option("settings_smtp_password"); $Mailer = new Mailer(array('Type' => 'SMTP', 'SMTP_Host' => $smtp_host, 'SMTP_Port' => $smtp_port, 'SMTP_Username' => $smtp_username, 'SMTP_Password' => $smtp_password)); } } } if ($from == '') { $from = read_config_option('settings_from_email'); $fromname = read_config_option('settings_from_name'); if ($from == "") { if (isset($_SERVER['HOSTNAME'])) { $from = 'Cacti@' . $_SERVER['HOSTNAME']; } else { $from = '*****@*****.**'; } } if ($fromname == "") { $fromname = "Cacti"; } $from = $Mailer->email_format($fromname, $from); if ($Mailer->header_set('From', $from) === false) { print "ERROR: " . $Mailer->error() . "\n"; return $Mailer->error(); } } else { $from = $Mailer->email_format('Cacti', $from); if ($Mailer->header_set('From', $from) === false) { print "ERROR: " . $Mailer->error() . "\n"; return $Mailer->error(); } } if ($to == '') { return "Mailer Error: No <b>TO</b> address set!!<br>If using the <i>Test Mail</i> link, please set the <b>Alert e-mail</b> setting."; } $to = explode(',', $to); foreach ($to as $t) { if (trim($t) != '' && !$Mailer->header_set("To", $t)) { print "ERROR: " . $Mailer->error() . "\n"; return $Mailer->error(); } } $wordwrap = read_config_option("settings_wordwrap"); if ($wordwrap == '') { $wordwrap = 76; } if ($wordwrap > 9999) { $wordwrap = 9999; } if ($wordwrap < 0) { $wordwrap = 76; } $Mailer->Config["Mail"]["WordWrap"] = $wordwrap; if (!$Mailer->header_set("Subject", $subject)) { print "ERROR: " . $Mailer->error() . "\n"; return $Mailer->error(); } if (is_array($filename) && !empty($filename) && strstr($message, '<GRAPH>') !== 0) { foreach ($filename as $val) { $graph_data_array = array("output_flag" => RRDTOOL_OUTPUT_STDOUT); $data = @rrdtool_function_graph($val['local_graph_id'], $val['rra_id'], $graph_data_array); if ($data != "") { $cid = $Mailer->content_id(); if ($Mailer->attach($data, $val['filename'] . '.png', "image/png", "inline", $cid) == false) { print "ERROR: " . $Mailer->error() . "\n"; return $Mailer->error(); } $message = str_replace('<GRAPH>', "<br><br><img src='cid:{$cid}'>", $message); } else { $message = str_replace('<GRAPH>', "<br><img src='" . $val['file'] . "'><br>Could not open!<br>" . $val['file'], $message); } } } $text = array('text' => '', 'html' => ''); if ($filename == '') { $message = str_replace('<br>', "\n", $message); $message = str_replace('<BR>', "\n", $message); $message = str_replace('</BR>', "\n", $message); $text['text'] = strip_tags($message); } else { $text['html'] = $message . '<br>'; $text['text'] = strip_tags(str_replace('<br>', "\n", $message)); } if ($Mailer->send($text) == false) { print "ERROR: " . $Mailer->error() . "\n"; return $Mailer->error(); } return ''; }
/** * Output interface utilisation graph for given switch & ports * @see function rrdtool_function_graph in lib/rrd.php * @param integer $switch * @param integer $port * @param array $data graph data, allowed keys: * from - plot graph from * to - plot graph to * rra_id - use instead of from/to - plot graph based on rra * @return png image */ public function getGraphImage($switch, $port, $data = array()) { //1st determine graph that switch & port have one generated for $graph_data_array = array(); if (!empty($data["from"]) && $data["from"] < 1600000000) { $graph_data_array["graph_start"] = $data["from"]; } /* override: graph end time (unix time) */ if (!empty($data["to"]) && $data["to"] < 1600000000) { $graph_data_array["graph_end"] = $data["to"]; } $gid = $this->getGraphID($switch, $port); if (!$gid) { return false; } print rrdtool_function_graph($gid, array_key_exists("rra_id", $data) ? $data["rra_id"] : null, $graph_data_array); }
function graph_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ $use_graph_template = true; if (!empty($_GET["id"])) { $local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . get_request_var("id")); $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . get_request_var("id")); $graphs_template = db_fetch_row("select * from graph_templates_graph where id=$local_graph_template_graph_id"); $device_id = db_fetch_cell("select device_id from graph_local where id=" . get_request_var("id")); $header_label = __("[edit: ") . get_graph_title(get_request_var("id")) . "]"; if ($graphs["graph_template_id"] == "0") { $use_graph_template = false; } }else{ $graphs = array(); $graphs_template = array(); $header_label = __("[new]"); $use_graph_template = false; } /* handle debug mode */ if (isset($_GET["debug"])) { if (get_request_var("debug") == "0") { kill_session_var("graph_debug_mode"); }elseif (get_request_var("debug") == "1") { $_SESSION["graph_debug_mode"] = true; } } $tip_text = "<tr><td align=\\'right\\'><a class=\\'popup_item\\' id=\\'changeGraphState\\' onClick=\\'changeGraphState()\\' href=\\'#\\'>Unlock/Lock</a></td></tr>"; $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('graphs.php?action=graph_edit&id=' . (isset($_GET["id"]) ? get_request_var("id") : 0) . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1")) . "\\'>" . __("Turn") . " <strong>" . (isset($_SESSION["graph_debug_mode"]) ? __("Off") : __(CHECKED)) . "</strong> " . __("Debug Mode") . "</a></td></tr>"; if (!empty($graphs["graph_template_id"])) { $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('graph_templates.php?action=template_edit&id=' . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")) . "\\'>" . __("Edit Template") . "</a></td></tr>"; } if (!empty($_GET["device_id"]) || !empty($device_id)) { $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('devices.php?action=edit&id=' . (isset($_GET["device_id"]) ? get_request_var("device_id") : $device_id)) . "\\'>" . __("Edit Host") . "</a></td></tr>"; } if (!empty($_GET["id"])) { ?> <script type="text/javascript"> <!-- var disabled = true; $().ready(function() { $("input").attr("disabled","disabled"); $("select").attr("disabled","disabled"); $("#cancel").removeAttr("disabled"); }); function changeGraphState() { if (disabled) { $("input").removeAttr("disabled"); $("select").removeAttr("disabled"); disabled = false; rrdtool_graph_dependencies(); // even when unlocking, disable distinct rrdtool options }else{ $("input").attr("disabled","disabled"); $("select").attr("disabled","disabled"); $("#cancel").removeAttr("disabled"); disabled = true; } } //--> </script> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print get_graph_title(get_request_var("id"));?> </td> <td style="white-space:nowrap;" align="right" width="1"><a id='tooltip' class='popup_anchor' href='#' onMouseOver="Tip('<?php print $tip_text;?>', BGCOLOR, '#EEEEEE', FIX, ['tooltip', -45, 0], STICKY, true, SHADOW, true, CLICKCLOSE, true, FADEOUT, 400, TEXTALIGN, 'right', BORDERCOLOR, '#F5F5F5')" onMouseOut="UnTip()">Graph Options</a></td> </tr> </table> <?php } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='graph_edit'>\n"; html_start_box("<strong>" . __("Graph Template Selection") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'template'); $form_array = array( "graph_template_id" => array( "method" => "autocomplete", "callback_function" => "./lib/ajax/get_graph_templates.php", "friendly_name" => __("Selected Graph Template"), "description" => __("Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied."), "id" => (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"), "name" => db_fetch_cell("SELECT name FROM graph_templates WHERE id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")) ), "device_id" => array( "method" => "autocomplete", "callback_function" => "./lib/ajax/get_device_detailed.php", "friendly_name" => __("Host"), "description" => __("Choose the device that this graph belongs to."), "id" => (isset($_GET["device_id"]) ? get_request_var("device_id") : $device_id), "name" => db_fetch_cell("SELECT CONCAT_WS('',description,' (',hostname,')') FROM device WHERE id=" . (isset($_GET['device_id']) ? $_GET['device_id'] : $device_id)) ), "graph_template_graph_id" => array( "method" => "hidden", "value" => (isset($graphs["id"]) ? $graphs["id"] : "0") ), "local_graph_id" => array( "method" => "hidden", "value" => (isset($graphs["local_graph_id"]) ? $graphs["local_graph_id"] : "0") ), "local_graph_template_graph_id" => array( "method" => "hidden", "value" => (isset($graphs["local_graph_template_graph_id"]) ? $graphs["local_graph_template_graph_id"] : "0") ), "_graph_template_id" => array( "method" => "hidden", "value" => (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0") ), "_device_id" => array( "method" => "hidden", "value" => (isset($device_id) ? $device_id : "0") ) ); draw_edit_form( array( "config" => array(), "fields" => $form_array ) ); print "</table></td></tr>"; /* end of html_header */ html_end_box(); # print "<form method='post' action='graphs.php'>\n"; /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graphs["graph_template_id"])) { html_start_box("<strong>" . __("Supplemental Graph Template Data") . "</strong>", "100", $colors["header"], "0", "center", ""); draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>" . __("Graph Fields") . "</strong>", true, true, 0); draw_nontemplated_fields_graph_item($graphs["graph_template_id"], get_request_var("id"), "|field|_|id|", "<strong>" . __("Graph Item Fields") ."</strong>", true); html_end_box(); } /* graph item list goes here */ if ((!empty($_GET["id"])) && (!array_key_exists("graph_template_id", $graphs))) { graph_template_item(); } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td align="center" class="textInfo" colspan="2"> <img src="<?php print htmlspecialchars("graph_image.php?action=edit&local_graph_id=" . get_request_var("id") . "&rra_id=" . read_graph_config_option("default_rra_id"));?>" alt=""> </td> <?php if ((isset($_SESSION["graph_debug_mode"])) && (isset($_GET["id"]))) { $graph_data_array = array(); $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR; /* make rrdtool_function_graph to only print the command without executing it */ $graph_data_array["print_source"] = 1; ?> <td> <span class="textInfo"><?php print __("RRDTool Command:");?></span><br> <pre><?php print rrdtool_function_graph(get_request_var("id"), read_graph_config_option("default_rra_id"), $graph_data_array);?></pre> <span class="textInfo"><?php print __("RRDTool Says:");?></span><br> <?php /* make rrdtool_function_graph to generate AND execute the rrd command, but only for fetching the "return code" */ unset($graph_data_array["print_source"]);?> <pre><?php print rrdtool_function_graph(get_request_var("id"), read_graph_config_option("default_rra_id"), $graph_data_array);?></pre> </td> <?php } ?> </tr> </table> <?php } if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($graphs["graph_template_id"]))) { html_start_box("<strong>" . __("Graph Configuration") . "</strong>", "100", $colors["header"], "0", "center", ""); ############ html_start_box("<strong>" . __("Labels") . "</strong>", "100", $colors["header"], "0", "center", "", true); draw_template_edit_form('header_graph_labels', graph_labels_form_list(), $graphs, $use_graph_template); html_end_box(false); /* TODO: we should not use rrd version in the code, when going data-driven */ if ( read_config_option("rrdtool_version") != RRD_VERSION_1_0 && read_config_option("rrdtool_version") != RRD_VERSION_1_2) { html_start_box("<strong>" . __("Right Axis Settings") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_right_axis"); draw_template_edit_form('header_graph_right_axis', graph_right_axis_form_list(), $graphs, $use_graph_template); } html_end_box(false); html_start_box("<strong>" . __("Graph Template Size") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_size"); draw_template_edit_form('header_graph_size', graph_size_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Limits") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_limits"); draw_template_edit_form('header_graph_limits', graph_limits_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Grid") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_grid"); draw_template_edit_form('header_graph_grid', graph_grid_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Color") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_color"); draw_template_edit_form('header_graph_color', graph_color_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Legend") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc"); draw_template_edit_form('header_graph_legend', graph_legend_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Misc") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc"); draw_template_edit_form('header_graph_misc', graph_misc_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Cacti Specifics") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_cacti"); draw_template_edit_form('header_graph_cacti', graph_cacti_form_list(), $graphs, $use_graph_template); html_end_box(false); } if ((isset($_GET["id"])) || (isset($_GET["new"]))) { form_hidden_box("save_component_graph","1",""); form_hidden_box("save_component_input","1",""); }else{ form_hidden_box("save_component_graph_new","1",""); } form_hidden_box("hidden_rrdtool_version", read_config_option("rrdtool_version"), ""); form_save_button_alt(); include_once(CACTI_BASE_PATH . "/access/js/colorpicker.js"); include_once(CACTI_BASE_PATH . "/access/js/graph_template_options.js"); ?> <script type="text/javascript"> $('#graph_item').tableDnD({ onDrop: function(table, row) { $('#AjaxResult').load("lib/ajax/jquery.tablednd/graphs_item.ajax.php?id=<?php isset($_GET["id"]) ? print get_request_var("id") : print "";?>&"+$.tableDnD.serialize()); // location.reload(); } }); </script> <?php }
/** mailer - function to send mails to users * @arg $from - a string email address, or an array in array(email_address, name format) * @arg $to - either a string of comma delimited email addresses, or an array of addresses in email_address => name format * @arg $cc - either a string of comma delimited email addresses, or an array of addresses in email_address => name format * @arg $bcc - either a string of comma delimited email addresses, or an array of addresses in email_address => name format * @arg $replyto - a string email address, or an array in array(email_address, name format) * @arg $subject - the email subject * @arg $body - the email body, in HTML format. If content_text is not set, the function will attempt to extract * from the HTML format. * @arg $body_text - the email body in TEXT format. If set, it will override the stripping tags method * @arg $attachments - the emails attachments as an array * @arg $headers - an array of name value pairs representing custom headers. * @arg $html - if set to true, html is the default, otherwise text format will be used */ function mailer($from, $to, $cc, $bcc, $replyto, $subject, $body, $body_text = '', $attachments, $headers, $html = true) { global $config; include_once $config['base_path'] . '/lib/PHPMailer/PHPMailerAutoload.php'; // Set the to informaiotn if ($to == '') { return 'Mailer Error: No <b>TO</b> address set!!<br>If using the <i>Test Mail</i> link, please set the <b>Alert e-mail</b> setting.'; } if (is_array($to)) { $toText = $to[1] . ' <' . $to[0] . '>'; } else { $toText = $to; } if (is_array($from)) { $fromText = $from[1] . ' <' . $from[0] . '>'; } else { $fromText = $from; } $body = str_replace('<SUBJECT>', $subject, $body); $body = str_replace('<TO>', $toText, $body); $body = str_replace('<FROM>', $fromText, $body); // Create the PHPMailer instance $mail = new PHPMailer(); // Set a reasonable timeout of 5 seconds $timeout = read_config_option('settings_smtp_timeout'); if (empty($timeout) || $timeout < 0 || $timeout > 300) { $mail->Timeout = 5; } else { $mail->Timeout = $timeout; } // Set the subject $mail->Subject = $subject; $how = read_config_option('settings_how'); if ($how < 0 || $how > 2) { $how = 0; } if ($how == 0) { $mail->isMail(); } else { if ($how == 1) { $mail->Sendmail = read_config_option('settings_sendmail_path'); $mail->isSendmail(); } else { if ($how == 2) { $mail->isSMTP(); $mail->Host = read_config_option('settings_smtp_host'); $mail->Port = read_config_option('settings_smtp_port'); $mail->Username = read_config_option('settings_smtp_username'); $mail->Password = read_config_option('settings_smtp_password'); if ($mail->Username != '') { $mail->SMTPAuth = true; } // Set a reasonable timeout of 5 seconds $timeout = read_config_option('settings_smtp_timeout'); if (empty($timeout) || $timeout < 0 || $timeout > 300) { $mail->Timeout = 5; } else { $mail->Timeout = $timeout; } $secure = read_config_option('settings_smtp_secure'); if (!empty($secure) && $secure != 'none') { $smtp->SMTPSecure = $secure; if (substr_count($mail->Host, ':') == 0) { $mail->Host = $secure . '://' . $mail->Host; } } } } } // Set the from information if (!is_array($from)) { $fromname = ''; if ($from == '') { $from = read_config_option('settings_from_email'); $fromname = read_config_option('settings_from_name'); if (isset($_SERVER['HOSTNAME'])) { $from = 'Cacti@' . $_SERVER['HOSTNAME']; } else { $from = '*****@*****.**'; } if ($fromname == '') { $fromname = 'Cacti'; } } $mail->setFrom($from, $fromname); } else { $mail->setFrom($from[0], $from[1]); } if (!is_array($to)) { $to = explode(',', $to); foreach ($to as $t) { $t = trim($t); if ($t != '') { $mail->addAddress($t); } } } else { foreach ($to as $email => $name) { $mail->addAddress($email, $name); } } if (!is_array($cc)) { if ($cc != '') { $cc = explode(',', $cc); foreach ($cc as $c) { $c = trim($c); $mail->addCC($c); } } } else { foreach ($cc as $email => $name) { $mail->addCC($email, $name); } } if (!is_array($bcc)) { if ($bcc != '') { $bcc = explode(',', $bcc); foreach ($bcc as $bc) { $bc = trim($bc); $mail->addBCC($bc); } } } else { foreach ($bcc as $email => $name) { $mail->addBCC($email, $name); } } if (!is_array($replyto)) { if ($replyto != '') { $mail->replyTo($replyto); } } else { $mail->replyTo($replyto[0], $replyto[1]); } // Set the wordwrap limits $wordwrap = read_config_option('settings_wordwrap'); if ($wordwrap == '') { $wordwrap = 76; } if ($wordwrap > 9999) { $wordwrap = 9999; } if ($wordwrap < 0) { $wordwrap = 76; } $mail->WordWrap = $wordwrap; $mail->setWordWrap(); $i = 0; // Handle Graph Attachments if (is_array($attachments) && sizeof($attachments) && substr_count($body, '<GRAPH>') > 0) { foreach ($attachments as $val) { $graph_data_array = array('output_flag' => RRDTOOL_OUTPUT_STDOUT); $data = rrdtool_function_graph($val['local_graph_id'], $val['rra_id'], $graph_data_array); if ($data != '') { /* get content id and create attachment */ $cid = getmypid() . '_' . $i . '@' . 'localhost'; /* attempt to attach */ if ($mail->addStringEmbededImage($data, $cid, $val['filename'] . '.png', 'base64', 'image/png', 'inline') === false) { cacti_log('ERROR: ' . $mail->ErrorInfo, false); return $mail->ErrorInfo; } $body = str_replace('<GRAPH>', "<br><br><img src='cid:{$cid}'>", $body); } else { $body = str_replace('<GRAPH>', "<br><img src='" . $val['file'] . "'><br>Could not open!<br>" . $val['file'], $body); } $i++; } } elseif (is_array($attachments) && sizeof($attachments) && substr_count($body, '<GRAPH:') > 0) { foreach ($attachments as $attachment) { if ($attachment['attachment'] != '') { /* get content id and create attachment */ $cid = getmypid() . '_' . $i . '@' . 'localhost'; /* attempt to attach */ if ($mail->addStringEmbeddedImage($attachment['attachment'], $cid, $attachment['filename'], 'base64', $attachment['mime_type'], $attachment['inline']) === false) { cacti_log('ERROR: ' . $mail->ErrorInfo, false); return $mail->ErrorInfo; } /* handle the body text */ switch ($attachment['inline']) { case 'inline': $body = str_replace('<GRAPH:' . $attachment['graphid'] . ':' . $attachment['timespan'] . '>', "<img border='0' src='cid:{$cid}' >", $body); break; case 'attachment': $body = str_replace('<GRAPH:' . $attachment['graphid'] . ':' . $attachment['timespan'] . '>', '', $body); break; } } else { $body = str_replace('<GRAPH:' . $attachment['graphid'] . ':' . $attachment['timespan'] . '>', "<img border='0' src='" . $attachment['filename'] . "' ><br>Could not open!<br>" . $attachment['filename'], $body); } $i++; } } /* process custom headers */ if (is_array($headers) && sizeof($headers)) { foreach ($headers as $name => $value) { $mail->addCustomHeader($name, $value); } } // Set both html and non-html bodies $text = array('text' => '', 'html' => ''); if ($body_text != '' && $html == true) { $text['html'] = $body . '<br>'; $text['text'] = $body_text; $mail->isHTML(true); $mail->Body = $text['html']; $mail->AltBody = $text['text']; } elseif ($attachments == '' && $html == false) { if ($body_text != '') { $body = $body_text; } else { $body = str_replace('<br>', "\n", $body); $body = str_replace('<BR>', "\n", $body); $body = str_replace('</BR>', "\n", $body); } $text['text'] = strip_tags($body); $mail->isHTML(false); $mail->Body = $text['text']; $mail->AltBody = $text['text']; } else { $text['html'] = $body . '<br>'; $text['text'] = strip_tags(str_replace('<br>', "\n", $body)); $mail->isHTML(true); $mail->Body = $text['html']; $mail->AltBody = $text['text']; } if ($mail->send()) { return ''; } else { return $mail->ErrorInfo; } }
function graph_edit() { global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { // graph add if ($_GET["id"] == "") { if ($_GET["host_id"] != -1) { input_validate_input_number(get_request_var("host_id")); if (!check_host($_GET["host_id"])) { access_denied(); } } // graph edit } else { $permission = check_graph($_GET["id"]); if ($permission != GRAPH_PRIVATE && $permission != GRAPH_PRIVATE + GRAPH_PUBLIC) { access_denied(); } } } /* modify for multi user end */ $use_graph_template = true; if (!empty($_GET["id"])) { $local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . $_GET["id"]); $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]); $graphs_template = db_fetch_row("select * from graph_templates_graph where id={$local_graph_template_graph_id}"); $host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]); $header_label = "[edit: " . htmlspecialchars(get_graph_title($_GET["id"])) . "]"; if ($graphs["graph_template_id"] == "0") { $use_graph_template = false; } } else { $header_label = "[new]"; $use_graph_template = false; } /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { unset($_GET["debug"]); } /* modify for multi user end */ /* handle debug mode */ if (isset($_GET["debug"])) { if ($_GET["debug"] == "0") { kill_session_var("graph_debug_mode"); } elseif ($_GET["debug"] == "1") { $_SESSION["graph_debug_mode"] = true; } } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print htmlspecialchars(get_graph_title($_GET["id"])); ?> </td> <td class="textInfo" align="right" valign="top"> <?php /* modify for multi user start */ if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) { ?> <span style="color: #c16921;">*<a href='<?php print htmlspecialchars("graphs.php?action=graph_edit&id=" . (isset($_GET["id"]) ? $_GET["id"] : "0") . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1")); ?> '>Turn <strong><?php print isset($_SESSION["graph_debug_mode"]) ? "Off" : "On"; ?> </strong> Graph Debug Mode.</a></span><br> <?php } if (!empty($graphs["graph_template_id"]) && $_SESSION["permission"] == ACCESS_ADMINISTRATOR) { ?> <span style="color: #c16921;">*<a href='<?php print htmlspecialchars("graph_templates.php?action=template_edit&id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")); ?> '>Edit Graph Template.</a></span><br><?php } /* modify for multi user end */ if (!empty($_GET["host_id"]) || !empty($host_id)) { ?> <span style="color: #c16921;">*<a href='<?php print htmlspecialchars("host.php?action=edit&id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id)); ?> '>Edit Host.</a></span><br><?php } ?> </td> </tr> </table> <br> <?php } html_start_box("<strong>Graph Template Selection</strong> {$header_label}", "100%", $colors["header"], "3", "center", ""); $form_array = array("graph_template_id" => array("method" => "drop_sql", "friendly_name" => "Selected Graph Template", "description" => "Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied.", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0", "none_value" => "None", "sql" => "select graph_templates.id,graph_templates.name from graph_templates order by name"), "host_id" => array("method" => "drop_sql", "friendly_name" => "Host", "description" => "Choose the host that this graph belongs to.", "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id, "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["id"] : "0"), "local_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_id"] : "0"), "local_graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0"), "_graph_template_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0"), "_host_id" => array("method" => "hidden", "value" => isset($host_id) ? $host_id : "0")); /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { unset($form_array["graph_template_id"]["none_value"]); $form_array["graph_template_id"]["sql"] = "SELECT graph_templates.id,graph_templates.name FROM graph_templates WHERE name NOT LIKE '%@system' ORDER BY name"; unset($form_array["host_id"]["none_value"]); $form_array["host_id"]["sql"] = "\r\n SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') AS name FROM host \r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3' \r\n ORDER BY host.description,host.hostname"; } /* modify for multi user end */ draw_edit_form(array("config" => array(), "fields" => $form_array)); html_end_box(); /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graphs["graph_template_id"])) { html_start_box("<strong>Supplemental Graph Template Data</strong>", "100%", $colors["header"], "3", "center", ""); draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>Graph Fields</strong>", true, true, 0); draw_nontemplated_fields_graph_item($graphs["graph_template_id"], $_GET["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true); html_end_box(); } /* graph item list goes here */ if (!empty($_GET["id"]) && empty($graphs["graph_template_id"])) { item(); } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td align="center" class="textInfo" colspan="2"> <img src="<?php print htmlspecialchars("graph_image.php?action=edit&local_graph_id=" . $_GET["id"] . "&rra_id=" . read_graph_config_option("default_rra_id")); ?> " alt=""> </td> <?php if (isset($_SESSION["graph_debug_mode"]) && isset($_GET["id"])) { $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR; $graph_data_array["print_source"] = 1; ?> <td> <span class="textInfo">RRDTool Command:</span><br> <pre><?php print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array); ?> </pre> <span class="textInfo">RRDTool Says:</span><br> <?php unset($graph_data_array["print_source"]); ?> <pre><?php print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array); ?> </pre> </td> <?php } ?> </tr> </table> <br> <?php } if ((isset($_GET["id"]) || isset($_GET["new"])) && empty($graphs["graph_template_id"])) { html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", ""); $form_array = array(); while (list($field_name, $field_array) = each($struct_graph)) { $form_array += array($field_name => $struct_graph[$field_name]); $form_array[$field_name]["value"] = isset($graphs) ? $graphs[$field_name] : ""; $form_array[$field_name]["form_id"] = isset($graphs) ? $graphs["id"] : "0"; if (!($use_graph_template == false || $graphs_template["t_" . $field_name] == "on")) { $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"]; $form_array[$field_name]["description"] = ""; } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); html_end_box(); } if (isset($_GET["id"]) || isset($_GET["new"])) { form_hidden_box("save_component_graph", "1", ""); form_hidden_box("save_component_input", "1", ""); } else { form_hidden_box("save_component_graph_new", "1", ""); } form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), ""); form_save_button("graphs.php"); //Now we need some javascript to make it dynamic ?> <script language="JavaScript"> dynamic(); function dynamic() { //alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'"); //alert("Log is '" + document.getElementById('auto_scale_log').checked + "'"); if (document.getElementById('scale_log_units')) { document.getElementById('scale_log_units').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('auto_scale_log').checked)) { document.getElementById('scale_log_units').disabled=false; } } } function changeScaleLog() { //alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'"); if (document.getElementById('scale_log_units')) { document.getElementById('scale_log_units').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('auto_scale_log').checked)) { document.getElementById('scale_log_units').disabled=false; } } } </script> <?php }
function graph_edit() { global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ $use_graph_template = true; if (!empty($_GET["id"])) { $local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . $_GET["id"]); $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]); $graphs_template = db_fetch_row("select * from graph_templates_graph where id=$local_graph_template_graph_id"); $host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]); $header_label = "[edit: " . get_graph_title($_GET["id"]) . "]"; if ($graphs["graph_template_id"] == "0") { $use_graph_template = false; } }else{ $header_label = "[new]"; $use_graph_template = false; } /* handle debug mode */ if (isset($_GET["debug"])) { if ($_GET["debug"] == "0") { kill_session_var("graph_debug_mode"); }elseif ($_GET["debug"] == "1") { $_SESSION["graph_debug_mode"] = true; } } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print get_graph_title($_GET["id"]);?> </td> <td class="textInfo" align="right" valign="top"> <span style="color: #c16921;">*<a href='graphs.php?action=graph_edit&id=<?php print (isset($_GET["id"]) ? $_GET["id"] : 0);?>&debug=<?php print (isset($_SESSION["graph_debug_mode"]) ? "0" : "1");?>'>Turn <strong><?php print (isset($_SESSION["graph_debug_mode"]) ? "Off" : "On");?></strong> Graph Debug Mode.</a><br> <?php if (!empty($graphs["graph_template_id"])) { ?><span style="color: #c16921;">*<a href='graph_templates.php?action=template_edit&id=<?php print (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0");?>'>Edit Graph Template.</a><br><?php } if (!empty($_GET["host_id"]) || !empty($host_id)) { ?><span style="color: #c16921;">*<a href='host.php?action=edit&id=<?php print (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id);?>'>Edit Host.</a><br><?php } ?> </td> </tr> </table> <br> <?php } html_start_box("<strong>Graph Template Selection</strong> $header_label", "100%", $colors["header"], "3", "center", ""); $form_array = array( "graph_template_id" => array( "method" => "drop_sql", "friendly_name" => "Selected Graph Template", "description" => "Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied.", "value" => (isset($graphs) ? $graphs["graph_template_id"] : "0"), "none_value" => "None", "sql" => "select graph_templates.id,graph_templates.name from graph_templates order by name" ), "host_id" => array( "method" => "drop_sql", "friendly_name" => "Host", "description" => "Choose the host that this graph belongs to.", "value" => (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id), "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname" ), "graph_template_graph_id" => array( "method" => "hidden", "value" => (isset($graphs) ? $graphs["id"] : "0") ), "local_graph_id" => array( "method" => "hidden", "value" => (isset($graphs) ? $graphs["local_graph_id"] : "0") ), "local_graph_template_graph_id" => array( "method" => "hidden", "value" => (isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0") ), "_graph_template_id" => array( "method" => "hidden", "value" => (isset($graphs) ? $graphs["graph_template_id"] : "0") ), "_host_id" => array( "method" => "hidden", "value" => (isset($host_id) ? $host_id : "0") ) ); draw_edit_form( array( "config" => array(), "fields" => $form_array ) ); html_end_box(); /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graphs["graph_template_id"])) { html_start_box("<strong>Supplemental Graph Template Data</strong>", "100%", $colors["header"], "3", "center", ""); print "<form method='post' action='graphs.php'>\n"; draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>Graph Fields</strong>", true, true, 0); draw_nontemplated_fields_graph_item($graphs["graph_template_id"], $_GET["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true); html_end_box(); } /* graph item list goes here */ if ((!empty($_GET["id"])) && (empty($graphs["graph_template_id"]))) { item(); } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td align="center" class="textInfo" colspan="2"> <img src="graph_image.php?action=edit&local_graph_id=<?php print $_GET["id"];?>&rra_id=<?php print read_graph_config_option("default_rra_id");?>" alt=""> </td> <?php if ((isset($_SESSION["graph_debug_mode"])) && (isset($_GET["id"]))) { $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR; $graph_data_array["print_source"] = 1; ?> <td> <span class="textInfo">RRDTool Command:</span><br> <pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);?></pre> <span class="textInfo">RRDTool Says:</span><br> <?php unset($graph_data_array["print_source"]);?> <pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);?></pre> </td> <?php } ?> </tr> </table> <br> <?php } if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($graphs["graph_template_id"]))) { html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", ""); $form_array = array(); while (list($field_name, $field_array) = each($struct_graph)) { $form_array += array($field_name => $struct_graph[$field_name]); $form_array[$field_name]["value"] = (isset($graphs) ? $graphs[$field_name] : ""); $form_array[$field_name]["form_id"] = (isset($graphs) ? $graphs["id"] : "0"); if (!(($use_graph_template == false) || ($graphs_template{"t_" . $field_name} == "on"))) { $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"]; $form_array[$field_name]["description"] = ""; } } draw_edit_form( array( "config" => array( "no_form_tag" => true ), "fields" => $form_array ) ); html_end_box(); } if ((isset($_GET["id"])) || (isset($_GET["new"]))) { form_hidden_box("save_component_graph","1",""); form_hidden_box("save_component_input","1",""); }else{ form_hidden_box("save_component_graph_new","1",""); } form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), ""); form_save_button("graphs.php"); //Now we need some javascript to make it dynamic ?> <script language="JavaScript"> dynamic(); function dynamic() { //alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'"); //alert("Log is '" + document.getElementById('auto_scale_log').checked + "'"); if (document.getElementById('scale_log_units')) { document.getElementById('scale_log_units').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('auto_scale_log').checked)) { document.getElementById('scale_log_units').disabled=false; } } } function changeScaleLog() { //alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'"); if (document.getElementById('scale_log_units')) { document.getElementById('scale_log_units').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('auto_scale_log').checked)) { document.getElementById('scale_log_units').disabled=false; } } } </script> <?php }
if (!empty($_GET["graph_start"]) && $_GET["graph_start"] < 1600000000) { $graph_data_array["graph_start"] = $_GET["graph_start"]; } /* override: graph end time (unix time) */ if (!empty($_GET["graph_end"]) && $_GET["graph_end"] < 1600000000) { $graph_data_array["graph_end"] = $_GET["graph_end"]; } /* override: graph height (in pixels) */ if (!empty($_GET["graph_height"]) && $_GET["graph_height"] < 3000) { $graph_data_array["graph_height"] = $_GET["graph_height"]; } /* override: graph width (in pixels) */ if (!empty($_GET["graph_width"]) && $_GET["graph_width"] < 3000) { $graph_data_array["graph_width"] = $_GET["graph_width"]; } /* override: skip drawing the legend? */ if (!empty($_GET["graph_nolegend"])) { $graph_data_array["graph_nolegend"] = $_GET["graph_nolegend"]; } /* print RRDTool graph source? */ if (!empty($_GET["show_source"])) { $graph_data_array["print_source"] = $_GET["show_source"]; } print rrdtool_function_graph(get_request_var("local_graph_id"), (array_key_exists("rra_id", $_GET) ? get_request_var("rra_id") : null), $graph_data_array);
function export_tree_graphs_and_graph_html($path, $tree_id) { global $colors, $config; include_once $config["library_path"] . "/tree.php"; include_once $config["library_path"] . "/data_query.php"; /* start the count of graphs */ $total_graphs_created = 0; $exported_files = array(); $cacti_export_path = read_config_option("path_html_export"); /* auth check for hosts on the trees */ $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id")); if (!export_is_tree_allowed($tree_id)) { return 0; } $sql_join = "LEFT JOIN graph_local ON (graph_templates_graph.local_graph_id=graph_local.id)\n\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\n\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\n\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $current_user["id"] . "))"; $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]); $sql_where = empty($sql_where) ? "" : "AND {$sql_where}"; $graphs = array(); if ($tree_id == 0) { $hosts = db_fetch_assoc("SELECT DISTINCT host_id FROM graph_tree_items"); } else { $hosts = db_fetch_assoc("SELECT DISTINCT host_id FROM graph_tree_items WHERE graph_tree_id=" . $tree_id); } /* get a list of host graphs first */ if (sizeof($hosts)) { foreach ($hosts as $host) { $hosts_sql = "SELECT DISTINCT\n\t\t\tgraph_templates_graph.id,\n\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\tgraph_templates_graph.height,\n\t\t\tgraph_templates_graph.width,\n\t\t\tgraph_templates_graph.title_cache,\n\t\t\tgraph_templates.name,\n\t\t\tgraph_local.host_id\n\t\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t\t{$sql_join}\n\t\t\tWHERE ((graph_templates_graph.local_graph_id<>0)\n\t\t\t{$sql_where}\n\t\t\tAND (graph_local.host_id=" . $host["host_id"] . ")\n\t\t\tAND (graph_templates_graph.export='on'))\n\t\t\tORDER BY graph_templates_graph.title_cache"; $host_graphs = db_fetch_assoc($hosts_sql); if (sizeof($host_graphs)) { if (sizeof($graphs)) { $graphs = array_merge($host_graphs, $graphs); } else { $graphs = $host_graphs; } } } } /* now get the list of graphs placed within the tree */ if ($tree_id == 0) { $sql_where = "WHERE graph_templates_graph.local_graph_id!=0\n\t\t\t{$sql_where}\n\t\t\tAND graph_templates_graph.export='on'"; } else { $sql_where = "WHERE graph_tree_items.graph_tree_id =" . $tree_id . "\n\t\t\t{$sql_where}\n\t\t\tAND graph_templates_graph.local_graph_id!=0\n\t\t\tAND graph_templates_graph.export='on'"; } $non_host_sql = "SELECT\n\t\tgraph_templates_graph.id,\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates.name,\n\t\tgraph_local.host_id,\n\t\tgraph_tree_items.id AS gtid\n\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\tAND graph_tree_items.local_graph_id = graph_templates_graph.local_graph_id\n\t\tAND graph_templates_graph.export='on'\n\t\tORDER BY graph_templates_graph.title_cache"; $non_host_graphs = db_fetch_assoc($non_host_sql); if (sizeof($non_host_graphs)) { if (sizeof($graphs)) { $graphs = array_merge($non_host_graphs, $graphs); } else { $graphs = $non_host_graphs; } } /* open a pipe to rrdtool for writing */ $rrdtool_pipe = rrd_init(); /* for each graph... */ $i = 0; if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { $rras = get_associated_rras($graph["local_graph_id"]); /* settings for preview graphs */ $graph_data_array["graph_height"] = read_config_option("export_default_height"); $graph_data_array["graph_width"] = read_config_option("export_default_width"); $graph_data_array["graph_nolegend"] = true; $graph_data_array["export"] = true; if (read_config_option("export_tree_isolation") == "on") { $graph_data_array["export_filename"] = "/" . $path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png"; $export_filename = $cacti_export_path . "/" . $path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png"; } else { $graph_data_array["export_filename"] = "/graphs/thumb_" . $graph["local_graph_id"] . ".png"; $export_filename = $cacti_export_path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png"; } if (!array_search($export_filename, $exported_files)) { /* add the graph to the exported list */ array_push($exported_files, $export_filename); export_log("Creating Graph '" . $cacti_export_path . $graph_data_array["export_filename"] . "'"); /* generate the graph */ rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe); $total_graphs_created++; /* generate html files for each graph */ if (read_config_option("export_tree_isolation") == "on") { export_log("Creating File '" . $cacti_export_path . "/" . $path . "/graph_" . $graph["local_graph_id"] . ".html'"); $fp_graph_index = fopen($cacti_export_path . "/" . $path . "/graph_" . $graph["local_graph_id"] . ".html", "w"); } else { export_log("Creating File '" . $cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html'"); $fp_graph_index = fopen($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html", "w"); } fwrite($fp_graph_index, HTML_HEADER_TREE); /* write the code for the tree at the left */ draw_html_left_tree($fp_graph_index, $tree_id); fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE_TREE); fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong></td></tr>"); fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO_TREE); fwrite($fp_graph_index, "<td>"); /* reset vars for actual graph image creation */ reset($rras); unset($graph_data_array); /* generate graphs for each rra */ foreach ($rras as $rra) { $graph_data_array["export"] = true; if (read_config_option("export_tree_isolation") == "on") { $graph_data_array["export_filename"] = "/" . $path . "/graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png"; } else { $graph_data_array["export_filename"] = "/graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png"; } export_log("Creating Graph '" . $cacti_export_path . $graph_data_array["export_filename"] . "'"); rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe); $total_graphs_created++; /* write image related html */ if (read_config_option("export_tree_isolation") == "off") { fwrite($fp_graph_index, "<div align=center><img src='graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png' border=0></div>\n\n\t\t\t\t\t\t<div align=center><strong>" . $rra["name"] . "</strong></div><br>"); } else { fwrite($fp_graph_index, "<div align=center><img src='" . "graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png' border=0></div>\n\n\t\t\t\t\t\t<div align=center><strong>" . $rra["name"] . "</strong></div><br>"); } } fwrite($fp_graph_index, "</td></tr></table></td></tr></table>"); fwrite($fp_graph_index, HTML_FOOTER_TREE); fclose($fp_graph_index); } } } /* close the rrdtool pipe */ rrd_close($rrdtool_pipe); return $total_graphs_created; }
header('Content-type: image/png'); /* flush the headers now */ ob_end_clean(); session_write_close(); $graph_data_array = array(); /* override: graph start time (unix time) */ if (!empty($_REQUEST['graph_start']) && $_REQUEST['graph_start'] < 1600000000) { $graph_data_array['graph_start'] = $_REQUEST['graph_start']; } /* override: graph end time (unix time) */ if (!empty($_REQUEST['graph_end']) && $_REQUEST['graph_end'] < 1600000000) { $graph_data_array['graph_end'] = $_REQUEST['graph_end']; } /* override: graph height (in pixels) */ if (!empty($_REQUEST['graph_height']) && $_REQUEST['graph_height'] < 3000) { $graph_data_array['graph_height'] = $_REQUEST['graph_height']; } /* override: graph width (in pixels) */ if (!empty($_REQUEST['graph_width']) && $_REQUEST['graph_width'] < 3000) { $graph_data_array['graph_width'] = $_REQUEST['graph_width']; } /* override: skip drawing the legend? */ if (!empty($_REQUEST['graph_nolegend'])) { $graph_data_array['graph_nolegend'] = $_REQUEST['graph_nolegend']; } /* print RRDTool graph source? */ if (!empty($_REQUEST['show_source'])) { $graph_data_array['print_source'] = $_REQUEST['show_source']; } print @rrdtool_function_graph($_REQUEST['local_graph_id'], array_key_exists('rra_id', $_REQUEST) ? $_REQUEST['rra_id'] : null, $graph_data_array);
// remove favorite } elseif ($permission == GRAPH_OTHER + GRAPH_PUBLIC) { $tree_item_id = db_fetch_cell("SELECT graph_tree_items.id FROM graph_tree_items WHERE graph_tree_id = '" . $_SESSION["private_tree_id"] . "' AND local_graph_id = '" . $_GET["local_graph_id"] . "'"); print " <a href=\"./tree.php?action=item_remove&id=" . $tree_item_id . "&tree_id=" . $_SESSION["public_tree_id"] . "\"><img src=\"images/fav_disable_icon.png\" style=\"border:none;vertical-align:text-bottom;\">Remove from favorites</a>"; } } if ($permission != GRAPH_PRIVATE) { // url $url = "http://" . $_SERVER["SERVER_NAME"] . "/gi.php?g=" . $_GET["local_graph_id"] . "&r=" . $_GET["rra_id"]; print " <font class='textEditTitle'>URL:</font><input type=\"text\" value=\"{$url}\" size=\"50\" onClick=\"javascript:this.select();\">"; // widget $widget = htmlspecialchars("<script src=\"http://" . $_SERVER["SERVER_NAME"] . "/include/widget.js\"></script><script>cactiWidget(" . $_GET["local_graph_id"] . "," . $_GET["rra_id"] . ");</script><div id=\"" . $_GET["local_graph_id"] . "_" . $_GET["rra_id"] . "\"></div>"); print " <font class='textEditTitle'>Widget:</font><input type=\"text\" value=\"{$widget}\" size=\"50\" onClick=\"javascript:this.select();\">"; } } else { print trim(@rrdtool_function_graph(get_request_var_request("local_graph_id"), get_request_var_request("rra_id"), $graph_data_array)); } /* modify for multi user end */ ?> </td> </tr> <?php } global $graph_views; load_current_session_value("action", "sess_cacti_graph_action", $graph_views[read_graph_config_option("default_tree_view_mode")]); ?> <tr> <?php if (basename($_SERVER["PHP_SELF"]) == "graph_view.php" && read_graph_config_option("default_tree_view_mode") == 2 && ($_REQUEST["action"] == "tree" || isset($_REQUEST["view_type"]) && $_REQUEST["view_type"] == "tree")) { ?> <td valign="top" style="padding: 5px; border-right: #aaaaaa 1px solid;background-repeat:repeat-y;background-color:#efefef;" bgcolor='#efefef' width='<?php
/* print RRDTool graph source? */ if (!empty($_REQUEST['show_source'])) { $graph_data_array['print_source'] = $_REQUEST['show_source']; } /* check ds */ if ($graph_data_array['ds_step'] < 1) { $graph_data_array['ds_step'] = read_config_option('realtime_interval'); } /* call poller */ $command = read_config_option('path_php_binary'); $args = sprintf('poller_realtime.php --graph=%s --interval=%d --poller_id=' . session_id(), $_REQUEST['local_graph_id'], $graph_data_array['ds_step']); shell_exec("{$command} {$args}"); /* construct the image name */ $graph_data_array['export_realtime'] = read_config_option('realtime_cache_path') . '/user_' . session_id() . '_lgi_' . $_REQUEST['local_graph_id'] . '.png'; $graph_data_array['output_flag'] = RRDTOOL_OUTPUT_GRAPH_DATA; rrdtool_function_graph($_REQUEST['local_graph_id'], '', $graph_data_array); /* send text information back to browser as well as image information */ $return_array = array('local_graph_id' => $_REQUEST['local_graph_id'], 'top' => $_REQUEST['top'], 'left' => $_REQUEST['left'], 'ds_step' => isset($_SESSION['sess_realtime_ds_step']) ? $_SESSION['sess_realtime_ds_step'] : $graph_data_array['ds_step'], 'graph_start' => isset($_SESSION['sess_realtime_graph_start']) ? $_SESSION['sess_realtime_graph_start'] : $graph_data_array['graph_start']); print json_encode($return_array); exit; break; case 'view': $graph_rrd = read_config_option('realtime_cache_path') . '/user_' . session_id() . '_lgi_' . $_REQUEST['local_graph_id'] . '.png'; if (file_exists($graph_rrd)) { header('Content-type: image/png'); print file_get_contents($graph_rrd); } exit; break; } /* ================= input validation ================= */
function graph_edit() { global $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('id')); /* ==================================================== */ $locked = 'false'; $use_graph_template = true; if (!empty($_REQUEST['id'])) { $_SESSION['sess_graph_lock_id'] = $_REQUEST['id']; $local_graph_template_graph_id = db_fetch_cell_prepared('SELECT local_graph_template_graph_id FROM graph_templates_graph WHERE local_graph_id = ?', array($_REQUEST['id'])); if ($_REQUEST['id'] != $_SESSION['sess_graph_lock_id'] && !empty($local_graph_template_graph_id)) { $locked = 'true'; $_SESSION['sess_graph_locked'] = $locked; } elseif (empty($local_graph_template_graph_id)) { $locked = 'false'; $_SESSION['sess_graph_locked'] = $locked; } elseif (isset($_SESSION['sess_graph_locked'])) { $locked = $_SESSION['sess_graph_locked']; } else { $locked = 'true'; $_SESSION['sess_graph_locked'] = $locked; } $graphs = db_fetch_row_prepared('SELECT * FROM graph_templates_graph WHERE local_graph_id = ?', array($_REQUEST['id'])); $graphs_template = db_fetch_row_prepared('SELECT * FROM graph_templates_graph WHERE id = ?', array($local_graph_template_graph_id)); $host_id = db_fetch_cell_prepared('SELECT host_id FROM graph_local WHERE id = ?', array($_REQUEST['id'])); $header_label = '[edit: ' . htmlspecialchars(get_graph_title($_REQUEST['id'])) . ']'; if ($graphs['graph_template_id'] == '0') { $use_graph_template = 'false'; } } else { $header_label = '[new]'; $use_graph_template = false; } /* handle debug mode */ if (isset($_REQUEST['debug'])) { if ($_REQUEST['debug'] == '0') { kill_session_var('graph_debug_mode'); } elseif ($_REQUEST['debug'] == '1') { $_SESSION['graph_debug_mode'] = true; } } if (!empty($_REQUEST['id'])) { ?> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print htmlspecialchars(get_graph_title($_REQUEST['id'])); ?> </td> <td class="textInfo" align="right" valign="top"> <span class="linkMarker">*<a class='hyperLink' href='<?php print htmlspecialchars('graphs.php?action=graph_edit&id=' . (isset($_REQUEST['id']) ? $_REQUEST['id'] : '0') . '&debug=' . (isset($_SESSION['graph_debug_mode']) ? '0' : '1')); ?> '>Turn <strong><?php print isset($_SESSION['graph_debug_mode']) ? 'Off' : 'On'; ?> </strong> Graph Debug Mode.</a></span><br> <?php if (!empty($graphs['graph_template_id'])) { ?> <span class="linkMarker">*<a class='hyperLink' href='<?php print htmlspecialchars('graph_templates.php?action=template_edit&id=' . (isset($graphs['graph_template_id']) ? $graphs['graph_template_id'] : '0')); ?> '>Edit Graph Template.</a></span><br><?php } if (!empty($_REQUEST['host_id']) || !empty($host_id)) { ?> <span class="linkMarker">*<a class='hyperLink' href='<?php print htmlspecialchars('host.php?action=edit&id=' . (isset($_REQUEST['host_id']) ? $_REQUEST['host_id'] : $host_id)); ?> '>Edit Device.</a></span><br><?php } if ($locked == 'true') { ?> <span class="linkMarker">* <span class='hyperLink' id='unlockid'>Unlock Graph</span></span><?php } else { ?> <span class="linkMarker">* <span class='hyperLink' id='lockid'>Lock Graph</span></span><?php } ?> </td> </tr> </table> <?php } html_start_box("<strong>Graph Template Selection</strong> {$header_label}", '100%', '', '3', 'center', ''); $form_array = array('graph_template_id' => array('method' => 'drop_sql', 'friendly_name' => 'Selected Graph Template', 'description' => 'Choose a Graph Template to apply to this Graph. Please note that Graph Data may be lost if you change the Graph Template after one is already applied.', 'value' => isset($graphs) ? $graphs['graph_template_id'] : '0', 'none_value' => 'None', 'sql' => 'SELECT graph_templates.id,graph_templates.name FROM graph_templates ORDER BY name'), 'host_id' => array('method' => 'drop_callback', 'friendly_name' => 'Device', 'description' => 'Choose the Device that this Graph belongs to.', 'sql' => "SELECT id,CONCAT_WS('',description,' (',hostname,')') as name FROM host ORDER BY description,hostname", 'action' => 'ajax_hosts_noany', 'id' => isset($_REQUEST['host_id']) ? $_REQUEST['host_id'] : $host_id, 'value' => db_fetch_cell_prepared('SELECT description AS name FROM host WHERE id = ?', isset($_REQUEST['host_id']) ? array($_REQUEST['host_id']) : array($host_id))), 'graph_template_graph_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['id'] : '0'), 'local_graph_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['local_graph_id'] : '0'), 'local_graph_template_graph_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['local_graph_template_graph_id'] : '0'), '_graph_template_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['graph_template_id'] : '0'), '_host_id' => array('method' => 'hidden', 'value' => isset($host_id) ? $host_id : '0')); draw_edit_form(array('config' => array(), 'fields' => $form_array)); html_end_box(); /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graphs['graph_template_id'])) { html_start_box('<strong>Supplemental Graph Template Data</strong>', '100%', '', '3', 'center', ''); draw_nontemplated_fields_graph($graphs['graph_template_id'], $graphs, '|field|', '<strong>Graph Fields</strong>', true, true, 0); draw_nontemplated_fields_graph_item($graphs['graph_template_id'], $_REQUEST['id'], '|field|_|id|', '<strong>Graph Item Fields</strong>', true, $locked); html_end_box(); } /* graph item list goes here */ if (!empty($_REQUEST['id']) && empty($graphs['graph_template_id'])) { item(); } if (!empty($_REQUEST['id'])) { ?> <table width="100%" align="center"> <tr> <td align="center" class="textInfo" colspan="2"> <img src="<?php print htmlspecialchars('graph_image.php?action=edit&local_graph_id=' . $_REQUEST['id'] . '&rra_id=' . read_graph_config_option('default_rra_id')); ?> " alt=""> </td> <?php if (isset($_SESSION['graph_debug_mode']) && isset($_REQUEST['id'])) { $graph_data_array['output_flag'] = RRDTOOL_OUTPUT_STDERR; $graph_data_array['print_source'] = 1; ?> <td> <span class="textInfo">RRDTool Command:</span><br> <pre><?php print @rrdtool_function_graph($_REQUEST['id'], 1, $graph_data_array); ?> </pre> <span class="textInfo">RRDTool Says:</span><br> <?php unset($graph_data_array['print_source']); ?> <pre><?php print @rrdtool_function_graph($_REQUEST['id'], 1, $graph_data_array); ?> </pre> </td> <?php } ?> </tr> </table> <br> <?php } if ((isset($_REQUEST['id']) || isset($_REQUEST['new'])) && empty($graphs['graph_template_id'])) { html_start_box('<strong>Graph Configuration</strong>', '100%', '', '3', 'center', ''); $form_array = array(); while (list($field_name, $field_array) = each($struct_graph)) { $form_array += array($field_name => $struct_graph[$field_name]); $form_array[$field_name]['value'] = isset($graphs) ? $graphs[$field_name] : ''; $form_array[$field_name]['form_id'] = isset($graphs) ? $graphs['id'] : '0'; if (!($use_graph_template == false || $graphs_template['t_' . $field_name] == 'on')) { $form_array[$field_name]['method'] = 'template_' . $form_array[$field_name]['method']; $form_array[$field_name]['description'] = ''; } } draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array)); html_end_box(); } if (isset($_REQUEST['id']) || isset($_REQUEST['new'])) { form_hidden_box('save_component_graph', '1', ''); form_hidden_box('save_component_input', '1', ''); } else { form_hidden_box('save_component_graph_new', '1', ''); } form_hidden_box('rrdtool_version', read_config_option('rrdtool_version'), ''); form_save_button('graphs.php'); //Now we need some javascript to make it dynamic ?> <script type='text/javascript'> dynamic(); function dynamic() { if ($('#scale_log_units').is(':checked')) { $('#scale_log_units').prop('disabled', true); if ($('#auto_scale_log').is(':checked')) { $('#scale_log_units').prop('disabled', false); } } } function changeScaleLog() { if ($('#scale_log_units').is(':checked')) { $('#scale_log_units').prop('disabled', true); if ($('#auto_scale_log').is(':checked')) { $('#scale_log_units').prop('disabled', false); } } } $(function() { $('#unlockid').click(function(event) { event.preventDefault; $('body').append("<div id='modal' class='ui-widget-overlay ui-front' style='z-index: 100;'><i style='position:absolute;top:50%;left:50%;' class='fa fa-spin fa-circle-o-notch'/></div>"); $.get('graphs.php?action=unlock&header=false&id='+$('#local_graph_id').val(), function(data) { $('#modal').remove(); $('#main').html(data); applySkin(); }); }); $('#lockid').click(function(event) { event.preventDefault; $.get('graphs.php?action=lock&header=false&id='+$('#local_graph_id').val(), function(data) { $('#main').html(data); applySkin(); }); }); }); if (<?php print $locked == '' ? 'true' : $locked; ?> == true) { $('input, select').not('input[value="Cancel"]').prop('disabled', true); } </script> <?php }
/** generate_report create the complete mail for a single report and send it * @param array $report - complete row of reports table for the report to work upon * @param bool $force - when forced, lastsent time will not be entered (e.g. Send Now) */ function generate_report($report, $force = false) { global $config, $alignment; include_once $config["base_path"] . "/lib/time.php"; include_once $config["base_path"] . "/lib/rrd.php"; reports_log(__FUNCTION__ . ", report_id: " . $report["id"], false, "REPORTS TRACE", POLLER_VERBOSITY_MEDIUM); $body = reports_generate_html($report["id"], REPORTS_OUTPUT_EMAIL); $time = time(); # get config option for first-day-of-the-week $first_weekdayid = read_graph_config_option("first_weekdayid"); $offset = 0; $graphids = array(); $attachments = array(); while (true) { $pos = strpos($body, "<GRAPH:", $offset); if ($pos) { $offset = $pos + 7; $graph = substr($body, $pos + 7, 10); $arr = explode(":", $graph); $arr1 = explode(">", $arr[1]); $graphid = $arr[0]; $timespan = $arr1[0]; $graphids[$graphid . ":" . $timespan] = $graphid; } else { break; } } if (sizeof($graphids)) { foreach ($graphids as $key => $graphid) { $arr = explode(":", $key); $timesp = $arr[1]; $timespan = array(); # get start/end time-since-epoch for actual time (now()) and given current-session-timespan get_timespan($timespan, $time, $timesp, $first_weekdayid); # provide parameters for rrdtool graph $graph_data_array = array('graph_start' => $timespan["begin_now"], 'graph_end' => $timespan["end_now"], 'graph_width' => $report["graph_width"], 'graph_height' => $report["graph_height"], 'output_flag' => RRDTOOL_OUTPUT_STDOUT); if ($report["thumbnails"] == "on") { $graph_data_array['graph_nolegend'] = true; } switch ($report["attachment_type"]) { case REPORTS_TYPE_INLINE_PNG: $attachments[] = array('attachment' => @rrdtool_function_graph($graphid, "", $graph_data_array), 'filename' => 'graph_' . $graphid . ".png", 'mime_type' => 'image/png', 'graphid' => $graphid, 'timespan' => $timesp, 'inline' => 'inline'); break; case REPORTS_TYPE_INLINE_JPG: $attachments[] = array('attachment' => png2jpeg(@rrdtool_function_graph($graphid, "", $graph_data_array)), 'filename' => 'graph_' . $graphid . ".jpg", 'mime_type' => 'image/jpg', 'graphid' => $graphid, 'timespan' => $timesp, 'inline' => 'inline'); break; case REPORTS_TYPE_INLINE_GIF: $attachments[] = array('attachment' => png2gif(@rrdtool_function_graph($graphid, "", $graph_data_array)), 'filename' => 'graph_' . $graphid . ".gif", 'mime_type' => 'image/gif', 'graphid' => $graphid, 'timespan' => $timesp, 'inline' => 'inline'); break; case REPORTS_TYPE_ATTACH_PNG: $attachments[] = array('attachment' => @rrdtool_function_graph($graphid, "", $graph_data_array), 'filename' => 'graph_' . $graphid . ".png", 'mime_type' => 'image/png', 'graphid' => $graphid, 'timespan' => $timesp, 'inline' => 'attachment'); break; case REPORTS_TYPE_ATTACH_JPG: $attachments[] = array('attachment' => png2jpeg(@rrdtool_function_graph($graphid, "", $graph_data_array)), 'filename' => 'graph_' . $graphid . ".jpg", 'mime_type' => 'image/jpg', 'graphid' => $graphid, 'timespan' => $timesp, 'inline' => 'attachment'); break; case REPORTS_TYPE_ATTACH_GIF: $attachments[] = array('attachment' => png2gif(@rrdtool_function_graph($graphid, "", $graph_data_array)), 'filename' => 'graph_' . $graphid . ".gif", 'mime_type' => 'image/gif', 'graphid' => $graphid, 'timespan' => $timesp, 'inline' => 'attachment'); break; case REPORTS_TYPE_INLINE_PNG_LN: $attachments[] = array('attachment' => @rrdtool_function_graph($graphid, "", $graph_data_array), 'filename' => '', 'mime_type' => 'image/png', 'graphid' => $graphid, 'timespan' => $timesp, 'inline' => 'inline'); break; case REPORTS_TYPE_INLINE_JPG_LN: $attachments[] = array('attachment' => png2jpeg(@rrdtool_function_graph($graphid, "", $graph_data_array)), 'filename' => '', 'mime_type' => 'image/jpg', 'graphid' => $graphid, 'timespan' => $timesp, 'inline' => 'inline'); break; case REPORTS_TYPE_INLINE_GIF_LN: $attachments[] = array('attachment' => png2gif(@rrdtool_function_graph($graphid, "", $graph_data_array)), 'filename' => '', 'mime_type' => 'image/gif', 'graphid' => $graphid, 'timespan' => $timesp, 'inline' => 'inline'); break; case REPORTS_TYPE_ATTACH_PDF: # $attachments[] = array( # 'attachment' => png2gif(@rrdtool_function_graph($graphid, "", $graph_data_array)), # 'filename' => 'graph_' . $graphid . ".gif", # 'mime_type' => 'image/gif', # 'graphid' => $graphid, # 'timespan' => $timesp, # 'inline' => 'attachment' # ); break; } } } if ($report["subject"] != '') { $subject = $report["subject"]; } else { $subject = $report["name"]; } if (!isset($report['bcc'])) { $report['bcc'] = ''; } $v = db_fetch_cell("SELECT cacti FROM version"); $headers['User-Agent'] = 'Cacti-Reports-v' . $v; $error = mailer(array($report['from_email'], $report['from_name']), $report['email'], '', $report['bcc'], '', $subject, $body, 'Cacti Reporting Requires and HTML Email Client', $attachments, $headers); session_start(); if (strlen($error)) { if (isset($_REQUEST["id"])) { $_SESSION['reports_error'] = "Problems sending Report '" . $report['name'] . "'. Problem with e-mail Subsystem Error is '{$error}'"; if (!isset($_POST["selected_items"])) { raise_message("reports_error"); } } else { reports_log(__FUNCTION__ . ", Problems sending Report '" . $report['name'] . "'. Problem with e-mail Subsystem Error is '{$error}'", false, "REPORTS", POLLER_VERBOSITY_LOW); } } elseif (isset($_REQUEST)) { $_SESSION['reports_message'] = "Report '" . $report['name'] . "' Sent Successfully"; if (!isset($_POST["selected_items"])) { raise_message("reports_message"); } } if (!isset($_REQUEST["id"]) && !$force) { $int = read_config_option("poller_interval"); if ($int == '') { $int = 300; } $next = reports_interval_start($report["intrvl"], $report["count"], $report["offset"], $report['mailtime']); $next = floor($next / $int) * $int; $sql = "UPDATE reports SET mailtime={$next}, lastsent=" . time() . " WHERE id = " . $report['id']; reports_log(__FUNCTION__ . ", update sql: " . $sql, false, "REPORTS TRACE", POLLER_VERBOSITY_MEDIUM); db_execute($sql); } }
function rrdtool_function_xport($local_graph_id, $rra_id, $xport_data_array, &$xport_meta) { global $config, $consolidation_functions; return rrdtool_function_graph($local_graph_id, $rra_id, $xport_data_array, "", $xport_meta); }
<tr> <td valign="top" height="1" colspan="3" bgcolor="#<?php print $colors['graph_menu_background']; ?> "> <?php $graph_data_array["print_source"] = true; /* override: graph start time (unix time) */ if (!empty($_GET["graph_start"])) { $graph_data_array["graph_start"] = $_GET["graph_start"]; } /* override: graph end time (unix time) */ if (!empty($_GET["graph_end"])) { $graph_data_array["graph_end"] = $_GET["graph_end"]; } print trim(rrdtool_function_graph($_GET["graph_id"], $_GET["rra_id"], $graph_data_array)); ?> </td> </tr> <?php } ?> <tr> <?php if (read_graph_config_option("default_tree_view_mode") == "2" && ($_REQUEST["action"] == "tree" || (isset($_REQUEST["view_type"]) ? $_REQUEST["view_type"] : "") == "tree")) { ?> <td valign="top" style="padding: 5px; border-right: #<?php print $colors['graph_menu_border']; ?> 1px solid;" bgcolor="#<?php
foreach ($config_customers[$customer]["graphs"] as $graph_key => $graph) { if ($email["html"] == 1) { /* Attach graph image for html formatted message - unique filename is important for proper caching */ $image_name = "graph_" . $customer . "_" . $graph["id"] . "_" . $config_customers[$customer]["timeframe"]["start"] . "_" . $config_customers[$customer]["timeframe"]["end"] . ".png"; $image_path = $tmp_dir . $image_name; /* Check that we haven't already generated this image */ if (file_exists($image_path)) { debug(" Using cached image: " . $image_name); if (($image_file = $obj_mail->read_file($image_path)) === false) { print "ERROR: Unable to read cached image: " . $obj_mail->error() . "\n"; exit; } } else { debug(" Generating image: " . $image_name); $rrdtool_pipe = ""; $image_file = rrdtool_function_graph($graph["id"], "", array("graph_start" => $config_customers[$customer]["timeframe"]["start"], "graph_end" => $config_customers[$customer]["timeframe"]["end"], "output_flag" => RRDTOOL_OUTPUT_STDOUT), $rrdtool_pipe); if (!($image_FH = fopen($image_path, "w"))) { print "ERROR: Unable to open file: " . $image_name . "\n"; exit; } fwrite($image_FH, $image_file); fclose($image_FH); $images[$image_path] = ""; } if (strlen($image_file) > 0) { $obj_mail->Attach($image_file, $image_name, "image/png", "inline", $image_name); } $html_part .= "<table border=\"1\" cellspacing=\"0\">\n"; $html_part .= "<tr><td colspan=\"6\"><font size=\"+1\"><b>" . $graph["graph_title"] . "</b></font></td></tr>\n"; $html_part .= "<tr><td colspan=\"6\" align=\"center\"><img src=\"cid:" . $image_name . "\"></td></tr>\n"; }
function thold_mail($to, $from, $subject, $message, $filename, $headers = '') { global $config; thold_debug('Preparing to send email'); include_once $config['base_path'] . '/plugins/settings/include/mailer.php'; include_once $config['base_path'] . '/plugins/thold/setup.php'; $subject = trim($subject); $message = str_replace('<SUBJECT>', $subject, $message); $how = read_config_option('settings_how'); if ($how < 0 && $how > 2) { $how = 0; } if ($how == 0) { $Mailer = new Mailer(array('Type' => 'PHP')); } else { if ($how == 1) { $sendmail = read_config_option('settings_sendmail_path'); $Mailer = new Mailer(array('Type' => 'DirectInject', 'DirectInject_Path' => $sendmail)); } else { if ($how == 2) { $smtp_host = read_config_option('settings_smtp_host'); $smtp_port = read_config_option('settings_smtp_port'); $smtp_username = read_config_option('settings_smtp_username'); $smtp_password = read_config_option('settings_smtp_password'); $Mailer = new Mailer(array('Type' => 'SMTP', 'SMTP_Host' => $smtp_host, 'SMTP_Port' => $smtp_port, 'SMTP_Username' => $smtp_username, 'SMTP_Password' => $smtp_password)); } } } if ($from == '') { $from = read_config_option('thold_from_email'); $fromname = read_config_option('thold_from_name'); if ($from == '') { if (isset($_SERVER['HOSTNAME'])) { $from = 'Cacti@' . $_SERVER['HOSTNAME']; } else { $from = 'Cacti@localhost'; } } if ($fromname == '') { $fromname = 'Cacti'; } $from = $Mailer->email_format($fromname, $from); if ($Mailer->header_set('From', $from) === false) { print 'ERROR: ' . $Mailer->error() . "\n"; return $Mailer->error(); } } else { $from = $Mailer->email_format('Cacti', $from); if ($Mailer->header_set('From', $from) === false) { print 'ERROR: ' . $Mailer->error() . "\n"; return $Mailer->error(); } } if ($to == '') { return 'Mailer Error: No <b>TO</b> address set!!<br>If using the <i>Test Mail</i> link, please set the <b>Alert e-mail</b> setting.'; } $to = explode(',', $to); foreach ($to as $t) { if (trim($t) != '' && !$Mailer->header_set('To', $t)) { print 'ERROR: ' . $Mailer->error() . "\n"; return $Mailer->error(); } } $wordwrap = read_config_option('settings_wordwrap'); if ($wordwrap == '') { $wordwrap = 76; } if ($wordwrap > 9999) { $wordwrap = 9999; } if ($wordwrap < 0) { $wordwrap = 76; } $Mailer->Config['Mail']['WordWrap'] = $wordwrap; if (!$Mailer->header_set('Subject', $subject)) { print 'ERROR: ' . $Mailer->error() . "\n"; return $Mailer->error(); } if (is_array($filename) && !empty($filename) && strstr($message, '<GRAPH>') !== 0) { foreach ($filename as $val) { $graph_data_array = array('output_flag' => RRDTOOL_OUTPUT_STDOUT); if (function_exists('imagecreatefrompng') && function_exists('imagejpeg')) { $data = @png2jpeg(rrdtool_function_graph($val['local_graph_id'], $val['rra_id'], $graph_data_array)); $ext = 'jpg'; } else { $data = @rrdtool_function_graph($val['local_graph_id'], $val['rra_id'], $graph_data_array); $ext = 'png'; } if ($data != '') { $cid = $Mailer->content_id(); if ($Mailer->attach($data, $val['filename'] . ".{$ext}", "image/{$ext}", 'inline', $cid) == false) { print 'ERROR: ' . $Mailer->error() . "\n"; return $Mailer->error(); } $message = str_replace('<GRAPH>', "<br><br><img src='cid:{$cid}'>", $message); } else { $message = str_replace('<GRAPH>', "<br><img src='" . $val['file'] . "'><br>Could not open!<br>" . $val['file'], $message); } } } $text = array('text' => '', 'html' => ''); if ($filename == '') { $message = str_replace('<br>', "\n", $message); $message = str_replace('<BR>', "\n", $message); $message = str_replace('</BR>', "\n", $message); $text['text'] = strip_tags($message); } else { $text['html'] = $message . '<br>'; $text['text'] = strip_tags(str_replace('<br>', "\n", $message)); } $v = thold_version(); $Mailer->header_set('X-Mailer', 'Cacti-Thold-v' . $v['version']); $Mailer->header_set('User-Agent', 'Cacti-Thold-v' . $v['version']); if (read_config_option('thold_email_prio') == 'on') { $Mailer->header_set('X-Priority', '1'); } thold_debug("Sending email to '" . trim(implode(',', $to), ',') . "'"); if ($Mailer->send($text) == false) { print 'ERROR: ' . $Mailer->error() . "\n"; return $Mailer->error(); } return ''; }
function graph_edit() { global $colors; if (!empty($_GET["id"])) { $graph = db_fetch_row("select * from graph where id=" . $_GET["id"]); if (!empty($graph["graph_template_id"])) { $graph_template = db_fetch_row("select * from graph_template where id=" . $graph["graph_template_id"]); } $header_label = _("[edit: ") . $graph["title_cache"] . "]"; } else { $header_label = _("[new]"); } /* handle debug mode */ if (isset($_GET["debug"])) { if ($_GET["debug"] == "0") { kill_session_var("graph_debug_mode"); } elseif ($_GET["debug"] == "1") { $_SESSION["graph_debug_mode"] = true; } } if (!empty($_GET["id"])) { ?> <table width="98%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php echo $graph["title_cache"]; ?> </td> <td class="textInfo" align="right" valign="top"> <span style="color: #c16921;">*<a href='graphs.php?action=edit&id=<?php print isset($_GET["id"]) ? $_GET["id"] : 0; ?> &debug=<?php print isset($_SESSION["graph_debug_mode"]) ? "0" : "1"; ?> '>Turn <strong><?php print isset($_SESSION["graph_debug_mode"]) ? "Off" : "On"; ?> </strong> Graph Debug Mode.</a> </td> </tr> </table> <br> <?php } /* ==================== Box: Device/Template Selection ==================== */ $form_array = array("graph_template_id" => array("method" => "drop_sql", "friendly_name" => _("Selected Graph Template"), "description" => _("Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied."), "value" => isset($graph) ? $graph["graph_template_id"] : "0", "none_value" => _("None"), "sql" => "select graph_template.id,graph_template.template_name as name from graph_template order by template_name"), "host_id" => array("method" => "drop_sql", "friendly_name" => _("Host"), "description" => _("Choose the host that this graph belongs to."), "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $graph["host_id"], "none_value" => _("None"), "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "id" => array("method" => "hidden", "value" => isset($graph) ? $graph["id"] : "0")); html_start_box("<strong>" . _("Device/Template Selection") . "</strong> {$header_label}", "98%", $colors["header_background"], "3", "center", ""); draw_edit_form(array("config" => array(), "fields" => $form_array)); html_end_box(); /* ==================== Box: Supplemental Template Data ==================== */ /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graph["graph_template_id"])) { ob_start(); html_start_box("<strong>" . _("Supplemental Template Data") . "</strong>", "98%", $colors["header_background"], "3", "center", ""); $num_output_fields = draw_nontemplated_fields_graph($graph["graph_template_id"], $graph, "g||field|", "<strong>" . _("Graph Fields") . "</strong>", true); $num_output_fields += draw_nontemplated_fields_graph_item($graph["graph_template_id"], array_rekey(db_fetch_assoc("select * from graph_item where graph_id = " . $graph["id"]), "graph_template_item_id", array("id", "data_source_item_id", "color", "graph_item_type", "cdef", "consolidation_function", "gprint_format", "legend_format", "legend_value", "hard_return")), "gip||field|||id|", "<strong>" . _("Graph Item Fields") . "</strong>", true); html_end_box(); if ($num_output_fields == 0) { ob_end_clean(); } else { ob_end_flush(); } } /* graph item list goes here */ if (!empty($_GET["id"]) && empty($graph["graph_template_id"])) { $graph_items = db_fetch_assoc("select\n\t\t\tgraph_item.id\n\t\t\tfrom graph_item\n\t\t\twhere graph_item.graph_id = " . $_GET["id"] . "\n\t\t\torder by graph_item.sequence"); /* ==================== Box: Graph Items ==================== */ html_start_box("<strong>" . _("Graph Items") . "</strong>", "98%", $colors["header_background"], "3", "center", "graphs_items.php?action=edit&graph_id=" . $_GET["id"]); draw_graph_item_editor($_GET["id"], "graph", false); html_end_box(); } /* display sample graph, or graph source in debug mode */ if (!empty($_GET["id"])) { ?> <table width="98%" align="center"> <tr> <td align="center" class="textInfo" colspan="2"> <img src="graph_image.php?graph_id=<?php print $_GET["id"]; ?> &rra_id=1" alt=""> </td> <?php if (isset($_SESSION["graph_debug_mode"]) && isset($_GET["id"])) { $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR; ?> <td> <span class="textInfo"><?php echo _("RRDTool Says:"); ?> </span><br> <pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array); ?> </pre> </td> <?php } ?> </tr> </table> <br> <?php } if (empty($graph["graph_template_id"]) && (isset($_GET["id"]) && is_numeric($_GET["id"]) || isset($_GET["host_id"]) && isset($_GET["graph_template_id"]))) { /* ==================== Box: Graph ==================== */ html_start_box("<strong>" . _("Graph") . "</strong>", "98%", $colors["header_background"], "3", "center", ""); field_row_header("General Options"); _graph_field__title("g|title", false, empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__vertical_label("g|vertical_label", false, isset($graph["vertical_label"]) ? $graph["vertical_label"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__image_format("g|image_format", false, isset($graph["image_format"]) ? $graph["image_format"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__export("g|export", false, isset($graph["export"]) ? $graph["export"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__force_rules_legend("g|force_rules_legend", false, isset($graph["force_rules_legend"]) ? $graph["force_rules_legend"] : ""); field_row_header("Image Size Options"); _graph_field__height("g|height", false, isset($graph["height"]) ? $graph["height"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__width("g|width", false, isset($graph["width"]) ? $graph["width"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); field_row_header("Grid Options"); _graph_field__x_grid("g|x_grid", false, isset($graph["x_grid"]) ? $graph["x_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__y_grid("g|y_grid", false, isset($graph["y_grid"]) ? $graph["y_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__y_grid_alt("g|y_grid_alt", false, isset($graph["y_grid_alt"]) ? $graph["y_grid_alt"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__no_minor("g|no_minor", false, isset($graph["no_minor"]) ? $graph["no_minor"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); field_row_header("Auto Scaling Options"); _graph_field__auto_scale("g|auto_scale", false, isset($graph["auto_scale"]) ? $graph["auto_scale"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__auto_scale_opts("g|auto_scale_opts", false, isset($graph["auto_scale_opts"]) ? $graph["auto_scale_opts"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__auto_scale_log("g|auto_scale_log", false, isset($graph["auto_scale_log"]) ? $graph["auto_scale_log"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__auto_scale_rigid("g|auto_scale_rigid", false, isset($graph["auto_scale_rigid"]) ? $graph["auto_scale_rigid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_field__auto_padding("g|auto_padding", false, isset($graph["auto_padding"]) ? $graph["auto_padding"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_padding"); field_row_header("Fixed Scaling Options"); _graph_field__upper_limit("g|upper_limit", false, isset($graph["upper_limit"]) ? $graph["upper_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_upper_limit"); _graph_field__lower_limit("g|lower_limit", false, isset($graph["lower_limit"]) ? $graph["lower_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_lower_limit"); _graph_field__base_value("g|base_value", false, isset($graph["base_value"]) ? $graph["base_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_base_value"); field_row_header("Units Display Options"); _graph_field__unit_value("g|unit_value", false, isset($graph["unit_value"]) ? $graph["unit_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_value"); _graph_field__unit_length("g|unit_length", false, isset($graph["unit_length"]) ? $graph["unit_length"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_length"); _graph_field__unit_exponent_value("g|unit_exponent_value", false, isset($graph["unit_exponent_value"]) ? $graph["unit_exponent_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); html_end_box(); } form_hidden_box("action_post", "graph_edit"); form_save_button("graphs.php"); }
function export() { global $config; if (!file_exists(read_config_option("path_html_export"))) { export_fatal("Export path does not exist!"); } export_log("Running graph export"); $cacti_root_path = $config["base_path"]; $cacti_export_path = read_config_option("path_html_export"); /* copy the css/images on the first time */ if (file_exists("$cacti_export_path/main.css") == false) { copy("$cacti_root_path/include/main.css", "$cacti_export_path/main.css"); copy("$cacti_root_path/images/tab_cacti.gif", "$cacti_export_path/tab_cacti.gif"); copy("$cacti_root_path/images/cacti_backdrop.gif", "$cacti_export_path/cacti_backdrop.gif"); copy("$cacti_root_path/images/transparent_line.gif", "$cacti_export_path/transparent_line.gif"); copy("$cacti_root_path/images/shadow.gif", "$cacti_export_path/shadow.gif"); } /* if the index file already exists, delete it */ check_remove($cacti_export_path . "/index.html"); /* open pointer to the new index file */ $fp_index = fopen($cacti_export_path . "/index.html", "w"); /* get a list of all graphs that need exported */ $graphs = db_fetch_assoc("select graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id from graph_templates_graph left join graph_templates on graph_templates_graph.graph_template_id=graph_templates.id left join graph_local on graph_templates_graph.local_graph_id=graph_local.id where graph_templates_graph.local_graph_id!=0 and graph_templates_graph.export='on' order by graph_templates_graph.title_cache"); $rras = db_fetch_assoc("select rra.id, rra.name from rra order by steps"); /* write the html header data to the index file */ fwrite($fp_index, HTML_HEADER); fwrite($fp_index, HTML_GRAPH_HEADER_ONE); fwrite($fp_index, "<strong>Displaying " . sizeof($graphs) . " Exported Graph" . ((sizeof($graphs) > 1) ? "s" : "") . "</strong>"); fwrite($fp_index, HTML_GRAPH_HEADER_TWO); /* open a pipe to rrdtool for writing */ $rrdtool_pipe = rrd_init(); /* for each graph... */ $i = 0; $k = 0; if ((sizeof($graphs) > 0) && (sizeof($rras) > 0)) { foreach ($graphs as $graph) { check_remove($cacti_export_path . "/thumb_" . $graph["local_graph_id"] . ".png"); check_remove($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html"); /* settings for preview graphs */ $graph_data_array["graph_height"] = "100"; $graph_data_array["graph_width"] = "300"; $graph_data_array["graph_nolegend"] = true; $graph_data_array["export"] = true; $graph_data_array["export_filename"] = "thumb_" . $graph["local_graph_id"] . ".png"; rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe); /* generate html files for each graph */ $fp_graph_index = fopen($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html", "w"); fwrite($fp_graph_index, HTML_HEADER); fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE); fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong>"); fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO); fwrite($fp_graph_index, "<td>"); /* reset vars for actual graph image creation */ reset($rras); unset($graph_data_array); /* generate graphs for each rra */ foreach ($rras as $rra) { $graph_data_array["export"] = true; $graph_data_array["export_filename"] = "graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png"; rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe); /* write image related html */ fwrite($fp_graph_index, "<div align=center><img src='graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png' border=0></div>\n <div align=center><strong>" . $rra["name"] . "</strong></div><br>"); } fwrite($fp_graph_index, "</td>"); fwrite($fp_graph_index, HTML_GRAPH_FOOTER); fwrite($fp_graph_index, HTML_FOOTER); fclose($fp_graph_index); /* main graph page html */ fwrite($fp_index, "<td align='center' width='" . (98 / 2) . "%'><a href='graph_" . $graph["local_graph_id"] . ".html'><img src='thumb_" . $graph["local_graph_id"] . ".png' border='0' alt='" . $graph["title_cache"] . "'></a></td>\n"); $i++; $k++; if (($i == 2) && ($k < count($graphs))) { $i = 0; fwrite($fp_index, "</tr><tr>"); } } }else{ fwrite($fp_index, "<td><em>No Graphs Found.</em></td>"); } /* close the rrdtool pipe */ rrd_close($rrdtool_pipe); fwrite($fp_index, HTML_GRAPH_FOOTER); fwrite($fp_index, HTML_FOOTER); fclose($fp_index); }
} /* override: graph end time (unix time) */ if (!empty($_GET["graph_end"])) { $graph_data_array["graph_end"] = $_GET["graph_end"]; } /* override: graph height (in pixels) */ if (!empty($_GET["graph_height"])) { $graph_data_array["graph_height"] = $_GET["graph_height"]; } /* override: graph width (in pixels) */ if (!empty($_GET["graph_width"])) { $graph_data_array["graph_width"] = $_GET["graph_width"]; } /* override: skip drawing the legend? */ if (!empty($_GET["graph_nolegend"])) { $graph_data_array["graph_nolegend"] = $_GET["graph_nolegend"]; } /* print RRDTool graph source? */ if (!empty($_GET["show_source"])) { $graph_data_array["print_source"] = $_GET["show_source"]; } print rrdtool_function_graph($_GET["local_graph_id"], $_GET["rra_id"], $graph_data_array); ?>
header("Content-type: image/png"); /* flush the headers now */ ob_end_clean(); session_write_close(); $graph_data_array = array(); /* override: graph start time (unix time) */ if (!empty($_GET["graph_start"]) && $_GET["graph_start"] < 1600000000) { $graph_data_array["graph_start"] = $_GET["graph_start"]; } /* override: graph end time (unix time) */ if (!empty($_GET["graph_end"]) && $_GET["graph_end"] < 1600000000) { $graph_data_array["graph_end"] = $_GET["graph_end"]; } /* override: graph height (in pixels) */ if (!empty($_GET["graph_height"]) && $_GET["graph_height"] < 3000) { $graph_data_array["graph_height"] = $_GET["graph_height"]; } /* override: graph width (in pixels) */ if (!empty($_GET["graph_width"]) && $_GET["graph_width"] < 3000) { $graph_data_array["graph_width"] = $_GET["graph_width"]; } /* override: skip drawing the legend? */ if (!empty($_GET["graph_nolegend"])) { $graph_data_array["graph_nolegend"] = $_GET["graph_nolegend"]; } /* print RRDTool graph source? */ if (!empty($_GET["show_source"])) { $graph_data_array["print_source"] = $_GET["show_source"]; } print @rrdtool_function_graph($_GET["local_graph_id"], array_key_exists("rra_id", $_GET) ? $_GET["rra_id"] : null, $graph_data_array);
function export_build_graphs($fp, $path, $tree_id, $parent_tree_item_id) { /* start the count of graphs */ $total_graphs_created = 0; $cacti_export_path = read_config_option("path_html_export"); $req=""; if (get_tree_item_type($parent_tree_item_id)=="host") { $req="select distinct graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id from graph_templates_graph left join graph_templates on (graph_templates_graph.graph_template_id=graph_templates.id) left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id) where graph_local.host_id=".get_host_id($parent_tree_item_id)." and graph_templates_graph.local_graph_id!=0 and graph_templates_graph.export='on' order by graph_templates_graph.title_cache"; }else { /* searching for the graph_tree_items of the tree_id which are graphs */ $req="select distinct graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id, graph_tree_items.id as gtid from graph_templates_graph left join graph_tree_items on (graph_templates_graph.local_graph_id=graph_tree_items.local_graph_id) left join graph_templates on (graph_templates_graph.graph_template_id=graph_templates.id) left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id) where graph_tree_items.graph_tree_id =".$tree_id." and graph_templates_graph.local_graph_id!=0 and graph_templates_graph.export='on' order by graph_templates_graph.title_cache"; } $graphs=db_fetch_assoc($req); $rras = db_fetch_assoc("select rra.id, rra.name from rra order by timespan"); /* open a pipe to rrdtool for writing */ $rrdtool_pipe = rrd_init(); /* for each graph... */ $i = 0; foreach($graphs as $graph) { /* this test gives us the graph_tree_items which are just under the parent_graph_tree_item */ if (((get_tree_item_type($parent_tree_item_id)=="header") || ($parent_tree_item_id == 0)) && (get_parent_id($graph["gtid"], "graph_tree_items","graph_tree_id = ".$tree_id) != $parent_tree_item_id)) { /* do nothing */ }else { /* settings for preview graphs */ $graph_data_array["graph_height"] = "100"; $graph_data_array["graph_width"] = "300"; $graph_data_array["graph_nolegend"] = true; $graph_data_array["export"] = true; $graph_data_array["export_filename"] = "'".$path."'/thumb_".$graph["local_graph_id"].".png"; rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe); $total_graphs_created++; /* generate html files for each graph */ $fp_graph_index = fopen($cacti_export_path."/".$path."/graph_".$graph["local_graph_id"].".html", "w"); fwrite($fp_graph_index, HTML_HEADER_TREE); draw_html_left_tree($fp_graph_index,$tree_id); fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE_TREE); fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong>"); fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO); fwrite($fp_graph_index, "<td>"); /* reset vars for actual graph image creation */ reset($rras); unset($graph_data_array); /* generate graphs for each rra */ foreach ($rras as $rra) { $graph_data_array["export"] = true; $graph_data_array["export_filename"] = "'".$path."'/graph_".$graph["local_graph_id"]."_".$rra["id"].".png"; rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe); $total_graphs_created++; /* write image related html */ fwrite($fp_graph_index, "<div align=center><img src='graph_".$graph["local_graph_id"]."_".$rra["id"].".png' border=0></div>\n <div align=center><strong>".$rra["name"]."</strong></div><br>"); } fwrite($fp_graph_index, "</tr></table>"); fwrite($fp_graph_index, HTML_FOOTER_TREE); fclose($fp_graph_index); /* main graph page html */ fwrite($fp, "<td align='center' width='\" . (98 / 2) . \"%'><a href='graph_" . $graph["local_graph_id"] . ".html'><img src='thumb_" . $graph["local_graph_id"] . ".png' border='0' alt='" . $graph["title_cache"] . "'></a></td>\n"); $i++; if (($i == 2)) { $i = 0; fwrite($fp, "</tr><tr>"); } } } /* close the rrdtool pipe */ rrd_close($rrdtool_pipe); return $total_graphs_created; }
function thold_mail($to_email, $from_email, $subject, $message, $filename, $headers = '') { thold_debug('Preparing to send email'); $subject = trim($subject); $message = str_replace('<SUBJECT>', $subject, $message); if ($from_email == '') { $from_email = read_config_option('thold_from_email'); $from_name = read_config_option('thold_from_name'); if ($from_email == '') { if (isset($_SERVER['HOSTNAME'])) { $from_email = 'Cacti@' . $_SERVER['HOSTNAME']; } else { $from_email = 'Cacti@localhost'; } } if ($from_name == '') { $from_name = 'Cacti'; } } if ($to_email == '') { return __('Mailer Error: No <b>TO</b> address set!!<br>If using the <i>Test Mail</i> link, please set the <b>Alert e-mail</b> setting.'); } $attachments = array(); if (is_array($filename) && !empty($filename) && strstr($message, '<GRAPH>') !== 0) { foreach ($filename as $val) { $graph_data_array = array('graph_start' => time() - 86400, 'graph_end' => time(), 'image_format' => 'png', 'graph_theme' => 'modern', 'output_flag' => RRDTOOL_OUTPUT_STDOUT, 'disable_cache' => true); $attachments[] = array('attachment' => @rrdtool_function_graph($val['local_graph_id'], '', $graph_data_array, ''), 'filename' => 'graph_' . $val['local_graph_id'] . '.png', 'mime_type' => 'image/png', 'local_graph_id' => $val['local_graph_id'], 'local_data_id' => $val['local_data_id'], 'inline' => 'inline'); } } $text = array('text' => '', 'html' => ''); if ($filename == '') { $message = str_replace('<br>', "\n", $message); $message = str_replace('<BR>', "\n", $message); $message = str_replace('</BR>', "\n", $message); $text['text'] = strip_tags($message); } else { $text['html'] = $message . '<br>'; $text['text'] = strip_tags(str_replace('<br>', "\n", $message)); } $version = db_fetch_cell("SELECT version \n\t\tFROM plugin_config \n\t\tWHERE name='thold'"); $headers['X-Mailer'] = 'Cacti-Thold-v' . $version; $headers['User-Agent'] = 'Cacti-Thold-v' . $version; if (read_config_option('thold_email_prio') == 'on') { $headers['X-Priority'] = '1'; } thold_debug("Sending email to '" . trim($to_email, ', ') . "'"); $error = mailer(array($from_email, $from_name), $to_email, '', '', '', $subject, $text['html'], $text['text'], $attachments, $headers); if (strlen($error)) { cacti_log('ERROR: Sending Email Failed. Error was ' . $error, true, 'THOLD'); return $error; } return ''; }