Skip to content

Commit 1d507dd

Browse files
committed
changes
2 parents 33733fd + d2e1de5 commit 1d507dd

File tree

5 files changed

+74
-58
lines changed

5 files changed

+74
-58
lines changed

client/.eslintcache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"D:\\Webdev\\remote-code-executor\\client\\src\\index.js":"1","D:\\Webdev\\remote-code-executor\\client\\src\\reducers\\index.js":"2","D:\\Webdev\\remote-code-executor\\client\\src\\constants\\theme.js":"3","D:\\Webdev\\remote-code-executor\\client\\src\\constants\\global.js":"4","D:\\Webdev\\remote-code-executor\\client\\src\\components\\header\\Header.js":"5","D:\\Webdev\\remote-code-executor\\client\\src\\reducers\\code.js":"6","D:\\Webdev\\remote-code-executor\\client\\src\\actions\\code.js":"7","D:\\Webdev\\remote-code-executor\\client\\src\\App.js":"8","D:\\Webdev\\remote-code-executor\\client\\src\\reportWebVitals.js":"9"},{"size":813,"mtime":1609936382132,"results":"10","hashOfConfig":"11"},{"size":115,"mtime":1609936382137,"results":"12","hashOfConfig":"11"},{"size":298,"mtime":1609936382130,"results":"13","hashOfConfig":"11"},{"size":527,"mtime":1609936382130,"results":"14","hashOfConfig":"11"},{"size":408,"mtime":1609936382126,"results":"15","hashOfConfig":"11"},{"size":683,"mtime":1609936382135,"results":"16","hashOfConfig":"11"},{"size":906,"mtime":1609936382122,"results":"17","hashOfConfig":"11"},{"size":888,"mtime":1609936877737,"results":"18","hashOfConfig":"11"},{"size":375,"mtime":1609936382138,"results":"19","hashOfConfig":"11"},{"filePath":"20","messages":"21","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"j0ormm",{"filePath":"22","messages":"23","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"24","messages":"25","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"26","messages":"27","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"28","messages":"29","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"30","messages":"31","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"32","messages":"33","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"34","messages":"35","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"D:\\Webdev\\remote-code-executor\\client\\src\\index.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\reducers\\index.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\constants\\theme.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\constants\\global.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\components\\header\\Header.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\reducers\\code.js",["38"],"D:\\Webdev\\remote-code-executor\\client\\src\\actions\\code.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\App.js",["39"],"D:\\Webdev\\remote-code-executor\\client\\src\\reportWebVitals.js",[],{"ruleId":"40","severity":1,"message":"41","line":9,"column":1,"nodeType":"42","endLine":33,"endColumn":2},{"ruleId":"43","severity":1,"message":"44","line":8,"column":8,"nodeType":"45","messageId":"46","endLine":8,"endColumn":19},"import/no-anonymous-default-export","Unexpected default export of anonymous function","ExportDefaultDeclaration","no-unused-vars","'InputOutput' is defined but never used.","Identifier","unusedVar"]
1+
[{"D:\\Webdev\\remote-code-executor\\client\\src\\index.js":"1","D:\\Webdev\\remote-code-executor\\client\\src\\reducers\\index.js":"2","D:\\Webdev\\remote-code-executor\\client\\src\\constants\\theme.js":"3","D:\\Webdev\\remote-code-executor\\client\\src\\constants\\global.js":"4","D:\\Webdev\\remote-code-executor\\client\\src\\components\\header\\Header.js":"5","D:\\Webdev\\remote-code-executor\\client\\src\\reducers\\code.js":"6","D:\\Webdev\\remote-code-executor\\client\\src\\actions\\code.js":"7","D:\\Webdev\\remote-code-executor\\client\\src\\App.js":"8","D:\\Webdev\\remote-code-executor\\client\\src\\reportWebVitals.js":"9"},{"size":813,"mtime":1609936382132,"results":"10","hashOfConfig":"11"},{"size":115,"mtime":1609936382137,"results":"12","hashOfConfig":"11"},{"size":298,"mtime":1609936382130,"results":"13","hashOfConfig":"11"},{"size":527,"mtime":1609936382130,"results":"14","hashOfConfig":"11"},{"size":408,"mtime":1609936382126,"results":"15","hashOfConfig":"11"},{"size":683,"mtime":1609936382135,"results":"16","hashOfConfig":"11"},{"size":906,"mtime":1609936382122,"results":"17","hashOfConfig":"11"},{"size":888,"mtime":1609936877737,"results":"18","hashOfConfig":"11"},{"size":375,"mtime":1609936382138,"results":"19","hashOfConfig":"11"},{"filePath":"20","messages":"21","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"j0ormm",{"filePath":"22","messages":"23","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"24","messages":"25","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"26","messages":"27","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"28","messages":"29","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"30","messages":"31","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"32","messages":"33","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"34","messages":"35","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"D:\\Webdev\\remote-code-executor\\client\\src\\index.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\reducers\\index.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\constants\\theme.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\constants\\global.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\components\\header\\Header.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\reducers\\code.js",["38"],"D:\\Webdev\\remote-code-executor\\client\\src\\actions\\code.js",[],"D:\\Webdev\\remote-code-executor\\client\\src\\App.js",["39"],"D:\\Webdev\\remote-code-executor\\client\\src\\reportWebVitals.js",[],{"ruleId":"40","severity":1,"message":"41","line":9,"column":1,"nodeType":"42","endLine":33,"endColumn":2},{"ruleId":"43","severity":1,"message":"44","line":8,"column":8,"nodeType":"45","messageId":"46","endLine":8,"endColumn":19},"import/no-anonymous-default-export","Unexpected default export of anonymous function","ExportDefaultDeclaration","no-unused-vars","'InputOutput' is defined but never used.","Identifier","unusedVar"]

client/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
.env.development.local
1818
.env.test.local
1919
.env.production.local
20+
.eslintcache
2021

2122
npm-debug.log*
2223
yarn-debug.log*

client/package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rce-server/server/api/services/code.service.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import fs from 'fs';
2-
import path from 'path';
3-
import util from 'util';
4-
import { execFile, spawn, exec } from 'child_process';
5-
import ValidationService from './validation.service';
1+
import fs from "fs";
2+
import path from "path";
3+
import util from "util";
4+
import { execFile, spawn, exec } from "child_process";
5+
import ValidationService from "./validation.service";
66
const ROOT_DIR = `${process.cwd()}`;
7-
const SOURCE_DIR = path.join(ROOT_DIR, 'executor');
7+
const SOURCE_DIR = path.join(ROOT_DIR, "executor");
88
const TARGET_DIR = `/app/codes`;
9-
const IMAGE_NAME = 'executor:1.0';
9+
const IMAGE_NAME = "executor:1.0";
1010
const VOL_NAME = `my_vol`;
11-
//const VOL_NAME = SOURCE_DIR;
11+
// const VOL_NAME = SOURCE_DIR;
1212

1313
class CodeService {
1414
async execute(code, input, lang, id) {
1515
//console.log('code', code);
1616
try {
17-
!input ? (input = '') : null;
17+
!input ? (input = "") : null;
1818

1919
// validating code
2020
// await this.validateCode(code, input, lang, id);
@@ -26,7 +26,7 @@ class CodeService {
2626
);
2727
if (!isValid) {
2828
throw {
29-
message
29+
message,
3030
};
3131
}
3232

@@ -52,7 +52,7 @@ class CodeService {
5252
);
5353

5454
if (OUTPUT) {
55-
console.log('output', OUTPUT.toString());
55+
console.log("output", OUTPUT.toString());
5656
return OUTPUT.toString();
5757
}
5858
} catch (error) {
@@ -63,28 +63,28 @@ class CodeService {
6363
async writeFile(code, lang, input, id) {
6464
let fileName = `${id}code`;
6565
switch (lang) {
66-
case 'javascript': {
67-
fileName += '.js';
66+
case "javascript": {
67+
fileName += ".js";
6868
break;
6969
}
70-
case 'cpp': {
71-
fileName += '.cpp';
70+
case "cpp": {
71+
fileName += ".cpp";
7272
break;
7373
}
74-
case 'python': {
75-
fileName += '.py';
74+
case "python": {
75+
fileName += ".py";
7676
break;
7777
}
78-
case 'java': {
79-
fileName += '.java';
78+
case "java": {
79+
fileName += ".java";
8080
break;
8181
}
82-
case 'c': {
83-
fileName += '.c';
82+
case "c": {
83+
fileName += ".c";
8484
break;
8585
}
8686
default: {
87-
throw { message: 'Invalid language' };
87+
throw { message: "Invalid language" };
8888
}
8989
}
9090
const write = util.promisify(fs.writeFile);
@@ -94,38 +94,38 @@ class CodeService {
9494
await write(path.join(SOURCE_DIR, `${id}input.txt`), input);
9595
return {
9696
file: fileName,
97-
inputFile: `${id}input.txt`
97+
inputFile: `${id}input.txt`,
9898
};
9999
} catch (error) {
100100
throw { message: error };
101101
}
102102
}
103103

104104
async writeCommand(lang, file, input, id) {
105-
let command = '';
105+
let command = "";
106106
switch (lang) {
107-
case 'javascript': {
107+
case "javascript": {
108108
command = `cd ${TARGET_DIR} && node ${file} < ${input}`;
109109
break;
110110
}
111-
case 'cpp': {
111+
case "cpp": {
112112
command = `cd ${TARGET_DIR} && g++ -o ${id} ${file} && ./${id} < ${input}`;
113113
break;
114114
}
115-
case 'python': {
115+
case "python": {
116116
command = `cd ${TARGET_DIR} && python ${file} < ${input}`;
117117
break;
118118
}
119-
case 'java': {
119+
case "java": {
120120
command = `cd ${TARGET_DIR} && javac ${file} && java Input < ${input}`;
121121
break;
122122
}
123-
case 'c': {
123+
case "c": {
124124
command = `cd ${TARGET_DIR} && gcc -o ${id} ${file} && ./${id} < ${input}`;
125125
break;
126126
}
127127
default: {
128-
throw { message: 'Invalid language' };
128+
throw { message: "Invalid language" };
129129
}
130130
}
131131

@@ -141,10 +141,10 @@ class CodeService {
141141
async execChild(runCode, runContainer, id, file, inputFile, lang) {
142142
return new Promise((resolve, reject) => {
143143
const execCont = exec(`${runContainer}`);
144-
execCont.on('error', err => {
145-
throw { status: '404', message: err };
144+
execCont.on("error", (err) => {
145+
throw { status: "404", message: err };
146146
});
147-
execCont.stdout.on('data', () => {
147+
execCont.stdout.on("data", () => {
148148
exec(`${runCode}`, async (error, stdout, stderr) => {
149149
await this.endContainer(id);
150150
await this.deleteFiles(file, inputFile, lang, id);
@@ -159,22 +159,22 @@ class CodeService {
159159
}
160160

161161
async deleteFiles(fileName, inputName, lang, id) {
162-
fs.unlinkSync(path.join(SOURCE_DIR, fileName), err => {
162+
fs.unlinkSync(path.join(SOURCE_DIR, fileName), (err) => {
163163
if (err) throw { message: err };
164164
});
165165
if (inputName) {
166-
fs.unlinkSync(path.join(SOURCE_DIR, inputName), err => {
166+
fs.unlinkSync(path.join(SOURCE_DIR, inputName), (err) => {
167167
if (err) throw { message: err };
168168
});
169169
}
170-
if (lang == 'cpp' || lang == 'c') {
170+
if (lang == "cpp" || lang == "c") {
171171
if (fs.existsSync(path.join(SOURCE_DIR, id)))
172-
fs.unlinkSync(path.join(SOURCE_DIR, id), err => {
172+
fs.unlinkSync(path.join(SOURCE_DIR, id), (err) => {
173173
if (err) throw err;
174174
});
175175
}
176-
if (lang == 'java') {
177-
fs.unlinkSync(path.join(SOURCE_DIR, 'Input.class'), err => {
176+
if (lang == "java") {
177+
fs.unlinkSync(path.join(SOURCE_DIR, "Input.class"), (err) => {
178178
if (err) throw err;
179179
});
180180
}
@@ -186,7 +186,7 @@ class CodeService {
186186
exec(`${exit}`, (error, stdout, stderr) => {
187187
if (error) {
188188
console.log(error);
189-
} else console.log('Container stoped and deleted');
189+
} else console.log("Container stoped and deleted");
190190
});
191191
}
192192
}

rce-server/server/api/services/validation.service.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
11
class ValidationService {
22
async execute(code, input, lang, id) {
3+
// console.log("validating");
34
switch (lang) {
4-
case 'javascript': {
5-
let words = ['require(', 'exports.', 'module.exports'];
5+
case "javascript": {
6+
let words = ["require(", "exports.", "module.exports"];
67
// prevent imports
7-
var valid = !words.some(el => {
8+
var valid = !words.some((el) => {
89
return code.includes(el);
910
});
1011
return {
1112
isValid: valid,
12-
message: 'You have unacceptable libs imported'
13+
message: "You have unacceptable libs imported",
1314
};
1415
}
15-
case 'python': {
16+
case "python": {
1617
let reg1 = RegExp(
1718
/\bimport\W+(?:\w+\W+){0,}(?:os|subprocess|importlib)\b/g
1819
);
19-
words = ['open('];
20+
let words = ["open("];
2021

2122
if (code.match(reg1)) {
2223
return {
2324
isValid: false,
24-
message: 'You have unacceptable libs imported'
25+
message: "You have unacceptable libs imported",
2526
};
2627
} else if (
27-
!words.every(el => code.toLowerCase().includes(el.toLowerCase()))
28+
words.every((el) => code.toLowerCase().includes(el.toLowerCase()))
2829
) {
2930
return {
3031
isValid: false,
31-
message: 'You have unacceptable libs imported'
32+
message: "You have unacceptable libs imported",
3233
};
3334
}
3435
return {
35-
isValid: true
36+
isValid: true,
3637
};
3738
}
38-
case 'java': {
39+
case "java": {
3940
return {
40-
isValid: true
41+
isValid: true,
4142
};
4243
}
43-
case 'cpp': {
44+
case "cpp": {
4445
return {
45-
isValid: true
46+
isValid: true,
4647
};
4748
}
48-
case 'c': {
49+
case "c": {
4950
return {
50-
isValid: true
51+
isValid: true,
5152
};
5253
}
5354
default: {
5455
return {
5556
isValid: false,
56-
message: 'Please select a valid language'
57+
message: "Please select a valid language",
5758
};
5859
}
5960
}

0 commit comments

Comments
 (0)