gui CHANGE prove of concept use of socket.io
Use socket.io interface to do hostcheck while connecting to a NETCONF device.
diff --git a/frontend/inventory/devices.component.html b/frontend/inventory/devices.component.html
index 2d41822..08f872c 100644
--- a/frontend/inventory/devices.component.html
+++ b/frontend/inventory/devices.component.html
@@ -60,6 +60,16 @@
<hr/>
</div>
+<div *ngIf="hostcheck" class="user-dialogue">
+ <div *ngIf="hostcheck.msg">{{hostcheck.msg}}</div>
+ <div>The authenticity of the host <span class="keyword">{{hostcheck.hostname}}</span> cannot be established.<br/>
+ <span class="keyword">{{hostcheck.keytype}}</span> key fingerprint is <span class="keyword">{{hostcheck.hexa}}</span>.</div>
+ <div>Are you sure you want to continue connecting?
+ <button (click)="hostcheckAnswer(true)">yes</button> /
+ <button (click)="hostcheckAnswer(false)">no</button>
+ </div>
+</div>
+
<p class="msg-failure msg-rounded" *ngIf="err_msg"><span class="msg-close" (click)="err_msg=''">x</span>{{err_msg}}</p>
<table class="items">
<tr class="item_header">
diff --git a/frontend/inventory/devices.component.ts b/frontend/inventory/devices.component.ts
index b55650e..bbd43c5 100644
--- a/frontend/inventory/devices.component.ts
+++ b/frontend/inventory/devices.component.ts
@@ -8,6 +8,15 @@
import {DevicesService} from './devices.service'
import {SessionsService} from '../config/sessions.service'
+import {SocketService} from 'app/services/socket.service';
+
+enum ssh_hostcheck_status {
+ SSH_SERVER_KNOWN_CHANGED = 2,
+ SSH_SERVER_FOUND_OTHER = 3,
+ SSH_SERVER_FILE_NOT_FOUND = 4,
+ SSH_SERVER_NOT_KNOWN = 0
+}
+
@Component({
selector: 'inventoryDevices',
templateUrl: './devices.component.html',
@@ -24,10 +33,12 @@
namePlaceholder: string = "";
id: number;
err_msg = "";
+ hostcheck = null;
constructor(
private devicesService: DevicesService,
private sessionsService: SessionsService,
+ public socketService: SocketService,
private router: Router) {}
getDevices(): void {
@@ -109,15 +120,32 @@
}
}
+ hostcheckAnswer(result: boolean) {
+ this.socketService.send('hostcheck_result', {'id': this.hostcheck.id, 'result': result});
+ delete this.hostcheck;
+ }
+
connect(device: Device) {
/* for backward compatibility */
if (!device.name) {
device.name = device.hostname + ":" + device.port;
}
+ this.socketService.listen('hostcheck').subscribe((message: any) => {
+ this.hostcheck = message;
+ switch(message['state']) {
+ case ssh_hostcheck_status.SSH_SERVER_KNOWN_CHANGED:
+ this.hostcheck['msg'] = "Server has changed.";
+ break;
+ case ssh_hostcheck_status.SSH_SERVER_NOT_KNOWN:
+ this.hostcheck['msg'] = "Server not known.";
+ break;
+ }
+ });
this.sessionsService.connect(device).subscribe(result => {
if (result['success']) {
this.router.navigateByUrl('/netopeer/config');
} else {
+ delete this.hostcheck;
this.err_msg = result['error-msg']
}
});
diff --git a/frontend/package.json b/frontend/package.json
index a31cf94..e651b9f 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -14,7 +14,7 @@
},
"homepage": "https://github.com/CESNET/Netopeer2GUI",
"dependencies" : {
- "@angular/material": "^5.0.0",
- "@angular/cdk": "^5.0.0"
+ "@angular/material": "^6.0.0",
+ "@angular/cdk": "^6.0.0"
}
}