Skip to content

Commit

Permalink
Revised My IP, build flow.
Browse files Browse the repository at this point in the history
  • Loading branch information
bia-pain-bache committed Nov 21, 2024
1 parent 802c6fb commit 8c622b3
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 43 deletions.
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@ body:
label: Relevant log output | لاگ برنامه یا پنل
description: Refer to the program menu and copy the log and send it to us.
render: shell
validations:
required: true
- type: textarea
id: panel-version
attributes:
label: Panel version | نسخه‌ی پنل
validations:
required: true
16 changes: 0 additions & 16 deletions .github/ISSUE_TEMPLATE/feature_request.yml

This file was deleted.

21 changes: 16 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Build and Deploy Worker
name: Build and Deploy Worker on Release

on:
push:
branches:
- dev
on:
release:
types: [published]

jobs:
build:
Expand All @@ -12,6 +11,8 @@ jobs:
steps:
- name: Check out the code
uses: actions/checkout@v4
with:
ref: dev

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -35,3 +36,13 @@ jobs:
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload built worker to release assets
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./_worker.js
asset_name: worker.js
asset_content_type: application/javascript
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Binary file modified docs/assets/images/My-IP.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,20 @@ export async function fallback(request) {
url.protocol = 'https:';
request = new Request(url, request);
return await fetch(request);
}

