Skip to content

Commit

Permalink
Merge pull request #404 from Sarthak-Biswas/Fixes
Browse files Browse the repository at this point in the history
Added UI for IDS and database setup
  • Loading branch information
adeyosemanputra authored Apr 3, 2023
2 parents 2184e97 + 1a4d71e commit b7134c5
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gui/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { SecurityComponent } from './security/security.component';
import { LogoutComponent } from './logout/logout.component';
import { LoginComponent } from './login/login.component';
import { RegisterComponent } from './register/register.component';
import { IDSComponent } from './ids/ids.component';
import { WAFComponent } from './waf/waf.component';

const routes: Routes = [
{ path: 'dashboard', component: DashboardComponent },
Expand All @@ -22,6 +24,8 @@ const routes: Routes = [
{ path: 'security', component: SecurityComponent},
{ path: 'logout', component: LogoutComponent },
{ path: 'error', component: ErrorComponent },
{ path: 'waf', component: WAFComponent},
{ path: 'ids', component: IDSComponent},
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: '**', component: ErrorComponent },
];
Expand Down
4 changes: 3 additions & 1 deletion gui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { LogoutComponent } from './logout/logout.component';
import { LoginComponent } from './login/login.component';
import { RegisterComponent } from './register/register.component';
import { WAFComponent } from './waf/waf.component';
import { IDSComponent } from './ids/ids.component';

@NgModule({
declarations: [
Expand All @@ -43,7 +44,8 @@ import { WAFComponent } from './waf/waf.component';
LogoutComponent,
LoginComponent,
RegisterComponent,
WAFComponent
WAFComponent,
IDSComponent
],
imports: [
BrowserModule,
Expand Down
Empty file.
47 changes: 47 additions & 0 deletions gui/src/app/ids/ids.component.html
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>

25 changes: 25 additions & 0 deletions gui/src/app/ids/ids.component.spec.ts
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();
});
});
51 changes: 51 additions & 0 deletions gui/src/app/ids/ids.component.ts
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);
}
});
}
}
13 changes: 13 additions & 0 deletions gui/src/app/sidebar/sidebar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@
<span class="hide-menu">Security</span>
</a>
</li>
<li class="nav-label">Montior</li>
<li>
<a href="/waf" aria-expanded="false">
<i class="bi bi-bricks"></i>
<span class="hide-menu">Web Application Firewall</span>
</a>
</li>
<li>
<a href="/ids" aria-expanded="false">
<i class="bi bi-shield-exclamation"></i>
<span class="hide-menu">Intrusion Detetion System</span>
</a>
</li>
<li class="nav-label">Logout</li>
<li>
<a href="/logout" aria-expanded="false">
Expand Down
83 changes: 83 additions & 0 deletions securetea/lib/ids/database.py
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

0 comments on commit b7134c5

Please sign in to comment.