From 29b6d813addf7c8562b2abf35f23ce22c04380e0 Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Mon, 10 Apr 2017 15:41:35 +0200 Subject: [PATCH 01/78] NEMEA: submodule for reporter configuration bootstrap --- .../exporters_configuration.component.ts | 20 +++++++++++++++++++ .../exporters_configuration.html | 10 ++++++++++ .../exporters_configuration.scss | 0 .../exporters_configuration.service.ts | 8 ++++++++ www/src/app/modules/nemea/nemea.component.ts | 8 ++++++++ www/src/app/modules/nemea/nemea.module.ts | 13 ++++++++++-- 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 www/src/app/modules/nemea/configuration/exporters_configuration.component.ts create mode 100644 www/src/app/modules/nemea/configuration/exporters_configuration.html create mode 100644 www/src/app/modules/nemea/configuration/exporters_configuration.scss create mode 100644 www/src/app/modules/nemea/configuration/exporters_configuration.service.ts diff --git a/www/src/app/modules/nemea/configuration/exporters_configuration.component.ts b/www/src/app/modules/nemea/configuration/exporters_configuration.component.ts new file mode 100644 index 0000000..274389a --- /dev/null +++ b/www/src/app/modules/nemea/configuration/exporters_configuration.component.ts @@ -0,0 +1,20 @@ +import { Component, Pipe, PipeTransform } from '@angular/core'; +//import { nConfService } from './exporter_configuration.service'; + +@Component({ + selector : 'nemea-exporters-configuration', + templateUrl : './exporters_configuration.html', + styleUrls : ['./exporters_configuration.scss'], + providers : [] +}) +export class nemeaExportersConfigurationComponent { + + constructor() {} + + ngOnInit() { + } + + ngOnDestroy() { + } + +} diff --git a/www/src/app/modules/nemea/configuration/exporters_configuration.html b/www/src/app/modules/nemea/configuration/exporters_configuration.html new file mode 100644 index 0000000..f518bc2 --- /dev/null +++ b/www/src/app/modules/nemea/configuration/exporters_configuration.html @@ -0,0 +1,10 @@ +

+ + Nemea + +

+ + +
+ Here should be NEMEA reporter configuration +
diff --git a/www/src/app/modules/nemea/configuration/exporters_configuration.scss b/www/src/app/modules/nemea/configuration/exporters_configuration.scss new file mode 100644 index 0000000..e69de29 diff --git a/www/src/app/modules/nemea/configuration/exporters_configuration.service.ts b/www/src/app/modules/nemea/configuration/exporters_configuration.service.ts new file mode 100644 index 0000000..cf7470c --- /dev/null +++ b/www/src/app/modules/nemea/configuration/exporters_configuration.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from '@angular/core'; +import { Http, Headers, RequestOptions, Response } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; + +@Injectable() +export class nConfService { + constructor(private http : Http) {} +} diff --git a/www/src/app/modules/nemea/nemea.component.ts b/www/src/app/modules/nemea/nemea.component.ts index 1a61a9b..a444ad7 100644 --- a/www/src/app/modules/nemea/nemea.component.ts +++ b/www/src/app/modules/nemea/nemea.component.ts @@ -24,6 +24,14 @@ export class nemeaBase {}; + +
+

+ + Nemea Configuration + +