export async function getMyIP(request) {
const ip = await request.text();
try {
const response = await fetch(`http://ip-api.com/json/${ip}?nocache=${Date.now()}`);
const geoLocation = await response.json();
return new Response(JSON.stringify(geoLocation), {
status: 200,
headers: {
'Content-Type': 'text/plain;charset=utf-8'
}
});
} catch (error) {
console.error('Error fetching IP address:', error);
}
}
2 changes: 1 addition & 1 deletion src/helpers/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function initParams(request, env) {
trojanPassword = env.TROJAN_PASS || 'bpb-trojan';
defaultHttpPorts = ['80', '8080', '2052', '2082', '2086', '2095', '8880'];
defaultHttpsPorts = ['443', '8443', '2053', '2083', '2087', '2096'];
panelVersion = '2.7.3';
panelVersion = '2.7.4';
hostName = request.headers.get('Host');
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
Expand Down
60 changes: 40 additions & 20 deletions src/pages/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ export async function renderHomePage (request, env, proxySettings, isPassSet) {
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3);
transform: translateY(-2px);
}
.header-container button:hover {
transform: scale(1.1);
}
button.button:hover { color: white; }
.button:active,
table button:active { transform: translateY(1px); box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3); }
Expand Down Expand Up @@ -372,6 +375,7 @@ export async function renderHomePage (request, env, proxySettings, isPassSet) {
#ips th { background-color: var(--hr-text-color); color: var(--background-color); width: unset; }
#ips td { background-color: unset; }
#ips td:first-child { background-color: var(--table-active-color); }
.header-container { display: flex; align-items: center; justify-content: center; }
@media only screen and (min-width: 768px) {
.form-container { max-width: 70%; }
.form-control {
Expand Down Expand Up @@ -672,7 +676,7 @@ export async function renderHomePage (request, env, proxySettings, isPassSet) {
</div>
</form>
<hr>
<h2>NORMAL SUB 🔗</h2>
<h2>🔗 NORMAL SUB</h2>
<div class="table-container">
<table id="normal-configs-table">
<tr>
Expand All @@ -698,7 +702,7 @@ export async function renderHomePage (request, env, proxySettings, isPassSet) {
</tr>
</table>
</div>
<h2>FULL NORMAL SUB 🔗</h2>
<h2>🔗 FULL NORMAL SUB</h2>
<div class="table-container">
<table id="full-normal-configs-table">
<tr>
Expand Down Expand Up @@ -734,7 +738,7 @@ export async function renderHomePage (request, env, proxySettings, isPassSet) {
</tr>
</table>
</div>
<h2>FRAGMENT SUB ⛓️</h2>
<h2>🔗 FRAGMENT SUB</h2>
<div class="table-container">
<table id="frag-sub-table">
<tr>
Expand All @@ -761,7 +765,7 @@ export async function renderHomePage (request, env, proxySettings, isPassSet) {
</tr>
</table>
</div>
<h2>WARP SUB 🔗</h2>
<h2>🔗 WARP SUB</h2>
<div class="table-container">
<table id="normal-configs-table">
<tr>
Expand Down Expand Up @@ -797,7 +801,7 @@ export async function renderHomePage (request, env, proxySettings, isPassSet) {
</tr>
</table>
</div>
<h2>WARP PRO SUB 🔗</h2>
<h2>🔗 WARP PRO SUB</h2>
<div class="table-container">
<table id="warp-pro-configs-table">
<tr>
Expand Down Expand Up @@ -852,26 +856,34 @@ export async function renderHomePage (request, env, proxySettings, isPassSet) {
</div>
</div>
<hr>
<h2>MY IP 💡</h2>
<div class="header-container">
<h2 style="margin: 0 5px;">💡 MY IP</h2>
<button type="button" id="resetSettings" onclick="fetchIPInfo()" style="background: none; margin: 0; border: none; cursor: pointer;">
<i class="fa fa-refresh fa-2x" style="color: var(--button-color);" aria-hidden="true"></i>
</button>
</div>
<div class="table-container">
<table id="ips" style="text-align: center; margin-bottom: 15px; text-wrap-mode: nowrap;">
<tr>
<th>Target Address</th>
<th>IP</th>
<th>Country</th>
<th>City</th>
<th>ISP</th>
</tr>
<tr>
<td>Cloudflare CDN</td>
<td id="cf-ip"></td>
<td><b id="cf-country"></b></td>
<td><b id="cf-city"></b></td>
<td><b id="cf-isp"></b></td>
</tr>
<tr>
<td>Others</td>
<td id="ip"></td>
<td><b id="country"></b></td>
<td><b id="city"></b></td>
<td><b id="isp"></b></td>
</tr>
</table>
</div>
Expand Down Expand Up @@ -1012,26 +1024,34 @@ export async function renderHomePage (request, env, proxySettings, isPassSet) {
});
const fetchIPInfo = async () => {
const updateUI = (ip = '-', country = '-', country_code = '-', city = '-', cfIP) => {
const flag = country_code !== '-' ? String.fromCodePoint(...[...country_code].map(c => 0x1F1E6 + c.charCodeAt(0) - 65)) : '';
const updateUI = (ip = '-', country = '-', countryCode = '-', city = '-', isp = '-', cfIP) => {
const flag = countryCode !== '-' ? String.fromCodePoint(...[...countryCode].map(c => 0x1F1E6 + c.charCodeAt(0) - 65)) : '';
document.getElementById(cfIP ? 'cf-ip' : 'ip').textContent = ip;
document.getElementById(cfIP ? 'cf-country' : 'country').textContent = country + ' ' + flag;
document.getElementById(cfIP ? 'cf-city' : 'city').textContent = city;
document.getElementById(cfIP ? 'cf-isp' : 'isp').textContent = isp;
};
const fetchIPApi = async (cfIP) => {
try {
const response = await fetch('https://ipwho.is/' + cfIP + '?nocache=' + Date.now(), { cache: "no-store" });
const { ip, country, country_code, city } = await response.json();
updateUI(ip, country, country_code, city, cfIP);
} catch (error) {
console.error('Error fetching IP address:', error);
updateUI();
}
try {
const ipResponse = await fetch('https://ipwho.is/' + '?nocache=' + Date.now(), { cache: "no-store" });
const ipResponseObj = await ipResponse.json();
const geoResponse = await fetch('/my-ip', {
method: 'POST',
body: ipResponseObj.ip
});
const ipGeoLocation = await geoResponse.json();
updateUI(ipResponseObj.ip, ipGeoLocation.country, ipGeoLocation.countryCode, ipGeoLocation.city, ipGeoLocation.isp);
const cfIPresponse = await fetch('https://ipv4.icanhazip.com/?nocache=' + Date.now(), { cache: "no-store" });
const cfIP = await cfIPresponse.text();
const cfGeoResponse = await fetch('/my-ip', {
method: 'POST',
body: cfIP.trim()
});
const cfIPGeoLocation = await cfGeoResponse.json();
updateUI(cfIP, cfIPGeoLocation.country, cfIPGeoLocation.countryCode, cfIPGeoLocation.city, cfIPGeoLocation.isp, true);
} catch (error) {
console.error('Error fetching IP address:', error);
}
await fetchIPApi('');
await fetchIPApi('${request.headers.get('cf-connecting-ip') || '-'}');
}
const getWarpConfigs = async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getSingBoxCustomConfig, getSingBoxWarpConfig } from './cores-configs/si
import { getClashNormalConfig, getClashWarpConfig } from './cores-configs/clash';
import { getNormalConfigs } from './cores-configs/normalConfigs';
import { initializeParams, userID, client, pathName } from './helpers/init';
import { fallback, handlePanel } from './helpers/helpers';
import { fallback, getMyIP, handlePanel } from './helpers/helpers';

export default {
async fetch(request, env) {
Expand Down Expand Up @@ -48,6 +48,9 @@ export default {

case '/panel/password':
return await resetPassword(request, env);

case '/my-ip':
return await getMyIP(request);

default:
return await fallback(request);
Expand Down

0 comments on commit 8c622b3

Please sign in to comment.