-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from Sarthak-Biswas/Fixes
Added UI for IDS and database setup
- Loading branch information
Showing
8 changed files
with
226 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<div id="main-wrapper"> | ||
<div class="header"> | ||
<app-header></app-header> | ||
</div> | ||
<app-sidebar></app-sidebar> | ||
<div class="page-wrapper"> | ||
<div class="row page-titles pt-2 pb-1 mb-1"> | ||
<div class="col-md-5 align-self-center"> | ||
<h1 class="text-primary head-1">Intrusion Detection System</h1> | ||
</div> | ||
<div class="col-md-7 align-self-center"> | ||
<ol class="breadcrumb"> | ||
<li class="breadcrumb-item"><a href='/dashboard'>Home</a></li> | ||
<li class="breadcrumb-item active">Intrusion Detection System</li> | ||
</ol> | ||
</div> | ||
</div> | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<h2 class="card-title">Detected Intruders</h2> | ||
<h3 class="card-subtitle">List of intruders detected</h3> | ||
<table id="myTable" class="table table-bordered table-striped"> | ||
<thead> | ||
<tr> | ||
<th>Warning</th> | ||
<th>IP Address</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let adapter of login"> | ||
<td class="py-0">{{ adapter['name'] }}</td> | ||
<td class="py-0">{{ adapter['date'] }}</td> | ||
<td class="py-0">{{ adapter['status'] }}</td> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<app-footer></app-footer> | ||
</div> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { IDSComponent } from './ids.component'; | ||
|
||
describe('LoginComponent', () => { | ||
let component: IDSComponent; | ||
let fixture: ComponentFixture<IDSComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ IDSComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(IDSComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Router} from '@angular/router'; | ||
import { CookieService } from 'ngx-cookie-service'; | ||
|
||
@Component({ | ||
selector: 'app-ids', | ||
templateUrl: './ids.component.html', | ||
styleUrls: ['./ids.component.css'] | ||
}) | ||
export class IDSComponent implements OnInit { | ||
|
||
apiRoot = ''; | ||
interval; | ||
login = []; | ||
|
||
constructor( | ||
private http: HttpClient, | ||
private router: Router, | ||
private cookie: CookieService | ||
) { } | ||
|
||
ngOnInit() { | ||
this.apiRoot = this.cookie.get("api") | ||
console.log(" Login api root" + this.apiRoot + "api root") | ||
if (this.apiRoot == "") { | ||
console.log("Login api root is null going to config") | ||
this.router.navigate(['/config']); | ||
} | ||
console.log("Login Api is" + this.cookie.get("api")) | ||
this.getIDSLogs(); | ||
this.interval = setInterval(() => { | ||
this.getIDSLogs(); | ||
}, 3000); | ||
} | ||
|
||
getIDSLogs() { | ||
const posturl = `${this.apiRoot}/ids`; | ||
this.http.post( | ||
posturl, | ||
{ | ||
"username":this.cookie.get('user_name') | ||
} | ||
).subscribe((res) => { | ||
if (res["status"] === 200) { | ||
this.login = res['data']; | ||
console.log(res); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import os | ||
import datetime | ||
import json | ||
from sqlalchemy import create_engine, Integer, String, Column, MetaData, select, Table, DateTime | ||
|
||
class DatabaseLogs: | ||
""" | ||
A class that stores the IDS logs in a sqlite3 database. | ||
function insert_log accepts logs of the user and stores it in database. | ||
function retrive_log takes the users ID as input and returns the corresponding logs. | ||
""" | ||
|
||
def __init__(self, data): | ||
""" | ||
Initializing the variables | ||
""" | ||
|
||
self.data = data | ||
|
||
self.user = self.data['user'] | ||
self.msg = self.data['msg'] | ||
self.From = "None" | ||
if self.data['From']: | ||
self.From = self.data['From'] | ||
|
||
|
||
self.db_path = "../db/logs.sqlite3" | ||
self.db_name = "logs.sqlite3" | ||
|
||
# creates the sqlite3 database if it does not exits | ||
|
||
self.db_exits = True | ||
|
||
if not os.path.isfile(self.db_path): | ||
os.makedirs(os.path.dirname(self.db_path), exist_ok=True) | ||
|
||
with open(self.db_path, "w") as f: | ||
self.db_exits = False | ||
|
||
self.abs_path = os.path.abspath(self.db_path) | ||
self.sqlite_abs_path = f"sqlite:///{self.abs_path}" | ||
|
||
self.engine = create_engine(self.sqlite_abs_path, echo=True) | ||
self.metadata = MetaData() | ||
|
||
self.users = Table('user_logs', self.metadata, | ||
Column('id', Integer, primary_key=True, autoincrement=True), | ||
Column('userID', String), | ||
Column('From', String), | ||
Column('date', DateTime) | ||
) | ||
|
||
if not self.db_exits: | ||
self.metadata.create_all(self.engine) | ||
|
||
|
||
# insert the waf logs in database | ||
|
||
def insert_log(self): | ||
|
||
with self.engine.connect() as conn: | ||
conn.execute(self.users.insert().values(userID=self.user, From=self.From, From=self.From, date=datetime.datetime.now())) | ||
|
||
# retrive the waf logs from the database | ||
|
||
def retrive_log(self): | ||
|
||
self.conn = self.engine.connect() | ||
|
||
self.query = select(self.users).where(self.users.c.userID == self.user) | ||
|
||
self.res = self.conn.execute(self.query).fetchall() | ||
|
||
json_data = {'msg': self.res[0][2], | ||
'From': self.res[0][3] | ||
} | ||
|
||
self.jsonDump = json.dumps(json_data) | ||
|
||
return self.jsonDump |