forked from CodeSalvageON/OCEAN-LOUNGE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
191 lines (143 loc) · 4.03 KB
/
index.js
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
// Server
// Downloads and settings start here
const fs = require('fs');
const express = require('express');
const app = require('express')();
const http = require('http').Server(app);
const bodyParser = require('body-parser');
const port = process.env.PORT || 3000;
const io = require('socket.io')(http);
const sanitizer = require('sanitizer');
app.use(bodyParser.json());
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
const createDOMPurify = require('dompurify');
const { JSDOM } = require('jsdom');
const window = new JSDOM('').window;
const DOMPurify = createDOMPurify(window);
const sjcl = require('sjcl');
// Google Firestore
const {
type,
project_id,
private_key_id,
private_key,
client_email,
client_id,
auth_uri,
token_uri,
auth_provider_x509_cert_url,
client_x509_cert_url
} = process.env;
const serviceAccount = {
type,
project_id,
private_key_id,
private_key,
client_email,
client_id,
auth_uri,
token_uri,
auth_provider_x509_cert_url,
client_x509_cert_url
};
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
const db = admin.firestore();
// Routes
app.get('', function (req, res) {
const index = __dirname + '/public/static/index.html';
res.sendFile(index);
});
app.get('/test', function (req, res) {
res.send("<style>body {background-color: powderblue;}</style>");
});
app.get('/call', async function (req, res) {
const gbkRef = db.collection('gbk').doc('chatlog');
const cleanDoc = await gbkRef.get();
const all = cleanDoc.data().log;
res.send(all);
});
app.post('/auth-create', async function (req, res) {
const handle = req.body.handle;
const pwd = req.body.pwd;
let chandle = sanitizer.escape(handle);
const cpwd = sanitizer.escape(pwd);
const gbkRef = db.collection('gbk').doc('chatlog');
const cleanDoc = await gbkRef.get();
const all = cleanDoc.data().log;
const encrypted_pwd = sjcl.encrypt(cpwd, cpwd);
if (handle.includes("#")) {
res.send("#");
}
if (chandle === "") {
chandle = "Stupid dumb idiot who tried to XSS";
}
else {
if (all.includes("#" + handle)) {
res.send("taken");
}
else {
const new_member = {
log : "<section class='msg join' id='#" + chandle + "' pwd='" + encrypted_pwd + "'><strong>" + chandle + "</strong><hr/>Became a member of Ocean Lounge!</section><br/>" + all
}
await gbkRef.set(new_member);
res.send("success");
}
}
});
app.post('/auth-login', async function (req, res) {
const handle = req.body.handle;
const pwd = req.body.pwd;
const gbkRef = db.collection('gbk').doc('chatlog');
const cleanDoc = await gbkRef.get();
const all = cleanDoc.data().log;
if (all.includes("#" + handle)) {
if (all.includes(sjcl.encrypt(pwd, pwd))) {
res.send(all);
}
else {
res.send(all);
}
}
else {
res.send("!exists");
}
});
app.post('/auth-post', async function (req, res) {
const handle = req.body.handle;
const msg = req.body.msg;
const bgcolor = req.body.bgcolor;
const border_type = req.body.border_type;
const bcolor = req.body.bcolor;
const gbkRef = db.collection('gbk').doc('chatlog');
const cleanDoc = await gbkRef.get();
const all = cleanDoc.data().log;
const chandle = sanitizer.escape(handle);
const cmsg = sanitizer.escape(msg);
const new_Dat = {
log : "<section class='msg' style='background-color: " + bgcolor + ";border-style: " + border_type + ";border-color:" + bcolor + ";'><strong>" + chandle + "</strong><hr/>" + cmsg + "</section><br/>" + all
}
await gbkRef.set(new_Dat);
res.send("test");
});
http.listen(port, function(){
console.log('listening on *:' + port);
const gbkRef = db.collection('gbk').doc('chatlog');
async function cleanGBK () {
const cleanDoc = await gbkRef.get();
if (!cleanDoc.exists) {
const fix_data = {
log : ""
}
await gbkRef.set(fix_data);
console.log("SET FIX");
}
else {
console.log("NO FIX NEEDED");
}
}
cleanGBK();
});