/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. Copyright (c) 2014 Mozilla Corporation Contributors: Jeff Bryner jbryner@mozilla.com Anthony Verez averez@mozilla.com */ if (Meteor.isClient) { //defaults: Meteor.startup(function () { Session.set('verisfilter',''); Session.set('alertsearchtext',''); Session.set('attackerlimit','10'); }); //helper functions for UI templates //and other client javascript routines dateOrNull=function(maybeDate){ adate=moment(maybeDate); if (adate.isValid()) { return adate.toDate(); }else{ return null; } }; dateFormat=function(adate){ mdate=moment(adate || null); if (mdate.isValid()) { dformat='MM/DD/YYYY hh:mm:ss A'; return mdate.format(dformat); }else{ return ''; } }; //debug/testing functions debugLog=function(logthis){ if (typeof console !== 'undefined') { console.log(logthis); } }; Template.hello.greeting = function () { if (typeof console !== 'undefined') console.log("mozdef starting"); return "MozDef: the Mozilla defense platform"; }; Template.hello.events({ 'click' : function () { // template data, if any, is available in 'this' Session.set('displayMessage', 'Welcome & to mozdef.') } }); // loads kibana dashboards Template.menu.kibanadashboards = function() { Meteor.call('loadKibanaDashboards'); return kibanadashboards.find(); }; UI.registerHelper('uiDateFormat',function(adate){ return dateFormat(adate); }); //helper functions for handlebars UI.registerHelper('now', function() { return new Date(); }); UI.registerHelper('mozdef',function(){ //return the mozdef server settings object. return mozdef }); UI.registerHelper('getAlertURL', function(alertid){ //could be mongo id or es id //assume mongo if ( alerts.find({'_id':alertid}).count() >0 ){ id=alerts.findOne({'_id':alertid}).esmetadata.id; return(getSetting('rootURL') + '/alert/' + id); }else{ return(getSetting('rootURL') + '/alert/' + alertid); } }); UI.registerHelper('isselected',function(optionvalue,datavalue){ if (optionvalue==datavalue){ return 'selected' }else{ return '' } }); UI.registerHelper('eachSorted',function(context,options){ var ret = ""; for(var i=0, j=context.length; i