From d867dec3d22ce5ea01c0189e05172a326ce15d5c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 17 Aug 2016 18:07:35 +0200 Subject: [dozmod] Add secret hidden block statistics --- modules-available/dozmod/page.inc.php | 47 ++++++++++++++++++++++ .../dozmod/templates/blockstats-details.html | 16 ++++++++ modules-available/dozmod/templates/blockstats.html | 33 +++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 modules-available/dozmod/templates/blockstats-details.html create mode 100644 modules-available/dozmod/templates/blockstats.html (limited to 'modules-available/dozmod') diff --git a/modules-available/dozmod/page.inc.php b/modules-available/dozmod/page.inc.php index 7bed2380..dfb49e0b 100644 --- a/modules-available/dozmod/page.inc.php +++ b/modules-available/dozmod/page.inc.php @@ -115,9 +115,25 @@ class Page_DozMod extends Page } Render::addTemplate('runtimeconfig', $runtimeConf); } + if ($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()); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $row['hash_hex'] = bin2hex($row['blocksha1']); + $row['blocksize_s'] = Util::readableFileSize($row['blocksize']); + $data['hashes'][] = $row; + } + Render::addTemplate('blockstats', $data); + } + private function listDeletePendingImages() { $res = Database::simpleQuery("SELECT b.displayname," @@ -182,7 +198,38 @@ class Page_DozMod extends Page $this->handleTestMail(); } elseif ($action === 'delimages') { die($this->handleDeleteImages()); + } elseif ($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)); } private function handleDeleteImages() diff --git a/modules-available/dozmod/templates/blockstats-details.html b/modules-available/dozmod/templates/blockstats-details.html new file mode 100644 index 00000000..68e03fbc --- /dev/null +++ b/modules-available/dozmod/templates/blockstats-details.html @@ -0,0 +1,16 @@ + + + + + + + + {{#rows}} + + + + + + + {{/rows}} +
{{lang_imageName}}{{lang_createTime}}{{lang_fileSize}}{{lang_blockCount}}
{{displayname}}{{createtime_s}}{{filesize_s}}{{blockcount}}
\ No newline at end of file diff --git a/modules-available/dozmod/templates/blockstats.html b/modules-available/dozmod/templates/blockstats.html new file mode 100644 index 00000000..82a66146 --- /dev/null +++ b/modules-available/dozmod/templates/blockstats.html @@ -0,0 +1,33 @@ + + + + + + + {{#hashes}} + + + + + + {{/hashes}} +
{{lang_hash}}{{lang_size}}{{lang_count}}
{{hash_hex}}{{blocksize_s}}{{blockcount}}
+ + + + \ No newline at end of file -- cgit v1.2.3-55-g7522