Skip to content

Commit 92a393b

Browse files
committed
fix(console): add safety to check job id before output to console
1 parent 46239f2 commit 92a393b

File tree

8 files changed

+31
-20
lines changed

8 files changed

+31
-20
lines changed

src/api/docker.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export function dockerExec(id: string, cmd: any, env: string[] = []): Observable
9999
.then(exec => exec.start())
100100
.then(stream => {
101101
const ws = new Writable();
102+
ws.setDefaultEncoding('utf8');
102103

103104
ws.on('finish', () => {
104105
const duration = new Date().getTime() - startTime;
@@ -107,27 +108,27 @@ export function dockerExec(id: string, cmd: any, env: string[] = []): Observable
107108
});
108109

109110
ws._write = (chunk, enc, next) => {
110-
let str = chunk.toString();
111+
let str = chunk.toString('utf8');
111112

112-
if (str.includes('[abstruse_error]')) {
113+
if (str.includes('[error]')) {
113114
const splitted = str.split(' ');
114-
exitCode = splitted[splitted.length - 1] || 1;
115+
exitCode = Number(splitted[splitted.length - 1]) || 1;
115116
ws.end();
116-
} else if (str.includes('[abstruse_success]')) {
117+
} else if (str.includes('[success]')) {
117118
exitCode = 0;
118119
ws.end();
119-
} else if (!str.startsWith('>') && !str.startsWith('abstruse@')) {
120+
} else {
120121
if (str.includes('//') && str.includes('@')) {
121122
str = str.replace(/\/\/(.*)@/, '//');
122123
}
123-
124124
observer.next({ type: 'data', data: str });
125125
}
126126

127127
next();
128128
};
129129

130130
container.modem.demuxStream(stream.output, ws, ws);
131+
stream.output.on('end', () => ws.end());
131132
})
132133
.catch(err => observer.error(err));
133134
});

src/api/socket.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { IMemoryData, memory } from './stats/memory';
2626
import { ICpuData, cpu } from './stats/cpu';
2727
import { decodeJwt } from './security';
2828
import { getLastBuild } from './db/build';
29+
import { Subscribable } from 'rxjs/Observable';
2930

