From: Marcin Haba Date: Thu, 15 Aug 2019 08:33:41 +0000 (+0200) Subject: baculum: Add to client status modal window to set bandwidth limit for client X-Git-Tag: Release-9.6.0~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=552b2f1535eeae68ac63dac28cffd0b751933822;p=thirdparty%2Fbacula.git baculum: Add to client status modal window to set bandwidth limit for client --- diff --git a/gui/baculum/protected/Web/JavaScript/misc.js b/gui/baculum/protected/Web/JavaScript/misc.js index 7b70867c3..408528b90 100644 --- a/gui/baculum/protected/Web/JavaScript/misc.js +++ b/gui/baculum/protected/Web/JavaScript/misc.js @@ -15,7 +15,7 @@ var Units = { ], speed: [ {short: '', long: 'B/s', value: 1}, - {short: 'kb/s', long: 'KB/s', value: 1000}, + {short: 'kb/s', long: 'kB/s', value: 1000}, {short: 'k/s', long: 'KiB/s', value: 1024}, {short: 'mb/s', long: 'MB/s', value: 1000}, {short: 'm/s', long: 'MiB/s', value: 1024} @@ -132,7 +132,7 @@ var Units = { if (decimal && [1, 1000].indexOf(this.units.speed[i].value) == -1) { continue; } - reminder = speed_bytes % this.units.speed[i].value + reminder = speed_bytes % this.units.speed[i].value; if (reminder === 0 || (float_val && speed_bytes >= this.units.speed[i].value)) { speed_bytes /= this.units.speed[i].value; f = this.units.speed[i].long; @@ -141,9 +141,18 @@ var Units = { break; } } - var ret = {value: speed_bytes, format: f}; - return ret; + return {value: speed_bytes, format: f}; }, + get_short_unit_by_long: function(unit_type, unit_long) { + var unit_short = ''; + for (var i = 0; i < this.units[unit_type].length; i++) { + if (this.units[unit_type][i].long === unit_long) { + unit_short = this.units[unit_type][i].short; + break; + } + } + return unit_short; + } } var Strings = { @@ -887,6 +896,14 @@ function clear_node(selector) { } } +function show_element(element, show) { + if (show === true) { + $(element).show('fast'); + } else { + $(element).hide('fast'); + } +} + /** * Set compatibility with Send Bacula Backup Report tool. * @see https://giunchi.net/send-bacula-backup-report diff --git a/gui/baculum/protected/Web/Lang/en/messages.mo b/gui/baculum/protected/Web/Lang/en/messages.mo index 38f61a6c6..ee971932c 100644 Binary files a/gui/baculum/protected/Web/Lang/en/messages.mo and b/gui/baculum/protected/Web/Lang/en/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/en/messages.po b/gui/baculum/protected/Web/Lang/en/messages.po index bcb9c304e..68b525a16 100644 --- a/gui/baculum/protected/Web/Lang/en/messages.po +++ b/gui/baculum/protected/Web/Lang/en/messages.po @@ -2314,3 +2314,21 @@ msgstr "Component stop finished successfully." msgid "Component restart finished successfully." msgstr "Component restart finished successfully." + +msgid "Set bandwidth" +msgstr "Set bandwidth" + +msgid "Set client bandwidth limit" +msgstr "Set client bandwidth limit" + +msgid "Here you can set bandwidth limit on client. This changes is applied on running client. There is no need to restart it." +msgstr "Here you can set bandwidth limit on client. This changes is applied on running client. There is no need to restart it." + +msgid "Bandwidth limit" +msgstr "Bandwidth limit" + +msgid "Here you can set bandwidth limit on client. This change is applied on running client. There is no need to restart it." +msgstr "Here you can set bandwidth limit on client. This change is applied on running client. There is no need to restart it." + +msgid "Setting 0 (zero) value disables bandwidth limitation." +msgstr "Setting 0 (zero) value disables bandwidth limitation." diff --git a/gui/baculum/protected/Web/Lang/ja/messages.mo b/gui/baculum/protected/Web/Lang/ja/messages.mo index 74b32786e..0e253be0a 100644 Binary files a/gui/baculum/protected/Web/Lang/ja/messages.mo and b/gui/baculum/protected/Web/Lang/ja/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/ja/messages.po b/gui/baculum/protected/Web/Lang/ja/messages.po index ec3106555..581c727d3 100644 --- a/gui/baculum/protected/Web/Lang/ja/messages.po +++ b/gui/baculum/protected/Web/Lang/ja/messages.po @@ -2400,3 +2400,21 @@ msgstr "Component stop finished successfully." msgid "Component restart finished successfully." msgstr "Component restart finished successfully." + +msgid "Set bandwidth" +msgstr "Set bandwidth" + +msgid "Set client bandwidth limit" +msgstr "Set client bandwidth limit" + +msgid "Here you can set bandwidth limit on client. This changes is applied on running client. There is no need to restart it." +msgstr "Here you can set bandwidth limit on client. This changes is applied on running client. There is no need to restart it." + +msgid "Bandwidth limit" +msgstr "Bandwidth limit" + +msgid "Here you can set bandwidth limit on client. This change is applied on running client. There is no need to restart it." +msgstr "Here you can set bandwidth limit on client. This change is applied on running client. There is no need to restart it." + +msgid "Setting 0 (zero) value disables bandwidth limitation." +msgstr "Setting 0 (zero) value disables bandwidth limitation." diff --git a/gui/baculum/protected/Web/Lang/pl/messages.mo b/gui/baculum/protected/Web/Lang/pl/messages.mo index c19d884d3..cb3786abc 100644 Binary files a/gui/baculum/protected/Web/Lang/pl/messages.mo and b/gui/baculum/protected/Web/Lang/pl/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pl/messages.po b/gui/baculum/protected/Web/Lang/pl/messages.po index 6a9f5d410..55b626e0a 100644 --- a/gui/baculum/protected/Web/Lang/pl/messages.po +++ b/gui/baculum/protected/Web/Lang/pl/messages.po @@ -2321,3 +2321,21 @@ msgstr "Zatrzymanie komponentu zakończyło się pomyślnie." msgid "Component restart finished successfully." msgstr "Restart komponentu zakończył się pomyślnie." + +msgid "Set bandwidth" +msgstr "Ustaw limit transferu" + +msgid "Set client bandwidth limit" +msgstr "Ustaw limit transferu klienta" + +msgid "Here you can set bandwidth limit on client. This changes is applied on running client. There is no need to restart it." +msgstr "Tutaj możesz ustawić limit transferu na kliencie. Ta zmiana is zastosowana na uruchomionym kliencie. Nie ma żadnej potrzeby restartowania go." + +msgid "Bandwidth limit" +msgstr "Limit transferu" + +msgid "Here you can set bandwidth limit on client. This change is applied on running client. There is no need to restart it." +msgstr "Tutaj możesz ustawić limit transferu dla klienta. Ta zmiana jest zastosowana na działającym kliencie. Nie ma żadnej potrzeby restartowania go." + +msgid "Setting 0 (zero) value disables bandwidth limitation." +msgstr "Ustawienie wartości 0 (zero) wyłącza limitowanie transferu." diff --git a/gui/baculum/protected/Web/Lang/pt/messages.mo b/gui/baculum/protected/Web/Lang/pt/messages.mo index d3e2b03f4..8e4261818 100644 Binary files a/gui/baculum/protected/Web/Lang/pt/messages.mo and b/gui/baculum/protected/Web/Lang/pt/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pt/messages.po b/gui/baculum/protected/Web/Lang/pt/messages.po index 9156b9c99..0fa163d07 100644 --- a/gui/baculum/protected/Web/Lang/pt/messages.po +++ b/gui/baculum/protected/Web/Lang/pt/messages.po @@ -2329,3 +2329,21 @@ msgstr "Component stop finished successfully." msgid "Component restart finished successfully." msgstr "Component restart finished successfully." + +msgid "Set bandwidth" +msgstr "Set bandwidth" + +msgid "Set client bandwidth limit" +msgstr "Set client bandwidth limit" + +msgid "Here you can set bandwidth limit on client. This changes is applied on running client. There is no need to restart it." +msgstr "Here you can set bandwidth limit on client. This changes is applied on running client. There is no need to restart it." + +msgid "Bandwidth limit" +msgstr "Bandwidth limit" + +msgid "Here you can set bandwidth limit on client. This change is applied on running client. There is no need to restart it." +msgstr "Here you can set bandwidth limit on client. This change is applied on running client. There is no need to restart it." + +msgid "Setting 0 (zero) value disables bandwidth limitation." +msgstr "Setting 0 (zero) value disables bandwidth limitation." diff --git a/gui/baculum/protected/Web/Pages/ClientView.page b/gui/baculum/protected/Web/Pages/ClientView.page index 73aacb502..a41d91477 100644 --- a/gui/baculum/protected/Web/Pages/ClientView.page +++ b/gui/baculum/protected/Web/Pages/ClientView.page @@ -21,7 +21,7 @@
<%[ Bandwidth limit: ]%> - + <%[ Debug: ]%> @@ -158,7 +158,7 @@ var oGraphicalClientStatus = { var img = document.createElement('I'); img.className = 'fa'; if (value == 1) { - img.className += ' fa-check w3-text-green'; + img.className += ' fa-check'; } else { img.className += ' fa-times w3-text-red'; } diff --git a/gui/baculum/protected/Web/Pages/ClientView.php b/gui/baculum/protected/Web/Pages/ClientView.php index 0e8436456..86da4a80a 100644 --- a/gui/baculum/protected/Web/Pages/ClientView.php +++ b/gui/baculum/protected/Web/Pages/ClientView.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2018 Kern Sibbald + * Copyright (C) 2013-2019 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -85,6 +85,7 @@ class ClientView extends BaculumWebPage { */ public function setClientId($clientid) { $clientid = intval($clientid); + $this->BWLimit->setClientId($clientid); $this->setViewState(self::CLIENTID, $clientid, 0); } @@ -103,6 +104,7 @@ class ClientView extends BaculumWebPage { * @return none; */ public function setClientName($client_name) { + $this->BWLimit->setClientName($client_name); $this->setViewState(self::CLIENT_NAME, $client_name); } @@ -132,6 +134,13 @@ class ClientView extends BaculumWebPage { ); if ($graph_status->error === 0) { $client_status['header'] = $graph_status->output; + if (!$this->BWLimit->BandwidthLimit->getDirectiveValue()) { + $this->BWLimit->setBandwidthLimit($client_status['header']->bwlimit); + $this->getCallbackClient()->callClientFunction( + 'oClientBandwidthLimit.set_value', + array($client_status['header']->bwlimit) + ); + } } $query_str = '?name=' . rawurlencode($this->getClientName()) . '&type=running'; diff --git a/gui/baculum/protected/Web/Portlets/ClientBandwidthLimit.php b/gui/baculum/protected/Web/Portlets/ClientBandwidthLimit.php new file mode 100644 index 000000000..d51482152 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/ClientBandwidthLimit.php @@ -0,0 +1,134 @@ +getClientId(); + + $result = $this->getModule('api')->set( + array('clients', $clientid, 'bandwidth'), + array('limit' => $this->BandwidthLimit->getValue()) + ); + + // this setting to empty string is required to not cache outputs for the same values + $this->BandwidthLog->Text = ''; + if ($result->error === 0) { + $this->BandwidthLog->Text = implode(PHP_EOL, $result->output); + } else { + $this->BandwidthLog->Text = $result->output; + } + + $this->getPage()->getCallbackClient()->callClientFunction( + 'show_element', + array('#client_bandwidth_limit_log', true) + ); + + $this->onCallback(null); + } + + /** + * Callback event method. + * + * @param mixed $param callback parameter or null + * @return none + */ + public function onCallback($param) { + $this->raiseEvent('OnCallback', $this, $param); + } + + /** + * Set client clientid. + * + * @return none; + */ + public function setClientId($clientid) { + $clientid = intval($clientid); + $this->setViewState(self::CLIENTID, $clientid, 0); + } + + /** + * Get client clientid. + * + * @return integer clientid + */ + public function getClientId() { + return $this->getViewState(self::CLIENTID, 0); + } + + /** + * Set client name. + * + * @return none; + */ + public function setClientName($client_name) { + $this->setViewState(self::CLIENT_NAME, $client_name); + } + + /** + * Get client name. + * + * @return string client name + */ + public function getClientName() { + return $this->getViewState(self::CLIENT_NAME); + } + + /** + * Get bandwidth limit value from field. + * + * @return mixed bandwidth limit integer value or null if bandwidth not set + */ + public function getBandwidthLimit() { + return $this->BandwidthLimit->getValue(); + } + + /** + * Set bandwidth limit value in field. + * + * @param integer $bwlimit bandiwdth limit in bytes + * @return none + */ + public function setBandwidthLimit($bwlimit) { + $this->BandwidthLimit->setDirectiveValue($bwlimit); + } +} +?> diff --git a/gui/baculum/protected/Web/Portlets/ClientBandwidthLimit.tpl b/gui/baculum/protected/Web/Portlets/ClientBandwidthLimit.tpl new file mode 100644 index 000000000..66f3582ec --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/ClientBandwidthLimit.tpl @@ -0,0 +1,71 @@ +   +
+
+
+ × +

<%[ Set client bandwidth limit ]%> - <%[ Client: ]%> <%=$this->getClientName()%>

+
+
+

<%[ Here you can set bandwidth limit on client. This change is applied on running client. There is no need to restart it. ]%>

+

<%[ Setting 0 (zero) value disables bandwidth limitation. ]%>

+
+ +
+
+
+  <%[ Cancel ]%> + + + document.getElementById('bandwidth_limit_loading').style.visibility = 'visible'; + + + document.getElementById('bandwidth_limit_loading').style.visibility = 'hidden'; + +  <%[ Set bandwidth ]%> + + +
+ +
+
+