do updatecheck

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-02-22 11:37:30 +01:00
parent 60029ba1c3
commit 1974cb5217
6 changed files with 36 additions and 21 deletions

View File

@@ -1,4 +1,5 @@
<?php
namespace Froxlor\Ajax;
use Exception;
@@ -161,14 +162,20 @@ class Ajax
private function getUpdateCheck(array $session)
{
UI::initTwig();
UI::twig()->addGlobal('s', $this->session);
// TODO: set variables from current session
try {
return \Froxlor\Api\Commands\Froxlor::getLocal([
$json_result = \Froxlor\Api\Commands\Froxlor::getLocal([
'adminid' => 1,
'adminsession' => 1,
'change_serversettings' => 1,
'loginname' => 'updatecheck'
])->checkUpdate();
$result = json_decode($json_result, true)['data'];
echo UI::twig()->render($this->theme . '/misc/version_top.html.twig', $result);
exit;
} catch (Exception $e) {
\Froxlor\UI\Response::dynamic_error($e->getMessage());
}

View File

@@ -132,15 +132,22 @@ class Response
public static function dynamic_error($message)
{
global $userinfo, $s, $header, $footer, $lng, $theme;
global $lng;
$_SESSION['requestData'] = $_POST;
$link = '';
$link_ref = '';
if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) !== false) {
$link = '<a href="' . htmlentities($_SERVER['HTTP_REFERER']) . '">' . $lng['panel']['back'] . '</a>';
$link_ref = htmlentities($_SERVER['HTTP_REFERER']);
}
$error = $message;
eval("echo \"" . Template::getTemplate('misc/error', '1') . "\";");
exit();
\Froxlor\UI\Panel\UI::twigBuffer('misc/alert.html.twig', [
'type' => 'danger',
'btntype' => 'light',
'heading' => $lng['error']['error'],
'alert_msg' => $message,
'redirect_link' => $link_ref
]);
\Froxlor\UI\Panel\UI::twigOutputBuffer();
exit;
}
/**

View File

@@ -18,7 +18,7 @@
{% endif %}
{% if redirect_link %}
<p class="mt-1">
<a href="{{ redirect_link }}" class="btn btn-{{ btntype }}">{% if type == 'danger' %}{{ lng('panel.back') }}{% else %}{{ lng('success.clickheretocontinue') }}{% endif %}</a>
<a href="{{ redirect_link|raw }}" class="btn btn-{{ btntype }}">{% if type == 'danger' %}{{ lng('panel.back') }}{% else %}{{ lng('success.clickheretocontinue') }}{% endif %}</a>
</p>
{% endif %}
</div>

View File

@@ -0,0 +1,8 @@
<a class="btn {% if isnewerversion == 0 %}btn-light text-success{% else %}btn-warning{% endif %} btn-sm d-block me-2" {% if isnewerversion == 0 %} href="#" {% else %} href="admin_autoupdate.php?page=overview&s={{ s }}" {% endif %} title="{% if isnewerversion == 0 %}{{ additional_info }}{% else %}{{ message }}{% endif %}">
{% if isnewerversion == 0 %}
<i class="fa-solid fa-circle-check me-1"></i>
{% else %}
<i class="fa-solid fa-circle-exclamation me-1"></i>
{% endif %}
{{ version }}
</a>

View File

@@ -3,21 +3,15 @@ $(document).ready(function () {
* updatecheck
*/
if (document.getElementById('updatecheck')) {
let role = "";
if (typeof $("#updatecheck").data("role") !== "undefined") {
role = "&role=" + $("#newsfeed").data("role");
}
$.ajax({
url: "lib/ajax.php?action=updatecheck" + role + "&theme=" + window.$theme + "&s=" + window.$session,
url: "lib/ajax.php?action=updatecheck&theme=" + window.$theme + "&s=" + window.$session,
type: "GET",
success: function (data) {
$("#newsfeeditems").html(data);
$("#updatecheck").html(data);
},
error: function (request, status, error) {
console.log(request, status, error)
$("#newsfeeditems").html('<div class="alert alert-warning" role="alert">Error loading newsfeed</div>');
$("#updatecheck").html('<div class="alert alert-warning" role="alert">Error checking version</div>');
}
});
}

View File

@@ -32,11 +32,10 @@
</div>
<div class="collapse navbar-collapse justify-content-end px-3" id="navbar">
<ul class="navbar-nav align-items-center">
<li class="nav-item text-nowrap d-block">
<a class="btn btn-link" title="{{ lng('login.logout') }}" href="{{ linker({'section': 'index', 'action': 'logout'}) }}">
<i class="fas fa-power-off"></i>
</a>
{% if userinfo.adminsession == 1 %}
<li class="nav-item text-nowrap d-block" id="updatecheck">
</li>
{% endif %}
<li class="nav-item text-nowrap d-block me-2">
<a class="btn btn-primary btn-sm d-block" href="{{ linker({'section': 'index'}) }}">
<i class="fa fa-dashboard"></i> {{ lng('panel.dashboard') }}