+
` }) diff --git a/www/src/app/modules/nemea/nemea.module.ts b/www/src/app/modules/nemea/nemea.module.ts index ceb9f5c..cd86b0c 100644 --- a/www/src/app/modules/nemea/nemea.module.ts +++ b/www/src/app/modules/nemea/nemea.module.ts @@ -4,8 +4,9 @@ import { Routes, RouterModule} from '@angular/router'; import { FormsModule } from '@angular/forms'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { nemeaBase, nemeaComponent } from './nemea.component'; -import { nemeaStatusComponent } from './status/nemea_status.component' -import { EventsComponent } from './events/events.component' +import { nemeaStatusComponent } from './status/nemea_status.component'; +import { EventsComponent } from './events/events.component'; +import { nemeaExportersConfigurationComponent } from './configuration/exporters_configuration.component'; import { AuthGuard } from 'app/utils/auth.guard'; import { IdeaPipe } from './events/idea.pipe'; @@ -49,6 +50,14 @@ const nemeaRoutes : Routes = [ data : { role : 10 } + }, + { + path : 'exporters', + component: nemeaExportersConfigurationComponent, + canActivate : [AuthGuard], + data : { + role : 10 + } } ] } From ecfcc16586abf50ace4a297740125f538ba9d13d Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Thu, 13 Apr 2017 09:14:32 +0200 Subject: [PATCH 02/78] NEMEA: Rename exporters to reporters --- www/src/app/modules/nemea/nemea.component.ts | 4 ++-- www/src/app/modules/nemea/nemea.module.ts | 7 ++++--- .../reporter_conf.component.ts} | 8 ++++---- .../reporter_conf.html} | 0 .../reporter_conf.scss} | 0 .../reporter_conf.service.ts} | 0 6 files changed, 10 insertions(+), 9 deletions(-) rename www/src/app/modules/nemea/{configuration/exporters_configuration.component.ts => reporter/reporter_conf.component.ts} (53%) rename www/src/app/modules/nemea/{configuration/exporters_configuration.html => reporter/reporter_conf.html} (100%) rename www/src/app/modules/nemea/{configuration/exporters_configuration.scss => reporter/reporter_conf.scss} (100%) rename www/src/app/modules/nemea/{configuration/exporters_configuration.service.ts => reporter/reporter_conf.service.ts} (100%) diff --git a/www/src/app/modules/nemea/nemea.component.ts b/www/src/app/modules/nemea/nemea.component.ts index de13933..2764544 100644 --- a/www/src/app/modules/nemea/nemea.component.ts +++ b/www/src/app/modules/nemea/nemea.component.ts @@ -27,8 +27,8 @@ export class nemeaBase {};

- - Nemea Configuration + + Nemea Reporter Configuration

diff --git a/www/src/app/modules/nemea/nemea.module.ts b/www/src/app/modules/nemea/nemea.module.ts index a61bcbc..2b9c902 100644 --- a/www/src/app/modules/nemea/nemea.module.ts +++ b/www/src/app/modules/nemea/nemea.module.ts @@ -6,7 +6,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { nemeaBase, nemeaComponent } from './nemea.component'; import { nemeaStatusComponent } from './status/nemea_status.component'; import { EventsComponent } from './events/events.component'; -import { nemeaExportersConfigurationComponent } from './configuration/exporters_configuration.component'; +import { nemeaReporterConfComponent } from './reporter/reporter_conf.component'; import { AuthGuard } from 'app/utils/auth.guard'; import { IdeaPipe } from './events/idea.pipe'; @@ -53,8 +53,8 @@ const nemeaRoutes : Routes = [ } }, { - path : 'exporters', - component: nemeaExportersConfigurationComponent, + path : 'reporters', + component: nemeaReporterConfComponent, canActivate : [AuthGuard], data : { role : 10 @@ -79,6 +79,7 @@ const nemeaRoutes : Routes = [ nemeaBase, nemeaComponent, nemeaStatusComponent, + nemeaReporterConfComponent, EventsComponent, EventItemComponent, EventDetailComponent], diff --git a/www/src/app/modules/nemea/configuration/exporters_configuration.component.ts b/www/src/app/modules/nemea/reporter/reporter_conf.component.ts similarity index 53% rename from www/src/app/modules/nemea/configuration/exporters_configuration.component.ts rename to www/src/app/modules/nemea/reporter/reporter_conf.component.ts index 274389a..4361fdb 100644 --- a/www/src/app/modules/nemea/configuration/exporters_configuration.component.ts +++ b/www/src/app/modules/nemea/reporter/reporter_conf.component.ts @@ -2,12 +2,12 @@ import { Component, Pipe, PipeTransform } from '@angular/core'; //import { nConfService } from './exporter_configuration.service'; @Component({ - selector : 'nemea-exporters-configuration', - templateUrl : './exporters_configuration.html', - styleUrls : ['./exporters_configuration.scss'], + selector : 'nemea-reporter-conf', + templateUrl : './reporter_conf.html', + styleUrls : ['./reporter_conf.scss'], providers : [] }) -export class nemeaExportersConfigurationComponent { +export class nemeaReporterConfComponent { constructor() {} diff --git a/www/src/app/modules/nemea/configuration/exporters_configuration.html b/www/src/app/modules/nemea/reporter/reporter_conf.html similarity index 100% rename from www/src/app/modules/nemea/configuration/exporters_configuration.html rename to www/src/app/modules/nemea/reporter/reporter_conf.html diff --git a/www/src/app/modules/nemea/configuration/exporters_configuration.scss b/www/src/app/modules/nemea/reporter/reporter_conf.scss similarity index 100% rename from www/src/app/modules/nemea/configuration/exporters_configuration.scss rename to www/src/app/modules/nemea/reporter/reporter_conf.scss diff --git a/www/src/app/modules/nemea/configuration/exporters_configuration.service.ts b/www/src/app/modules/nemea/reporter/reporter_conf.service.ts similarity index 100% rename from www/src/app/modules/nemea/configuration/exporters_configuration.service.ts rename to www/src/app/modules/nemea/reporter/reporter_conf.service.ts From 4d53863e648a32d0fa24ff338d01ce0e7445cf2a Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Thu, 13 Apr 2017 09:41:34 +0200 Subject: [PATCH 03/78] NEMEA: symlink for reporter module --- api/liberouterapi/modules/nemea-reporter-rest | 1 + 1 file changed, 1 insertion(+) create mode 120000 api/liberouterapi/modules/nemea-reporter-rest diff --git a/api/liberouterapi/modules/nemea-reporter-rest b/api/liberouterapi/modules/nemea-reporter-rest new file mode 120000 index 0000000..36cfd0b --- /dev/null +++ b/api/liberouterapi/modules/nemea-reporter-rest @@ -0,0 +1 @@ +../../../modules/Nemea-Dashboard/api/modules/nemea/reporter-rest \ No newline at end of file From dab49143b4d7041a8a6558791c70465ee6adc2b9 Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Thu, 13 Apr 2017 14:48:34 +0200 Subject: [PATCH 04/78] Reporter service with dummy data and methods --- .../nemea/reporter/reporter.service.spec.ts | 16 ++++ .../nemea/reporter/reporter.service.ts | 85 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 www/src/app/modules/nemea/reporter/reporter.service.spec.ts create mode 100644 www/src/app/modules/nemea/reporter/reporter.service.ts diff --git a/www/src/app/modules/nemea/reporter/reporter.service.spec.ts b/www/src/app/modules/nemea/reporter/reporter.service.spec.ts new file mode 100644 index 0000000..f7d207d --- /dev/null +++ b/www/src/app/modules/nemea/reporter/reporter.service.spec.ts @@ -0,0 +1,16 @@ +/* tslint:disable:no-unused-variable */ + +import { TestBed, async, inject } from '@angular/core/testing'; +import { ReporterService } from './reporter.service'; + +describe('ReporterService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ReporterService] + }); + }); + + it('should ...', inject([ReporterService], (service: ReporterService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/www/src/app/modules/nemea/reporter/reporter.service.ts b/www/src/app/modules/nemea/reporter/reporter.service.ts new file mode 100644 index 0000000..39eebd8 --- /dev/null +++ b/www/src/app/modules/nemea/reporter/reporter.service.ts @@ -0,0 +1,85 @@ +import { Injectable } from '@angular/core'; +import { Http, Headers, RequestOptions, Response, URLSearchParams } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; + +let test_conf = [["hoststats2idea", {"idx": 12, "status": "running", "CPU-u": 0, "MEM-rss": 24502272, "MEM-vms": 209367040, "config": "/etc/nemea/reporters/config.yaml", "CPU-s": 0, "outputs": [], "inputs": [{"messages": 1, "type": "t", "is-conn": 1, "ID": "12002", "buffers": 1}], "path": "python", "params": "/usr/bin/nemea/hoststats2idea.py --name=cz.cesnet.nemea.hoststats --config=/etc/nemea/reporters/config.yaml --verbose=1"}], ["haddrscan2idea", {"idx": 13, "status": "stopped", "CPU-u": 1, "MEM-rss": 15761408, "MEM-vms": 122785792, "CPU-s": 0, "outputs": [], "inputs": [], "path": "/usr/bin/nemea/haddrscan2idea.py", "params": "--name=cz.cesnet.nemea.haddrscan --mongodb=nemeadb --mongodb-coll=alerts_new"}], ["vportscan2idea", {"idx": 14, "status": "stopped", "CPU-u": 1, "MEM-rss": 15761408, "MEM-vms": 122785792, "CPU-s": 0, "outputs": [], "inputs": [], "path": "/usr/bin/nemea/vportscan2idea.py", "params": "--name=cz.cesnet.nemea.vportscan --mongodb=nemeadb --mongodb-coll=alerts_new"}], ["bruteforce2idea", {"idx": 15, "status": "stopped", "CPU-u": 1, "MEM-rss": 15503360, "MEM-vms": 122511360, "CPU-s": 0, "outputs": [], "inputs": [], "path": "python", "params": "/usr/bin/nemea/bruteforce2idea.py --name=cz.cesnet.nemea.bruteforce_detector --mongodb=nemeadb --mongodb-coll=alerts_new"}], ["amplification2idea", {"idx": 16, "status": "stopped", "CPU-u": 1, "MEM-rss": 15769600, "MEM-vms": 122761216, "CPU-s": 0, "outputs": [], "inputs": [], "path": "/usr/bin/nemea/amplification2idea.py", "params": "--name=cz.cesnet.nemea.amplification_detection --mongodb=nemeadb --mongodb-coll=alerts_new"}], ["ipblacklist2idea", {"idx": 17, "status": "stopped", "CPU-u": 1, "MEM-rss": 15785984, "MEM-vms": 122806272, "CPU-s": 0, "outputs": [], "inputs": [], "path": "/usr/bin/nemea/ipblacklist2idea.py", "params": "--name=cz.cesnet.nemea.ipblacklistfilter --mongodb=nemeadb --mongodb-coll=alerts_new"}], ["voipfraud2idea", {"idx": 22, "status": "stopped", "CPU-u": 0, "MEM-rss": 0, "MEM-vms": 0, "CPU-s": 0, "outputs": [], "inputs": [], "path": "/usr/bin/nemea/voipfraud2idea.py", "params": "--name=org.tf-csirt.nemea.voipfraud_detection --mongodb=nemeadb --mongodb-coll=alerts_new"}], ["sipbf2idea", {"idx": 25, "status": "stopped", "CPU-u": 0, "MEM-rss": 0, "MEM-vms": 0, "CPU-s": 0, "outputs": [], "inputs": [], "path": "/usr/bin/nemea/sipbf2idea.py", "params": "--name=org.tf-csirt.nemea.sip_bf_detector --mongodb=nemeadb --mongodb-coll=alerts_new"}], ["haddrscan2idea2", {"idx": 27, "status": "stopped", "CPU-u": 0, "MEM-rss": 0, "MEM-vms": 0, "CPU-s": 0, "outputs": [], "inputs": [], "path": "/usr/bin/nemea/haddrscan2idea.py", "params": "--name=org.tf-csirt.nemea.haddrscan --mongodb=nemeadb --mongodb-coll=alerts_new"}], ["vportscan2idea2", {"idx": 28, "status": "stopped", "CPU-u": 0, "MEM-rss": 0, "MEM-vms": 0, "CPU-s": 0, "outputs": [], "inputs": [], "path": "/usr/bin/nemea/vportscan2idea.py", "params": "--name=org.tf-csirt.nemea.vportscan --mongodb=nemeadb --mongodb-coll=alerts_new"}], ["hoststats2idea2", {"idx": 34, "status": "stopped", "CPU-u": 0, "MEM-rss": 0, "MEM-vms": 0, "CPU-s": 0, "outputs": [], "inputs": [], "path": "python", "params": "/usr/bin/nemea/hoststats2idea.py --name=org.tf-csirt.nemea.hoststats --mongodb=nemeadb --mongodb-coll=alerts_new"}]]; + +let test_rep_config = `custom_actions: +- id: warden1 + type: warden + warden: + url: https://warden1 +- id: mongo1 + type: mongo + host: localhost + #port: 1234 + db: nemea_test + collection: alerts +- id: marktest + type: mark + mark: + path: Mark + value: test +- id: markwhitelisted + type: mark + mark: + path: _CESNET.Whitelisted + value: 'True' +addressgroups: +- id: main_whitelist + file: "whitelists/whitelist1" +- id: whitelist2 + list: + - 1.1.0.0/24 + - 1.2.3.4 +rules: +- id: 1 + condition: Source.IP4 in main_whitelist or Target.IP4 in main_whitelist + actions: + - markwhitelisted + - mongo1 + elseactions: + - mongo1` + + +@Injectable() +export class ReporterService { + + constructor(private http : Http) { } + + reporters_dummy() { + return test_conf; + } + + reporters() { + return this.http.get('/nemea/reporters').map( + (response : Response) => { + return response.json(); + }) + .catch(this.handleError); + } + + config_dummy(idx) { + if (idx < 0) + throw "Index not set"; + + console.debug("Should get id " + idx) + return test_rep_config; + } + + save(idx : number, conf : string) { + if (idx < 0) + throw "Index not set"; + + if (conf == '') + throw "Configuration is empty" + + console.log(idx); + console.log(conf); + } + + private handleError(err : Response | any) { + return Promise.reject(err); + } + +} From 823fd3d8bdfa745aa30bee1a6468ef43d8cde4b7 Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Thu, 13 Apr 2017 14:49:32 +0200 Subject: [PATCH 05/78] Reporter configuration front-end Backend communication is currently missing --- www/angular-cli.json | 3 +- www/package.json | 1 + www/src/app/modules/nemea/nemea.module.ts | 12 +++ .../nemea/reporter/reporter_conf.component.ts | 82 ++++++++++++++++++- .../modules/nemea/reporter/reporter_conf.html | 43 +++++++++- .../modules/nemea/reporter/reporter_conf.scss | 40 +++++++++ www/src/styles/main.scss | 6 ++ 7 files changed, 182 insertions(+), 5 deletions(-) diff --git a/www/angular-cli.json b/www/angular-cli.json index 32872b3..e719c7b 100644 --- a/www/angular-cli.json +++ b/www/angular-cli.json @@ -21,7 +21,8 @@ "styles": [ "styles/main.scss", "../node_modules/font-awesome/css/font-awesome.css", - "../node_modules/bootstrap/dist/css/bootstrap.min.css" + "../node_modules/bootstrap/dist/css/bootstrap.min.css", + "../node_modules/codemirror/lib/codemirror.css" ], "scripts": [], "environments": { diff --git a/www/package.json b/www/package.json index fa03587..4cd8e6e 100644 --- a/www/package.json +++ b/www/package.json @@ -26,6 +26,7 @@ "bootstrap": "^4.0.0-alpha.6", "core-js": "^2.4.1", "font-awesome": "^4.7.0", + "ng2-codemirror": "^1.1.1", "node-sass": "^4.5.0", "rxjs": "^5.0.1", "ts-helpers": "^1.1.1", diff --git a/www/src/app/modules/nemea/nemea.module.ts b/www/src/app/modules/nemea/nemea.module.ts index 2b9c902..a8c8a29 100644 --- a/www/src/app/modules/nemea/nemea.module.ts +++ b/www/src/app/modules/nemea/nemea.module.ts @@ -6,6 +6,9 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { nemeaBase, nemeaComponent } from './nemea.component'; import { nemeaStatusComponent } from './status/nemea_status.component'; import { EventsComponent } from './events/events.component'; + +import { CodemirrorModule } from 'ng2-codemirror'; + import { nemeaReporterConfComponent } from './reporter/reporter_conf.component'; import { AuthGuard } from 'app/utils/auth.guard'; @@ -59,6 +62,14 @@ const nemeaRoutes : Routes = [ data : { role : 10 } + }, + { + path : 'reporters/:id', + component: nemeaReporterConfComponent, + canActivate : [AuthGuard], + data : { + role : 10 + } } ] } @@ -71,6 +82,7 @@ const nemeaRoutes : Routes = [ CommonModule, FormsModule, SafePipeModule, + CodemirrorModule, NgbModule.forRoot(), RouterModule.forChild(nemeaRoutes) ], diff --git a/www/src/app/modules/nemea/reporter/reporter_conf.component.ts b/www/src/app/modules/nemea/reporter/reporter_conf.component.ts index 4361fdb..9fb7c41 100644 --- a/www/src/app/modules/nemea/reporter/reporter_conf.component.ts +++ b/www/src/app/modules/nemea/reporter/reporter_conf.component.ts @@ -1,20 +1,98 @@ import { Component, Pipe, PipeTransform } from '@angular/core'; +import { Router } from '@angular/router'; + +import { ReporterService } from './reporter.service'; + //import { nConfService } from './exporter_configuration.service'; @Component({ selector : 'nemea-reporter-conf', templateUrl : './reporter_conf.html', styleUrls : ['./reporter_conf.scss'], - providers : [] + providers : [ReporterService] }) export class nemeaReporterConfComponent { - constructor() {} + reporters = []; + error : string = ''; + selectedConfig : string = ''; + activeConfig = -1; + + config = { + lineNumbers: true, + mode : "x-yaml", + gutter : true + }; + + constructor(private router : Router, private reporterService : ReporterService) {} ngOnInit() { + /*this.reporterService.reporters().subscribe( + (data) => { this.reporters = data; }, + (error : Object) => this.processError(error) + );*/ + + this.reporters = this.reporterService.reporters_dummy(); } ngOnDestroy() { } + selectReporter(reporter : number) { + console.log(reporter); + this.activeConfig = reporter['idx']; + try { + this.getConfig(reporter["config"]) + } catch (err) { + this.error = err; + } + + this.router.navigate(["nemea/reporters", reporter['idx']]) + } + + getConfig(path : string) { + if (path == undefined) { + this.error = "Config file for this reporter doesn't exist"; + this.selectedConfig = ''; + return; + } + this.error = ''; + console.log("should get " + path) + + this.selectedConfig = this.reporterService.config_dummy(this.activeConfig); + } + + private processError(error : Object) { + console.log(error); + this.error = "Something went wrong"; + } + + saveConfig() { + try { + this.reporterService.save(this.activeConfig, this.selectedConfig); + } catch (err) { + console.log(err) + this.error = err; + + } + /* + for (let rep of this.reporters) { + if (rep[1]['idx'] == this.activeConfig) { + console.log(rep) + return; + } + } + + console.error("Couldnt find the exporter") + */ + } + + onBlur() { + console.log("onblur"); + } + + onFocus() { + console.log("onfocus"); + } + } diff --git a/www/src/app/modules/nemea/reporter/reporter_conf.html b/www/src/app/modules/nemea/reporter/reporter_conf.html index f518bc2..81158d6 100644 --- a/www/src/app/modules/nemea/reporter/reporter_conf.html +++ b/www/src/app/modules/nemea/reporter/reporter_conf.html @@ -5,6 +5,45 @@

