From 92527b0b2d8a76ee8ae368541c60d0a07c889dbc Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 26 Feb 2020 15:19:34 +0100 Subject: [backup/systemstatus] Show up/downloads in backup page Add AJAX API to dozmod module to query the fileserver status of dmsd. --- .../backup/lang/de/template-tags.json | 3 + .../backup/lang/en/template-tags.json | 3 + modules-available/backup/templates/_page.html | 21 +++++- modules-available/dozmod/page.inc.php | 59 +-------------- modules-available/dozmod/pages/special.inc.php | 85 ++++++++++++++++++++++ modules-available/dozmod/templates/blockstats.html | 5 +- .../systemstatus/lang/de/messages.json | 1 - .../systemstatus/lang/de/template-tags.json | 4 +- .../systemstatus/lang/en/messages.json | 1 - .../systemstatus/lang/en/template-tags.json | 4 +- modules-available/systemstatus/page.inc.php | 27 ++----- .../systemstatus/templates/_page.html | 27 ++++++- .../systemstatus/templates/ajax-reboot.html | 14 ---- 13 files changed, 150 insertions(+), 104 deletions(-) create mode 100644 modules-available/dozmod/pages/special.inc.php delete mode 100644 modules-available/systemstatus/templates/ajax-reboot.html diff --git a/modules-available/backup/lang/de/template-tags.json b/modules-available/backup/lang/de/template-tags.json index 907e6b07..7f5e05ab 100644 --- a/modules-available/backup/lang/de/template-tags.json +++ b/modules-available/backup/lang/de/template-tags.json @@ -1,4 +1,5 @@ { + "lang_automaticRebootHint": "Nach dem Import der Konfiguration wird der Server automatisch neugestartet. Bitte stellen Sie daher sicher, dass zur Zeit keine wichtigen Veranstaltungen laufen, oder Up-\/Downloads der bwLehrpool-Suite.", "lang_backup": "Sichern", "lang_backupDescription": "Hier k\u00f6nnen Sie die Konfiguration des Satellitenservers sichern. Dies beinhaltet die Datenbank \u00fcber alle Virtuellen Maschinen, Veranstaltungen, Authentifizerungsmodule, Passw\u00f6rter, Proxies, den konfigurierten VM-Store sowie weitere Konfiguration des MiniLinux.\r\nDie Festplattenabbilder der Virtuellen Maschinen auf dem VM-Store werden hierbei nicht gesichert. Eventuelle Backups des Stores m\u00fcssen separat durchgef\u00fchrt werden.", "lang_backupRestore": "Sichern und Wiederherstellen", @@ -13,6 +14,8 @@ "lang_restoreDozmodConfig": "bwLehrpool-Suite-Konfiguration wiederherstellen", "lang_restoreFailed": "Wiederherstellung der Konfiguration fehlgeschlagen.", "lang_restoreSystemConfig": "Systemkonfiguration wiederherstellen", + "lang_runningDownloads": "Laufende VM-Downloads", + "lang_runningUploads": "Laufenden VM-Uploads", "lang_selectFile": "Bitte w\u00e4hlen Sie ein Backup-Archiv", "lang_stopping": "Stoppe", "lang_systemExplanation": "Die Grundkonfiguration des Satelliten wiederherstellen: Authentifizierungmethode, Passw\u00f6rter, Proxies, VM-Storage, etc.\r\nACHTUNG: Wenn Sie ein Backup von vor WS15\/16 einspielen (Backup-Format vor Version 10), wird die Systemkonfiguration in jedem Fall wiederhergestellt, auch wenn Sie diesen Haken nicht setzen.", diff --git a/modules-available/backup/lang/en/template-tags.json b/modules-available/backup/lang/en/template-tags.json index b70ce793..d14c9070 100644 --- a/modules-available/backup/lang/en/template-tags.json +++ b/modules-available/backup/lang/en/template-tags.json @@ -1,4 +1,5 @@ { + "lang_automaticRebootHint": "The server will be rebooted once the import is finished. Please make sure there are no important courses or bwLehrpool-Suite up-\/downloads running.", "lang_backup": "Backup", "lang_backupDescription": "Here you can backup the complete configuration of this satellite server. This includes lecture and virtual machine meta data. The HDD images of the virtual machines on the vm store are not included in this backup, because of their size. If desired, the store needs to be backed up manually.", "lang_backupRestore": "Backup and Restore", @@ -13,6 +14,8 @@ "lang_restoreDozmodConfig": "Restore bwLehrpool-Suite config", "lang_restoreFailed": "Restoring configuration failed.", "lang_restoreSystemConfig": "Restore system config", + "lang_runningDownloads": "Running VM downloads", + "lang_runningUploads": "Running VM uploads", "lang_selectFile": "Please select a backup archive", "lang_stopping": "Stopping", "lang_systemExplanation": "Restore basic configuration like authentication method, passwords, vm storage location, proxy config, etc. WARNING: If you restore a configuration backup that was made before WS15\/16 (backup format version <10), the system configuration will be restored regardless of this check mark.", diff --git a/modules-available/backup/templates/_page.html b/modules-available/backup/templates/_page.html index fa88b966..3e57c033 100644 --- a/modules-available/backup/templates/_page.html +++ b/modules-available/backup/templates/_page.html @@ -48,7 +48,26 @@

{{lang_dozmodExplanation}}

+

{{lang_automaticRebootHint}}

+
+ {{lang_runningUploads}}: ??, + {{lang_runningDownloads}}: ?? +
- \ No newline at end of file + + + \ No newline at end of file diff --git a/modules-available/dozmod/page.inc.php b/modules-available/dozmod/page.inc.php index 67b791d1..57e5ca4c 100644 --- a/modules-available/dozmod/page.inc.php +++ b/modules-available/dozmod/page.inc.php @@ -5,7 +5,8 @@ class Page_DozMod extends Page /** @var bool true if we have a proper subpage */ private $haveSubPage = false; - private $validSections = ['expiredimages', 'mailconfig', 'templates', 'runtimeconfig', 'users', 'actionlog', 'networkshares', 'ldapfilters', 'runscripts', 'networkrules']; + private $validSections = ['expiredimages', 'mailconfig', 'templates', 'runtimeconfig', 'users', 'actionlog', + 'networkshares', 'ldapfilters', 'runscripts', 'networkrules', 'special']; private $section; @@ -15,8 +16,6 @@ class Page_DozMod extends Page return; /* different pages for different sections */ $this->section = Request::any('section', false, 'string'); - if ($this->section === 'blockstats') // HACK HACK - return; if ($this->section === false) { foreach ($this->validSections as $this->section) { if (User::hasPermission($this->section . '.*')) @@ -82,26 +81,6 @@ class Page_DozMod extends Page return; } - if ($this->section === 'blockstats') { - $this->showBlockStats(); - } - - } - - private function showBlockStats() - { - $res = Database::simpleQuery("SELECT blocksha1, blocksize, Count(*) AS blockcount FROM sat.imageblock" - . " GROUP BY blocksha1, blocksize HAVING blockcount > 1 ORDER BY blockcount DESC, blocksha1 ASC"); - $data = array('hashes' => array()); - $spaceWasted = 0; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $row['hash_hex'] = bin2hex($row['blocksha1']); - $row['blocksize_s'] = Util::readableFileSize($row['blocksize']); - $data['hashes'][] = $row; - $spaceWasted += $row['blocksize'] * ($row['blockcount'] - 1); - } - $data['spacewasted'] = Util::readableFileSize($spaceWasted); - Render::addTemplate('blockstats', $data); } protected function doAjax() @@ -114,40 +93,6 @@ class Page_DozMod extends Page return; } - $action = Request::post('action'); - - if ($action === 'getblockinfo') { - $this->ajaxGetBlockInfo(); - } - } - - private function ajaxGetBlockInfo() - { - $hash = Request::any('hash', false, 'string'); - $size = Request::any('size', false, 'string'); - if ($hash === false || $size === false) { - die('Missing parameter'); - } - if (!is_numeric($size) || strlen($hash) !== 40 || !preg_match('/^[a-f0-9]+$/i', $hash)) { - die('Malformed parameter'); - } - $res = Database::simpleQuery("SELECT i.displayname, v.createtime, v.filesize, Count(*) AS blockcount FROM sat.imageblock ib" - . " INNER JOIN sat.imageversion v USING (imageversionid)" - . " INNER JOIN sat.imagebase i USING (imagebaseid)" - . " WHERE ib.blocksha1 = :hash AND ib.blocksize = :size" - . " GROUP BY ib.imageversionid" - . " ORDER BY i.displayname ASC, v.createtime ASC", - array('hash' => hex2bin($hash), 'size' => $size), true); - if ($res === false) { - die('Database error: ' . Database::lastError()); - } - $data = array('rows' => array()); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $row['createtime_s'] = date('d.m.Y H:i', $row['createtime']); - $row['filesize_s'] = Util::readableFileSize($row['filesize']); - $data['rows'][] = $row; - } - die(Render::parse('blockstats-details', $data)); } } diff --git a/modules-available/dozmod/pages/special.inc.php b/modules-available/dozmod/pages/special.inc.php new file mode 100644 index 00000000..5a532b51 --- /dev/null +++ b/modules-available/dozmod/pages/special.inc.php @@ -0,0 +1,85 @@ + 1 ORDER BY blockcount DESC, blocksha1 ASC"); + $data = array('hashes' => array()); + $spaceWasted = 0; + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $row['hash_hex'] = bin2hex($row['blocksha1']); + $row['blocksize_s'] = Util::readableFileSize($row['blocksize']); + $data['hashes'][] = $row; + $spaceWasted += $row['blocksize'] * ($row['blockcount'] - 1); + } + $data['spacewasted'] = Util::readableFileSize($spaceWasted); + Render::addTemplate('blockstats', $data); + } + + public static function doAjax() + { + $action = Request::any('action'); + + if ($action === 'getblockinfo') { + self::ajaxGetBlockInfo(); + } elseif ($action === 'dmsd-status') { + self::ajaxDmsdStatus(); + } + } + + private static function ajaxGetBlockInfo() + { + $hash = Request::any('hash', false, 'string'); + $size = Request::any('size', false, 'string'); + if ($hash === false || $size === false) { + die('Missing parameter'); + } + if (!is_numeric($size) || strlen($hash) !== 40 || !preg_match('/^[a-f0-9]+$/i', $hash)) { + die('Malformed parameter'); + } + $res = Database::simpleQuery("SELECT i.displayname, v.createtime, v.filesize, Count(*) AS blockcount FROM sat.imageblock ib" + . " INNER JOIN sat.imageversion v USING (imageversionid)" + . " INNER JOIN sat.imagebase i USING (imagebaseid)" + . " WHERE ib.blocksha1 = :hash AND ib.blocksize = :size" + . " GROUP BY ib.imageversionid" + . " ORDER BY i.displayname ASC, v.createtime ASC", + array('hash' => hex2bin($hash), 'size' => $size), true); + if ($res === false) { + die('Database error: ' . Database::lastError()); + } + $data = array('rows' => array()); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $row['createtime_s'] = date('d.m.Y H:i', $row['createtime']); + $row['filesize_s'] = Util::readableFileSize($row['filesize']); + $data['rows'][] = $row; + } + die(Render::parse('blockstats-details', $data)); + } + + private static function ajaxDmsdStatus() + { + $ret = Download::asStringPost('http://127.0.0.1:9080/status/fileserver', false, 2, $code); + $args = array(); + if ($code != 200) { + $args['error'] = true; + } else { + $data = @json_decode($ret, true); + if (is_array($data)) { + $args['uploads'] = $data['activeUploads']; + $args['downloads'] = $data['activeDownloads']; + } + } + Header('Content-Type: application/json'); + echo json_encode($args); + } + +} \ No newline at end of file diff --git a/modules-available/dozmod/templates/blockstats.html b/modules-available/dozmod/templates/blockstats.html index cba3b476..b71d219c 100644 --- a/modules-available/dozmod/templates/blockstats.html +++ b/modules-available/dozmod/templates/blockstats.html @@ -30,8 +30,9 @@ \ No newline at end of file diff --git a/modules-available/systemstatus/lang/de/messages.json b/modules-available/systemstatus/lang/de/messages.json index 1a6df1b3..44e4fad1 100644 --- a/modules-available/systemstatus/lang/de/messages.json +++ b/modules-available/systemstatus/lang/de/messages.json @@ -1,4 +1,3 @@ { - "reboot-unconfirmed": "Sicherheitsabfrage zum Reboot nicht best\u00e4tigt", "update-reboot-required": "Das Update der folgenden Pakete erfordert einen Reboot des Servers: {{0}}" } \ No newline at end of file diff --git a/modules-available/systemstatus/lang/de/template-tags.json b/modules-available/systemstatus/lang/de/template-tags.json index eeb75f9a..27760c1e 100644 --- a/modules-available/systemstatus/lang/de/template-tags.json +++ b/modules-available/systemstatus/lang/de/template-tags.json @@ -7,7 +7,6 @@ "lang_capacity": "Kapazit\u00e4t", "lang_cpuLoad": "CPU-Last", "lang_dmsdUnreachable": "dmsd nicht erreichbar", - "lang_downloads": "Downloads", "lang_failure": "Fehler", "lang_foundStore": "Vorgefunden:", "lang_free": "Frei", @@ -20,6 +19,8 @@ "lang_onlyOS": "Nur OS", "lang_overview": "\u00dcbersicht", "lang_ramUsage": "RAM-Nutzung", + "lang_runningDownloads": "Aktive Downloads", + "lang_runningUploads": "Aktive Uploads", "lang_serverReboot": "Server neustarten", "lang_services": "Dienste", "lang_space": "Speicherplatz", @@ -33,7 +34,6 @@ "lang_total": "Gesamt", "lang_unknownState": "Unbekannter Status", "lang_updatedPackages": "Ausstehende Updates", - "lang_uploads": "Uploads", "lang_uptimeOS": "OS Uptime", "lang_vmStore": "VM-Speicher", "lang_vmStoreError": "Fehler beim Ermitteln des verf\u00fcgbaren Speicherplatzes am VM-Speicherort. Bitte \u00fcberpr\u00fcfen Sie die Konfiguration." diff --git a/modules-available/systemstatus/lang/en/messages.json b/modules-available/systemstatus/lang/en/messages.json index 5098eb76..c38c8e66 100644 --- a/modules-available/systemstatus/lang/en/messages.json +++ b/modules-available/systemstatus/lang/en/messages.json @@ -1,4 +1,3 @@ { - "reboot-unconfirmed": "Confirmation prompt to reboot not confirmed", "update-reboot-required": "Updating the following system packages requires reboot: {{0}}" } \ No newline at end of file diff --git a/modules-available/systemstatus/lang/en/template-tags.json b/modules-available/systemstatus/lang/en/template-tags.json index 5f6ad898..90e0576a 100644 --- a/modules-available/systemstatus/lang/en/template-tags.json +++ b/modules-available/systemstatus/lang/en/template-tags.json @@ -7,7 +7,6 @@ "lang_capacity": "Capacity", "lang_cpuLoad": "CPU Load", "lang_dmsdUnreachable": "dmsd not reachable", - "lang_downloads": "Downloads", "lang_failure": "Failure", "lang_foundStore": "Found:", "lang_free": "Free", @@ -20,6 +19,8 @@ "lang_onlyOS": "OS Only", "lang_overview": "Overview", "lang_ramUsage": "RAM Usage", + "lang_runningDownloads": "Running downloads", + "lang_runningUploads": "Running uploads", "lang_serverReboot": "Reboot Server", "lang_services": "Services", "lang_space": "Space", @@ -33,7 +34,6 @@ "lang_total": "Total", "lang_unknownState": "Unknown status", "lang_updatedPackages": "Pending updates", - "lang_uploads": "Uploads", "lang_uptimeOS": "OS Uptime", "lang_vmStore": "VM Store", "lang_vmStoreError": "Error determining available space of the VM storage. Please check the configuration." diff --git a/modules-available/systemstatus/page.inc.php b/modules-available/systemstatus/page.inc.php index 74ed3f47..6876d0b5 100644 --- a/modules-available/systemstatus/page.inc.php +++ b/modules-available/systemstatus/page.inc.php @@ -37,6 +37,11 @@ class Page_SystemStatus extends Page ); } Permission::addGlobalTags($data['perms'], null, ['serverreboot']); + if (file_exists('/run/reboot-required.pkgs')) { + $lines = file('/run/reboot-required.pkgs', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $lines = array_unique($lines); + $data['packages'] = implode(', ', $lines); + } Render::addTemplate('_page', $data); } @@ -55,28 +60,6 @@ class Page_SystemStatus extends Page echo "Action $action not known in " . get_class(); } } - - protected function ajaxDmsdUsers() - { - User::assertPermission("show.overview.dmsdusers"); - $ret = Download::asStringPost('http://127.0.0.1:9080/status/fileserver', false, 2, $code); - $args = array(); - if ($code != 200) { - $args['dmsd_error'] = true; - } else { - $data = @json_decode($ret, true); - if (is_array($data)) { - $args['uploads'] = $data['activeUploads']; - $args['downloads'] = $data['activeDownloads']; - } - } - if (file_exists('/run/reboot-required.pkgs')) { - $lines = file('/run/reboot-required.pkgs', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - $lines = array_unique($lines); - $args['packages'] = implode(', ', $lines); - } - echo Render::parse('ajax-reboot', $args); - } protected function ajaxDiskStat() { diff --git a/modules-available/systemstatus/templates/_page.html b/modules-available/systemstatus/templates/_page.html index 3d0f9dfb..f879ea7a 100644 --- a/modules-available/systemstatus/templates/_page.html +++ b/modules-available/systemstatus/templates/_page.html @@ -100,7 +100,16 @@ -
+
+ {{lang_runningUploads}}: ??, + {{lang_runningDownloads}}: ?? +
{{lang_dmsdUnreachable}}
+
+
+ {{#packages}} + {{lang_updatedPackages}}: {{packages}} + {{/packages}} +
@@ -123,7 +132,6 @@ $('#addresses').load('?do=SystemStatus&action=AddressList'); $('#systeminfo').load('?do=SystemStatus&action=SystemInfo'); $('#services').load('?do=SystemStatus&action=Services'); - $('#dmsd-users').load('?do=SystemStatus&action=DmsdUsers'); var slxDone = {}; $('.ajax-tab').on('shown.bs.tab', function (e) { var $this = $(this); @@ -134,5 +142,20 @@ $pane.load('?do=SystemStatus&action=' + w.substring(3)); } }); + var $dmsd = $('#dmsd-users'); + $.ajax({ + url: '?do=dozmod§ion=special&action=dmsd-status', + timeout: 3000, + dataType: 'json' + }).done(function (data) { + if (!data || data.error) { + $dmsd.find('.alert').show(); + } else { + if (data.downloads !== null) $dmsd.find('.downloads').text(data.downloads); + if (data.uploads !== null) $dmsd.find('.uploads').text(data.uploads); + } + }).fail(function () { + $dmsd.find('.alert').show(); + }); }, false); //--> diff --git a/modules-available/systemstatus/templates/ajax-reboot.html b/modules-available/systemstatus/templates/ajax-reboot.html deleted file mode 100644 index a1aaf1e6..00000000 --- a/modules-available/systemstatus/templates/ajax-reboot.html +++ /dev/null @@ -1,14 +0,0 @@ -
- {{^dmsd_error}} - {{lang_uploads}}: {{uploads}}, - {{lang_downloads}}: {{downloads}} - {{/dmsd_error}} - {{#dmsd_error}} -
{{lang_dmsdUnreachable}}
- {{/dmsd_error}} -
-
- {{#packages}} - {{lang_updatedPackages}}: {{packages}} - {{/packages}} -
\ No newline at end of file -- cgit v1.2.3-55-g7522