]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add to client status modal window to set bandwidth limit for client
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 15 Aug 2019 08:33:41 +0000 (10:33 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 14 Dec 2019 14:55:58 +0000 (15:55 +0100)
13 files changed:
gui/baculum/protected/Web/JavaScript/misc.js
gui/baculum/protected/Web/Lang/en/messages.mo
gui/baculum/protected/Web/Lang/en/messages.po
gui/baculum/protected/Web/Lang/ja/messages.mo
gui/baculum/protected/Web/Lang/ja/messages.po
gui/baculum/protected/Web/Lang/pl/messages.mo
gui/baculum/protected/Web/Lang/pl/messages.po
gui/baculum/protected/Web/Lang/pt/messages.mo
gui/baculum/protected/Web/Lang/pt/messages.po
gui/baculum/protected/Web/Pages/ClientView.page
gui/baculum/protected/Web/Pages/ClientView.php
gui/baculum/protected/Web/Portlets/ClientBandwidthLimit.php [new file with mode: 0644]
gui/baculum/protected/Web/Portlets/ClientBandwidthLimit.tpl [new file with mode: 0644]

index 7b70867c3b5f658d7ec80d48d58e8523e5ff1999..408528b9009f038d06fbcf21656d3e901a5bdb49 100644 (file)
@@ -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
index 38f61a6c6af42c30e1640fcbc909130f5ff2f5e7..ee971932c68be258375241d2637457d2471a3354 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/en/messages.mo and b/gui/baculum/protected/Web/Lang/en/messages.mo differ
index bcb9c304ef989287283ca936d50df22ec114e7e8..68b525a16949e6ca820a2e3bd702f053752bb2a1 100644 (file)
@@ -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."
index 74b32786e53ed7ce53cc9c07c930b014277f0cef..0e253be0a91df9b9125c5c64518142d07574c50d 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/ja/messages.mo and b/gui/baculum/protected/Web/Lang/ja/messages.mo differ
index ec31065550634856850914da7e20570968b15e09..581c727d311cb807a06a3d2f3dda9d340bc2eb65 100644 (file)
@@ -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."
index c19d884d3847d5039a205b092b6c003ec49fa648..cb3786abcca438731ed1a1f1941d7d9bd1291e78 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/pl/messages.mo and b/gui/baculum/protected/Web/Lang/pl/messages.mo differ
index 6a9f5d410219a38c0c83aff3548a747cc6076969..55b626e0a26165c35aa42b236907eff28731040c 100644 (file)
@@ -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."
index d3e2b03f4155d43b9ccc7f41618fd7fb2b8fc0b6..8e4261818e435b2af1107d8175fcc2b8be5da913 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/pt/messages.mo and b/gui/baculum/protected/Web/Lang/pt/messages.mo differ
index 9156b9c99782b078136d45e9c3d7ccb894f66118..0fa163d07622173ec5847639bef81ba9a9067232 100644 (file)
@@ -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."
index 73aacb502f95d7af241f77cb0b31dc8d91b2ed33..a41d9147770ca8ca4668fbbb765f4839f511dd65 100644 (file)
@@ -21,7 +21,7 @@
        <div class="w3-container tab_item" id="client_actions">
                <com:TActiveLinkButton
                        ID="ClientStatusBtn"
-                       OnClick="status"
+                       OnCallback="status"
                        CssClass="w3-button w3-green w3-margin-bottom"
                        CausesValidation="false"
                        ClientSide.OnLoading="$('#status_client_loading').show();$('#status_client_error').hide();"
@@ -79,7 +79,7 @@
                                                        </tr>
                                                        <tr>
                                                                <td><%[ Bandwidth limit: ]%></td>
-                                                               <td id="status_client_bwlimit"></td>
+                                                               <td><span id="status_client_bwlimit"></span><com:Application.Web.Portlets.ClientBandwidthLimit ID="BWLimit" OnCallback="status" /></td>
                                                        </tr>
                                                        <tr>
                                                                <td><%[ Debug: ]%></td>
@@ -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';
                        }
