mirror of
https://github.com/rsyslog/loganalyzer.git
synced 2025-09-26 03:09:21 +02:00
Added support for Outputtarget REPORT_TARGET_FILE including error handling
This commit is contained in:
parent
6d7437f9d9
commit
c23a349168
@ -496,6 +496,15 @@ abstract class Report {
|
||||
return $this->_arrOutputTargetDetails;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper function to return the OutputTarget
|
||||
*/
|
||||
public function GetOutputTarget()
|
||||
{
|
||||
// return OutputTarget
|
||||
return $this->_outputTarget;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper function to trigger initialisation
|
||||
*/
|
||||
@ -546,15 +555,18 @@ abstract class Report {
|
||||
/*
|
||||
* This function outputs the report to the browser in the desired format!
|
||||
*/
|
||||
public function OutputReport($szOutputBuffer)
|
||||
public function OutputReport($szOutputBuffer, &$szErrorStr)
|
||||
{
|
||||
global $gl_root_path;
|
||||
|
||||
// Helper variable, init with buffer
|
||||
$szFinalOutput = $szOutputBuffer;
|
||||
$res = SUCCESS;
|
||||
|
||||
// Simple HTML Output!
|
||||
if ( $this->_outputFormat == REPORT_OUTPUT_HTML )
|
||||
{
|
||||
// HTML Header
|
||||
echo $szOutputBuffer;
|
||||
// do nothing
|
||||
}
|
||||
else if ( $this->_outputFormat == REPORT_OUTPUT_PDF )
|
||||
{
|
||||
@ -568,8 +580,51 @@ abstract class Report {
|
||||
// $pdf->SetFontSize(12);
|
||||
$pdf->WriteHTML( $szOutputBuffer );
|
||||
// Header('Content-Type: application/pdf');
|
||||
$pdf->Output('', 'I'); // Output to STANDARD Input!
|
||||
$szFinalOutput = $pdf->Output('', 'S'); // Output to STANDARD Input!
|
||||
}
|
||||
|
||||
// Simple HTML Output!
|
||||
if ( $this->_outputTarget == REPORT_TARGET_STDOUT )
|
||||
{
|
||||
// Kindly output to browser
|
||||
echo $szFinalOutput;
|
||||
$res = SUCCESS;
|
||||
}
|
||||
else if ( $this->_outputTarget == REPORT_TARGET_FILE )
|
||||
{
|
||||
// Get Filename first
|
||||
if ( isset($this->_arrOutputTargetDetails['filename']) )
|
||||
{
|
||||
// Get Filename property
|
||||
$szFilename = $this->_arrOutputTargetDetails['filename'];
|
||||
|
||||
// Create file and Write Report into it!
|
||||
$handle = @fopen($szFilename, "w");
|
||||
if ( $handle === false )
|
||||
{
|
||||
$szErrorStr = "Could not create '" . $szFilename . "'!";
|
||||
$res = ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($handle, $szFinalOutput);
|
||||
fflush($handle);
|
||||
fclose($handle);
|
||||
|
||||
// For result
|
||||
$szErrorStr = "Results were saved into '" . $szFilename . "'";
|
||||
$res = SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$szErrorStr = "The parameter 'filename' was missing.";
|
||||
$res = ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// return result
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -348,6 +348,8 @@ $content['LN_ORACLE_WHOIS'] = "WHOIS Lookup for '%1' value '%2'";
|
||||
$content['LN_REPORT_FILTERTYPE_DATE'] = "Date";
|
||||
$content['LN_REPORT_FILTERTYPE_NUMBER'] = "Number";
|
||||
$content['LN_REPORT_FILTERTYPE_STRING'] = "String";
|
||||
|
||||
$content['LN_GEN_SUCCESS_WHILEREPORTGEN'] = "Report was successfully generated";
|
||||
$content['LN_GEN_ERROR_REPORTFAILEDTOGENERATE'] = "Failed to generate report, error details: %1";
|
||||
$content['LN_GEN_SUCCESS_REPORTWASGENERATED_DETAILS'] = "Successfully generated report: %1";
|
||||
|
||||
?>
|
@ -55,6 +55,7 @@ InitReportModules();
|
||||
|
||||
// --- READ CONTENT Vars
|
||||
$content['error_occured'] = false;
|
||||
$content['report_success'] = false;
|
||||
|
||||
if ( isset($_GET['op']) )
|
||||
$content['op'] = DB_RemoveBadChars($_GET['op']);
|
||||
@ -82,63 +83,6 @@ else
|
||||
$content['error_occured'] = "error";
|
||||
$content['error_details'] = $content['LN_GEN_ERROR_MISSINGSAVEDREPORTID'];
|
||||
}
|
||||
|
||||
/*
|
||||
if ( isset($_GET['width']) )
|
||||
{
|
||||
$content['chart_width'] = intval($_GET['width']);
|
||||
|
||||
// Limit Chart Size for now
|
||||
if ( $content['chart_width'] < 100 )
|
||||
$content['chart_width'] = 100;
|
||||
else if ( $content['chart_width'] > 1000 )
|
||||
$content['chart_width'] = 1000;
|
||||
}
|
||||
else
|
||||
$content['chart_width'] = 100;
|
||||
|
||||
if ( isset($_GET['byfield']) )
|
||||
{
|
||||
if ( isset($fields[ $_GET['byfield'] ]) )
|
||||
{
|
||||
$content['chart_field'] = $_GET['byfield'];
|
||||
$content['chart_fieldtype'] = $fields[ $content['chart_field'] ]['FieldType'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$content['error_occured'] = true;
|
||||
$content['error_details'] = $content['LN_GEN_ERROR_INVALIDFIELD'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$content['error_occured'] = true;
|
||||
$content['error_details'] = $content['LN_GEN_ERROR_MISSINGCHARTFIELD'];
|
||||
}
|
||||
|
||||
if ( isset($_GET['maxrecords']) )
|
||||
{
|
||||
// read and verify value
|
||||
$content['maxrecords'] = intval($_GET['maxrecords']);
|
||||
if ( $content['maxrecords'] < 2 || $content['maxrecords'] > 100 )
|
||||
$content['maxrecords'] = 10;
|
||||
}
|
||||
else
|
||||
$content['maxrecords'] = 10;
|
||||
|
||||
if ( isset($_GET['showpercent']) )
|
||||
{
|
||||
// read and verify value
|
||||
$content['showpercent'] = intval($_GET['showpercent']);
|
||||
if ( $content['showpercent'] >= 1 )
|
||||
$content['showpercent'] = 1;
|
||||
else
|
||||
$content['showpercent'] = 0;
|
||||
}
|
||||
else
|
||||
$content['showpercent'] = 0;
|
||||
*/
|
||||
|
||||
// ---
|
||||
|
||||
// --- BEGIN CREATE TITLE
|
||||
@ -218,9 +162,20 @@ if ( !$content['error_occured'] )
|
||||
// Parse template
|
||||
$page -> parser($content, $myReportObj->GetBaseFileName());
|
||||
|
||||
// Output to browser
|
||||
$myReportObj->OutputReport( $page ->result() );
|
||||
//$page->output();
|
||||
// Output the result
|
||||
$res = $myReportObj->OutputReport( $page ->result(), $szErrorStr );
|
||||
if ( $res == SUCCESS && $myReportObj->GetOutputTarget() != REPORT_TARGET_STDOUT )
|
||||
{
|
||||
// Output wasn't STDOUT, so we need to display what happened to the user
|
||||
$content['report_success'] = true;
|
||||
$content['error_details'] = GetAndReplaceLangStr($content["LN_GEN_SUCCESS_REPORTWASGENERATED_DETAILS"], $szErrorStr);
|
||||
}
|
||||
else if ( $res == ERROR )
|
||||
{
|
||||
// Output failed, display what happened to the user
|
||||
$content['error_occured'] = true;
|
||||
$content['error_details'] = GetAndReplaceLangStr($content["LN_GEN_ERROR_REPORTFAILEDTOGENERATE"], $szErrorStr);
|
||||
}
|
||||
// ---
|
||||
}
|
||||
}
|
||||
@ -240,11 +195,14 @@ if ( !$content['error_occured'] )
|
||||
}
|
||||
|
||||
// Output error if necessary
|
||||
if ( $content['error_occured'] )
|
||||
if ( $content['error_occured'] || $content['report_success'] )
|
||||
{
|
||||
// $content['TITLE'] = InitPageTitle();
|
||||
$content['TITLE'] .= " :: " . $content['LN_GEN_ERROR_WHILEREPORTGEN'];
|
||||
if ( $content['error_occured'] )
|
||||
$content['TITLE'] .= " :: " . $content['LN_GEN_ERROR_WHILEREPORTGEN'];
|
||||
else
|
||||
$content['TITLE'] .= " :: " . $content['LN_GEN_SUCCESS_WHILEREPORTGEN'];
|
||||
|
||||
// Create template Parser and output results
|
||||
InitTemplateParser();
|
||||
$page -> parser($content, "reportgenerator.html");
|
||||
$page -> output();
|
||||
|
@ -8,6 +8,7 @@
|
||||
<body TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
|
||||
|
||||
<br><br>
|
||||
<!-- IF error_occured="true" -->
|
||||
<table width="600" align="center" class="with_border_alternate ErrorMsg" cellpadding="2">
|
||||
<tr>
|
||||
<td class="PriorityError" align="center" colspan="2">
|
||||
@ -22,6 +23,23 @@
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- ENDIF error_occured="true" -->
|
||||
<!-- IF report_success="true" -->
|
||||
<table width="600" align="center" class="with_border_alternate ErrorMsg" cellpadding="2">
|
||||
<tr>
|
||||
<td class="PriorityInfo" align="center" colspan="2">
|
||||
<H3>{LN_GEN_SUCCESS_WHILEREPORTGEN}</H3>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td class="cellmenu1_naked" align="left">{LN_GEN_MESSAGEDETAILS}</td>
|
||||
<td class="tableBackground" align="left">
|
||||
<br>
|
||||
{error_details}
|
||||
<br><br>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- ENDIF report_success="true" -->
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user