summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--css/style.css10
-rw-r--r--execute.php18
-rw-r--r--index.php4
-rw-r--r--js/looking-glass.js30
-rw-r--r--routers/router.php17
5 files changed, 62 insertions, 17 deletions
diff --git a/css/style.css b/css/style.css
index 0c815ba..669df5a 100644
--- a/css/style.css
+++ b/css/style.css
@@ -5,7 +5,7 @@ body {
.header_bar {
color: #000000;
text-align: center;
- margin-bottom: 1em;
+ margin: 1em;
}
.footer_bar {
color: #000000;
@@ -25,7 +25,7 @@ body {
}
.content {
color: #000000;
- font-size: 1.1em;
+ font-size: 1.3em;
text-align: center;
width: 50%;
display: block;
@@ -48,6 +48,12 @@ body {
margin-left: auto;
margin-right: auto;
}
+#error {
+ font-size: 1.3em;
+ width: 50%;
+ margin-left: auto;
+ margin-right: auto;
+}
#dontlook {
display: none;
}
diff --git a/execute.php b/execute.php
index dd24a6c..6a5cd45 100644
--- a/execute.php
+++ b/execute.php
@@ -68,10 +68,22 @@ if (isset($_POST['query']) && !empty($_POST['query']) &&
// Do the processing
$router = Router::instance($hostname, $_SERVER['REMOTE_ADDR']);
- $data = $router->send_command($query, $parameters);
- // Display the result of the command
- print process_output($data);
+ try {
+ $output = $router->send_command($query, $parameters);
+ } catch (Exception $e) {
+ $error = $e->getMessage();
+ }
+
+ if (isset($output)) {
+ // Display the result of the command
+ $data = array('result' => process_output($output));
+ } else {
+ // Display the error
+ $data = array('error' => $error);
+ }
+
+ print json_encode($data);
}
// End of execute.php
diff --git a/index.php b/index.php
index 0369515..75af1d5 100644
--- a/index.php
+++ b/index.php
@@ -102,6 +102,10 @@ final class LookingGlass {
}
private function render_content() {
+ print '<div class="alert alert-danger alert-dismissable" id="error">';
+ print '<button type="button" class="close" aria-hidden="true">&times;</button>';
+ print '<strong>Error!</strong>&nbsp;<span id="error-text"></span>';
+ print '</div>';
print '<div class="content" id="command_options">';
print '<form role="form" action="execute.php" method="post">';
print '<fieldset id="command_properties">';
diff --git a/js/looking-glass.js b/js/looking-glass.js
index b837e82..3a72f23 100644
--- a/js/looking-glass.js
+++ b/js/looking-glass.js
@@ -2,10 +2,12 @@ $(document).ready(function() {
// hide the optional parameters field
$('.result').hide();
$('.loading').hide();
+ $('.alert').hide();
// show and hide loading bar
$(document).ajaxStart(function() {
$('#command_properties').attr('disabled', '');
+ $('.alert').hide();
$('.loading').show();
});
$(document).ajaxStop(function() {
@@ -13,6 +15,14 @@ $(document).ready(function() {
$('.loading').hide();
});
+ // close the alert bar
+ $('.close').click(function() {
+ $('.alert').slideUp();
+ });
+ $('#clear').click(function() {
+ $('.alert').slideUp();
+ });
+
// reset the view to the default one
$('#backhome').click(function() {
$('.content').slideDown();
@@ -27,12 +37,20 @@ $(document).ready(function() {
type: 'post',
url: 'execute.php',
data: $('form').serialize()
- }).done(function(response, state, xhr) {
- $('#output').text(response);
- $('.content').slideUp();
- $('.result').slideDown();
- }).fail(function(xhr, state, error) {
- alert('The following error occured: ' + state, error);
+ }).done(function(response) {
+ var response = $.parseJSON(response);
+
+ if (response.error) {
+ $('#error-text').text(response.error);
+ $('.alert').slideDown();
+ } else {
+ $('#output').text(response.result);
+ $('.content').slideUp();
+ $('.result').slideDown();
+ }
+ }).fail(function(xhr) {
+ $('#error-text').text(xhr.responseText);
+ $('.alert').slideDown();
});
});
});
diff --git a/routers/router.php b/routers/router.php
index b061411..cee1c35 100644
--- a/routers/router.php
+++ b/routers/router.php
@@ -45,16 +45,21 @@ abstract class Router {
try {
$complete_command = $this->build_command($command, $parameters);
} catch (Exception $e) {
- return $e->getMessage();
+ throw $e;
}
$auth = Authentication::instance($this->config);
- $auth->connect();
- $data = $auth->send_command($complete_command);
- $auth->disconnect();
- log_to_file('[client: '.$this->requester.'] '.$this->config['host'].'> '.
- $complete_command);
+ try {
+ $auth->connect();
+ $data = $auth->send_command($complete_command);
+ } catch (Exception $e) {
+ throw $e;
+ } finally {
+ $auth->disconnect();
+ log_to_file('[client: '.$this->requester.'] '.$this->config['host'].'> '.
+ $complete_command);
+ }
return $data;
}