]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Improve error handling in web part
authorMarcin Haba <marcin.haba@bacula.pl>
Sat, 18 Aug 2018 18:48:27 +0000 (20:48 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 18 Aug 2018 18:50:11 +0000 (20:50 +0200)
13 files changed:
gui/baculum/protected/Web/Class/BaculumAPIClient.php
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/Layouts/Main.tpl
gui/baculum/protected/Web/Layouts/MessageBox.tpl
gui/baculum/protected/Web/Pages/BaculumError.page
gui/baculum/protected/Web/Pages/Monitor.php

index ab11e4592f5dee90d65ef72dc0b8519188318344..1721c08a50685dbc97de5db8a8e22a118f712864 100644 (file)
@@ -465,11 +465,15 @@ class BaculumAPIClient extends WebModule {
                }
 
                if ($show_error === true && $resource->error != 0) {
-                       $url = $this->Service->constructUrl('BaculumError', (array)$resource, false);
-                       header("Location: $url");
-                       // write all logs before exiting, otherwise they will be lost
-                       $this->getModule('log')->collectLogs(null);
-                       exit();
+                       $headers = $this->Request->getHeaders(CASE_UPPER);
+                       if (!isset($headers['X-REQUESTED-WITH']) || $headers['X-REQUESTED-WITH'] !== 'XMLHttpRequest') {
+                               // it is non-ajax request - redirect it to error page
+                               $url = $this->Service->constructUrl('BaculumError', (array)$resource, false);
+                               header("Location: $url");
+                               // write all logs before exiting, otherwise they will be lost
+                               $this->getModule('log')->collectLogs(null);
+                               exit();
+                       }
                }
 
                $this->Application->getModule('logging')->log(
index ef485bb2b72b0046833999c681146939555ac296..233e33fa36562a3593e9a1c91de3e7174ace12b6 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 fe3bbd932205311f0d791bd98cf74f66e32a21c4..612aa9580e8440b2778da3bdaae5a7020cf354e7 100644 (file)
@@ -1828,3 +1828,10 @@ msgstr "Log order"
 
 msgid "Close Menu"
 msgstr "Close Menu"
+
+msgid "Error code:"
+msgstr "Error code:"
+
+msgid "Message:"
+msgstr "Message:"
+
index b2e7a791537e24ebd9f2e8411cce2e0dc5eaaa44..2015cf2262097550e238fe20264127c6eb26292f 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 ddea82e883b69e0c04c8a8e9cfa8c9bae9a1a846..b6e6227c1f6e2ffe7620795c37a41a3ea87344f4 100644 (file)
@@ -1579,3 +1579,10 @@ msgstr "Log order"
 
 msgid "Close Menu"
 msgstr "Close Menu"
+
+msgid "Error code:"
+msgstr "Error code:"
+
+msgid "Message:"
+msgstr "Message:"
+
index c3942485a33554516484bd4bdcc5f5b3f5146c6c..48c7918dfa32eb4a6e54dfc3ab3951f13db409cf 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 ac06df7492eb6480bab3230efaf9c36b51d35870..c7f3fb67c1cf9748399f451c2fff6382e67b68d9 100644 (file)
@@ -1835,3 +1835,9 @@ msgstr "Kolejność dziennika"
 
 msgid "Close Menu"
 msgstr "Zamknij Menu"
+
+msgid "Error code:"
+msgstr "Kod błędu:"
+
+msgid "Message:"
+msgstr "Wiadomość:"
index 32c34f4820d1df084b4a3638cf7583003f116bc9..a7ec95d0390cb9891f83dfd155eb0ab9dabe3439 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 f58d1fc27cd77c1ceb4c300fd32a9f0fef4a579e..695c9fed354b6e43dfe253c0b6eee68d49ae27e5 100644 (file)
@@ -1843,3 +1843,10 @@ msgstr "Ordenar log"
 
 msgid "Close Menu"
 msgstr "Fechar menu"
+
+msgid "Error code:"
+msgstr "Error code:"
+
+msgid "Message:"
+msgstr "Message:"
+
index 042c898275ca877a2b9230520f263497a9176e4b..16b87c0faf218cca6482b2fb3ed947a9cb1f1cad 100644 (file)
                        </div>
                </com:TForm>
                <div id="small" class="w3-hide-large"></div>
+               <div id="error_message_box" class="w3-modal" style="display: none">
+                       <div class="w3-modal-content w3-card-4 w3-animate-zoom" style="width:600px">
+                               <header class="w3-container w3-red">
+                                       <span onclick="document.getElementById('error_message_box').style.display='none'" class="w3-button w3-display-topright">×</span>
+                                       <h2><%[ Error ]%></h2>
+                               </header>
+                               <div class="w3-panel w3-padding">
+                                       <p><strong><%[ Error code: ]%></strong> <span id="error_message_error_code"></span></p>
+                                       <p><strong><%[ Message: ]%></strong> <span id="error_message_error_msg"></span></p>
+                               </div>
+                               <footer class="w3-container w3-center">
+                                       <button type="button" class="w3-button w3-section w3-red" onclick="document.getElementById('error_message_box').style.display='none'"><i class="fa fa-check"></i> &nbsp;<%[ OK ]%></button>
+                               </footer>
+                       </div>
+               </div>
 <script type="text/javascript">
 var is_small = $('#small').is(':visible');
 
@@ -68,6 +83,15 @@ $(function() {
                                if (timeout_handler) {
                                        clearTimeout(timeout_handler);
                                }
+                               if (response && response.hasOwnProperty('error') && response.error.error !== 0) {
+                                       var err_box = document.getElementById('error_message_box');
+                                       var err_code = document.getElementById('error_message_error_code');
+                                       var err_msg = document.getElementById('error_message_error_msg');
+                                       err_code.textContent = response.error.error;
+                                       err_msg.textContent = response.error.output;
+                                       err_box.style.display = 'block';
+                               }
+
                                oData = response;
                                if ('<%=get_class($this->Service->getRequestedPage())%>' == 'Dashboard') {
                                        Statistics.grab_statistics(oData, JobStatus.get_states());
index 56ea9ca7264cfbe33f25a47507ac8c1ed27db38a..1d16391bcef114ffc87429b1c0f873895d3bf92f 100644 (file)
@@ -2,6 +2,9 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
        <com:THead Title="Baculum - Bacula Web Interface" ShortcutIcon="<%=$this->getPage()->getTheme()->getBaseUrl()%>/favicon.ico" />
        <body id="message-body">
-               <com:TContentPlaceHolder ID="Message" />
+               <com:TForm>
+                       <com:BClientScript ScriptUrl=<%~ ../JavaScript/fontawesome-all.js %> />
+                       <com:TContentPlaceHolder ID="Message" />
+               </com:TForm>
        </body>
 </html>
index 6e6c65ef2cad502f40417ae478b99fdc25f4d423..cd8185a5a390321607f0d9bb2faf4278bb768f48 100644 (file)
@@ -1,14 +1,16 @@
-<%@ MasterClass="Application.Web.Layouts.MessageBox" Theme="Baculum-v1"%>
+<%@ MasterClass="Application.Web.Layouts.MessageBox" Theme="Baculum-v2"%>
 <com:TContent ID="Message">
-<div id="message-box">
+<div class="w3-container w3-red">
        <h2><%[ Baculum problem ]%></h2>
+</div>
+<div class="w3-container">
        <h3>Error <%=$this->error%> - <%=$this->output%></h3>
        <hr />
-       <p class="center">
-               <a href="<%=$this->Service->constructUrl('Dashboard')%>"><%[ TRY AGAIN ]%></a>
+       <div class="w3-center">
+               <a class="w3-button w3-green" href="<%=$this->Service->constructUrl('Dashboard')%>"><i class="fa fa-redo-alt"></i> &nbsp;<%[ TRY AGAIN ]%></a>
                <%[ or run ]%>
-               <a href="<%=$this->Service->constructUrl('WebConfigWizard')%>"><%[ Baculum Initial Wizard ]%></a>
-       </p>
+               <a class="w3-button w3-green" href="<%=$this->Service->constructUrl('WebConfigWizard')%>"><i class="fa fa-reply"></i> &nbsp;<%[ Baculum Initial Wizard ]%></a>
+       </div>
 </div>
 <script type="text/javascript">
        window.history.pushState('page', 'Title', '<%=$this->Service->constructUrl('Dashboard')%>');
index a1f4620163fdb83e735b5cff89905665c3e8e35c..33924948b03fe5a8c5188dbb922aedd54ec592da 100644 (file)
@@ -34,7 +34,8 @@ class Monitor extends BaculumWebPage {
                        'terminated_jobs' => array(),
                        'pools' => array(),
                        'jobtotals' => array(),
-                       'dbsize' => array()
+                       'dbsize' => array(),
+                       'error' => array('error' => 0, 'output' => '')
                );
 
                $web_config = $this->getModule('web_config')->getConfig();
@@ -43,26 +44,59 @@ class Monitor extends BaculumWebPage {
                        $job_limit = $web_config['baculum']['max_jobs'];
                }
 
+               $error = null;
                $params = $this->Request->contains('params') ? $this->Request['params'] : array();
                if (in_array('jobs', $params)) {
                        $job_params = array('jobs');
                        if ($this->Request->contains('use_limit') && $this->Request['use_limit'] == 1) {
                                $job_params[] = '?limit=' . $job_limit;
                        }
-                       $monitor_data['jobs'] = $this->getModule('api')->get($job_params)->output;
+                       $result = $this->getModule('api')->get($job_params);
+                       if ($result->error === 0) {
+                               $monitor_data['jobs'] = $result->output;
+                       } else {
+                               $error = $result;
+                       }
                }
-               $monitor_data['running_jobs'] = $this->getModule('api')->get(array('jobs', '?jobstatus=CR'))->output;
-               if (in_array('clients', $params)) {
-                       $monitor_data['clients'] = $this->getModule('api')->get(array('clients'))->output;
+               if (!$error) {
+                       $result = $this->getModule('api')->get(array('jobs', '?jobstatus=CR'));
+                       if ($result->error === 0) {
+                               $monitor_data['running_jobs'] = $result->output;
+                       } else {
+                               $error = $result;
+                       }
                }
-               if (in_array('pools', $params)) {
-                       $monitor_data['pools'] = $this->getModule('api')->get(array('pools'))->output;
+               if (!$error && in_array('clients', $params)) {
+                       $result = $this->getModule('api')->get(array('clients'));
+                       if ($result->error === 0) {
+                               $monitor_data['clients'] = $result->output;
+                       } else {
+                               $error = $result;
+                       }
                }
-               if (in_array('job_totals', $params)) {
-                       $monitor_data['jobtotals'] = $this->getModule('api')->get(array('jobs', 'totals'))->output;
+               if (!$error && in_array('pools', $params)) {
+                       $result = $this->getModule('api')->get(array('pools'));
+                       if ($result->error === 0) {
+                               $monitor_data['pools'] = $result->output;
+                       } else {
+                               $error = $result;
+                       }
                }
-               if ($_SESSION['admin'] && in_array('dbsize', $params)) {
-                       $monitor_data['dbsize'] = $this->getModule('api')->get(array('dbsize'))->output;
+               if (!$error && in_array('job_totals', $params)) {
+                       $result = $this->getModule('api')->get(array('jobs', 'totals'));
+                       if ($result->error === 0) {
+                               $monitor_data['jobtotals'] = $result->output;
+                       } else {
+                               $error = $result;
+                       }
+               }
+               if (!$error && $_SESSION['admin'] && in_array('dbsize', $params)) {
+                       $result = $this->getModule('api')->get(array('dbsize'));
+                       if ($result->error === 0) {
+                               $monitor_data['dbsize'] = $result->output;
+                       } else {
+                               $error = $result;
+                       }
                }
 
                $running_job_states = $this->Application->getModule('misc')->getRunningJobStates();
@@ -74,6 +108,10 @@ class Monitor extends BaculumWebPage {
                                }
                        }
                }
+               if (is_object($error)) {
+                       $monitor_data['error'] = $error;
+               }
+
                echo json_encode($monitor_data);
                exit();
        }