2 typeof define === "function" ? function (m) { define("kismet-ui-settings-js", m); } :
3 typeof exports === "object" ? function (m) { module.exports = m(); } :
4 function(m){ this.kismet_ui_settings = m(); }
11 var local_uri_prefix = "";
12 if (typeof(KISMET_URI_PREFIX) !== 'undefined')
13 local_uri_prefix = KISMET_URI_PREFIX;
15 // Flag we're still loading
16 exports.load_complete = 0;
24 href: local_uri_prefix + 'css/kismet.ui.settings.css'
28 * Settings are stored as an array of objects which define a title and a
29 * callback executed when the title is selected, or when the save/reset
32 * The settings panel is a modular alert window which implements a two-pane
33 * settings window with multiple settings categories on the left and the
34 * settings pane itself in the center.
38 var SettingsPanes = new Array();
40 /* Add a settings pane
42 * Options is a dictionary which must include:
44 * listTitle: Title shown in list
45 * windowTitle: Title appended to window (optional, if omitted, will use listTitle)
46 * create: Function creating the settings panel in a provided element
47 * save: Function for saving the panel
48 * priority: priority in list, lower is higher (optional)
50 * Settings panels should notify the when a setting is changed via
51 * kismet_ui_settings.SettingsChanged()
54 exports.AddSettingsPane = function(options) {
55 if (! 'listTitle' in options ||
56 ! 'create' in options ||
57 ! 'save' in options) {
61 if (! 'priority' in options)
62 options['priority'] = 0;
64 SettingsPanes.push(options);
68 var settingspanel = null;
69 var alertpanel = null;
71 /* Indicate to the settings UI that an option has been modified so that the
72 * save and reset buttons can be activated */
73 exports.SettingsModified = function(mod = true) {
77 $('.k-s-button-save', settingspanel.content).button("enable");
78 $('.k-s-button-save', settingspanel.content).addClass('k-s-button-hot');
80 $('.k-s-button-reset', settingspanel.content).button("enable");
84 $('.k-s-button-save', settingspanel.content).button("disable");
85 $('.k-s-button-save', settingspanel.content).removeClass('k-s-button-hot');
87 $('.k-s-button-reset', settingspanel.content).button("disable");
92 var selected_item = null;
94 function clickSetting(c) {
95 if (c == selected_item)
100 if ('windowTitle' in c)
101 settingspanel.headerTitle('Settings - ' + c.windowTitle);
103 settingspanel.headerTitle('Settings - ' + c.listTitle);
105 exports.SettingsModified(false);
107 $('.k-s-list-item', settingspanel.content).removeClass('k-s-list-item-active');
108 $('.k-s-list-item#sb_' + c.position,
109 settingspanel.content).addClass('k-s-list-item-active');
114 function populateSetting(c) {
116 var content = $('.k-s-pane-content', settingspanel.content);
122 function createClickCallback(c) {
123 return function() { checkClose(c); };
126 function populateList(list) {
127 SettingsPanes.sort(function(a, b) {
128 if (a.priority < b.priority)
130 if (a.priority > b.priority)
136 for (var i in SettingsPanes) {
137 var c = SettingsPanes[i];
143 class: 'k-s-list-item',
144 id: 'sb_' + c.position,
147 .on('click', createClickCallback(c))
152 function checkClose(transfer = null) {
154 if (transfer != null) {
155 clickSetting(transfer);
163 var content = $('<div>', {
168 class: 'k-s-alert-content'
172 class: 'k-s-alert-header'
174 .html("Settings changed")
178 .html("Would you like to save the changes?")
183 class: 'k-s-pane-buttons'
187 class: 'k-s-button-reset'
191 .on('click', function() {
192 exports.SettingsModified(false);
193 if (transfer != null) {
195 clickSetting(transfer);
197 settingspanel.close();
203 class: 'k-s-button-save'
205 .text("Save Changes")
207 .on('click', function() {
208 if (selected_item != null) {
209 selected_item.save(settingspanel.content);
210 exports.SettingsModified(false);
213 if (transfer != null) {
215 clickSetting(transfer);
217 settingspanel.close();
223 alertpanel = $.jsPanel({
224 template: jsPanel.tplContentOnly,
225 container: settingspanel,
234 of: '.k-s-container',
237 width: $('.k-s-container', settingspanel.content).width() * 0.4,
238 height: $('.k-s-container', settingspanel.content).height() * 0.25,
240 theme: 'red filledlight',
242 show: 'animated bounceInLeft',
250 exports.ShowSettings = function(starter) {
251 var w = $(window).width() * 0.75;
252 var h = $(window).height() * 0.75;
254 if (w < 450 || h < 450) {
255 w = $(window).width() - 5;
256 h = $(window).height() - 5;
259 var content = $('<div>', {
260 class: 'k-s-container'
269 class: 'k-s-pane-holder'
273 class: 'k-s-pane-content'
277 .html("Kismet Settings")
281 .html('Kismet UI settings are stored in your browsers local storage, and are unique to each browser.')
285 .html('To perform some actions (configuring data sources, downloading pcap files, and changing other server-side options), you need to be logged in. Kismet generates a random password, which can be found in the file <code>~/.kismet/kismet_httpd.conf</code>.')
289 .html('If you do not want to log in or are a guest on this server, you can still set local preferences and view device information.')
294 class: 'k-s-pane-buttons'
298 class: 'k-s-button-reset'
303 .on('click', function() {
304 if (selected_item != null) {
305 exports.SettingsModified(false);
306 populateSetting(selected_item);
312 class: 'k-s-button-save'
314 .text("Save Changes")
317 .on('click', function() {
318 if (selected_item != null) {
319 selected_item.save(content);
320 exports.SettingsModified(false);
327 populateList($('.k-s-list', content));
329 selected_item = null;
331 settingspanel = $.jsPanel({
333 headerTitle: '<i class="fa fa-gear" /> Settings',
336 controls: 'closeonly',
339 onbeforeclose: function() {
353 for (var i in SettingsPanes) {
354 var c = SettingsPanes[i];
356 if (c.id == starter) {
365 /* Add the settings sidebar */
366 kismet_ui_sidebar.AddSidebarItem({
367 id: 'sidebar-settings',
368 listTitle: '<i class="fa fa-gear"></i> Settings',
370 clickCallback: function() {
371 exports.ShowSettings();
376 // We're done loading
377 exports.load_complete = 1;