Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intrusion detection #20

Merged
merged 37 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
38eea9c
Finished displaying image detections
Jan 26, 2024
f3fbc8c
Merge branch 'main' of https://github.com/unicam-complex-system/camer…
Jan 26, 2024
451f763
Completed everything except video display not woring with nvr
Jan 29, 2024
3be71a1
committing for backup
Jan 29, 2024
28b69a0
finished mobile size display
Jan 31, 2024
23a43a8
Added rerouting on login to avoid token 401
Jan 31, 2024
6b9cf6a
removed unused
Glydric Jan 31, 2024
3a2d507
remove vide supppor
Jan 31, 2024
f05ce6a
ip correction
Glydric Jan 31, 2024
65fcba6
started hls implementation
Jan 31, 2024
5696521
Merge branch 'intrusion-detection' of https://github.com/unicam-compl…
Jan 31, 2024
c95cf84
Replaced openvidu player with HLS
Jan 31, 2024
a7f8943
performed some cleaning
Jan 31, 2024
4551c33
Changed diagram modelling
Feb 1, 2024
721180d
frame rate and fixes, with hot plugging
Glydric Feb 1, 2024
065c018
removed useless fs save
Glydric Feb 1, 2024
383984d
minor MSE changes
Glydric Feb 1, 2024
c02827f
delete send_frame.py
nicorossini Feb 2, 2024
57b74f1
track when camera is on or off and support mobile size view
Feb 2, 2024
c94768b
removed video segments
Feb 2, 2024
21f8864
FIxed navbar on click, displaying on mobile, streaming with low quali…
Feb 5, 2024
cc0647e
GOT RID of files segments commited by mistake
Feb 5, 2024
1b490f8
Dockerized
Feb 5, 2024
988b878
Merge branch 'glydric' into intrusion-detection
Glydric Feb 5, 2024
5dcbd50
removed ls
Feb 5, 2024
d53a7c6
Merge branch 'intrusion-detection' of https://github.com/unicam-compl…
Feb 5, 2024
117edb7
fixes
Glydric Feb 5, 2024
30c5956
some config changes
Feb 5, 2024
6f7ab8a
updates
Glydric Feb 5, 2024
0d6f7ff
commitiing port change
Feb 5, 2024
11bc09f
Merge branch 'intrusion-detection' of https://github.com/unicam-compl…
Feb 5, 2024
a968fee
final integration
Glydric Feb 5, 2024
4c56e92
Merge branch 'intrusion-detection' of https://github.com/unicam-compl…
Feb 5, 2024
ef9c22b
fixed test error
Feb 5, 2024
bdafcfb
removed useless
Glydric Feb 6, 2024
07be313
Merge branch 'intrusion-detection' of https://github.com/unicam-compl…
Glydric Feb 6, 2024
8319bf7
improved
Glydric Feb 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Backend/.env-example
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#The SSL_CERTIFICATE and PRIVATE_KEY refer to the variables used for https encryption, you can specify your own if
#you have generated a cert from a CA. Otherwise you can live it as it is.

#SSL_CERTIFICATE=/path-to/server.crt
#PRIVATE_KEY=/path-to/server.key
LISTEN_PORT=8080
MONGO_PROTOCOL=mongodb
MONGO_HOST=localhost:27017
MONGO_HOST=127.0.0.1:27017
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=123123
JWT_SECRET=RIpEW4QJCzEovH8wNsxv16aMiyGn0yNk
CSD_USER=root
CSD_PASSWORD=123123
TELEGRAM_TOKEN=TOKEN_FROM_TELEGRAM
TELEGRAM_TOKEN=TELEGRAM_TOKEN_FROM_TELEGRAM
BCRYPT_SALT=$2b$10$0H7uZ2aSzUll9k96X7EvHu
OPENVIDU_URL=http://localhost:4443/
OPENVIDU_SECRET=MY_SECRET
NVR_IP_ADDRESS=rtsp://192.168.1.41:80
1 change: 0 additions & 1 deletion Backend/.env-openvidu

This file was deleted.

