Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions deps/rabbitmq_management/priv/www/js/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ QUEUE_TYPE["default"] = {
"operator_policy_arguments": "classic-queue-operator-policy-arguments",
"list" : "classic-queue-list",
"stats" : "classic-queue-stats",
"node_details" : "classic-queue-node-details"
"node_details" : "classic-queue-node-details",
"get_message" : "classic-queue-get-message"
}
};

Expand All @@ -952,7 +953,8 @@ QUEUE_TYPE["classic"] = {
"operator_policy_arguments": "classic-queue-operator-policy-arguments",
"list" : "classic-queue-list",
"stats" : "classic-queue-stats",
"node_details" : "classic-queue-node-details"
"node_details" : "classic-queue-node-details",
"get_message" : "classic-queue-get-message"
}
};

Expand All @@ -973,7 +975,8 @@ QUEUE_TYPE["quorum"] = {
"operator_policy_arguments": "quorum-queue-operator-policy-arguments",
"list" : "quorum-queue-list",
"stats": "quorum-queue-stats",
"node_details" : "quorum-queue-node-details"
"node_details" : "quorum-queue-node-details",
"get_message" : "classic-queue-get-message"
}
};

Expand Down Expand Up @@ -1110,3 +1113,63 @@ var BINARY_STATISTICS = {
{name: 'System', colour: 'system',
keys: [['other', 'other']]}]]
};


// Which postprocesor functions we need to call from postprocess() function call
var current_postprocessors = new Map();
function registerPostProcessor(name, postProcessorFun) {
if (current_postprocessors.has(name)) {
return false;
}
current_postprocessors.set(name, postProcessorFun);
}
function clear_postprocessors() {
current_postprocessors.clear();
}
function is_postprocessor_registered(name) {
return current_postprocessors.has(name);
}
function unregisterPostProcessor(name) {
current_postprocessors.delete(name);
}
function invokeRegisteredPostProcessors() {
for (const [name, processorFun] of current_postprocessors) {
console.log(`Calling postprocessor ${name}`);
processorFun();
}
}

