1 // Display the messagebus message system from Kismet
3 // dragorn@kismetwireless.net
4 // MIT/GPL License (pick one); the web ui code is licensed more
5 // freely than GPL to reflect the generally MIT-licensed nature
6 // of the web/jquery environment
9 // use_color (bool) (true) - Colorize messages
10 // scroll (bool) (true) - Make scrollable
11 // max_messages (int) (30) - Maximum messages to show
12 // old_time (int) (30) - How long before a message is considered 'old'
13 // class_debug (string) (messagebus_debug) - Display class applied to debug msgs
14 // class_info (string) (messagebus_info) - Display class applied to info msgs
15 // class_error (string) (messagebus_error) - Display class applied to error msgs
16 // class_alert (string) (messagebus_alert) - Display class applied to alert msgs
17 // class_fatal (string) (messagebus_fatal) - Display class applied to fatal msgs
18 // class_old (string) (messagebus_old) - Display class applied to old msgs
22 var local_uri_prefix = "";
23 if (typeof(KISMET_URI_PREFIX) !== 'undefined')
24 local_uri_prefix = KISMET_URI_PREFIX;
28 var MSGFLAG_DEBUG = 1;
30 var MSGFLAG_ERROR = 4;
31 var MSGFLAG_ALERT = 8;
32 var MSGFLAG_FATAL = 16;
38 class_debug: "messagebus_debug",
39 class_info: "messagebus_info",
40 class_error: "messagebus_error",
41 class_alert: "messagebus_alert",
42 class_fatal: "messagebus_fatal",
43 class_old: "messagebus_old",
46 var merge_messages = function(state, messages) {
47 var divs = $('div.messagebus_message', state['element']);
49 $.merge(messages, state['message_list']);
51 state['message_list'] = messages.slice(0, state['options'].max_messages);
53 for (var x = 0; x < state['message_list'].length; x++) {
56 // Compute trimmed date
57 var ds = (new Date(state['message_list'][x]['kismet.messagebus.message_time'] * 1000).toString()).substring(4, 25);
60 var pse = $('<p>').text(ds);
61 var ce = $('<span>').html(kismet.sanitizeHTML(kismet.censorMAC(state['message_list'][x]['kismet.messagebus.message_string'])));
68 d.html(`<p>${ds}</p> ${kismet.censorMAC(state['message_list'][x]['kismet.messagebus.message_string'])}`);
70 // Remove all flagged clases
71 d.removeClass("messagebus_debug");
72 d.removeClass("messagebus_info");
73 d.removeClass("messagebus_error");
74 d.removeClass("messagebus_alert");
75 d.removeClass("messagebus_fatal");
77 var f = state['message_list'][x]['kismet.messagebus.message_flags'];
79 if (f & MSGFLAG_FATAL) {
80 d.addClass("messagebus_fatal");
81 } else if (f & MSGFLAG_ALERT) {
82 d.addClass("messagebus_alert");
83 } else if (f & MSGFLAG_ERROR) {
84 d.addClass("messagebus_error");
85 } else if (f & MSGFLAG_INFO) {
86 d.addClass("messagebus_info");
87 } else if (f & MSGFLAG_DEBUG) {
88 d.addClass("messagebus_debug");
93 var messagebus_refresh = function(state) {
94 $.get(local_uri_prefix + "messagebus/last-time/" +
95 state['last_msg_time'] + "/messages.json")
96 .done(function(data) {
97 data['kismet.messagebus.list'].reverse();
99 merge_messages(state, kismet.sanitizeObject(data['kismet.messagebus.list']));
103 $.fn.messagebus = function(inopt) {
106 options: base_options,
112 state['element'].empty();
114 state['element'].addClass('messagebus');
116 state['options'] = $.extend(base_options, inopt);
118 // Fill the div with placeholders for as many messages as we need
119 var ndiv = $('div.messagebus_message', state['element']).length;
121 if (ndiv < state['options'].max_messages) {
122 for (var x = ndiv; x < state['options'].max_messages; x++) {
123 var d = $('<div>', { class: "messagebus_message" });
124 state['element'].append(d);
126 } else if (ndiv > state['options'].max_messages) {
128 $('div.messagebus_message', state['element']).each(function() {
129 if (ndiv - nremoved <= state['options'].max_messages) {
138 messagebus_refresh(state);
140 kismet_ui_base.SubscribeEventbus("MESSAGE", [], function(data) {
141 data = kismet.sanitizeObject(data);
142 merge_messages(state, [data]);