Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同步 #1

Merged
merged 9 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
# Worker 部署(一键直达)
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/jyx04/oaifree_helper)
- 一键为全家桶,包含主服务/选车面板服务/API服务/反代voice服务,且无需手动关联KV,即点即用
- 配置完成后,请按照下方Turnstile人机验证服务教程,获得`站点密钥`和`密钥`
- 配置完成后,如需添加人机验证器防爆破,请按照下方Turnstile人机验证服务教程,获得`站点密钥`和`密钥`
- 访问部署域名,在初始界面一键保存各项变量,完成部署!
- 添加token:在登陆页点击logo,选择Token Management进入token管理面板添加
# Worker 部署(手动部署)
### 1. 配置Turnstile人机验证服务(不可跳过)
### 1. 配置Turnstile人机验证服务(不建议跳过)
- 如需跳过,后期将`RemoveTurnstile`参数设置为1即可
- 注册/登陆你的cloudflare,右上角可设置语言为中文。
- 左侧找到`Turnstile`,选择`添加站点`
- `站点名称`随意,`域`为:`workers.dev`或你自己的域名
Expand All @@ -50,12 +51,13 @@
```
Admin //管理员,用于管理面板的验证使用,且可看所有聊天记录【必填】
TurnstileKeys //turnsile的密钥【必填】
TurnstileSiteKey //站点密钥【必填】
TurnstileSiteKey //turnsile的密钥【必填】
RemoveTurnstile//跳过turnsile人机验证。设置跳过,以上两参数随便填
WebName //站点名称
WorkerURL //站点域名,无需https://若无自己的域名,则为worker默认域名:[worker名].[用户名].workers.dev
LogoURL //图片地址,需https://,若无图床可填图片本地base64编码,不宜过大
ChatLogoURL //chat界面显示的用户头像地址,需https://,若无图床可填图片本地base64编码,不宜过大
ChatUesrName //chat界面显示的用户名
ChatUserName //chat界面显示的用户名
ChatMail //chat界面显示的用户邮箱

Users //默认用户,以aaa,bbb,ccc形式填写,能访问所有车牌
Expand Down
78 changes: 63 additions & 15 deletions _worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ function generatePassword(token) {
return hashStr.substring(0, 15)
}
async function verifyTurnstile(responseToken) {
const removeTurnstile = await KV.get('RemoveTurnstile')||'';
if (removeTurnstile){return 'true'}
const verifyUrl = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
const secretKey = await KV.get('TurnstileKeys');
const response = await fetch(verifyUrl, {
Expand Down Expand Up @@ -234,7 +236,7 @@ async function handleInitialPostRequest(request) {
'TurnstileKeys', 'TurnstileSiteKey', 'Users', 'VIPUsers', 'FreeUsers',
'Admin', 'ForceAN', 'SetAN', 'PlusMode', 'FreeMode', 'WebName',
'WorkerURL','VoiceURL', 'LogoURL', 'CDKEY', 'AutoDeleteCDK', 'FKDomain', 'Status',
'PlusAliveAccounts', 'FreeAliveAccounts', 'rt_1', 'rt_2', 'at_1', 'at_2', 'FreeURL', 'ChatUesrName', 'ChatMail', 'ChatLogoURL'
'PlusAliveAccounts', 'FreeAliveAccounts', 'rt_1', 'rt_2', 'at_1', 'at_2', 'FreeURL', 'ChatUserName', 'ChatMail', 'ChatLogoURL', 'RemoveTurnstile'
];

for (const field of fields) {
Expand Down Expand Up @@ -352,13 +354,14 @@ function getInitialFieldsHTML() {
{ name: 'Admin', label: '【必填】管理员 (用于管理面板的验证使用,且可看所有聊天记录)' ,isrequired: 'required'},
{ name: 'TurnstileKeys', label: '【必填】Turnstile密钥' ,isrequired: 'required'},
{ name: 'TurnstileSiteKey', label: '【必填】Turnstile站点密钥' ,isrequired: 'required'},
{ name: 'Remove Turnstile', label: '【选填】有值则禁用Turnstile验证,以上两个参数随意' },
{ name: 'WorkerURL', label: '站点域名 (无需https://【选填,不填则自动储存worker的域名】' },
{ name: 'VoiceURL', label: 'voice服务域名 (无需https://【选填,不填则自动储存worker的域名】' },
{ name: 'FreeURL', label: 'Free选车面板域名 (无需https://【选填,不填则自动储存worker的域名】' },
{ name: 'WebName', label: '站点名称' },
{ name: 'LogoURL', label: 'Logo图片地址 (需https://)' },
{ name: 'ChatLogoURL', label: 'chat界面用户头像地址(需https://)' },
{ name: 'ChatUesrName', label: 'chat界面用户名 (需https://)' },
{ name: 'ChatUserName', label: 'chat界面用户名 (需https://)' },
{ name: 'ChatMail', label: 'chat界面用户邮箱 (需https://)' },
{ name: 'Users', label: '默认用户 (以aaa,bbb,ccc形式填写)' },
{ name: 'VIPUsers', label: 'VIP用户 (即私车用户,无速率和时间限制)' },
Expand Down Expand Up @@ -415,29 +418,45 @@ async function handlePlusPostRequest(request) {
return generatePlusResponse('Unauthorized access.', adminuserName);
}


// 更新跟车 users
if (accountUsers) {
// 获取当前 users 数据并更新
const currentUsers = await KV.get('VIPUsers');
const newUsers = accountUsers.split(',').map(vipuser => `${vipuser}_${accountNumber}`).join(',');
const updatedUsers = `${currentUsers},${newUsers}`;
await KV.put('VIPUsers', updatedUsers);
}

// 处理 JSON 格式的 refreshToken
let jsonAccessToken, jsonRefreshToken;
try {
const tokenData = JSON.parse(refreshToken);
if (tokenData.access_token && tokenData.refresh_token) {
const rtKey = `rt_${accountNumber}`;
const atKey = `at_${accountNumber}`;
if (tokenData.access_token) {
jsonAccessToken = tokenData.access_token;
jsonRefreshToken = tokenData.refresh_token;
jsonRefreshToken = tokenData.refresh_token ||'';
await KV.put(atKey, jsonAccessToken);
await KV.put(rtKey, jsonRefreshToken);
await addToAliveAccountList(jsonAccessToken, accountNumber);
return generatePlusResponse(`account_number:\n${accountNumber}\n\nrefresh_token:\n${jsonRefreshToken}\n\naccess_token:\n${jsonAccessToken}`, adminuserName);
} else if (tokenData.accessToken) {
jsonAccessToken = tokenData.accessToken;
jsonRefreshToken = '';
await KV.put(atKey, jsonAccessToken);
await KV.put(rtKey, jsonRefreshToken);
await addToAliveAccountList(jsonAccessToken, accountNumber);
return generatePlusResponse(`account_number:\n${accountNumber}\n\nrefresh_token:\n${jsonRefreshToken}\n\naccess_token:\n${jsonAccessToken}`, adminuserName);
}
// const result = await processToken(refreshToken, accountNumber, adminuserName);
// return result;

} catch (e) {
// 输入不是 JSON 格式
}

// 更新跟车 users
if (accountUsers) {
// 获取当前 users 数据并更新
const currentUsers = await KV.get('VIPUsers');
const newUsers = accountUsers.split(',').map(vipuser => `${vipuser}_${accountNumber}`).join(',');
const updatedUsers = `${currentUsers},${newUsers}`;
await KV.put('VIPUsers', updatedUsers);
}


// 批量处理非 JSON 格式的 token
if (!jsonAccessToken && refreshToken.includes(',')) {
Expand All @@ -462,7 +481,7 @@ async function processToken(token, accountNumber, adminuserName) {
const rtKey = `rt_${accountNumber}`;
const atKey = `at_${accountNumber}`;

// 使用非 JSON 格式的 token
// 使用st
if (token.startsWith('fk-')) {
await KV.put(atKey, token);
await addToAliveAccountList('', accountNumber);
Expand Down Expand Up @@ -546,7 +565,7 @@ async function addToAliveAccountList(accessToken, accountNumber) {
const accountType = await checkAccountType(accessToken);
const aliveAccountsKey = `${accountType}AliveAccounts`;

let aliveAccount = await KV.get(aliveAccountsKey) || '';
let aliveAccount = await KV.get(aliveAccountsKey);
let aliveAccountList = aliveAccount ? aliveAccount.split(',') : [];
if (!aliveAccountList.includes(accountNumber)) {
aliveAccountList.push(accountNumber);
Expand Down Expand Up @@ -582,6 +601,7 @@ async function generatePlusResponse(message, adminuserName) {
async function getPlusHTML() {
const WorkerURL = await KV.get('WorkerURL');
const turnstileSiteKey = await KV.get('TurnstileSiteKey');
const removeTurnstile = await KV.get('RemoveTurnstile')||'';
return `
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -672,7 +692,7 @@ async function getPlusHTML() {
<form id="managePlus" action="/token" method="POST">
<label for="adminusername">Admin Username:</label>
<input type="password" id="adminsername" name="adminusername" required>
<label for="refresh_token">Refresh Token (or AT):</label>
<label for="refresh_token">RT/AT:</label>
<input type="text" id="refresh_token" name="refresh_token" required>
<label for="account_number">Account Number:</label>
<input type="number" id="account_number" name="account_number" required>
Expand All @@ -691,6 +711,10 @@ async function getPlusHTML() {
</form>
</div>
<script>
if ('${removeTurnstile}') {
document.getElementById('cf-turnstile-response').value= "111";
}

function onTurnstileCallback(token) {
document.getElementById('cf-turnstile-response').value = token;
}
Expand Down Expand Up @@ -810,6 +834,7 @@ else {return new Response('Unauthorized access', { status: 403 });

async function getExportHTML() {
const turnstileSiteKey = await KV.get('TurnstileSiteKey');
const removeTurnstile = await KV.get('RemoveTurnstile')||'';
return `
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -900,6 +925,9 @@ async function getExportHTML() {
</form>
</div>
<script>
if ('${removeTurnstile}') {
document.getElementById('cf-turnstile-response').value= "111";
}
function onTurnstileCallback(token) {
document.getElementById('cf-turnstile-response').value = token;
}
Expand Down Expand Up @@ -991,6 +1019,7 @@ async function generateAdminResponse(message) {
async function getAdminHTML() {
const WorkerURL=await KV.get('WorkerURL');
const turnstileSiteKey=await KV.get('TurnstileSiteKey');
const removeTurnstile = await KV.get('RemoveTurnstile')||'';
return `
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -1119,6 +1148,9 @@ async function getAdminHTML() {
<div class="cf-turnstile" data-sitekey="${turnstileSiteKey}" data-callback="onTurnstileCallback"></div>
</div>
<script>
if ('${removeTurnstile}') {
document.getElementById('cf-turnstile-response').value= "111";
}
function onTurnstileCallback(token) {
document.getElementById('cf-turnstile-response').value = token;
}
Expand Down Expand Up @@ -1396,6 +1428,7 @@ async function queryLimits(accessToken, shareToken) {

async function getUserHTML() {
const turnstileSiteKey=await KV.get('TurnstileSiteKey');
const removeTurnstile = await KV.get('RemoveTurnstile')||'';
return `
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -1495,6 +1528,9 @@ async function getUserHTML() {
</form>
</div>
<script>
if ('${removeTurnstile}') {
document.getElementById('cf-turnstile-response').value= "111";
}
function onTurnstileCallback(token) {
document.getElementById('cf-turnstile-response').value = token;
}
Expand Down Expand Up @@ -1593,6 +1629,7 @@ async function getRegisterHTML() {
const turnstileSiteKey=await KV.get('TurnstileSiteKey');
const websiteName = await KV.get('WebName') || 'Haibara AI';
const logourl = await KV.get('LogoURL') || logo;
const removeTurnstile = await KV.get('RemoveTurnstile')||'';
return `
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -2022,6 +2059,9 @@ async function getRegisterHTML() {
<p>&copy; All rights reserved. | Powered by <a href="https://linux.do" target="_blank">Pandora</a> & <a href="https://chatgpt.com" target="_blank">ChatGPT</a></p>
</footer>
<script>
if ('${removeTurnstile}') {
document.getElementById('cf-turnstile-response').value= "111";
}
document.addEventListener('DOMContentLoaded', function() {
const cdkeyInput = document.getElementById('cdkey');
const usernameWrapper = document.getElementById('usernameWrapper');
Expand Down Expand Up @@ -2191,6 +2231,7 @@ async function saveUsageLogs(usersData) {


async function getTableUserHTML() {
const removeTurnstile = await KV.get('RemoveTurnstile')||'';
const turnstileSiteKey = await KV.get('TurnstileSiteKey');
return `
<!DOCTYPE html>
Expand Down Expand Up @@ -2290,6 +2331,9 @@ async function getTableUserHTML() {
</form>
</div>
<script>
if ('${removeTurnstile}') {
document.getElementById('cf-turnstile-response').value= "111";
}
function onTurnstileCallback(token) {
document.getElementById('cf-turnstile-response').value = token;
}
Expand Down Expand Up @@ -3063,6 +3107,7 @@ async function getLoginHTML(setan) {
const turnstileSiteKey=await KV.get('TurnstileSiteKey');
const websiteName = await KV.get('WebName') || 'Haibara AI';
const logourl = await KV.get('LogoURL') || logo;
const removeTurnstile = await KV.get('RemoveTurnstile')||'';
const commonHTML = `
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -3520,6 +3565,9 @@ async function getLoginHTML(setan) {
</footer>

<script>
if ('${removeTurnstile}') {
document.getElementById('cf-turnstile-response').value= "111";
}
document.addEventListener('DOMContentLoaded', function() {
const helpIcon = document.querySelector('.help-icon');
const tooltip = document.createElement('div');
Expand Down
7 changes: 7 additions & 0 deletions free_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ if (cookies) {


async function verifyTurnstile(responseToken) {
const removeTurnstile = await KV.get('RemoveTurnstile')||'';
if (removeTurnstile){return 'true'}
const verifyUrl = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
const secretKey = await KV.get('TurnstileKeys');
const response = await fetch(verifyUrl, {
Expand Down Expand Up @@ -887,6 +889,7 @@ if (cookies) {
const WorkerURL=await KV.get('WorkerURL');
const turnstileSiteKey=await KV.get('TurnstileSiteKey');
const websiteName = await KV.get('FreeWebName') || await KV.get('WebName') || 'Haibara AI';
const removeTurnstile = await KV.get('RemoveTurnstile')||'';
return `
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -1306,6 +1309,10 @@ if (cookies) {
</div>
</div>
<script>
if ('${removeTurnstile}') {
document.getElementById('cf-turnstile-response').value= "111";
}

document.addEventListener('DOMContentLoaded', function() {
const helpIcon = document.querySelector('.help-icon');
const tooltip = document.createElement('div');
Expand Down
Loading