diff options
author | Simon Rettberg | 2016-08-17 18:07:35 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-08-17 18:07:35 +0200 |
commit | d867dec3d22ce5ea01c0189e05172a326ce15d5c (patch) | |
tree | 566b0c60e29692b96ca55ad877fd1ef29c9860b6 /modules-available/dozmod | |
parent | Clean up css a bit (diff) | |
download | slx-admin-d867dec3d22ce5ea01c0189e05172a326ce15d5c.tar.gz slx-admin-d867dec3d22ce5ea01c0189e05172a326ce15d5c.tar.xz slx-admin-d867dec3d22ce5ea01c0189e05172a326ce15d5c.zip |
[dozmod] Add secret hidden block statistics
Diffstat (limited to 'modules-available/dozmod')
-rw-r--r-- | modules-available/dozmod/page.inc.php | 47 | ||||
-rw-r--r-- | modules-available/dozmod/templates/blockstats-details.html | 16 | ||||
-rw-r--r-- | modules-available/dozmod/templates/blockstats.html | 33 |
3 files changed, 96 insertions, 0 deletions
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 @@ +<table class="table table-bordered table-striped"> + <tr> + <th>{{lang_imageName}}</th> + <th>{{lang_createTime}}</th> + <th>{{lang_fileSize}}</th> + <th>{{lang_blockCount}}</th> + </tr> + {{#rows}} + <tr> + <td>{{displayname}}</td> + <td>{{createtime_s}}</td> + <td>{{filesize_s}}</td> + <td>{{blockcount}}</td> + </tr> + {{/rows}} +</table>
\ 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 @@ +<table class="table table-condensed table-striped" style="width: auto"> + <tr> + <th>{{lang_hash}}</th> + <th>{{lang_size}}</th> + <th>{{lang_count}}</th> + </tr> + {{#hashes}} + <tr> + <td>{{hash_hex}}</td> + <td>{{blocksize_s}}</td> + <td>{{blockcount}} <button class="btn btn-xs btn-default" onclick="slxLoadBlocks('{{hash_hex}}', '{{blocksize}}')"><span class="glyphicon glyphicon-eye-open"></span></button></td> + </tr> + {{/hashes}} +</table> + +<div class="modal fade" id="block-details" tabindex="-1" role="dialog"> + <div class="modal-dialog"> + <div class="modal-content"> + <div class="modal-header"></div> + <div class="modal-body"></div> + <div class="modal-footer"><a class="btn btn-primary" data-dismiss="modal">{{lang_close}}</a></div> + </div> + </div> +</div> + +<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('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 |