-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
243 lines (111 loc) · 4.64 KB
/
app.js
File metadata and controls
243 lines (111 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// Core Modules
import crypto from "crypto";
import fs from "fs";
import path from "path";
// Third party Modules
import * as dotenv from "dotenv";
dotenv.config(
{path: "./.config.env"}
);
import express from "express";
import morgan from "morgan";
import cors from "cors";
import compression from "compression";
// Local Modules
import configRouter from "./Routes/configRoute.js";
import loginRouter from "./Routes/loginRoute.js";
import confirmRouter from "./Routes/confirmConnectionRoute.js";
import sseRouter from "./Routes/sseRoute.js";
import detailsRouter from "./Routes/detailsRoute.js";
///////////////////////////
// The instance of the express application
const app = express();
// Makes sure the real ip address is given.
app.set("trust proxy", true);
// Middlewares
// Compresses the response
//app.use(compression())
// Enable cors policy
app.use(cors());
// Enables parsing of JSON request body
app.use(express.json());
// Enables parsing of textrequest body
app.use(express.text());
// Serves static files
app.use(express.static(`${path.join(process.env.PWD, "Public")}`, {index:false, dotfiles: "allow"}))
// Disables the x-powered-by property in the response header
app.disable("x-powered-by");
// app.use(morgan("dev"));
/////////////////////////
// For decryption
function decryptData(data, key, iv) {
const cipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
let decryptedText = cipher.update(data.toString(), "hex", "utf-8");
decryptedText += cipher.final("utf-8");
return decryptedText;
}
// Checks if the server name is set
let serverName;
try {
serverName = decryptData(atob(process.env.SERVERNAME.toString()), Buffer.from(process.env.SERVERNAMEENCRYPTIONKEY, "hex"), Buffer.from(process.env.SERVERNAMEINITIALIZATIONVECTOR, "hex")).toString().trim();
if(serverName.toString() == "") {
throw new Error ();
} else {
app.locals.serverName = `${serverName.toString()}'s `;
}
} catch (err) {
app.locals.serverName = "";
}
// Checks if a password is set for authentication
try {
app.locals.password = decryptData(atob(process.env.CONNECTIONPASSWORD.toString()), Buffer.from(process.env.CONNECTIONPASSWORDENCRYPTIONKEY, "hex"), Buffer.from(process.env.CONNECTIONPASSWORDINITIALIZATIONVECTOR, "hex"));
} catch (err) {
app.locals.password = "";
}
// Checks if the maximum number of connections is set
try {
app.locals.connectionLimit = decryptData(atob(process.env.CONNECTIONLIMIT.toString()), Buffer.from(process.env.CONNECTIONLIMITENCRYPTIONKEY, "hex"), Buffer.from(process.env.CONNECTIONLIMITINITIALIZATIONVECTOR, "hex"));
} catch (err) {
app.locals.connectionLimit = "";
}
// checks if the confirm connection is set
try {
app.locals.confirmConnection = decryptData(atob(process.env.CONFIRMCONNECTION.toString()), Buffer.from(process.env.CONFIRMCONNECTIONENCRYPTIONKEY, "hex"), Buffer.from(process.env.CONFIRMCONNECTIONINITIALIZATIONVECTOR, "hex"));
if(app.locals.confirmConnection.toString() == "false") {
throw new Error ();
}
} catch (err) {
app.locals.confirmConnection = "";
}
// checks if file operations is allowed
try {
app.locals.fileOperations = decryptData(atob(process.env.ENABLEFILEOPERATIONS.toString()), Buffer.from(process.env.ENABLEFILEOPERATIONSENCRYPTIONKEY, "hex"), Buffer.from(process.env.ENABLEFILEOPERATIONSINITIALIZATIONVECTOR, "hex"));
if(app.locals.fileOperations.toString() == "false") {
throw new Error ();
}
} catch (err) {
app.locals.fileOperations = "";
}
// checks if a password is set for file operations
try {
app.locals.fileOperationsPassword = decryptData(atob(process.env.FILEOPERATIONSPASSWORD.toString()), Buffer.from(process.env.FILEOPERATIONSPASSWORDENCRYPTIONKEY, "hex"), Buffer.from(process.env.FILEOPERATIONSPASSWORDINITIALIZATIONVECTOR, "hex"));
} catch (err) {
app.locals.fileOperationsPassword = "";
}
// checks if the owner is connected
app.locals.ownerConnected = false;
// creates a set of authenticated ip address
app.locals.whiteList = new Set();
// creates a set of connected ip address
app.locals.connectionList = new Set();
// creates a set of confirmed ip address
app.locals.confirmedList = new Set();
app.locals.confirmedObj = new Set();
app.locals.deniedObj = new Set();
// creates a set of denied IP address
app.locals.deniedList = new Set();
app.use("/sse", sseRouter);
app.use("/confirmConnection", confirmRouter);
app.use("/login", loginRouter);
app.use("/details", detailsRouter);
export {app, express};