Update server.js
Browse files
server.js
CHANGED
|
@@ -2,6 +2,7 @@ const express = require("express");
|
|
| 2 |
const puppeteer = require("puppeteer-extra");
|
| 3 |
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
|
| 4 |
const cheerio = require("cheerio");
|
|
|
|
| 5 |
|
| 6 |
// Add stealth plugin
|
| 7 |
puppeteer.use(StealthPlugin());
|
|
@@ -11,6 +12,7 @@ const PORT = 7860;
|
|
| 11 |
|
| 12 |
// Browser instance management
|
| 13 |
let browser = null;
|
|
|
|
| 14 |
|
| 15 |
async function getBrowser() {
|
| 16 |
if (!browser) {
|
|
@@ -32,6 +34,57 @@ async function getBrowser() {
|
|
| 32 |
return browser;
|
| 33 |
}
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
// Enhanced page setup for maximum stealth
|
| 36 |
async function setupPage(browser) {
|
| 37 |
const page = await browser.newPage();
|
|
|
|
| 2 |
const puppeteer = require("puppeteer-extra");
|
| 3 |
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
|
| 4 |
const cheerio = require("cheerio");
|
| 5 |
+
require('dotenv').config();
|
| 6 |
|
| 7 |
// Add stealth plugin
|
| 8 |
puppeteer.use(StealthPlugin());
|
|
|
|
| 12 |
|
| 13 |
// Browser instance management
|
| 14 |
let browser = null;
|
| 15 |
+
let isLoggedIn = false;
|
| 16 |
|
| 17 |
async function getBrowser() {
|
| 18 |
if (!browser) {
|
|
|
|
| 34 |
return browser;
|
| 35 |
}
|
| 36 |
|
| 37 |
+
// Login function
|
| 38 |
+
async function performLogin(page) {
|
| 39 |
+
if (isLoggedIn) return true;
|
| 40 |
+
|
| 41 |
+
try {
|
| 42 |
+
console.log('Performing login...');
|
| 43 |
+
|
| 44 |
+
// Navigate to login page
|
| 45 |
+
await page.goto('https://getsms.cc/auth/login', {
|
| 46 |
+
waitUntil: 'networkidle2',
|
| 47 |
+
timeout: 30000
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
// Wait for form to be visible
|
| 51 |
+
await page.waitForSelector('form#login', { timeout: 10000 });
|
| 52 |
+
|
| 53 |
+
// Fill in credentials
|
| 54 |
+
await page.type('input[name="mail"]', process.env.LOGIN_EMAIL, { delay: 100 });
|
| 55 |
+
await new Promise(resolve => setTimeout(resolve, 500));
|
| 56 |
+
|
| 57 |
+
await page.type('input[name="password"]', process.env.LOGIN_PASSWORD, { delay: 100 });
|
| 58 |
+
await new Promise(resolve => setTimeout(resolve, 500));
|
| 59 |
+
|
| 60 |
+
// Submit form
|
| 61 |
+
await page.click('input[type="submit"]');
|
| 62 |
+
|
| 63 |
+
// Wait for navigation after login
|
| 64 |
+
await page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 15000 });
|
| 65 |
+
|
| 66 |
+
// Check if login was successful (look for logout or dashboard elements)
|
| 67 |
+
const loginSuccess = await page.evaluate(() => {
|
| 68 |
+
// Check if we're redirected away from login page or if there are user-specific elements
|
| 69 |
+
return !window.location.pathname.includes('/auth/login') ||
|
| 70 |
+
document.querySelector('[href*="logout"]') !== null ||
|
| 71 |
+
document.querySelector('.user-profile') !== null;
|
| 72 |
+
});
|
| 73 |
+
|
| 74 |
+
if (loginSuccess) {
|
| 75 |
+
isLoggedIn = true;
|
| 76 |
+
console.log('Login successful');
|
| 77 |
+
return true;
|
| 78 |
+
} else {
|
| 79 |
+
console.log('Login may have failed');
|
| 80 |
+
return false;
|
| 81 |
+
}
|
| 82 |
+
} catch (error) {
|
| 83 |
+
console.error('Login error:', error);
|
| 84 |
+
return false;
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
// Enhanced page setup for maximum stealth
|
| 89 |
async function setupPage(browser) {
|
| 90 |
const page = await browser.newPage();
|