add dberrornice template for database-errors
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -441,7 +441,7 @@ class FroxlorInstall
|
||||
return bin2hex(openssl_random_pseudo_bytes($length));
|
||||
}
|
||||
// if everything else fails, use unsafe fallback
|
||||
return md5(uniqid(microtime(), 1));
|
||||
return substr(md5(uniqid(microtime(), 1)), 0, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Froxlor\Database;
|
||||
|
||||
/**
|
||||
@@ -428,7 +429,7 @@ class Database
|
||||
/**
|
||||
* log error for reporting
|
||||
*/
|
||||
$errid = substr(md5(microtime()), 5, 5);
|
||||
$errid = self::genUniqueToken();
|
||||
$err_file = \Froxlor\FileDir::makeCorrectFile($sl_dir . "/" . $errid . "_sql-error.log");
|
||||
$errlog = @fopen($err_file, 'w');
|
||||
@fwrite($errlog, "|CODE " . $error->getCode() . "\n");
|
||||
@@ -453,42 +454,60 @@ class Database
|
||||
}
|
||||
|
||||
if ($showerror) {
|
||||
// fallback
|
||||
$theme = 'Sparkle';
|
||||
|
||||
// clean up sensitive data
|
||||
unset($sql);
|
||||
unset($sql_root);
|
||||
|
||||
if ((isset($theme) && $theme != '') && !isset($_SERVER['SHELL']) || (isset($_SERVER['SHELL']) && $_SERVER['SHELL'] == '')) {
|
||||
// if we're not on the shell, output a nice error
|
||||
$_errtpl = dirname($sl_dir) . '/templates/' . $theme . '/misc/dberrornice.tpl';
|
||||
if (file_exists($_errtpl)) {
|
||||
$err_hint = file_get_contents($_errtpl);
|
||||
// replace values
|
||||
$err_hint = str_replace("<TEXT>", $error_message, $err_hint);
|
||||
$err_hint = str_replace("<DEBUG>", $error_trace, $err_hint);
|
||||
$err_hint = str_replace("<CURRENT_YEAR>", date('Y', time()), $err_hint);
|
||||
|
||||
$err_report_html = '';
|
||||
$err_report_link = '';
|
||||
if (is_array($userinfo) && (($userinfo['adminsession'] == '1' && \Froxlor\Settings::Get('system.allow_error_report_admin') == '1') || ($userinfo['adminsession'] == '0' && \Froxlor\Settings::Get('system.allow_error_report_customer') == '1'))) {
|
||||
$err_report_html = '<a href="<LINK>" title="Click here to report error">Report error</a>';
|
||||
$err_report_html = str_replace("<LINK>", $linker->getLink(array(
|
||||
$err_report_link = $linker->getLink(array(
|
||||
'section' => 'index',
|
||||
'page' => 'send_error_report',
|
||||
'errorid' => $errid
|
||||
)), $err_report_html);
|
||||
));
|
||||
}
|
||||
$err_hint = str_replace("<REPORT>", $err_report_html, $err_hint);
|
||||
|
||||
// show
|
||||
die($err_hint);
|
||||
}
|
||||
\Froxlor\UI\Panel\UI::initTwig(true);
|
||||
\Froxlor\UI\Panel\UI::Twig()->addGlobal('install_mode', '1');
|
||||
\Froxlor\UI\Panel\UI::TwigBuffer('misc/dberrornice.html.twig', [
|
||||
'page_title' => 'Database error',
|
||||
'message' => $error_message,
|
||||
'debug' => $error_trace,
|
||||
'report' => $err_report_link
|
||||
]);
|
||||
echo \Froxlor\UI\Panel\UI::TwigOutputBuffer();
|
||||
die();
|
||||
}
|
||||
die("We are sorry, but a MySQL - error occurred. The administrator may find more information in the syslog");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generate safe unique token
|
||||
*
|
||||
* @param int $length
|
||||
* @return string
|
||||
*/
|
||||
private static function genUniqueToken(int $length = 16)
|
||||
{
|
||||
if (!isset($length) || intval($length) <= 8) {
|
||||
$length = 16;
|
||||
}
|
||||
if (function_exists('random_bytes')) {
|
||||
return bin2hex(random_bytes($length));
|
||||
}
|
||||
if (function_exists('mcrypt_create_iv')) {
|
||||
return bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM));
|
||||
}
|
||||
if (function_exists('openssl_random_pseudo_bytes')) {
|
||||
return bin2hex(openssl_random_pseudo_bytes($length));
|
||||
}
|
||||
// if everything else fails, use unsafe fallback
|
||||
return substr(md5(uniqid(microtime(), 1)), 0, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitutes patterns in content.
|
||||
*
|
||||
|
||||
26
templates/Froxlor/misc/dberrornice.html.twig
Normal file
26
templates/Froxlor/misc/dberrornice.html.twig
Normal file
@@ -0,0 +1,26 @@
|
||||
{% extends "Froxlor/base.html.twig" %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container my-auto">
|
||||
<div class="alert alert-danger fade show" role="alert">
|
||||
<h4 class="alert-heading">
|
||||
A database error occurred
|
||||
</h4>
|
||||
<p>
|
||||
{{ message }}
|
||||
</p>
|
||||
{% if debug is not empty %}
|
||||
<hr>
|
||||
<p class="mb-0">
|
||||
<pre>{{ debug }}</pre>
|
||||
</p>
|
||||
{% endif %}
|
||||
<p class="mt-1 text-center">
|
||||
<a href="#" class="btn btn-primary" title="Click here to go back" id="historyback">Go back</a>
|
||||
{% if report is not empty %}
|
||||
<a href="{{ report|raw }}" class="btn btn-warning" title="Click here to report error">Report error</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user