-
- Here should be NEMEA reporter configuration + + +
+
+
+
+

+ {{ rep[0] }} + {{ rep[1]['status'] }} +

+

Memory Usage: {{ rep[1]["MEM-vms"] / 1048576 | number : '1.3-3' }} MB

+ +

Config path: {{ rep[1]["config"] }}

+ +
+
+ +
+
+ + +
+
+ Please select a reporter +
+
+ +
+ + + +
+
+ +
+
diff --git a/www/src/app/modules/nemea/reporter/reporter_conf.scss b/www/src/app/modules/nemea/reporter/reporter_conf.scss index e69de29..57851d3 100644 --- a/www/src/app/modules/nemea/reporter/reporter_conf.scss +++ b/www/src/app/modules/nemea/reporter/reporter_conf.scss @@ -0,0 +1,40 @@ +$light-grey : #EEE; + +h3 { + span { + font-size: 0.5em; + font-weight: normal; + background-color: $light-grey; + padding: 0.25em 0.5em; + position: relative; + bottom: 0.45em; + &.running { + color: green; + } + + &.stopped { + color: red; + } + } +} + +.config { + height: 100%; + display: block; + position: relative; + right: 1em; + + .box { + //height: 90vh; + } + + textarea { + width: 100%; + height: 100%; + } +} + +.active { + border: 1px solid #CCC; + background: #EEE; +} diff --git a/www/src/styles/main.scss b/www/src/styles/main.scss index 7575140..88aa296 100644 --- a/www/src/styles/main.scss +++ b/www/src/styles/main.scss @@ -142,3 +142,9 @@ nemea-events .modal-dialog { .row-space { margin: 1em; } + + +.CodeMirror { + border: 1px solid #eee; + height: calc(90vh - 2em)!important; +} From 71b70cc164c10021804aa225d2e2707ff6f5b8c2 Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Mon, 29 May 2017 13:21:34 +0200 Subject: [PATCH 06/78] Nicer user adding with validation --- www/src/app/modules/users/user-add.scss | 10 ++ www/src/app/modules/users/users-add.html | 124 ++++++++++--------- www/src/app/modules/users/users.component.ts | 2 +- 3 files changed, 77 insertions(+), 59 deletions(-) create mode 100644 www/src/app/modules/users/user-add.scss diff --git a/www/src/app/modules/users/user-add.scss b/www/src/app/modules/users/user-add.scss new file mode 100644 index 0000000..5f205e8 --- /dev/null +++ b/www/src/app/modules/users/user-add.scss @@ -0,0 +1,10 @@ +.pw-verify { + position: absolute; + right: -0.5em; + top: 2.5em; + color: green; + + .fa-times { + color: red; + } +} diff --git a/www/src/app/modules/users/users-add.html b/www/src/app/modules/users/users-add.html index b51ef5d..5803ce6 100644 --- a/www/src/app/modules/users/users-add.html +++ b/www/src/app/modules/users/users-add.html @@ -1,78 +1,86 @@ -