class ApplicationListener {
onRefresh() {
}
onVhostChange(newVhost) {
}
onTabDeactivated(tab) {

}
}
var applicationListeners = new Map();
function registerApplicationListener(name, listener) {
if (applicationListeners.has(name)) {
return false;
}
applicationListeners.set(name, listener);
}
function unregisterApplicationListener(name) {
applicationListeners.delete(name);
}
function notifyOnRefresh() {
for (const [name, listener] of applicationListeners) {
listener.onRefresh();
}
}
function notifyOnVhostChange(newVhost) {
for (const [_name, listener] of applicationListeners) {
listener.onVhostChange(newVhost);
}
}
function notifyActivatedTab(tab) {
for (const [_name, listener] of applicationListeners) {
listener.onTabActivated(tab);
}
}
91 changes: 84 additions & 7 deletions deps/rabbitmq_management/priv/www/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ function setup_constant_events() {
$('#show-vhost').on('change', function() {
current_vhost = $(this).val();
store_pref('vhost', current_vhost);
update();
if (current_reqs && Object.keys(current_reqs).length > 0) {
update();
}
notifyOnVhostChange(current_vhost);
});
if (!vhosts_interesting) {
$('#vhost-form').hide();
Expand Down Expand Up @@ -235,19 +238,83 @@ function update_vhosts() {
function setup_extensions() {
var extensions = JSON.parse(sync_get('/extensions'));
extension_count = 0;
var javascript_files = [];

for (var i in extensions) {
var extension = extensions[i];
if ($.isPlainObject(extension) && extension.hasOwnProperty('javascript')) {
dynamic_load(extension.javascript);
if ($.isPlainObject(extension)) {
if (extension.hasOwnProperty('javascript')) {
// Collect JavaScript files for sequential loading
if (Array.isArray(extension.javascript)) {
for (var j = 0; j < extension.javascript.length; j++) {
javascript_files.push(extension.javascript[j]);
}
} else {
javascript_files.push(extension.javascript);
}
}
if (extension.hasOwnProperty('css')) {
dynamic_css_load(extension.css);
}
extension_count++;
}
}
// Load JavaScript files sequentially to ensure dependencies are available
load_javascript_files_sequentially(javascript_files, 0);
}

function dynamic_load(filename) {
function load_javascript_files_sequentially(files, index) {
if (index >= files.length) {
return; // All files loaded
}
console.debug(`Loading extension ${files[index]} ...`);
dynamic_javascript_file_load(files[index], function() {
// Load next file after current one has finished loading
console.debug(`Loaded extension ${files[index]} !`);
load_javascript_files_sequentially(files, index + 1);
});
}

function dynamic_javascript_load(arrayOrString) {
if (Array.isArray(arrayOrString)) {
for (const file of arrayOrString) {
dynamic_javascript_file_load(file);
}
}else {
dynamic_javascript_file_load(arrayOrString);
}
}
function dynamic_javascript_file_load(filename, callback) {
var element = document.createElement('script');
element.setAttribute('type', 'text/javascript');
element.setAttribute('src', 'js/' + filename);

// Set up callback to fire when script has loaded
if (callback) {
element.onload = callback;
element.onerror = function() {
console.error('Failed to load script: ' + filename);
callback(); // Continue loading other scripts even if one fails
};
}

document.getElementsByTagName('head')[0].appendChild(element);
return element;
}
function dynamic_css_load(arrayOrString) {
if (Array.isArray(arrayOrString)) {
for (const file of arrayOrString) {
dynamic_css_file_load(file);
}
}else {
dynamic_css_file_load(arrayOrString);
}
}
function dynamic_css_file_load(filename) {
var element = document.createElement('link');
element.setAttribute('rel', 'stylesheet');
element.setAttribute('type', 'text/css');
element.setAttribute('href', 'css/' + filename);
document.getElementsByTagName('head')[0].appendChild(element);
return element;
}
Expand Down Expand Up @@ -331,6 +398,7 @@ function render(reqs, template, highlight) {
var old_template = current_template;
current_template = template;
current_reqs = reqs;
clear_postprocessors();
for (var i in outstanding_reqs) {
outstanding_reqs[i].abort();
}
Expand All @@ -340,6 +408,11 @@ function render(reqs, template, highlight) {
window.scrollTo(0, 0);
}
update();
notifyActivatedTab(current_highlight);
}

function reset_current_reqs() {
current_reqs = {};
}

function update() {
Expand Down Expand Up @@ -839,6 +912,8 @@ function postprocess() {
$('.administrator-only').remove();
}

invokeRegisteredPostProcessors();

update_multifields();
}

Expand Down Expand Up @@ -1319,15 +1394,15 @@ function update_status(status) {



function with_req(method, path, body, fun) {
function with_req(method, path, body, fun, on404fun) {
if(!has_auth_credentials()) {
// Clear any lingering auth settings in local storage and navigate to the login form.
clear_auth();
location.reload();
return;
}

var json;
const full_page_404 = !on404fun
var req = xmlHttpRequest();
req.open(method, 'api' + path, true );
var header = authorization_header();
Expand All @@ -1341,9 +1416,11 @@ function with_req(method, path, body, fun) {
if (ix != -1) {
outstanding_reqs.splice(ix, 1);
}
if (check_bad_response(req, true)) {
if (check_bad_response(req, full_page_404)) {
last_successful_connect = new Date();
fun(req);
} else if (req.status == 404) {
on404fun(JSON.parse(req.responseText))
}
}
};
Expand Down
5 changes: 3 additions & 2 deletions deps/rabbitmq_management/priv/www/js/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function get_local_pref(k) {
}
}

function get_pref(k) {
function get_pref(k, defaultValue = undefined) {
var val;
if (local_storage_available()) {
val = window.localStorage['rabbitmq.' + k];
Expand All @@ -177,7 +177,8 @@ function get_pref(k) {
val = parse_cookie()[short_key(k)];

}
var res = (val == undefined) ? default_pref(k) : val;
var res = (val == undefined) ?
(defaultValue != undefined ? defaultValue : default_pref(k)) : val;
return res;
}

Expand Down
44 changes: 1 addition & 43 deletions deps/rabbitmq_management/priv/www/js/tmpl/queue.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -101,49 +101,7 @@
<%= format('publish', {'mode': 'queue', 'queue': queue}) %>

<% if (QUEUE_TYPE(queue).actions.get_message) { %>
<div class="section-hidden">
<h2>Get messages</h2>
<div class="hider">
<p>
Warning: getting messages from a queue is a destructive action.
<span class="help" id="message-get-requeue"></span>
</p>
<form action="#/queues/get" method="post">
<input type="hidden" name="vhost" value="<%= fmt_string(queue.vhost) %>"/>
<input type="hidden" name="name" value="<%= fmt_string(queue.name) %>"/>
<input type="hidden" name="truncate" value="50000"/>
<table class="form">
<tr>
<th><label>Ack Mode:</label></th>
<td>
<select name="ackmode">
<option value="ack_requeue_true" selected>Nack message requeue true</option>
<option value="ack_requeue_false">Automatic ack</option>
<option value="reject_requeue_true">Reject requeue true</option>
<option value="reject_requeue_false">Reject requeue false</option>
</select>
</td>
</tr>
<tr>
<th><label>Encoding:</label></th>
<td>
<select name="encoding">
<option value="auto">Auto string / base64</option>
<option value="base64">base64</option>
</select>
<span class="help" id="string-base64"></span>
</td>
</tr>
<tr>
<th><label>Messages:</label></th>
<td><input type="text" name="count" value="1"/></td>
</tr>
</table>
<input type="submit" value="Get Message(s)" />
</form>
<div id="msg-wrapper"></div>
</div>
</div>
<%= format(QUEUE_TYPE(queue).tmpl.get_message, {queue: queue}) %>
<% } %>

<% if (is_user_policymaker) { %>
Expand Down
6 changes: 5 additions & 1 deletion deps/rabbitmq_management/src/rabbit_mgmt_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

%% TODO sort all this out; maybe there's scope for rabbit_mgmt_request?

-export([is_authorized/2, is_authorized_admin/2, is_authorized_admin/4,
-export([is_authorized/2, is_authorized/4, is_authorized_admin/2, is_authorized_admin/4,
is_authorized_admin/3, vhost/1, vhost_from_headers/1]).
-export([is_authorized_vhost/2, is_authorized_user/3,
is_authorized_user/4, is_authorized_user/5,
Expand Down Expand Up @@ -89,6 +89,10 @@ is_authorized_admin(ReqData, Context) ->
Context,
auth_config()).

is_authorized(ReqData, Context, ErrorMsg, Fun) ->
rabbit_web_dispatch_access_control:is_authorized(ReqData,
Context, ErrorMsg, Fun, auth_config()).

is_authorized_admin(ReqData, Context, Token) ->
AuthConfig = auth_config(),
rabbit_web_dispatch_access_control:is_authorized(
Expand Down
Loading
Loading