-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmain.js
319 lines (284 loc) · 10.8 KB
/
main.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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
const WebSocket = require('ws');
const { promisify } = require('util');
const fs = require('fs');
const readline = require('readline');
const axios = require('axios');
const HttpsProxyAgent = require('https-proxy-agent');
const chalk = require('chalk');
console.log(chalk.cyan.bold(`███████╗██╗ ██╗ ██╗ ██████╗██╗ ██╗██████╗ ███████╗██████╗`));
console.log(chalk.cyan.bold(`╚══███╔╝██║ ██║ ██╔╝ ██╔════╝╚██╗ ██╔╝██╔══██╗██╔════╝██╔══██╗`));
console.log(chalk.cyan.bold(` ███╔╝ ██║ █████╔╝ ██║ ╚████╔╝ ██████╔╝█████╗ ██████╔╝`));
console.log(chalk.cyan.bold(` ███╔╝ ██║ ██╔═██╗ ██║ ╚██╔╝ ██╔══██╗██╔══╝ ██╔══██╗`));
console.log(chalk.cyan.bold(`███████╗███████╗██║ ██╗ ╚██████╗ ██║ ██████╔╝███████╗██║ ██║`));
console.log(chalk.cyan.bold(`╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝`));
console.log(chalk.cyan.bold(` Running Teneo Node BETA CLI Version `));
console.log(chalk.cyan.bold(` t.me/zlkcyber *** github.com/zlkcyber `));
let socket = null;
let pingInterval;
let countdownInterval;
let potentialPoints = 0;
let countdown = "Calculating...";
let pointsTotal = 0;
let pointsToday = 0;
let retryDelay = 1000;
const auth = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imlra25uZ3JneHV4Z2pocGxicGV5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjU0MzgxNTAsImV4cCI6MjA0MTAxNDE1MH0.DRAvf8nH1ojnJBc3rD_Nw6t1AV8X_g6gmY_HByG2Mag"
const reffCode = "OwAG3kib1ivOJG4Y0OCZ8lJETa6ypvsDtGmdhcjB";
const readFileAsync = promisify(fs.readFile);
const writeFileAsync = promisify(fs.writeFile);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function getLocalStorage() {
try {
const data = await readFileAsync('localStorage.json', 'utf8');
return JSON.parse(data);
} catch (error) {
return {};
}
}
async function setLocalStorage(data) {
const currentData = await getLocalStorage();
const newData = { ...currentData, ...data };
await writeFileAsync('localStorage.json', JSON.stringify(newData));
}
async function connectWebSocket(token, proxy) {
if (socket) return;
const version = "v0.2";
const url = "wss://secure.ws.teneo.pro";
const wsUrl = `${url}/websocket?accessToken=${encodeURIComponent(token)}&version=${encodeURIComponent(version)}`;
const options = {};
if (proxy) {
options.agent = new HttpsProxyAgent(proxy);
}
socket = new WebSocket(wsUrl, options);
socket.onopen = async () => {
const connectionTime = new Date().toISOString();
await setLocalStorage({ lastUpdated: connectionTime });
console.log("WebSocket connected at", connectionTime);
startPinging();
startCountdownAndPoints();
};
socket.onmessage = async (event) => {
const data = JSON.parse(event.data);
console.log("Received message from WebSocket:", data);
if (data.pointsTotal !== undefined && data.pointsToday !== undefined) {
const lastUpdated = new Date().toISOString();
await setLocalStorage({
lastUpdated: lastUpdated,
pointsTotal: data.pointsTotal,
pointsToday: data.pointsToday,
});
pointsTotal = data.pointsTotal;
pointsToday = data.pointsToday;
}
};
let reconnectAttempts = 0;
socket.onclose = () => {
socket = null;
console.log("WebSocket disconnected");
stopPinging();
const delay = Math.min(1000 * 2 ** reconnectAttempts, 30000);
setTimeout(() => connectWebSocket(token, proxy), delay);
reconnectAttempts++;
};
socket.onerror = (error) => {
console.error("WebSocket error:", error);
};
}
function disconnectWebSocket() {
if (socket) {
socket.close();
socket = null;
stopPinging();
}
}
function startPinging() {
stopPinging();
pingInterval = setInterval(async () => {
if (socket && socket.readyState === WebSocket.OPEN) {
socket.send(JSON.stringify({ type: "PING" }));
await setLocalStorage({ lastPingDate: new Date().toISOString() });
}
}, 10000);
}
function stopPinging() {
if (pingInterval) {
clearInterval(pingInterval);
pingInterval = null;
}
}
process.on('SIGINT', () => {
console.log('Received SIGINT. Stopping pinging and disconnecting WebSocket...');
stopPinging();
disconnectWebSocket();
process.exit(0);
});
function startCountdownAndPoints() {
clearInterval(countdownInterval);
updateCountdownAndPoints();
countdownInterval = setInterval(updateCountdownAndPoints, 60 * 1000); // 1 minute interval
}
async function updateCountdownAndPoints() {
const { lastUpdated, pointsTotal, pointsToday } = await getLocalStorage();
if (lastUpdated) {
const nextHeartbeat = new Date(lastUpdated);
nextHeartbeat.setMinutes(nextHeartbeat.getMinutes() + 15);
const now = new Date();
const diff = nextHeartbeat.getTime() - now.getTime();
if (diff > 0) {
const minutes = Math.floor(diff / 60000);
const seconds = Math.floor((diff % 60000) / 1000);
countdown = `${minutes}m ${seconds}s`;
const maxPoints = 25;
const timeElapsed = now.getTime() - new Date(lastUpdated).getTime();
const timeElapsedMinutes = timeElapsed / (60 * 1000);
let newPoints = Math.min(maxPoints, (timeElapsedMinutes / 15) * maxPoints);
newPoints = parseFloat(newPoints.toFixed(2));
if (Math.random() < 0.1) {
const bonus = Math.random() * 2;
newPoints = Math.min(maxPoints, newPoints + bonus);
newPoints = parseFloat(newPoints.toFixed(2));
}
potentialPoints = newPoints;
} else {
countdown = "Calculating...";
potentialPoints = 25;
}
} else {
countdown = "Calculating...";
potentialPoints = 0;
}
console.log("Total Points:", pointsTotal, "| Today Points:", pointsToday, "| Countdown:", countdown);
await setLocalStorage({ potentialPoints, countdown });
}
async function getUserId(proxy) {
const loginUrl = "https://auth.teneo.pro/api/login";
rl.question('Email: ', (email) => {
rl.question('Password: ', async (password) => {
try {
const response = await axios.post(loginUrl, {
email: email,
password: password
}, {
headers: {
'x-api-key': reffCode
}
});
const access_token = response.data.access_token;
await setLocalStorage({ access_token });
await startCountdownAndPoints();
await connectWebSocket(access_token, proxy);
} catch (error) {
console.error('Error:', error.response ? error.response.data : error.message);
} finally {
rl.close();
}
});
});
}
async function registerUser() {
const isExistUrl = 'https://auth.teneo.pro/api/check-user-exists';
const signupUrl = "https://node-b.teneo.pro/auth/v1/signup";
rl.question('Enter your email: ', (email) => {
rl.question('Enter your password: ', (password) => {
rl.question('Enter invited_by code: ', async (invitedBy) => {
try {
const isExist = await axios.post(isExistUrl, { email: email }, {
headers: {
'x-api-key': reffCode
}
});
if (isExist && isExist.data && isExist.data.exists) {
console.log('User already exists, please just login with:', email);
return;
} else {
const response = await axios.post(signupUrl, {
email: email,
password: password,
data: { invited_by: invitedBy },
gotrue_meta_security: {},
code_challenge: null,
code_challenge_method: null
}, {
headers: {
'apikey': auth,
'Content-Type': 'application/json',
'authorization': `Bearer ${auth}`,
'x-client-info': 'supabase-js-web/2.47.10',
'x-supabase-api-version': '2024-01-01',
}
});
}
console.log('Registration successful Please Confirm your email at :', email);
} catch (error) {
console.error('Error during registration:', error.response ? error.response.data : error.message);
} finally {
rl.close();
}
});
});
});
}
async function main() {
const localStorageData = await getLocalStorage();
let access_token = localStorageData.access_token;
rl.question('Do you want to use a proxy? (y/n): ', async (useProxy) => {
let proxy = null;
if (useProxy.toLowerCase() === 'y') {
proxy = await new Promise((resolve) => {
rl.question('Please enter your proxy URL (e.g., http://username:password@host:port): ', (inputProxy) => {
resolve(inputProxy);
});
});
}
if (!access_token) {
rl.question('User Token not found. Would you like to:\n1. Register an account\n2. Login to your account\n3. Enter Token manually\nChoose an option: ', async (option) => {
switch (option) {
case '1':
await registerUser();
break;
case '2':
await getUserId(proxy);
break;
case '3':
rl.question('Please enter your access token: ', async (accessToken) => {
userToken = accessToken;
await setLocalStorage({ userToken });
await startCountdownAndPoints();
await connectWebSocket(userToken, proxy);
rl.close();
});
break;
default:
console.log('Invalid option. Exiting...');
process.exit(0);
}
});
} else {
rl.question('Menu:\n1. Logout\n2. Start Running Node\nChoose an option: ', async (option) => {
switch (option) {
case '1':
fs.unlink('localStorage.json', (err) => {
if (err) {
console.error('Error deleting localStorage.json:', err.message);
} else {
console.log('Logged out successfully.');
process.exit(0);
}
});
break;
case '2':
await startCountdownAndPoints();
await connectWebSocket(access_token, proxy);
break;
default:
console.log('Invalid option. Exiting...');
process.exit(0);
}
});
}
});
}
//run
main();