Add new user

- -
-
- +
+

+ + Add new user +

+ +
+
+ + +
+
+ + type="email" + id="email" + class="form-control"> +
-
- - - - -
- - - - - - +
+
+ + +
+
+ +
-
- + +
+
+ + +
- -
+
+ + -
- +
+ + + + + + +
+
+
+ +
+ +
- + + + Cancel Error: {{ error }}
- -{{ user | json }} +
diff --git a/www/src/app/modules/users/users.component.ts b/www/src/app/modules/users/users.component.ts index 2202d20..4718f1c 100644 --- a/www/src/app/modules/users/users.component.ts +++ b/www/src/app/modules/users/users.component.ts @@ -14,9 +14,9 @@ import { UsersService } from './users.service'; export class usersComponent {}; @Component({ - //moduleId : module.id.replace("/dist/", "/"), selector : 'users-add', templateUrl : './users-add.html', + styleUrls: ['./user-add.scss'], providers : [UsersService] }) export class usersAddComponent { From f56bbb2f70e14aef93e86a592fe74417375993e7 Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Mon, 29 May 2017 13:24:53 +0200 Subject: [PATCH 07/78] Whitelisting NEMEA Events Option to hide whitelisted events (_CESNET.Whitelisted is set to true). --- .../nemea/events/events.component.html | 4 +++- .../nemea/events/events.component.scss | 10 ++++++++++ .../modules/nemea/events/events.component.ts | 20 ++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/www/src/app/modules/nemea/events/events.component.html b/www/src/app/modules/nemea/events/events.component.html index 00e403e..7d32fe5 100644 --- a/www/src/app/modules/nemea/events/events.component.html +++ b/www/src/app/modules/nemea/events/events.component.html @@ -61,6 +61,8 @@

+ + Hide whitelisted items ({{ totalWhitelisted }}):
@@ -98,7 +100,7 @@

{{ loadBtn }}

No events match given criteria.

- + diff --git a/www/src/app/modules/nemea/events/events.component.scss b/www/src/app/modules/nemea/events/events.component.scss index 75b11fc..e70b6d4 100644 --- a/www/src/app/modules/nemea/events/events.component.scss +++ b/www/src/app/modules/nemea/events/events.component.scss @@ -2,3 +2,13 @@ margin: 1em auto 0 auto; display: block; } + +tr { + &.whitelisted { + color: #AAA; + background: #fbfbfb;; + &.hidden { + display: none; + } + } +} diff --git a/www/src/app/modules/nemea/events/events.component.ts b/www/src/app/modules/nemea/events/events.component.ts index c6046d1..41d099e 100644 --- a/www/src/app/modules/nemea/events/events.component.ts +++ b/www/src/app/modules/nemea/events/events.component.ts @@ -35,13 +35,18 @@ export class EventsComponent implements OnInit { } loadBtn = "LOAD"; error; + totalWhitelisted = 0; constructor(private eventsService : EventsService, private router : Router) { } ngOnInit() { this.loadBtn = "LOADING..."; this.eventsService.last_events(100).subscribe( - (data) => { this.events = data; this.loadBtn = "LOAD" }, + (data) => { + this.events = data; + this.loadBtn = "LOAD"; + this.countWhitelisted(); + }, (error : Object) => this.processError(error) ); this.selectToday(); @@ -52,6 +57,7 @@ export class EventsComponent implements OnInit { this.events = data; this.loadBtn = "LOAD"; this.setParams(); + this.countWhitelisted(); } private appendData(data : any) { @@ -59,6 +65,7 @@ export class EventsComponent implements OnInit { this.events = this.events.concat(data); this.loadBtn = "LOAD"; this.setParams(); + this.countWhitelisted(); } @@ -148,4 +155,15 @@ export class EventsComponent implements OnInit { this.query['from'] = Math.floor((time)/1000); this.runQuery(true); } + + private countWhitelisted() { + for (let item of this.events) { + try { + if (item["_CESNET"]["Whitelisted"] == "True") + this.totalWhitelisted += 1; + } catch(e) { + continue; + } + } + } } From 3fcb6e1e051b794d358b15324add66f391df8af6 Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Mon, 29 May 2017 14:44:07 +0200 Subject: [PATCH 08/78] Update nemea API --- modules/Nemea-Dashboard | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Nemea-Dashboard b/modules/Nemea-Dashboard index 8d85015..409cc14 160000 --- a/modules/Nemea-Dashboard +++ b/modules/Nemea-Dashboard @@ -1 +1 @@ -Subproject commit 8d85015253c459c77784435b4b0d366b532c2413 +Subproject commit 409cc148cb88bad3581cc27b1adcc042924c6f72 From b7eb2b3f480b21ed1dddc3ef92c7e38ec57223f2 Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Tue, 30 May 2017 10:25:52 +0200 Subject: [PATCH 09/78] NEMEA: add NgGrid module --- www/package.json | 1 + www/src/app/modules/nemea/nemea.module.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/www/package.json b/www/package.json index 4cd8e6e..bf0ac5d 100644 --- a/www/package.json +++ b/www/package.json @@ -23,6 +23,7 @@ "@angular/platform-browser-dynamic": "^2.4.0", "@angular/router": "^3.4.0", "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.20", + "angular2-grid": "^2.0.2", "bootstrap": "^4.0.0-alpha.6", "core-js": "^2.4.1", "font-awesome": "^4.7.0", diff --git a/www/src/app/modules/nemea/nemea.module.ts b/www/src/app/modules/nemea/nemea.module.ts index a8c8a29..cf8aa70 100644 --- a/www/src/app/modules/nemea/nemea.module.ts +++ b/www/src/app/modules/nemea/nemea.module.ts @@ -7,6 +7,8 @@ import { nemeaBase, nemeaComponent } from './nemea.component'; import { nemeaStatusComponent } from './status/nemea_status.component'; import { EventsComponent } from './events/events.component'; +import { NgGridModule } from 'angular2-grid'; + import { CodemirrorModule } from 'ng2-codemirror'; import { nemeaReporterConfComponent } from './reporter/reporter_conf.component'; @@ -75,14 +77,13 @@ const nemeaRoutes : Routes = [ } ]; -//export const dummyRouting = RouterModule.forChild(dummyRoutes); - @NgModule({ imports : [ CommonModule, FormsModule, SafePipeModule, CodemirrorModule, + NgGridModule, NgbModule.forRoot(), RouterModule.forChild(nemeaRoutes) ], From ba87d9d4f515722e9d182525c1373beaf55890f4 Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Tue, 30 May 2017 10:26:26 +0200 Subject: [PATCH 10/78] NEMEA: initial mockup for dashboard --- .../nemea/dashboard/dashboard.component.html | 36 +++++++++ .../nemea/dashboard/dashboard.component.scss | 26 +++++++ .../dashboard/dashboard.component.spec.ts | 28 +++++++ .../nemea/dashboard/dashboard.component.ts | 78 +++++++++++++++++++ www/src/app/modules/nemea/nemea.component.ts | 13 +++- www/src/app/modules/nemea/nemea.module.ts | 12 ++- 6 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 www/src/app/modules/nemea/dashboard/dashboard.component.html create mode 100644 www/src/app/modules/nemea/dashboard/dashboard.component.scss create mode 100644 www/src/app/modules/nemea/dashboard/dashboard.component.spec.ts create mode 100644 www/src/app/modules/nemea/dashboard/dashboard.component.ts diff --git a/www/src/app/modules/nemea/dashboard/dashboard.component.html b/www/src/app/modules/nemea/dashboard/dashboard.component.html new file mode 100644 index 0000000..c054431 --- /dev/null +++ b/www/src/app/modules/nemea/dashboard/dashboard.component.html @@ -0,0 +1,36 @@ +

+ dashboard works! +

+ +
+ +
+
Handle
+ Box +
+ +
+
+
+

{{ box.title}}

+ +
+ + +
+
+ + +
+ + {{ box.content }} + + {{ box.config | json }} +
+
+ +Add Box diff --git a/www/src/app/modules/nemea/dashboard/dashboard.component.scss b/www/src/app/modules/nemea/dashboard/dashboard.component.scss new file mode 100644 index 0000000..c2a5fd5 --- /dev/null +++ b/www/src/app/modules/nemea/dashboard/dashboard.component.scss @@ -0,0 +1,26 @@ +.grid-item { + border: solid 1px #ccc; + + &.moving { + box-shadow: 0px 4px 5px -2px rgba(0, 0, 0, 0.2), + 0px 7px 10px 1px rgba(0, 0, 0, 0.14), + 0px 2px 16px 1px rgba(0, 0, 0, 0.12); + } +} + +.handle { + width: 100%; + height: 50px; + background: #eee; + color: black; + font-weight: 500; + padding: 15px; + box-sizing: border-box; + + .dropdown { + cursor: pointer; + margin-right: 1em; + font-size: 1.25em; + top: -0.25em; + } +} diff --git a/www/src/app/modules/nemea/dashboard/dashboard.component.spec.ts b/www/src/app/modules/nemea/dashboard/dashboard.component.spec.ts new file mode 100644 index 0000000..a29783c --- /dev/null +++ b/www/src/app/modules/nemea/dashboard/dashboard.component.spec.ts @@ -0,0 +1,28 @@ +/* tslint:disable:no-unused-variable */ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; + +import { DashboardComponent } from './dashboard.component'; + +describe('DashboardComponent', () => { + let component: DashboardComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ DashboardComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(DashboardComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/www/src/app/modules/nemea/dashboard/dashboard.component.ts b/www/src/app/modules/nemea/dashboard/dashboard.component.ts new file mode 100644 index 0000000..ce317e1 --- /dev/null +++ b/www/src/app/modules/nemea/dashboard/dashboard.component.ts @@ -0,0 +1,78 @@ +import { Component, OnInit } from '@angular/core'; + +import {NgGrid, NgGridItem, NgGridConfig, NgGridItemConfig, NgGridItemEvent} from 'angular2-grid'; +import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'; + +interface Box { + id : number; + config : any; + title : string; + content : string; +} + +@Component({ + selector: 'app-dashboard', + templateUrl: './dashboard.component.html', + styleUrls: ['./dashboard.component.scss'] +}) +export class DashboardComponent implements OnInit { + + private boxes : Array = []; + + private gridConfig: NgGridConfig = { + 'margins': [5], + 'draggable': true, + 'resizable': true, + 'max_cols': 0, + 'max_rows': 0, + 'visible_cols': 0, + 'visible_rows': 0, + 'min_cols': 1, + 'min_rows': 1, + 'col_width': 200, + 'row_height': 200, + 'cascade': 'up', + 'min_width': 100, + 'min_height': 100, + 'fix_to_grid': false, + 'auto_style': true, + 'auto_resize': false, + 'maintain_ratio': false, + 'prefer_new': false, + 'zoom_on_drag': false, + 'limit_to_screen': true + }; + + config = { 'dragHandle': '.handle', 'col': 1, 'row': 1, 'sizex': 2, 'sizey': 2 }; + + constructor() {} + + ngOnInit() { + this.boxes.push({ + id : 0, + config : { + 'dragHandle': '.handle', + 'sizex': 2, + 'sizey': 2 + }, + title : "New Box", + content : "Newly new box" + }); + } + + addBox() { + console.log("should add box"); + + this.boxes.push({ + id : 0, + config : { + 'dragHandle': '.handle', + 'sizex': 2, + 'sizey': 2 + }, + title : "New Box", + content : "Newly new box" + }); + } + +} diff --git a/www/src/app/modules/nemea/nemea.component.ts b/www/src/app/modules/nemea/nemea.component.ts index 2764544..e081390 100644 --- a/www/src/app/modules/nemea/nemea.component.ts +++ b/www/src/app/modules/nemea/nemea.component.ts @@ -13,22 +13,29 @@ export class nemeaBase {};

- Nemea Status + NEMEA Status

- Nemea Events + NEMEA Events

+
+

+ + NEMEA Dashboard + +

+

- Nemea Reporter Configuration + NEMEA Reporter Configuration

diff --git a/www/src/app/modules/nemea/nemea.module.ts b/www/src/app/modules/nemea/nemea.module.ts index cf8aa70..a9fc6d9 100644 --- a/www/src/app/modules/nemea/nemea.module.ts +++ b/www/src/app/modules/nemea/nemea.module.ts @@ -18,6 +18,7 @@ import { IdeaPipe } from './events/idea.pipe'; import { EventItemComponent } from './events/event-item/event-item.component'; import { EventDetailComponent } from './events/event-detail/event-detail.component'; import { SafePipe, SafePipeModule } from 'app/utils/safe.pipe'; +import { DashboardComponent } from './dashboard/dashboard.component'; const nemeaRoutes : Routes = [ { @@ -57,6 +58,14 @@ const nemeaRoutes : Routes = [ role : 10 } }, + { + path : 'dashboard', + component : DashboardComponent, + canActivate : [AuthGuard], + data : { + role : 255 + } + }, { path : 'reporters', component: nemeaReporterConfComponent, @@ -95,7 +104,8 @@ const nemeaRoutes : Routes = [ nemeaReporterConfComponent, EventsComponent, EventItemComponent, - EventDetailComponent], + EventDetailComponent, + DashboardComponent], exports : [], providers : [SafePipe], entryComponents : [EventDetailComponent] From d3d26c2285e4ca8e7ca9319b769dc5e493a87238 Mon Sep 17 00:00:00 2001 From: Petr Stehlik Date: Tue, 30 May 2017 11:39:40 +0200 Subject: [PATCH 11/78] Display user info only when user is logged in --- www/src/app/app.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/src/app/app.component.html b/www/src/app/app.component.html index 22631bc..0b99dc3 100644 --- a/www/src/app/app.component.html +++ b/www/src/app/app.component.html @@ -8,7 +8,7 @@

- {{ user.user.username }} + {{ user?.user?.username }}