index 0e8436456a2370a7491bf2343aad4c413618d10d..86da4a80a9886c2f148925bd0508c75c3745a33d 100644 (file)
@@ -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 (file)
index 0000000..d514821
--- /dev/null
@@ -0,0 +1,134 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2019 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+
+Prado::using('System.Web.UI.ActiveControls.TActiveLabel');
+Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
+Prado::using('Application.Web.Portlets.DirectiveSpeed');
+Prado::using('Application.Web.Portlets.Portlets');
+
+/**
+ * Set client bandwidth limit control.
+ */
+class ClientBandwidthLimit extends Portlets {
+
+       const CLIENTID = 'ClientId';
+       const CLIENT_NAME = 'ClientName';
+
+       /**
+        * Set up bandwidth limit value.
+        *
+        * @param TActiveLinkButton $sender sender
+        * @param TCallbackEventParameter $param callback parameter
+        * @return none
+        */
+       public function setupBandwidthLimit($sender, $param) {
+               $clientid = $this->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 (file)
index 0000000..66f3582
--- /dev/null
@@ -0,0 +1,71 @@
+ &nbsp;<a class="w3-hover-opacity" href="javascript:void(0)" onclick="oClientBandwidthLimit.open_popup();" title="<%[ Set bandwidth ]%>"><i class="fas fa-tachometer-alt w3-large"></i></a>
+<div id="client_bandwidth_limit_popup" class="w3-modal">
+       <div class="w3-modal-content w3-animate-top w3-card-4">
+               <header class="w3-container w3-teal">
+                       <span onclick="oClientBandwidthLimit.close_popup();" class="w3-button w3-display-topright">&times;</span>
+                       <h2><%[ Set client bandwidth limit ]%> - <%[ Client: ]%> <%=$this->getClientName()%></h2>
+               </header>
+               <div class="w3-container w3-margin-left w3-margin-right">
+                       <p><%[ Here you can set bandwidth limit on client. This change is applied on running client. There is no need to restart it. ]%></p>
+                       <p><%[ Setting 0 (zero) value disables bandwidth limitation. ]%></p>
+                       <div class="w3-row w3-section w3-medium">
+                               <com:Application.Web.Portlets.DirectiveSpeed
+                                       ID="BandwidthLimit"
+                                       DirectiveName="BandwidthLimit"
+                                       DefaultValue="0"
+                                       Show="true"
+                                       Label="<%[ Bandwidth limit ]%>"
+                                       UnitType="decimal"
+                               />
+                       </div>
+               </div>
+               <footer class="w3-container w3-center">
+                       <a class="w3-button w3-red" href="javascript:void(0)" onclick="oClientBandwidthLimit.close_popup()"><i class="fas fa-times"></i> &nbsp<%[ Cancel ]%></a>
+                       <com:TActiveLinkButton
+                               ID="SetBandwidthLimit"
+                               OnCallback="setupBandwidthLimit"
+                               CssClass="w3-button w3-section w3-green w3-padding"
+                       >
+                               <prop:ClientSide.OnLoading>
+                                       document.getElementById('bandwidth_limit_loading').style.visibility = 'visible';
+                               </prop:ClientSide.OnLoading>
+                               <prop:ClientSide.OnComplete>
+                                       document.getElementById('bandwidth_limit_loading').style.visibility = 'hidden';
+                               </prop:ClientSide.OnComplete>
+                               <i class="fa fa-check"></i> &nbsp;<%[ Set bandwidth ]%>
+                       </com:TActiveLinkButton>
+                       <i id="bandwidth_limit_loading" class="fa fa-sync w3-spin" style="visibility: hidden;"></i>
+               </footer>
+               <div id="client_bandwidth_limit_log" class="w3-panel w3-card w3-light-grey" style="display: none; max-height: 200px; overflow-x: auto;">
+                       <div class="w3-code">
+                               <pre><com:TActiveLabel ID="BandwidthLog" /></pre>
+                       </div>
+               </div>
+       </div>
+</div>
+<script>
+var oClientBandwidthLimit = {
+       ids: {
+               popup: 'client_bandwidth_limit_popup',
+               log: 'client_bandwidth_limit_log'
+       },
+       open_popup: function() {
+               document.getElementById(this.ids.popup).style.display = 'block';
+       },
+       close_popup: function() {
+               document.getElementById(this.ids.popup).style.display = 'none';
+               this.cleanup_log();
+       },
+       cleanup_log: function() {
+               document.getElementById(this.ids.log).style.display = 'none';
+               document.getElementById('<%=$this->BandwidthLog->ClientID%>').textContent = '';
+       },
+       set_value: function(value) {
+               var bwlimit_val = document.getElementById('<%=$this->BandwidthLimit->Directive->ClientID%>');
+               var bwlimit_unit = document.getElementById('<%=$this->BandwidthLimit->SpeedFormat->ClientID%>');
+               var val = Units.format_speed(value, null, false, true);
+               bwlimit_val.value = val.value;
+               bwlimit_unit.value = Units.get_short_unit_by_long('speed', val.format) || val.format;
+       }
+};
+</script>