Skip to content

Commit

Permalink
Commit a mostly-complete version of Email Reports converted to bootst…
Browse files Browse the repository at this point in the history
…rap. Ticket #5578

Known Issues: Deleting items from a report does not work.
  • Loading branch information
jim-p committed Dec 7, 2015
1 parent 3b33953 commit 4a0ec13
Show file tree
Hide file tree
Showing 9 changed files with 614 additions and 563 deletions.
2 changes: 1 addition & 1 deletion mail/pfSense-pkg-mailreport/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# $FreeBSD$

PORTNAME= pfSense-pkg-mailreport
PORTVERSION= 2.3
PORTVERSION= 2.4
PORTREVISION= 1
CATEGORIES= mail
MASTER_SITES= # empty
Expand Down
54 changes: 22 additions & 32 deletions mail/pfSense-pkg-mailreport/files/etc/inc/mail_reports.inc
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ function mail_report_generate_graph($database, $style, $graph, $start, $end) {
require_once("rrd.inc");
require_once("util.inc");
global $g;
$g['theme'] = get_current_theme();

$pgtitle = array(gettext("System"),gettext("RRD Graphs"),gettext("Image viewer"));

Expand Down Expand Up @@ -392,36 +391,29 @@ function mail_report_generate_graph($database, $style, $graph, $start, $end) {

$speedlimit = ($upstream + $downstream);

/* Set default colors explicitly, the theme can then override them below.
This prevents missing colors in themes from crashing the graphs. */
$colortrafficup = array("666666", "CCCCCC");
$colortrafficdown = array("990000", "CC0000");
$colortraffic95 = array("660000", "FF0000");
$colorpacketsup = array("666666", "CCCCCC");
$colorpacketsdown = array("990000", "CC0000");
$colorstates = array('990000','a83c3c','b36666','bd9090','cccccc','000000');
$colorprocessor = array('990000','a83c3c','b36666','bd9090','cccccc','000000');
$colormemory = array('990000','a83c3c','b36666','bd9090','cccccc','000000');
$colormbuf = array('990000','a83c3c','b36666','bd9090','cccccc','000000');
$colorqueuesup = array('000000','7B0000','990000','BB0000','CC0000','D90000','EE0000','FF0000','CC0000');
$colorqueuesdown = array('000000','7B7B7B','999999','BBBBBB','CCCCCC','D9D9D9','EEEEEE','FFFFFF','CCCCCC');
$colorqueuesdropup = array('000000','7B0000','990000','BB0000','CC0000','D90000','EE0000','FF0000','CC0000');
$colorqueuesdropdown = array('000000','7B7B7B','999999','BBBBBB','CCCCCC','D9D9D9','EEEEEE','FFFFFF','CCCCCC');
$colorqualityrtt = array('990000','a83c3c','b36666','bd9090','cccccc','000000');
$colorqualityloss = "ee0000";
$colorwireless = array('333333','a83c3c','999999');
$colorspamdtime = array('DDDDFF', 'AAAAFF', 'DDDDFF', '000066');
$colorspamdconn = array('00AA00BB', 'FFFFFFFF', '00660088', 'FFFFFF88', '006600');
$colorvpnusers = array('990000');
/* Set default colors explicitly. */
$colortrafficup = array('666666', 'CCCCCC', '2217AA', '625AE7');
$colortrafficdown = array('990000', 'CC0000', 'FFC875', 'FF9900');
$colorpacketsup = array('666666', 'CCCCCC', '2217AA', '625AE7');
$colorpacketsdown = array('990000', 'CC0000', 'FFC875', 'FF9900');
$colortraffic95 = array('660000', 'FF0000');
$colorstates = array('00AA00', '990000', '0000FF', '000000', 'DD9B00');
$colorprocessor = array('00AA00', '990000', '0000FF', 'DD9B00', '000000');
$colormemory = array('00AA00', '990000', '0000FF', '666666', 'DD9B00');
$colormbuf = array('0080FF', '00E344', 'FF0000', '000000');
$colorqueuesup = array('000000', '7B0000', '0080FF', '00E344', 'FF0000', '2217AA', 'FFC875', 'FF9900', 'CC0000');
$colorqueuesdown = array('000000', '7B7B7B', '999999', 'BBBBBB', 'CCCCCC', 'D9D9D9', 'EEEEEE', 'FFFFFF', 'CCCCCC');
$colorqueuesdropup = array('000000', '7B0000', '0080FF', '00E344', 'FF0000', '2217AA', 'FFC875', 'FF9900', 'CC0000');
$colorqueuesdropdown = array('000000', '7B7B7B', '999999', 'BBBBBB', 'CCCCCC', 'D9D9D9', 'EEEEEE', 'FFFFFF', 'CCCCCC');
$colorqualityrtt = array('990000', 'a83c3c', 'b36666', 'bd9090', 'cccccc', '000000');
$colorqualityloss = 'ee0000';
$colorwireless = array('333333', 'a83c3c', '999999');
$colorspamdtime = array('DDDDFF', 'AAAAFF', 'DDDDFF', '000066');
$colorspamdconn = array('AA00BB', 'FFFFFF', '660088', 'FFFF88', '006600');
$colorvpnusers = array('990000');
$colorntpd = array('0080FF', '00E344', 'FF0000', '000000');
$colorcaptiveportalusers = array('990000');

/* select theme colors if the inclusion file exists */
$rrdcolors = "{$g['www_path']}/themes/{$g['theme']}/rrdcolors.inc.php";
if(file_exists($rrdcolors)) {
include($rrdcolors);
} else {
log_error(sprintf(gettext("rrdcolors.inc.php for theme %s does not exist, using defaults!"),$g['theme']));
}
$colordhcpd = array('990000', '0000FF', '000000');

switch ($curstyle) {
case "absolute":
Expand Down Expand Up @@ -1215,8 +1207,6 @@ function mail_report_generate_graph($database, $style, $graph, $start, $end) {
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$file= "/usr/local/www/themes/{$g['theme']}/images/misc/rrd_error.png";
return($file);
} else {
$file = "$rrdtmppath$curdatabase-$curgraph.png";
if(file_exists("$file")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
]]>
</copyright>
<name>mailreport</name>
<version>2.3</version>
<version>2.4</version>
<title>Status: Email Reports</title>
<additional_files_needed>
<prefix>/usr/local/bin/</prefix>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>mailreport</name>
<descr><![CDATA[Allows you to setup periodic e-mail reports containing command output, log file contents, and RRD graphs.]]></descr>
<category>System</category>
<version>2.3_1</version>
<version>2.4</version>
<status>RELEASE</status>
<port_category>mail</port_category>
<required_version>2.2</required_version>
Expand Down
159 changes: 105 additions & 54 deletions mail/pfSense-pkg-mailreport/files/usr/local/www/status_mail_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/*
/*
pfSense_MODULE: system
*/

Expand All @@ -46,69 +46,120 @@

$a_mailreports = &$config['mailreports']['schedule'];

if ($_GET['act'] == "del") {
if ($a_mailreports[$_GET['id']]) {
$name = $a_mailreports[$_GET['id']]['descr'];
unset($a_mailreports[$_GET['id']]);

// Fix up cron job(s)
set_mail_report_cron_jobs($a_mailreports);

write_config("Removed Email Report '{$name}'");
if (isset($_POST['del'])) {
if (is_array($_POST['reports']) && count($_POST['reports'])) {
foreach ($_POST['reports'] as $reportsi) {
unset($a_mailreports[$reportsi]);
set_mail_report_cron_jobs($a_mailreports);
}
write_config("Removed Multiple Email Reports");
configure_cron();
header("Location: status_mail_report.php");
exit;
}
} else {
unset($delbtn);
foreach ($_POST as $pn => $pd) {
if (preg_match("/del_(\d+)/", $pn, $matches)) {
$delbtn = $matches[1];
}
}

if (isset($delbtn)) {
if ($a_mailreports[$delbtn]) {
$name = $a_mailreports[$delbtn]['descr'];
unset($a_mailreports[$delbtn]);

// Fix up cron job(s)
set_mail_report_cron_jobs($a_mailreports);

write_config("Removed Email Report '{$name}'");
configure_cron();
header("Location: status_mail_report.php");
exit;
}
}
}

$pgtitle = array(gettext("Status"),gettext("Email Reports"));

$pgtitle = array(gettext("Status"), gettext("Email Reports"), gettext("Add Log"));
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td><div id="mainarea">
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="4">Here you can define a list of reports to be sent by email. </td></tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td width="34%" class="listhdr"><?=gettext("Description");?></td>
<td width="24%" class="listhdr"><?=gettext("Schedule");?></td>
<td width="12%" class="listhdr"><?=gettext("Commands");?></td>
<td width="12%" class="listhdr"><?=gettext("Logs");?></td>
<td width="12%" class="listhdr"><?=gettext("Graphs");?></td>
<td width="6%" class="list"><a href="status_mail_report_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
</tr>

<form name="mainform" method="post">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title"><?=gettext('Email Reports')?></h2>
<?=gettext("Define reports to by sent periodically via email.");?>
</div>
<div class="panel-body table-responsive">
<table class="table table-striped table-hover">
<thead>
<th>&nbsp;</th>
<th><?=gettext("Description")?></th>
<th><?=gettext("Schedule")?></th>
<th><?=gettext("Commands")?></th>
<th><?=gettext("Logs")?></th>
<th><?=gettext("Graphs")?></th>
<th><?=gettext("Actions")?></th>
</thead>
<tbody class="services">

<?php $i = 0; foreach ($a_mailreports as $mailreport): ?>
<tr ondblclick="document.location='status_mail_report_edit.php?id=<?=$i;?>'">
<td class="listlr"><?php echo $mailreport['descr']; ?></td>
<td class="listlr"><?php echo $mailreport['schedule_friendly']; ?></td>
<td class="listlr"><?php echo count($mailreport['cmd']['row']); ?></td>
<td class="listlr"><?php echo count($mailreport['log']['row']); ?></td>
<td class="listlr"><?php echo count($mailreport['row']); ?></td>
<td valign="middle" nowrap class="list">
<a href="status_mail_report_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a>
&nbsp;
<a href="status_mail_report.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this entry?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a>
</td>
</tr>
<?php $i++; endforeach; ?>
<tr>
<td class="list" colspan="5"></td>
<td class="list"><a href="status_mail_report_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
</tr>
<tr>
<td colspan="3" class="list"><p class="vexpl">
<span class="red"><strong><?=gettext("Note:");?><br></strong></span>
<?=gettext("Click + above to add scheduled reports.");?><br/>
Configure your SMTP settings under <a href="/system_advanced_notifications.php">System -&gt; Advanced, on the Notifications tab</a>.
<td><input type="checkbox" id="frc<?=$i?>" name="reports[]" value="<?=$i?>" onclick="fr_bgcolor('<?=$i?>')" /></td>
<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>" ondblclick="document.location='status_mail_report_edit.php?id=<?=$i?>';">
<?=$mailreport['descr']; ?>
</td>
<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>" ondblclick="document.location='status_mail_report_edit.php?id=<?=$i?>';">
<?=$mailreport['schedule_friendly']; ?>
</td>
<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>" ondblclick="document.location='status_mail_report_edit.php?id=<?=$i?>';">
<?=count($mailreport['cmd']['row']); ?>
</td>
<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>" ondblclick="document.location='status_mail_report_edit.php?id=<?=$i?>';">
<?=count($mailreport['log']['row']); ?>
</td>
<td onclick="fr_toggle(<?=$i?>)" id="frd<?=$i?>" ondblclick="document.location='status_mail_report_edit.php?id=<?=$i?>';">
<?=count($mailreport['row']); ?>
</td>
<td style="cursor: pointer;">
<a class="fa fa-pencil" href="status_mail_report_edit.php?id=<?=$i?>" title="<?=gettext("Edit Report"); ?>"></a>
<a class="fa fa-trash no-confirm" id="Xdel_<?=$i?>" title="<?=gettext('Delete Report'); ?>"></a>
<button style="display: none;" class="btn btn-xs btn-warning" type="submit" id="del_<?=$i?>" name="del_<?=$i?>" value="del_<?=$i?>" title="<?=gettext('Delete Report'); ?>">Delete</button>
</td>
<td class="list">&nbsp;</td>
</tr>
</table>
</div></td></tr>
</table>
<?php $i++; endforeach; ?>

</tbody>
</table>
</div>
</div>
<nav class="action-buttons">
<br />
<a href="status_mail_report_edit.php" class="btn btn-success btn-sm">
<i class="fa fa-plus icon-embed-btn"></i>
<?=gettext("Add New Report")?>
</a>
<?php if ($i !== 0): ?>
<button type="submit" name="del" class="btn btn-danger btn-sm" value="<?=gettext("Delete Selected Reports")?>">
<i class="fa fa-trash icon-embed-btn"></i>
<?=gettext("Delete")?>
</button>
<?php endif; ?>
</nav>
</form>
<?php print_info_box(gettext("Configure SMTP settings under <a href=\"/system_advanced_notifications.php\">System -&gt; Advanced, on the Notifications tab</a>"), 'info'); ?>
<script type="text/javascript">
//<![CDATA[

<?php include("fend.inc"); ?>
</body>
</html>
events.push(function() {
$('[id^=Xdel_]').click(function (event) {
if(confirm("<?=gettext('Delete this patch entry?')?>")) {
$('#' + event.target.id.slice(1)).click();
}
});
});
//]]>
</script>
<?php include("foot.inc"); ?>
Original file line number Diff line number Diff line change
Expand Up @@ -88,59 +88,52 @@
return;
}


$pgtitle = array(gettext("Status"),gettext("Add Email Report Command"));
$pgtitle = array(gettext("Status"), gettext("Email Reports"), gettext("Add Command"));
include("head.inc");

$form = new Form();

$section = new Form_Section('Command Settings');

$section->addInput(new Form_Input(
'descr',
'Name',
'text',
$pconfig['descr']
))->setHelp('Enter a description here for reference.');

$section->addInput(new Form_Input(
'detail',
'Command',
'text',
$pconfig['detail']
))->setHelp('Enter the full path to a command here.')->setWidth(6);

$form->add($section);

$form->addGlobal(new Form_Input(
'reportid',
null,
'hidden',
$reportid
));

if (isset($id) && $a_cmds[$id]) {
$form->addGlobal(new Form_Input(
'id',
null,
'hidden',
$id
));
}
print($form);

?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td><div id="mainarea">
<form action="status_mail_report_add_cmd.php" method="post" name="iform" id="iform">
<table class="tabcont" width="100%" border="0" cellpadding="1" cellspacing="1">
<tr>
<td class="listtopic" colspan="2">Command Settings</td>
</tr>
<tr>
<td width="20%" class="listhdr">
<?=gettext("Name:");?>
</td>
<td width="80%" class="listhdr">
<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>">
</td>
</tr>
<tr>
<td class="listhdr">
<?=gettext("Command:");?>
</td>
<td class="listhdr">
<input name="detail" type="text" class="formfld unknown" id="detail" size="60" value="<?=htmlspecialchars($pconfig['detail']);?>">
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<br/>NOTE: Use full paths to commands to ensure they run properly. The command will be run during the report and its stdout output will be included in the report body. Be extremely careful what commands you choose to run, the same warnings apply as those when using Diagnostics &gt; Command.
<br/>
<br/>Do not use this solely as a way to run a command on a schedule, use the Cron package for that purpose instead.
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>">
<a href="status_mail_report_edit.php?id=<?php echo $reportid;?>"><input name="cancel" type="button" class="formbtn" value="<?=gettext("Cancel");?>"></a>
<input name="reportid" type="hidden" value="<?=htmlspecialchars($reportid);?>">
<?php if (isset($id) && $a_cmds[$id]): ?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
<?php endif; ?>
</td>
<td></td>
</tr>
</table>
</form>
</div></td></tr>
</table>

<?php include("fend.inc"); ?>
</body>
</html>

<div>
<?=print_info_box(gettext("Use full paths to commands to ensure they run properly. The command will be run during the report and its stdout output will be included in the report body. Be extremely careful what commands are run, the same warnings apply as those when using Diagnostics &gt; Command.") .
"<br /><br />" .
gettext("Do not use this solely as a way to run a command on a schedule, use the Cron package for that purpose instead."), 'warning'); ?>
</div>

<?php include("foot.inc"); ?>
Loading

0 comments on commit 4a0ec13

Please sign in to comment.