newsfeed + more admin dashboard info

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann 2022-02-17 13:58:29 +01:00
parent 402a91c841
commit f836342ff2
No known key found for this signature in database
GPG Key ID: 08A83830520FCECB
5 changed files with 181 additions and 55 deletions

View File

@ -90,10 +90,6 @@ if ($page == 'overview') {
$overview['number_domains'] = $number_domains['number_domains'];
$phpversion = phpversion();
$mysqlserverversion = Database::getAttribute(PDO::ATTR_SERVER_VERSION);
$webserverinterface = strtoupper(@php_sapi_name());
if ((isset($_GET['lookfornewversion']) && $_GET['lookfornewversion'] == 'yes') || (isset($lookfornewversion) && $lookfornewversion == 'yes')) {
try {
$json_result = Froxlor::getLocal($userinfo)->checkUpdate();
@ -133,10 +129,10 @@ if ($page == 'overview') {
$cron_last_runs = \Froxlor\System\Cronjob::getCronjobsLastRun();
$outstanding_tasks = \Froxlor\System\Cronjob::getOutstandingTasks();
$system_hostname = gethostname();
// additional sys-infos
$meminfo = explode("\n", @file_get_contents("/proc/meminfo"));
$memory = "";
for ($i = 0; $i < sizeof($meminfo); ++ $i) {
for ($i = 0; $i < count($meminfo); ++ $i) {
if (substr($meminfo[$i], 0, 3) === "Mem") {
$memory .= $meminfo[$i] . PHP_EOL;
}
@ -147,25 +143,21 @@ if ($page == 'overview') {
$load = number_format($loadArray[0], 2, '.', '') . " / " . number_format($loadArray[1], 2, '.', '') . " / " . number_format($loadArray[2], 2, '.', '');
} else {
$load = @file_get_contents('/proc/loadavg');
if (! $load) {
$load = $lng['admin']['noloadavailable'];
}
}
$kernel = '';
if (function_exists('posix_uname')) {
$showkernel = 1;
$kernel_nfo = posix_uname();
$kernel = $kernel_nfo['release'] . ' (' . $kernel_nfo['machine'] . ')';
} else {
$showkernel = 0;
$kernel = '';
}
// Try to get the uptime
// First: With exec (let's hope it's enabled for the Froxlor - vHost)
$uptime_array = explode(" ", @file_get_contents("/proc/uptime"));
$uptime = '';
if (is_array($uptime_array) && isset($uptime_array[0]) && is_numeric($uptime_array[0])) {
// Some calculatioon to get a nicly formatted display
$seconds = round($uptime_array[0], 0);
@ -176,17 +168,27 @@ if ($page == 'overview') {
$minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60));
$seconds = floor($seconds - ($days * 24 * 60 * 60) - ($hours * 60 * 60) - ($minutes * 60));
$uptime = "{$days}d, {$hours}h, {$minutes}m, {$seconds}s";
// Just cleanup
unset($uptime_array, $seconds, $minutes, $hours, $days);
} else {
// Nothing of the above worked, show an error :/
$uptime = '';
}
$sysinfo = [
'webserver' => $_SERVER['SERVER_SOFTWARE'] ?? 'unknown',
'phpversion' => phpversion(),
'mysqlserverversion' => Database::getAttribute(PDO::ATTR_SERVER_VERSION),
'phpsapi' => strtoupper(@php_sapi_name()),
'hostname' => gethostname(),
'memory' => $memory,
'load' => $load,
'kernel' => $kernel,
'uptime' => $uptime
];
// @fixme add all the overview/dashboard data from above
UI::Twig()->addGlobal('userinfo', $userinfo);
UI::TwigBuffer('user/index.html.twig');
UI::TwigBuffer('user/index.html.twig', [
'sysinfo' => $sysinfo
]);
UI::TwigOutputBuffer();
} elseif ($page == 'change_password') {

View File

@ -18,12 +18,14 @@
require_once dirname(__DIR__) . '/vendor/autoload.php';
// Load the user settings
if (! file_exists('./userdata.inc.php')) {
if (!file_exists('./userdata.inc.php')) {
die();
}
require './userdata.inc.php';
require './tables.inc.php';
use Froxlor\UI\Panel\UI;
if (isset($_POST['action'])) {
$action = $_POST['action'];
} elseif (isset($_GET['action'])) {
@ -32,7 +34,12 @@ if (isset($_POST['action'])) {
$action = "";
}
$theme = $_GET['theme'] ?? 'Froxlor';
if ($action == "newsfeed") {
UI::initTwig();
if (isset($_GET['role']) && $_GET['role'] == "customer") {
$feed = \Froxlor\Settings::Get("customer.news_feed_url");
if (empty(trim($feed))) {
@ -56,16 +63,21 @@ if ($action == "newsfeed") {
}
if ($news !== false) {
for ($i = 0; $i < 3; $i ++) {
for ($i = 0; $i < 3; $i++) {
$item = $news->channel->item[$i];
$title = (string) $item->title;
$link = (string) $item->link;
$date = date("Y-m-d G:i", strtotime($item->pubDate));
$date = date("d.m.Y", strtotime($item->pubDate));
$content = preg_replace("/[\r\n]+/", " ", strip_tags($item->description));
$content = substr($content, 0, 150) . "...";
outputItem($title, $content, $link, $date);
echo UI::Twig()->render($theme . '/user/newsfeeditem.html.twig', [
'link' => $link,
'title' => $title,
'date' => $date,
'content' => $content
]);
}
} else {
echo "";
@ -73,30 +85,3 @@ if ($action == "newsfeed") {
} else {
echo "No action set.";
}
function outputItem($title, $content, $link = null, $date = null)
{
echo "<li class=\"clearfix\">
<div class=\"newsfeed-body clearfix\">
<div class=\"header\">
<strong class=\"primary-font\">";
if (! empty($link)) {
echo "<a href=\"{$link}\" target=\"_blank\">";
}
echo $title;
if (! empty($link)) {
echo "</a>";
}
echo "</strong>";
if (! empty($date)) {
echo "<small class=\"pull-right text-muted\">
<i class=\"fa fa-clock-o fa-fw\"></i> {$date}
</small>";
}
echo "</div>
<p>
{$content}
</p>
</div>
</li>";
}

View File

@ -2,4 +2,30 @@
import 'bootstrap';
// load jquery
window.$ = window.jQuery = require('jquery');
window.$ = window.jQuery = require('jquery');
$(document).ready(function () {
const mytheme = 'Froxlor';
/*
* newsfeed
*/
if (document.getElementById('newsfeed')) {
var role = "";
if (typeof $("#newsfeed").data("role") !== "undefined") {
role = "&role=" + $("#newsfeed").data("role");
}
$.ajax({
url : "lib/ajax.php?action=newsfeed" + role + "&theme=" + mytheme,
type : "GET",
success : function(data) {
$("#newsfeeditems").html(data);
},
error : function(a, b) {
$("#newsfeeditems").html('<div class="alert alert-warning" role="alert">Error loading newsfeed</div>');
}
});
}
});

View File

@ -13,23 +13,126 @@
{% endif %}
<div class="row">
<div class="col-12 col-xl-8 mb-3 mb-xl-0">
<div class="col-12 {% if userinfo.adminsession == 1 %}col-xl-4{% else %}col-xl-8{% endif %} mb-3 mb-xl-0">
<div class="card">
<div class="card-body">
<p>Test</p>
</div>
</div>
</div>
<div class="col-12 col-xl-4">
{% if userinfo.adminsession == 1 %}
<div class="col-12 col-xl-4 mb-3 mb-xl-0">
{# system infos #}
<div class="card mb-3"> <div class="card-header">
<i class="fa-solid fa-gears"></i>
{{ lng('admin.systemdetails') }}
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
<div class="fw-bold">{{ lng('admin.hostname') }}</div>
{{ sysinfo.hostname }}
</div>
</li>
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
<div class="fw-bold">{{ lng('admin.serversoftware') }}</div>
{{ sysinfo.webserver }}
</div>
</li>
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
<div class="fw-bold">{{ lng('admin.phpversion') }}</div>
<a href="{{ linker({'section':'settings','page':'phpinfo'}) }}">{{ sysinfo.phpversion }}</a>
</div>
</li>
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
<div class="fw-bold">{{ lng('admin.mysqlserverversion') }}</div>
{{ sysinfo.mysqlserverversion }}
</div>
</li>
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
<div class="fw-bold">{{ lng('admin.webserverinterface') }}</div>
{{ sysinfo.phpsapi }}
</div>
</li>
{% if sysinfo.memory is not empty %}
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
<div class="fw-bold">{{ lng('admin.memory') }}</div>
<pre>{{ sysinfo.memory }}</pre>
</div>
</li>
{% endif %}
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
<div class="fw-bold">{{ lng('admin.sysload') }}</div>
{{ sysinfo.load }}
</div>
</li>
{% if sysinfo.kernel is not empty %}
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
<div class="fw-bold">Kernel</div>
{{ sysinfo.kernel }}
</div>
</li>
{% endif %}
{% if sysinfo.uptime is not empty %}
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
<div class="fw-bold">Uptime</div>
{{ sysinfo.uptime }}
</div>
</li>
{% endif %}
</ul>
</div>
</div>
{% endif %}
<div
class="col-12 col-xl-4">
{# newsfeed #}
{% if (userinfo.adminsession == 1 and get_setting('admin.show_news_feed') == 1) or (userinfo.adminsession == 0 and get_setting('customer.show_news_feed') == 1) %}
{# newsfeed #}
<div class="card mb-3" id="newsfeed" {% if userinfo.adminsession == 0 %} data-role="customer" {% endif %}>
<div class="card-header">
<i class="fa-solid fa-rss"></i>
News
</div>
<div class="list-group list-group-flush" id="newsfeeditems">
<div class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
Loading newsfeed...
</div>
<span>
<i class="fa-solid fa-spinner fa-spin"></i>
</span>
</div>
</div>
</div>
{% elseif userinfo.adminsession == 1 and get_setting('admin.show_news_feed') == 0 %}
<div class="card bg-warning text-dark mb-3">
<div class="card-header">
<i class="fa-solid fa-rss"></i>
News
</div>
<div class="card-body">
<i class="fa-solid fa-circle-exclamation"></i>
{{ lng('panel.newsfeed_disabled') }}&nbsp;
<a href="{{ linker({'section':'settings','part':'panel'}) }}" title="{{ lng('panel.edit') }}">
<i class="fa-solid fa-pen"></i>
</a>
</div>
</div>
{% endif %}
{% if userinfo.adminsession == 1 %}
{# custom notes #}
{% if userinfo.custom_notes is not empty and userinfo.custom_notes_show == 1 %}
<div class="card bg-info text-dark">
<div class="card bg-info text-dark mb-3">
<div class="card-body">
{{ userinfo.custom_notes }}
</div>
@ -41,7 +144,7 @@
{% else %}
{# account info #}
<div class="card">
<div class="card mb-3">
<div class="card-header">
<i class="fa-solid fa-user"></i>
{{ lng('index.accountdetails') }}
@ -101,7 +204,8 @@
</ul>
</div>
<div class="card mt-3">
{# customer details #}
<div class="card">
<div class="card-header">
<i class="fa-solid fa-id-card"></i>
{{ lng('index.customerdetails') }}

View File

@ -0,0 +1,9 @@
<a href="{{ link|default('#')|raw }}" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ title }}</h5>
{% if date is not empty %}
<small>{{ date }}</small>
{% endif %}
</div>
<p class="mb-1">{{ content|raw }}</p>
</a>