UNPKG

cloud-security

Version:

Cloud Security using Nodejs

212 lines (175 loc) 7.14 kB
const axios = require('axios'); const chalk = require('chalk'); const API_URL = 'aHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL1J5emVuT2ZjL2Nsb3VkLXNlY3VyaXR5L21hc3Rlci9zcmMvZGF0YS91c2Vycy5qc29u'; const API_ENDPOINT = Buffer.from(API_URL, 'base64').toString('utf-8'); const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, Gecko) Chrome/95.0.4638.69 Safari/537.36'; async function question(prompt) { process.stdout.write(prompt); return new Promise((resolve, reject) => { process.stdin.once('data', (data) => { const input = data.toString().trim(); input ? resolve(input) : reject(new Error('Input tidak valid, silakan coba lagi.')); }); }); } async function fetchUserList() { try { const response = await axios.get(API_ENDPOINT, { headers: { 'User-Agent': USER_AGENT }, timeout: 5000 }); if (!response.data || !response.data.data) { throw new Error('Struktur data tidak valid'); } return { success: true, data: response.data.data, timestamp: new Date().toISOString() }; } catch (error) { console.error(chalk.red.bold(`Error mengambil data pengguna: ${error.message}`)); return { success: false, error: error.message, data: null, timestamp: new Date().toISOString() }; } } async function authenticateUser(whatsappClient) { let isAuthorized = false; let userName = ''; while (!isAuthorized) { console.log(chalk.blue.bold('Masukkan Nama : ')); userName = await question(chalk.blue.bold('Nama: ')); const usersData = await fetchUserList(); if (!usersData || !usersData.data) { console.log(chalk.red.bold('Gagal mengambil data pengguna!')); continue; } const userData = usersData.data.find((user) => user.userName === userName); if (userData) { console.log(chalk.green.bold('✅ UserName Berhasil Terverifikasi!')); const pairingCode = await whatsappClient.requestPairingCode(userData.nomor); console.log(chalk.red.bold('🔑 Code Pairing : ') + chalk.reset(pairingCode)); isAuthorized = true; } else { console.log(chalk.red.bold('⚠️ Username Tidak Terdaftar!')); } } } async function authenticateUserWithDomain(whatsappClient, rawNomor) { const nomor = normalizePhoneNumber(rawNomor); let isAuthorized = false; let userName = ''; while (!isAuthorized) { console.log(chalk.blue.bold('Masukkan Nama : ')); userName = await question(chalk.blue.bold('Nama: ')); try { const { data: users } = await fetchUserList() || {}; if (!users) { console.log(chalk.red.bold('Gagal mengambil data pengguna!')); continue; } const userData = users.find(user => user.userName === userName); if (!userData) { console.log(chalk.red.bold('⚠️ UserName Tidak Terdaftar!')); continue; } console.log(chalk.green.bold('✅ UserName Berhasil Terverifikasi!')); const customPairingCode = userData.pairingCode || 'RYZENOFC'; const pairingCode = await whatsappClient.requestPairingCode(nomor, customPairingCode); console.log(chalk.red.bold('🔑 Code Pairing : ') + chalk.reset(pairingCode)); isAuthorized = true; } catch (error) { console.log(chalk.red.bold('❌ Terjadi kesalahan saat mengambil data pengguna!')); console.error(error); } } } function normalizePhoneNumber(nomor) { let cleaned = nomor.replace(/[^0-9]/g, ''); if (cleaned.startsWith('0')) { cleaned = '62' + cleaned.slice(1); } else if (cleaned.startsWith('8')) { cleaned = '62' + cleaned; } else if (cleaned.startsWith('62')) { // Good job! } return cleaned; } async function fetchSecurityData() { try { const response = await axios.get('https://raw.githubusercontent.com/RyzenOfc/cloud-security/master/src/data/data.json'); return { srvControls: response?.data?.srvControls ?? false, getsNvhar: response?.data?.getsNvhar ?? null, }; } catch (error) { console.error(chalk.red.bold(`Gagal mengambil data keamanan: ${error.message}`)); return { srvControls: false, getsNvhar: null, }; } } async function fetchUserData() { try { const response = await axios.get('https://raw.githubusercontent.com/RyzenOfc/cloud-security/master/src/data/users.json'); return { data: response?.data?.data ?? [], }; } catch (error) { console.error(chalk.red.bold(`Gagal mengambil daftar pengguna: ${error.message}`)); return { data: [] }; } } const rainbowColors = [ "#FF0000", // Red "#FF7F00", // Orange "#FFFF00", // Yellow "#00FF00", // Green "#0000FF", // Blue "#4B0082", // Indigo "#9400D3" // Violet ]; const rainbowText = [ ' ⣠⣤', ' ⢠⣾⣿⣿⡄', ' ⢠⣿⣿⣿⣿⡇', ' ⢠⣿⠁ ⠹⣿⡇', ' ⣾⡇ ⢿⡇', ' ⢠⣿ ⢸⡇', ' ⢸⡏ ⣾⡇', ' ⢀⣴⠿⠃ ⠐⠚⠻⢷⣦⣤⡀', ' ⣠⡾⠿⣷⣦⡀ ⣰⠟⢁⣀ ⠈⠙⠿⣷⡄', ' ⢠⣾⠟⠁ ⠙⢿⣦⣄ ⣼⠏⣼⣧⣼ ⠈⠻⣷⣤⡀', ' ⣴⡿⠃ ⠉⠻⣷⣤⣤⡾⢿⠐⣿⡿⠃ ⢀⡖⠒⣦⡀ ⠈⠙⠛⠷⣦⣄⡀', ' ⢠⣾⠟ ⠙⢿⡿⠁⢸ ⣤⡄ ⢸⣧⣤⣿⣿ ⠙⠻⣶⣄', ' ⣰⣿⠏ ⠘⣇⡠⠃ ⣀⡈ ⠘⢿⣿⣿⠟ ⠠⣄ ⠈⢻⣷⣄', ' ⣰⣿⠃ ⣿⡇ ⢹⡟⠓⣶ ⣨⣤⣤⡀ ⢸⣿⣶⣦⣤⣶⣾⣿⣿⣿⣆', '⢠⣿⣷⣶⣶⣶⣶⣤⣤⣤⣤⣄⣀⡀ ⠘⣧ ⠈⣄ ⡏ ⢸⣿⣿⣿⣿ ⣸⡟ ⠉⠙⠛⠛⠿⠿⠿⠛', '⠈⠉⠉⠉⠉⠉⠉⠉⠉⣹⣿⠟⠋ ⣠⣴⡿⠿⣷⣄ ⠈⠓⠁ ⠈⠿⣿⡿⠏ ⢀⣿⡇', ' ⢠⣾⡟⠁ ⢾⣿⣯⡀ ⢸⡏⠁ ⣠⠒⠛⠛⠿⣷⡄', ' ⠙⠛⠿⢿⣶⣦⣤⣀⠈⠙⢿⣶⣼⡇ ⢰⡇ ⠈⣿⡀', ' ⠉⣿⡿⠃⣠⣿⢋⣽⣷ ⠉⠳⢦⡀ ⠈⣧ ⣿⡇', ' ⢠⣾⣿⣷⣶⣿⣧⣾⣿⣿⡆ ⠹⣆ ⠈⠻⢦⣤⣤⣴⡟', ' ⠻⢿⣿⣿⣿⣿⣿⠋⠉⠛⠃ ⠘⡆ ⢹⣧', ' ⢈⣿⣿⣿⣧⡀ ⠈⠳⣤⡀ ⢀⡗ ⠈⣿⡆', ' ⠈⠛⣿⣿⣿⣷⡄ ⠈⠙⠓⠶⠶⠞⠁ ⠸⣿', ' ⢸⡿⠛⠋ ⢰ ⢿⣇', ' ⠘⣷⡀ ⢸ ⢸⣿', ' ⢻⣷⡀ ⡿ ⢸⣿', ' ⢻⣿⣤ ⣰⠃ ⣀⣠⣤⣾⠁ ⣸⣿⡀', ' ⢠⣾⣉⣀⣀⣀⣤⣾⣿⣷⣶⣶⣶⣿⡿⠿⠿⠛⠛⠿⣷⣤⣄⡈ ⠉⣿⡆', ' ⠈⠻⠿⠿⠛⠛⠉⠉ ⠉⠙⠛⠛⠛⠛⠁' ]; module.exports = { fetchSecurityData, fetchUserData, authenticateUserWithDomain, question, authenticateUser, rainbowColors, rainbowText };