diff options
author | Simon Rettberg | 2020-02-26 15:19:34 +0100 |
---|---|---|
committer | Simon Rettberg | 2020-02-26 15:19:34 +0100 |
commit | 92527b0b2d8a76ee8ae368541c60d0a07c889dbc (patch) | |
tree | fa84f70230e2d444d426fdd0b798f693d035fc8a /modules-available/dozmod | |
parent | [dnbd3] Run mount script when toggling dnbd3 usage (diff) | |
download | slx-admin-92527b0b2d8a76ee8ae368541c60d0a07c889dbc.tar.gz slx-admin-92527b0b2d8a76ee8ae368541c60d0a07c889dbc.tar.xz slx-admin-92527b0b2d8a76ee8ae368541c60d0a07c889dbc.zip |
[backup/systemstatus] Show up/downloads in backup page
Add AJAX API to dozmod module to query the fileserver status
of dmsd.
Diffstat (limited to 'modules-available/dozmod')
-rw-r--r-- | modules-available/dozmod/page.inc.php | 59 | ||||
-rw-r--r-- | modules-available/dozmod/pages/special.inc.php | 85 | ||||
-rw-r--r-- | modules-available/dozmod/templates/blockstats.html | 5 |
3 files changed, 90 insertions, 59 deletions
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 @@ +<?php + +class SubPage +{ + + + public static function doPreprocess() + { + + } + + public static function doRender() + { + $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); + } + + 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 @@ <script type="application/javascript"><!-- function slxLoadBlocks(hash, size) { $('#block-details .modal-header').text(hash + '/' + size); - $('#block-details .modal-body').html('<div class="slx-rotation"><span class="glyphicon glyphicon-refresh"></span></div>'); + $('#block-details .modal-body') + .html('<div class="slx-rotation"><span class="glyphicon glyphicon-refresh"></span></div>') + .load('?do=dozmod§ion=special', { token: TOKEN, action: 'getblockinfo', hash: hash, size: size }); $('#block-details').modal('show'); - $('#block-details .modal-body').load('?do=dozmod§ion=blockstats', { token: TOKEN, action: 'getblockinfo', hash: hash, size: size }); } //--></script>
\ No newline at end of file |