File size: 9,136 Bytes
fd211b3 | 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 | /**
* protocol.js - ChatAIBot.pro ็บฏ HTTP ๅ่ฎฎๆณจๅๆจกๅ
*
* ๅทฒ็กฎ่ฎค็ API ็ซฏ็น (Express + Apache/Ubuntu):
* POST /api/register โ 201 {"success":true} (ๆณจๅ, ่ฟๅ connect.sid session cookie)
* POST /api/register/verify โ 200 (้ช่ฏ, ้่ฆ {email, token})
* POST /api/login โ 200 (็ปๅฝ, ้่ฆ {email, password})
* POST /api/logout โ 200 OK
*
* ๆณจๅๆต็จ (้ๅ่ชๅ็ซฏ sign-up chunk + module 40933):
* 1. POST /api/register { email, password, isAdvertisingAccepted, mainSiteUrl,
* utmSource, utmCampaign, connectBusiness, yandexClientId }
* Headers: Content-Type: application/json, Accept-Language: en
* โ 201 {"success":true} + Set-Cookie: connect.sid
* 2. ้ฎไปถไธญๅ
ๅซ 6 ไฝๆฐๅญ้ช่ฏ็ (token)
* ๆ ผๅผ: "Your code: 528135"
* 3. POST /api/register/verify { email, token, connectBusiness, syncToken }
* โ ้ช่ฏๅฎๆ๏ผ่ดฆๅทๆฟๆดป
* 4. POST /api/login { email, password }
* โ ่ทๅ session
*/
import { request, get, post, sleep } from './http.js';
import config from './config.js';
const API_BASE = config.siteBase;
// ==================== ๅทฅๅ
ทๅฝๆฐ ====================
function humanDelay(baseMs) {
return Math.floor(baseMs * (0.8 + Math.random() * 1.7));
}
// ==================== ๆณจๅๆญฅ้ชค ====================
/**
* Step 1: ๆณจๅ่ดฆๅท
* POST /api/register
* ้ๅ่ชๅ็ซฏ sign-up-d2a668c82094de73.js + module 40933
* ๆต่งๅจๅ้็ๅฎๆดๅญๆฎตๅ headers
*/
async function stepRegister(account) {
console.log(' [Step 1] ๆไบคๆณจๅ...');
const resp = await post(`${API_BASE}/api/register`, {
email: account.email,
password: account.password,
isAdvertisingAccepted: false,
mainSiteUrl: `${config.siteBase}/api`,
utmSource: '',
utmCampaign: '',
connectBusiness: '',
yandexClientId: '',
}, {
headers: {
'Origin': config.siteBase,
'Referer': config.signupUrl,
'Accept-Language': 'en',
},
});
const body = resp.text();
console.log(` ็ถๆ: ${resp.status}`);
console.log(` ๅๅบ: ${body.substring(0, 200)}`);
if (resp.status === 201 || resp.ok) {
const sessionCookie = resp.cookies.get('connect.sid');
console.log(` Session: ${sessionCookie ? sessionCookie.substring(0, 50) + '...' : 'ๆ '}`);
return { success: true, cookies: resp.cookies };
}
let errorMsg = body;
try {
const json = JSON.parse(body);
errorMsg = json.message || json.error || body;
} catch {}
throw new Error(`ๆณจๅๅคฑ่ดฅ (${resp.status}): ${errorMsg}`);
}
/**
* Step 2: ไป้ฎ็ฎฑ่ทๅ 6 ไฝ้ช่ฏ็
* chataibot.pro ็้ช่ฏ็ ๅฐฑๆฏ token๏ผๆฏไธไธช 6 ไฝๆฐๅญ
*/
async function stepGetVerifyToken(mailProvider, senderFilter) {
console.log(' [Step 2] ็ญๅพ
้ช่ฏ้ฎไปถ...');
const pollOptions = {
initialDelay: 8000,
maxAttempts: 15,
pollInterval: 5000,
};
const code = await mailProvider.fetchVerificationCode(senderFilter, pollOptions);
if (code) {
console.log(` ้ช่ฏ็ : ${code}`);
return code;
}
return null;
}
/**
* Step 3: ๆไบค้ช่ฏ็
* POST /api/register/verify { email, token, connectBusiness, syncToken }
* ้ๅ่ชๅ็ซฏ: verify ่ฟๅ้ connectBusiness ๅ syncToken
*/
async function stepVerify(email, token, cookies) {
console.log(' [Step 3] ๆไบค้ช่ฏ...');
const resp = await post(`${API_BASE}/api/register/verify`, {
email,
token,
connectBusiness: '',
syncToken: '',
}, {
cookies,
headers: {
'Origin': config.siteBase,
'Referer': `${config.siteBase}/app/verify`,
'Accept-Language': 'en',
},
});
const body = resp.text();
console.log(` ็ถๆ: ${resp.status}`);
console.log(` ๅๅบ: ${body.substring(0, 300)}`);
if (resp.ok) {
let data;
try { data = JSON.parse(body); } catch { data = { raw: body }; }
return { success: true, data, cookies: resp.cookies };
}
throw new Error(`้ช่ฏๅคฑ่ดฅ (${resp.status}): ${body.substring(0, 200)}`);
}
/**
* Step 4: ็ปๅฝ่ทๅ session
* POST /api/login
*/
async function stepLogin(email, password) {
console.log(' [Step 4] ็ปๅฝ...');
await sleep(humanDelay(1000));
const resp = await post(`${API_BASE}/api/login`, {
email,
password,
}, {
headers: {
'Origin': config.siteBase,
'Referer': `${config.siteBase}/app/auth/sign-in`,
'Accept-Language': 'en',
},
});
const body = resp.text();
console.log(` ็ถๆ: ${resp.status}`);
console.log(` ๅๅบ: ${body.substring(0, 300)}`);
if (resp.ok) {
let data;
try { data = JSON.parse(body); } catch { data = { raw: body }; }
return {
success: true,
data,
cookies: resp.cookies,
sessionCookie: resp.cookies.get('connect.sid'),
};
}
console.log(' ็ปๅฝๅคฑ่ดฅ๏ผๅฏ่ฝ้่ฆๅ
้ช่ฏ้ฎ็ฎฑ๏ผ');
return { success: false, status: resp.status, body };
}
// ==================== ไธปๆณจๅๆต็จ ====================
/**
* ็บฏๅ่ฎฎๆณจๅ ChatAIBot.pro ่ดฆๅท
*
* @param {object} account - { email, password, firstName, lastName, fullName }
* @param {object} mailProvider - ้ฎ็ฎฑ provider ๅฎไพ
* @returns {object} { success, account, session, error }
*/
export async function register(account, mailProvider) {
console.log(`\n โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ`);
console.log(` ๆณจๅ: ${account.email}`);
console.log(` โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n`);
try {
// Step 1: ๆณจๅ
await sleep(humanDelay(500));
const regResult = await stepRegister(account);
// Step 2: ่ทๅ 6 ไฝ้ช่ฏ็
const senderFilter = config.senderFilter || 'chataibot';
const token = await stepGetVerifyToken(mailProvider, senderFilter);
if (!token) {
console.log('\n [่ญฆๅ] ๆช่ทๅๅฐ้ช่ฏ็ ๏ผ่ดฆๅทๅทฒๅๅปบไฝๆช้ช่ฏ');
console.log(' ่ฏทๆๅจๆฃๆฅ้ฎ็ฎฑๅฎๆ้ช่ฏ');
return {
success: true,
verified: false,
account,
session: { cookies: regResult.cookies },
cookies: regResult.cookies,
};
}
// Step 3: ๆไบค้ช่ฏ
await sleep(humanDelay(1000));
const verifyResult = await stepVerify(account.email, token, regResult.cookies);
// Step 4: ็ปๅฝ
await sleep(humanDelay(1500));
const loginResult = await stepLogin(account.email, account.password);
return {
success: true,
verified: true,
account,
session: loginResult.data || verifyResult.data,
cookies: loginResult.cookies || verifyResult.cookies || regResult.cookies,
loginSuccess: loginResult.success,
};
} catch (e) {
console.log(`\n [้่ฏฏ] ${e.message}`);
return {
success: false,
account,
error: e.message,
};
}
}
/**
* ๆขๆต API (ไฟ็ไพ่ฐ่ฏ็จ)
*/
export async function probe() {
console.log('\n โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
console.log(' โ ChatAIBot.pro API ๆขๆต โ');
console.log(' โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n');
const endpoints = [
['GET', '/api/register', null],
['POST', '/api/register', { email: 'probe@test.com', password: 'Probe123!' }],
['POST', '/api/register/verify', { email: 'probe@test.com', token: 'test' }],
['POST', '/api/login', { email: 'probe@test.com', password: 'Probe123!' }],
['POST', '/api/logout', {}],
];
const results = [];
for (const [method, path, body] of endpoints) {
try {
const opts = {
headers: {
'Origin': config.siteBase,
'Referer': config.signupUrl,
},
followRedirect: false,
timeout: 10000,
};
let resp;
if (method === 'POST') {
resp = await post(`${API_BASE}${path}`, body, opts);
} else {
resp = await get(`${API_BASE}${path}`, opts);
}
const text = resp.text();
const status = resp.status;
console.log(` ${status} ${method} ${path}`);
console.log(` ${text.substring(0, 200)}`);
console.log(` Cookies: ${[...resp.cookies.keys()].join(', ') || 'ๆ '}`);
results.push({ method, path, status, body: text.substring(0, 200) });
} catch (e) {
results.push({ method, path, status: 0, error: e.message });
}
}
return results;
}
|