10 changes: 10 additions & 0 deletions Backend/cleaner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
rm -r ./static/stream/*
mkdir -p ./static/stream/cam0
mkdir -p ./static/stream/cam1
mkdir -p ./static/stream/cam2
mkdir -p ./static/stream/cam3
mkdir -p ./static/stream/cam4
mkdir -p ./static/stream/cam5
mkdir -p ./static/stream/cam6
mkdir -p ./static/stream/cam7
58 changes: 58 additions & 0 deletions Backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"private": true,
"license": "GPL",
"scripts": {
"docker:start": "npm ci && nest start",
"css:start": "chmod +x cleaner.sh && ./cleaner.sh && npm ci && nest start",
"docker:dev": "npm run docker:start -- --watch",
"docker:test": "npm ci && jest",
"build": "nest build",
"start": "nest start",
"start:linux": "./cleaner.sh && nest start",
"start:dev": "nest start --watch",
"start:debug": "npm start -- --debug --watch",
"start:prod": "node dist/main",
Expand All @@ -30,6 +31,7 @@
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.2.10",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/swagger": "^7.1.16",
"@nestjs/websockets": "^10.2.10",
"bcrypt": "^5.1.1",
Expand All @@ -38,7 +40,6 @@
"dotenv": "^16.3.1",
"mongodb": "^6.3.0",
"node-telegram-bot-api": "^0.64.0",
"openvidu-node-client": "^2.29.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"ws": "^8.14.2"
Expand Down
7 changes: 5 additions & 2 deletions Backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { LoginController } from './app/login.controller';
import { CameraStreamGateway } from './cameraStream/cameraStream.gateway';
import { LoginService } from './login/login.service';
import { MediaServerController } from './app/mediaServer/mediaServer.controller';
import { CSSOpenVidu } from './cameraStream/open-vidu.service';
import { SharedController } from './app/shared/shared.controller';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';

@Module({
imports: [
Expand All @@ -25,6 +26,9 @@ import { SharedController } from './app/shared/shared.controller';
// FIXME Error: Payload as string is not allowed with the following sign options: expiresIn
// signOptions: { expiresIn: "60s" },
}),
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'static'),
}),
],
controllers: [
MachineLearningController,
Expand All @@ -38,7 +42,6 @@ import { SharedController } from './app/shared/shared.controller';
TelegramService,
CameraStreamGateway,
LoginService,
CSSOpenVidu,
],
exports: [DatabaseService, TelegramService],
})
Expand Down
4 changes: 2 additions & 2 deletions Backend/src/app/machineLearning/machineLearning.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ export class MachineLearningController {
) {
const date = new Date();

console.log('Adding data to database');
// console.log('Adding data to database');
await this.database.addData(new DataType(cameraId, date, null, file));
console.log('Sending intrusion detection notification');
// console.log('Sending intrusion detection notification');
await this.telegramApi.sendIntrusionDetectionNotification(
cameraId,
date,
Expand Down
4 changes: 1 addition & 3 deletions Backend/src/cameraStream/cameraStream.gateway.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CameraStreamGateway } from './cameraStream.gateway';
import { JwtModule } from '@nestjs/jwt';

import { CSSOpenVidu } from './open-vidu.service';
import { DatabaseService } from '../database/database.service';

describe('WebStreamGateway', () => {
let gateway: CameraStreamGateway;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [CameraStreamGateway, CSSOpenVidu, DatabaseService],
providers: [CameraStreamGateway, DatabaseService],
imports: [
JwtModule.register({
global: true,
Expand Down
63 changes: 11 additions & 52 deletions Backend/src/cameraStream/cameraStream.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import {
UseGuards,
} from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { CSSOpenVidu } from './open-vidu.service';
import { ConnectionProperties, ConnectionType } from 'openvidu-node-client';
import { DatabaseService } from '../database/database.service';
import { transcode } from './transcode';

@Catch(WsException, HttpException)
export class WsExceptionFilter implements WsExceptionFilter {
Expand Down Expand Up @@ -49,32 +48,24 @@ export class CameraStreamGateway implements OnGatewayConnection {

constructor(
private readonly jwtService: JwtService,
private readonly openvidu: CSSOpenVidu,
private readonly database: DatabaseService,
) {}

async afterInit() {
try {
const session = await this.openvidu.instance.createSession();
this.sessionId = session.sessionId;
const nvr = await this.database.getNVRData();

nvr.channels.forEach((id: number) => {
const connectionProperties: ConnectionProperties = {
type: ConnectionType.IPCAM,
rtspUri: `${nvr.ip}/ch${id}_0.264`,
adaptativeBitrate: true,
onlyPlayWithSubscribers: true,
networkCache: 1000,
data: id.toString(),
};
console.log(connectionProperties);
/* To be used with NVR */
const cameras = nvr.channels.map((id: number) => ({
id: id.toString(),
rtspUri: `${nvr.ip}/ch${id}_0.264`,
}));

session
.createConnection(connectionProperties)
.then((connection: unknown) => console.log(connection))
.catch((error) => console.error(error));
});
Promise.all(
cameras.map((camera) => {
transcode(camera, this.io);
}),
);
} catch (error) {
console.error(error);
}
Expand All @@ -85,10 +76,6 @@ export class CameraStreamGateway implements OnGatewayConnection {
new AuthGuard(this.jwtService).checkToken(client.handshake.headers);

console.log(`Welcome new client .... ${client.id}`);
client.emit(
'session_delivery',
JSON.stringify({ sessionId: this.sessionId }),
);
} catch (e) {
client.disconnect();
return;
Expand All @@ -110,34 +97,6 @@ export class CameraStreamGateway implements OnGatewayConnection {
}
}

@SubscribeMessage('token_request')
private async createToken(
@ConnectedSocket() client: Socket,
@MessageBody() data: string,
) {
try {
const message = JSON.parse(data) as { sessionId: string };
const session = this.openvidu.instance.activeSessions.find(
(s) => s.sessionId === message.sessionId,
);

if (!session) {
client.emit(
'error',
JSON.stringify({ message: 'Error getting the session' }),
);
} else {
const connection = await session.createConnection();
client.emit(
'token_delivery',
JSON.stringify({ token: connection.token }),
);
}
} catch (e) {
return e.message;
}
}

broadcastEvent(event: any) {
console.log(event);
this.io.to('clients').emit('participantLeft', JSON.stringify(event));
Expand Down
14 changes: 0 additions & 14 deletions Backend/src/cameraStream/open-vidu.service.ts

This file was deleted.

Loading
Loading