You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by om...@apache.org on 2015/12/08 07:37:56 UTC

[32/51] [partial] incubator-metron git commit: Initial import of code from https://github.com/OpenSOC/opensoc at ac0b00373f8f56dfae03a8109af5feb373ea598e.

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/directives/kibanaPanel.js
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/directives/kibanaPanel.js b/opensoc-ui/lib/public/app/directives/kibanaPanel.js
new file mode 100755
index 0000000..f9e7fd6
--- /dev/null
+++ b/opensoc-ui/lib/public/app/directives/kibanaPanel.js
@@ -0,0 +1,131 @@
+define([
+  'angular',
+  'jquery'
+],
+function (angular,$) {
+  'use strict';
+
+  angular
+    .module('kibana.directives')
+    .directive('kibanaPanel', function($compile) {
+      var container = '<div class="panel-container" ng-style="{\'min-height\':row.height}"></div>';
+      var content = '<div class="panel-content"></div>';
+
+      var panelHeader =
+      '<div class="panel-header">'+
+        '<div class="row-fluid">' +
+          '<div class="span12 alert-error panel-error" ng-hide="!panel.error">' +
+            '<a class="close" ng-click="panel.error=false">&times;</a>' +
+            '<i class="icon-exclamation-sign"></i> <strong>Oops!</strong> {{panel.error}}' +
+          '</div>' +
+        '</div>\n' +
+
+        '<div class="row-fluid panel-extra">' +
+          '<div class="panel-extra-container">' +
+
+            '<span class="extra row-button" ng-show="panel.editable != false && panel.removable != false">' +
+              '<span confirm-click="row.panels = _.without(row.panels,panel)" '+
+              'confirmation="Are you sure you want to remove this {{panel.type}} panel?" class="pointer">'+
+              '<i class="icon-remove pointer" bs-tooltip="\'Remove\'"></i></span>'+
+            '</span>' +
+
+            '<span class="extra row-button" ng-hide="panel.draggable == false">' +
+              '<span class="pointer" bs-tooltip="\'Drag here to move\'"' +
+              'data-drag=true data-jqyoui-options="kbnJqUiDraggableOptions"'+
+              ' jqyoui-draggable="'+
+              '{'+
+                'animate:false,'+
+                'mutate:false,'+
+                'index:{{$index}},'+
+                'onStart:\'panelMoveStart\','+
+                'onStop:\'panelMoveStop\''+
+                '}"  ng-model="row.panels"><i class="icon-move"></i></span>'+
+            '</span>' +
+
+            '<span class="row-button extra" ng-show="panel.editable != false">' +
+              '<span config-modal="./app/partials/paneleditor.html" kbn-model="panel" class="pointer">'+
+              '<i class="icon-cog pointer" bs-tooltip="\'Configure\'"></i></span>'+
+            '</span>' +
+
+            '<span ng-repeat="task in panelMeta.modals" class="row-button extra" ng-show="task.show">' +
+              '<span bs-modal="task.partial" class="pointer"><i ' +
+                'bs-tooltip="task.description" ng-class="task.icon" class="pointer"></i></span>'+
+            '</span>' +
+
+            '<span class="row-button extra" ng-show="panelMeta.loading == true">' +
+              '<span>'+
+                '<i class="icon-spinner icon-spin icon-large"></i>' +
+              '</span>'+
+            '</span>' +
+
+            '<span class="panel-text panel-title">' +
+              '{{panel.title?panel.title:panel.type}}' +
+            '</span>'+
+
+          '</div>'+
+        '</div>\n'+
+      '</div>';
+      return {
+        restrict: 'E',
+        link: function($scope, elem, attr) {
+          // once we have the template, scan it for controllers and
+          // load the module.js if we have any
+          var newScope = $scope.$new();
+
+          $scope.kbnJqUiDraggableOptions = {
+            revert: 'invalid',
+            helper: function() {
+              return $('<div style="width:200px;height:100px;background: rgba(100,100,100,0.50);"/>');
+            },
+            placeholder: 'keep'
+          };
+
+          // compile the module and uncloack. We're done
+          function loadModule($module) {
+            $module.appendTo(elem);
+            elem.wrap(container);
+            /* jshint indent:false */
+            $compile(elem.contents())(newScope);
+            elem.removeClass("ng-cloak");
+          }
+
+          newScope.$on('$destroy',function(){
+            elem.unbind();
+            elem.remove();
+          });
+
+          $scope.$watch(attr.type, function (name) {
+            elem.addClass("ng-cloak");
+            // load the panels module file, then render it in the dom.
+            var nameAsPath = name.replace(".", "/");
+            $scope.require([
+              'jquery',
+              'text!panels/'+nameAsPath+'/module.html',
+              'text!panels/'+nameAsPath+'/editor.html'
+            ], function ($, moduleTemplate) {
+              var $module = $(moduleTemplate);
+              // top level controllers
+              var $controllers = $module.filter('ngcontroller, [ng-controller], .ng-controller');
+              // add child controllers
+              $controllers = $controllers.add($module.find('ngcontroller, [ng-controller], .ng-controller'));
+
+              if ($controllers.length) {
+                $controllers.first().prepend(panelHeader);
+
+                $controllers.first().find('.panel-header').nextAll().wrapAll(content);
+
+                $scope.require([
+                  'panels/'+nameAsPath+'/module'
+                ], function() {
+                  loadModule($module);
+                });
+              } else {
+                loadModule($module);
+              }
+            });
+          });
+        }
+      };
+    });
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/directives/kibanaSimplePanel.js
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/directives/kibanaSimplePanel.js b/opensoc-ui/lib/public/app/directives/kibanaSimplePanel.js
new file mode 100755
index 0000000..7bae5a4
--- /dev/null
+++ b/opensoc-ui/lib/public/app/directives/kibanaSimplePanel.js
@@ -0,0 +1,77 @@
+define([
+  'angular',
+  'lodash'
+],
+function (angular, _) {
+  'use strict';
+
+  angular
+    .module('kibana.directives')
+    .directive('kibanaSimplePanel', function($compile) {
+      var panelLoading = '<span ng-show="panelMeta.loading == true">' +
+        '<span style="font-size:24px;font-weight:200">'+
+          '<i class="icon-spinner icon-spin"></i> loading ...' +
+        '</span>'+
+      '</span>';
+
+      return {
+        restrict: 'E',
+        link: function($scope, elem, attr) {
+
+          // once we have the template, scan it for controllers and
+          // load the module.js if we have any
+
+          // compile the module and uncloack. We're done
+          function loadModule($module) {
+            $module.appendTo(elem);
+            /* jshint indent:false */
+            $compile(elem.contents())($scope);
+            elem.removeClass("ng-cloak");
+          }
+
+          function loadController(name) {
+            elem.addClass("ng-cloak");
+            // load the panels module file, then render it in the dom.
+            var nameAsPath = name.replace(".", "/");
+            $scope.require([
+              'jquery',
+              'text!panels/'+nameAsPath+'/module.html'
+            ], function ($, moduleTemplate) {
+              var $module = $(moduleTemplate);
+              // top level controllers
+              var $controllers = $module.filter('ngcontroller, [ng-controller], .ng-controller');
+              // add child controllers
+              $controllers = $controllers.add($module.find('ngcontroller, [ng-controller], .ng-controller'));
+
+              if ($controllers.length) {
+                $controllers.first().prepend(panelLoading);
+                $scope.require([
+                  'panels/'+nameAsPath+'/module'
+                ], function() {
+                  loadModule($module);
+                });
+              } else {
+                loadModule($module);
+              }
+            });
+          }
+
+          $scope.$watch(attr.type, function (name) {
+            loadController(name);
+          });
+
+          if(attr.panel) {
+            $scope.$watch(attr.panel, function (panel) {
+              // If the panel attribute is specified, create a new scope. This ruins configuration
+              // so don't do it with anything that needs to use editor.html
+              if(!_.isUndefined(panel)) {
+                $scope = $scope.$new();
+                $scope.panel = angular.fromJson(panel);
+              }
+            });
+          }
+        }
+      };
+    });
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/directives/ngBlur.js
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/directives/ngBlur.js b/opensoc-ui/lib/public/app/directives/ngBlur.js
new file mode 100755
index 0000000..469a4d1
--- /dev/null
+++ b/opensoc-ui/lib/public/app/directives/ngBlur.js
@@ -0,0 +1,20 @@
+define([
+  'angular'
+],
+function (angular) {
+  'use strict';
+
+  angular
+    .module('kibana.directives')
+    .directive('ngBlur', ['$parse', function($parse) {
+      return function(scope, element, attr) {
+        var fn = $parse(attr['ngBlur']);
+        element.bind('blur', function(event) {
+          scope.$apply(function() {
+            fn(scope, {$event:event});
+          });
+        });
+      };
+    }]);
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/directives/ngModelOnBlur.js
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/directives/ngModelOnBlur.js b/opensoc-ui/lib/public/app/directives/ngModelOnBlur.js
new file mode 100755
index 0000000..cc01ff0
--- /dev/null
+++ b/opensoc-ui/lib/public/app/directives/ngModelOnBlur.js
@@ -0,0 +1,25 @@
+define(['angular'],
+function (angular) {
+  'use strict';
+
+  angular
+    .module('kibana.directives')
+    .directive('ngModelOnblur', function() {
+      return {
+        restrict: 'A',
+        require: 'ngModel',
+        link: function(scope, elm, attr, ngModelCtrl) {
+          if (attr.type === 'radio' || attr.type === 'checkbox') {
+            return;
+          }
+
+          elm.unbind('input').unbind('keydown').unbind('change');
+          elm.bind('blur', function() {
+            scope.$apply(function() {
+              ngModelCtrl.$setViewValue(elm.val());
+            });
+          });
+        }
+      };
+    });
+});

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/directives/tip.js
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/directives/tip.js b/opensoc-ui/lib/public/app/directives/tip.js
new file mode 100755
index 0000000..d21b71f
--- /dev/null
+++ b/opensoc-ui/lib/public/app/directives/tip.js
@@ -0,0 +1,20 @@
+define([
+  'angular',
+  'kbn'
+],
+function (angular, kbn) {
+  'use strict';
+
+  angular
+    .module('kibana.directives')
+    .directive('tip', function($compile) {
+      return {
+        restrict: 'E',
+        link: function(scope, elem, attrs) {
+          var _t = '<i class="icon-'+(attrs.icon||'question-sign')+'" bs-tooltip="\''+
+            kbn.addslashes(elem.text())+'\'"></i>';
+          elem.replaceWith($compile(angular.element(_t))(scope));
+        }
+      };
+    });
+});

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/factories/store.js
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/factories/store.js b/opensoc-ui/lib/public/app/factories/store.js
new file mode 100755
index 0000000..1a714ef
--- /dev/null
+++ b/opensoc-ui/lib/public/app/factories/store.js
@@ -0,0 +1,59 @@
+define([
+  'angular',
+  'lodash'
+],
+function (angular, _) {
+  'use strict';
+
+  var module = angular.module('kibana.factories');
+  module.factory('storeFactory', function() {
+
+    return function storeFactory($scope, name, defaults) {
+      if (!_.isFunction($scope.$watch)) {
+        throw new TypeError('Invalid scope.');
+      }
+      if (!_.isString(name)) {
+        throw new TypeError('Invalid name, expected a string that the is unique to this store.');
+      }
+      if (defaults && !_.isPlainObject(defaults)) {
+        throw new TypeError('Invalid defaults, expected a simple object or nothing');
+      }
+
+      defaults = defaults || {};
+
+      // get the current value, parse if it exists
+      var current = localStorage.getItem(name);
+      if (current != null) {
+        try {
+          current = JSON.parse(current);
+        } catch (e) {
+          current = null;
+        }
+      }
+
+      if (current == null) {
+        current = _.clone(defaults);
+      } else if (_.isPlainObject(current)) {
+        _.defaults(current, defaults);
+      } else {
+        throw new TypeError('Invalid store value' + current);
+      }
+
+      $scope[name] = current;
+
+      // listen for changes and store them in localStorage.
+      // delete the value to reset to the defaults, ie. `delete $scope[name]` -> digest cycle -> `$scope[name] == defaults`
+      $scope.$watch(name, function (val) {
+        if (val === void 0) {
+          localStorage.removeItem(name);
+          $scope[name] = _.clone(defaults);
+        } else {
+          localStorage.setItem(name, JSON.stringify(val));
+        }
+      }, true);
+
+      return current;
+    };
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/filters/all.js
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/filters/all.js b/opensoc-ui/lib/public/app/filters/all.js
new file mode 100755
index 0000000..d9b3ced
--- /dev/null
+++ b/opensoc-ui/lib/public/app/filters/all.js
@@ -0,0 +1,133 @@
+define([
+  'angular',
+  'jquery',
+  'lodash',
+  'moment'
+], function (angular, $, _, moment) {
+  'use strict';
+
+  var module = angular.module('kibana.filters');
+
+  module.filter('stringSort', function() {
+    return function(input) {
+      return input.sort();
+    };
+  });
+
+  module.filter('pinnedQuery', function(querySrv) {
+    return function( items, pinned) {
+      var ret = _.filter(querySrv.ids(),function(id){
+        var v = querySrv.list()[id];
+        if(!_.isUndefined(v.pin) && v.pin === true && pinned === true) {
+          return true;
+        }
+        if((_.isUndefined(v.pin) || v.pin === false) && pinned === false) {
+          return true;
+        }
+      });
+      return ret;
+    };
+  });
+
+  module.filter('slice', function() {
+    return function(arr, start, end) {
+      if(!_.isUndefined(arr)) {
+        return arr.slice(start, end);
+      }
+    };
+  });
+
+  module.filter('stringify', function() {
+    return function(arr) {
+      if(_.isObject(arr) && !_.isArray(arr)) {
+        return angular.toJson(arr);
+      } else {
+        return _.isNull(arr) ? null : arr.toString();
+      }
+    };
+  });
+
+  module.filter('moment', function() {
+    return function(date,mode) {
+      switch(mode) {
+      case 'ago':
+        return moment(date).fromNow();
+      }
+      return moment(date).fromNow();
+    };
+  });
+
+  module.filter('noXml', function() {
+    var noXml = function(text) {
+      return _.isString(text)
+        ? text
+            .replace(/&/g, '&amp;')
+            .replace(/</g, '&lt;')
+            .replace(/>/g, '&gt;')
+            .replace(/'/g, '&#39;')
+            .replace(/"/g, '&quot;')
+        : text;
+    };
+    return function(text) {
+      return _.isArray(text)
+        ? _.map(text, noXml)
+        : noXml(text);
+    };
+  });
+
+  module.filter('urlLink', function() {
+    var  //URLs starting with http://, https://, or ftp://
+      r1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim,
+      //URLs starting with "www." (without // before it, or it'd re-link the ones done above).
+      r2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim,
+      //Change email addresses to mailto:: links.
+      r3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
+
+    var urlLink = function(text) {
+      var t1,t2,t3;
+      if(!_.isString(text)) {
+        return text;
+      } else {
+        _.each(text.match(r1), function() {
+          t1 = text.replace(r1, "<a href=\"$1\" target=\"_blank\">$1</a>");
+        });
+        text = t1 || text;
+        _.each(text.match(r2), function() {
+          t2 = text.replace(r2, "$1<a href=\"http://$2\" target=\"_blank\">$2</a>");
+        });
+        text = t2 || text;
+        _.each(text.match(r3), function() {
+          t3 = text.replace(r3, "<a href=\"mailto:$1\">$1</a>");
+        });
+        text = t3 || text;
+        return text;
+      }
+    };
+    return function(text) {
+      return _.isArray(text)
+        ? _.map(text, urlLink)
+        : urlLink(text);
+    };
+  });
+
+  module.filter('editable', function () {
+    return function (data) {
+      return _.filter(data, function (item) {
+        return item.editable !== false;
+      });
+    };
+  });
+
+  module.filter('gistid', function() {
+    var gist_pattern = /(\d{5,})|([a-z0-9]{10,})|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/;
+    return function(input) {
+      if(!(_.isUndefined(input))) {
+        var output = input.match(gist_pattern);
+        if(!_.isNull(output) && !_.isUndefined(output)) {
+          return output[0].replace(/.*\//, '');
+        }
+      }
+    };
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/panels/bettermap/editor.html
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/panels/bettermap/editor.html b/opensoc-ui/lib/public/app/panels/bettermap/editor.html
new file mode 100755
index 0000000..f3142c6
--- /dev/null
+++ b/opensoc-ui/lib/public/app/panels/bettermap/editor.html
@@ -0,0 +1,17 @@
+  <div class="editor-row">
+    <div class="editor-option">
+      <form>
+        <h6>Coordinate Field <tip>geoJSON array! Long,Lat NOT Lat,Long</tip></h6>
+        <input  bs-typeahead="fields.list" type="text" class="input-small" ng-model="panel.field">
+      </form>
+    </div>
+    <div class="editor-option">
+      <form>
+        <h6>Tooltip Field</h6>
+        <input  bs-typeahead="fields.list" type="text" class="input-small" ng-model="panel.tooltip">
+      </form>
+    </div>
+    <div class="editor-option"><h6>Max Points</h6>
+      <input type="number" class="input-small" ng-model="panel.size">
+    </div>
+  </div>

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/layers-2x.png
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/layers-2x.png b/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/layers-2x.png
new file mode 100755
index 0000000..a2cf7f9
Binary files /dev/null and b/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/layers-2x.png differ

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/layers.png
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/layers.png b/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/layers.png
new file mode 100755
index 0000000..bca0a0e
Binary files /dev/null and b/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/layers.png differ

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-icon-2x.png
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-icon-2x.png b/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-icon-2x.png
new file mode 100755
index 0000000..0015b64
Binary files /dev/null and b/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-icon-2x.png differ

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-icon.png
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-icon.png b/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-icon.png
new file mode 100755
index 0000000..e2e9f75
Binary files /dev/null and b/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-icon.png differ

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/05e188ba/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-shadow.png
----------------------------------------------------------------------
diff --git a/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-shadow.png b/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-shadow.png
new file mode 100755
index 0000000..d1e773c
Binary files /dev/null and b/opensoc-ui/lib/public/app/panels/bettermap/leaflet/images/marker-shadow.png differ