From f836342ff2b5c7cfb80691be7e523957b640e167 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Thu, 17 Feb 2022 13:58:29 +0100 Subject: [PATCH] newsfeed + more admin dashboard info Signed-off-by: Michael Kaufmann --- admin_index.php | 36 +++--- lib/ajax.php | 47 +++---- templates/Froxlor/src/main.js | 28 ++++- templates/Froxlor/user/index.html.twig | 116 +++++++++++++++++- templates/Froxlor/user/newsfeeditem.html.twig | 9 ++ 5 files changed, 181 insertions(+), 55 deletions(-) create mode 100644 templates/Froxlor/user/newsfeeditem.html.twig diff --git a/admin_index.php b/admin_index.php index 8bcdadea..067ad4a8 100644 --- a/admin_index.php +++ b/admin_index.php @@ -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') { diff --git a/lib/ajax.php b/lib/ajax.php index d6823768..42c72eca 100644 --- a/lib/ajax.php +++ b/lib/ajax.php @@ -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 "
  • -
    -
    - "; - if (! empty($link)) { - echo ""; - } - echo $title; - if (! empty($link)) { - echo ""; - } - echo ""; - if (! empty($date)) { - echo " - {$date} - "; - } - echo "
    -

    - {$content} -

    -
    -
  • "; -} diff --git a/templates/Froxlor/src/main.js b/templates/Froxlor/src/main.js index 8c9bfaef..321c3a40 100644 --- a/templates/Froxlor/src/main.js +++ b/templates/Froxlor/src/main.js @@ -2,4 +2,30 @@ import 'bootstrap'; // load jquery -window.$ = window.jQuery = require('jquery'); \ No newline at end of file +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(''); + } + }); + } + +}); diff --git a/templates/Froxlor/user/index.html.twig b/templates/Froxlor/user/index.html.twig index cf607dd2..a7323319 100644 --- a/templates/Froxlor/user/index.html.twig +++ b/templates/Froxlor/user/index.html.twig @@ -13,23 +13,126 @@ {% endif %}
    -
    +

    Test

    -
    + {% if userinfo.adminsession == 1 %} +
    + {# system infos #} +
    + + {{ lng('admin.systemdetails') }} +
    +
      +
    • +
      +
      {{ lng('admin.hostname') }}
      + {{ sysinfo.hostname }} +
      +
    • +
    • +
      +
      {{ lng('admin.serversoftware') }}
      + {{ sysinfo.webserver }} +
      +
    • +
    • +
      +
      {{ lng('admin.phpversion') }}
      + {{ sysinfo.phpversion }} +
      +
    • +
    • +
      +
      {{ lng('admin.mysqlserverversion') }}
      + {{ sysinfo.mysqlserverversion }} +
      +
    • +
    • +
      +
      {{ lng('admin.webserverinterface') }}
      + {{ sysinfo.phpsapi }} +
      +
    • + {% if sysinfo.memory is not empty %} +
    • +
      +
      {{ lng('admin.memory') }}
      +
      {{ sysinfo.memory }}
      +
      +
    • + {% endif %} +
    • +
      +
      {{ lng('admin.sysload') }}
      + {{ sysinfo.load }} +
      +
    • + {% if sysinfo.kernel is not empty %} +
    • +
      +
      Kernel
      + {{ sysinfo.kernel }} +
      +
    • + {% endif %} + {% if sysinfo.uptime is not empty %} +
    • +
      +
      Uptime
      + {{ sysinfo.uptime }} +
      +
    • + {% endif %} +
    +
    +
    + {% endif %} +
    + {# 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 #} +
    +
    + + News +
    +
    +
    +
    + Loading newsfeed... +
    + + + +
    +
    +
    + {% elseif userinfo.adminsession == 1 and get_setting('admin.show_news_feed') == 0 %} +
    +
    + + News +
    +
    + + {{ lng('panel.newsfeed_disabled') }}  + + + +
    +
    {% endif %} {% if userinfo.adminsession == 1 %} {# custom notes #} {% if userinfo.custom_notes is not empty and userinfo.custom_notes_show == 1 %} -
    +
    {{ userinfo.custom_notes }}
    @@ -41,7 +144,7 @@ {% else %} {# account info #} -
    +
    {{ lng('index.accountdetails') }} @@ -101,7 +204,8 @@
    -
    + {# customer details #} +
    {{ lng('index.customerdetails') }} diff --git a/templates/Froxlor/user/newsfeeditem.html.twig b/templates/Froxlor/user/newsfeeditem.html.twig new file mode 100644 index 00000000..d79fee3c --- /dev/null +++ b/templates/Froxlor/user/newsfeeditem.html.twig @@ -0,0 +1,9 @@ + +
    +
    {{ title }}
    + {% if date is not empty %} + {{ date }} + {% endif %} +
    +

    {{ content|raw }}

    +