3031
export interface ISocketServerOptions {
3132
app: express.Application;
@@ -41,7 +42,7 @@ export interface Client {
4142
session: { cookie: any, ip: string, userId: number, email: string, isAdmin: boolean };
4243
socket: uws.Socket;
4344
send: Function;
44-
subscriptions: { stats: Subscription };
45+
subscriptions: { stats: Subscription, jobOutput: Subscription, logs: Subscription };
4546
}
4647

4748
export class SocketServer {
@@ -109,7 +110,7 @@ export class SocketServer {
109110
session: socket.upgradeReq.session,
110111
socket: socket,
111112
send: (message: any) => client.socket.send(JSON.stringify(message)),
112-
subscriptions: { stats: null }
113+
subscriptions: { stats: null, jobOutput: null, logs: null }
113114
};
114115
this.addClient(client);
115116

@@ -147,6 +148,13 @@ export class SocketServer {
147148
private removeClient(socket: uws.Socket): void {
148149
const index = this.clients.findIndex(c => c.socket === socket);
149150
const client = this.clients[index];
151+
152+
Object.keys(client.subscriptions).forEach(sub => {
153+
if (client.subscriptions[sub]) {
154+
client.subscriptions[sub].unsubscribe();
155+
}
156+
});
157+
150158
const msg: LogMessageType = {
151159
message: `[socket]: user ${client.session.email} from ${client.session.ip} disconnected`,
152160
type: 'info',
@@ -276,13 +284,13 @@ export class SocketServer {
276284
const idx = processes.findIndex(proc => Number(proc.job_id) === jobId);
277285
if (idx !== -1) {
278286
const proc = processes[idx];
279-
client.send({ type: 'data', data: proc.log });
287+
client.send({ type: 'jobLog', data: proc.log });
280288
client.send({ type: 'exposed ports', data: proc.exposed_ports || null });
281289
client.send({ type: 'debug', data: proc.debug || null });
282290
}
283291

284-
terminalEvents
285-
.filter(e => e.job_id === parseInt(event.data.jobId, 10))
292+
client.subscriptions.jobOutput = terminalEvents
293+
.filter(e => Number(e.job_id) === Number(event.data.jobId))
286294
.subscribe(output => client.send(output));
287295
break;
288296

@@ -291,7 +299,7 @@ export class SocketServer {
291299
client.send({ type: 'error', data: 'not authorized' });
292300
} else {
293301
client.send({ type: 'request_received' });
294-
logger.subscribe(msg => client.send(msg));
302+
client.subscriptions.logs = logger.subscribe(msg => client.send(msg));
295303
}
296304
break;
297305

src/app/components/app-images/app-images.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class AppImagesComponent implements OnInit, OnDestroy {
156156
'',
157157
'# your commands go below: ',
158158
'# example; install Chromium',
159-
'RUN sudo apt-get install chromium-browser libgconf2-dev -y',
159+
'RUN sudo apt-get update && sudo apt-get install chromium-browser libgconf2-dev -y',
160160
'',
161161
'# example; install nvm (Node Version Manager)',
162162
'RUN cd /home/abstruse \\',
@@ -194,6 +194,7 @@ export class AppImagesComponent implements OnInit, OnDestroy {
194194
'FROM ubuntu:17.10',
195195
'',
196196
'ENV DEBIAN_FRONTEND=noninteractive',
197+
'ENV DISPLAY=:99',
197198
'',
198199
'# please do not edit between lines or image on abstruse will not work properly',
199200
'',

src/app/components/app-job/app-job.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ export class AppJobComponent implements OnInit, OnDestroy {
6868

6969
this.termSub = this.socketService.outputEvents
7070
.subscribe(event => {
71-
if (event.type === 'data' || event.type === 'exit' || event.type === 'container') {
72-
this.terminalInput = event.data;
71+
if (event.type === 'data' || event.type === 'exit' || event.type === 'container' || event.type === 'jobLog') {
72+
if (Number(event.job_id) === Number(this.id) || event.type === 'jobLog') {
73+
this.terminalInput = event.data;
74+
}
7375
} else if (event.type === 'job stopped' && event.data === this.id) {
7476
this.processing = false;
7577
} else if (event.type === 'job restarted' && event.data === this.id) {
@@ -110,7 +112,7 @@ export class AppJobComponent implements OnInit, OnDestroy {
110112
this.jobRun.status = 'success';
111113
this.jobRun.end_time = event.additionalData;
112114
this.previousRuntime = this.jobRun.end_time - this.jobRun.start_time;
113-
} else if (event.data === 'job failed' || event.data === 'job stopped') {
115+
} else if (event.data === 'job failed') {
114116
this.jobRun.status = 'failed';
115117
this.jobRun.end_time = event.additionalData;
116118
this.previousRuntime = this.jobRun.end_time - this.jobRun.start_time;
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

src/files/docker-essential/abstruse-pty.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ int main(int argc, char *argv[]) {
5555
if (WIFEXITED(status)) {
5656
const int code = WEXITSTATUS(status);
5757
if (code == 0) {
58-
printf("\n[abstruse_success]: 0\n");
58+
printf("\n[success]: 0\n");
5959
} else {
60-
printf("\n[abstruse_error]: %d\n", code);
60+
printf("\n[error]: %d\n", code);
6161
}
6262

6363
return code;

src/files/docker-essential/entry.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
VNC_STORE_PWD_FILE=/home/abstruse/.vnc/passwd
44
if [ ! -e "${VNC_STORE_PWD_FILE}" -o -n "${VNC_PASSWORD}" ]; then
55
mkdir -vp /home/abstruse/.vnc > /dev/null 2>&1
6-
x11vnc -storepasswd ${VNC_PASSWORD:-abstruse} ${VNC_STORE_PWD_FILE} > /dev/null 2>&1
6+
x11vnc -storepasswd ${VNC_PASSWORD:-abstrusePass} ${VNC_STORE_PWD_FILE} > /dev/null 2>&1
77
fi
88

9-
export CHROME=${CHROME:-/opt/google/chrome/google-chrome}
109
export DISPLAY=:99
1110

1211
{

0 commit comments

Comments
 (0)