Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e8aa6ad772801bb715c84fd5cc32bf4150e24831
Author: SaintShit <saintshit@proton.me>
Date:   Sun May 19 13:45:54 2024 +0330

    fix: build frontend

commit 9ee83f2fe8620d6f34160d3dd7f848a7394170d3
Author: SaintShit <saintshit@proton.me>
Date:   Sun May 19 13:45:38 2024 +0330

    fix: more options for get_public_ip

commit 31e060d2bc3186b901b0d9755fe82f428bee5024
Author: SaintShit <saintshit@proton.me>
Date:   Sun May 19 13:44:38 2024 +0330

    fix: get_public_ipv6 function was missing

commit ee4fdfb5c0e22335d21a88c9d3e093022b6f1254
Merge: 50d3d5c 8f6ac62
Author: SaintShit <saintshit@proton.me>
Date:   Sun May 19 13:27:13 2024 +0330

    Merge branch 'dev' of gozargah:Gozargah/Marzban; branch 'server-ipv6-variable' of github.com:fodhelper/Marzban into fodhelper-server-ipv6-variable

commit 8f6ac62
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:23:43 2024 +0100

    Update en.json

commit 22d99f6
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:23:40 2024 +0100

    Update fa.json

commit 2f5e177
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:23:37 2024 +0100

    Update ru.json

commit 9b66def
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:23:34 2024 +0100

    Update zh.json

commit ca72d5d
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:23:32 2024 +0100

    Update en.json

commit db95abe
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:23:29 2024 +0100

    Update fa.json

commit c8e5388
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:23:26 2024 +0100

    Update ru.json

commit 44db592
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:23:23 2024 +0100

    Update zh.json

commit 65afcc3
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:20:48 2024 +0100

    Update HostsDialog.tsx

commit 1c4e375
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:19:15 2024 +0100

    Update system.py

commit 561776d
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:18:38 2024 +0100

    Update share.py

commit 4e5ef0c
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Mon Apr 8 09:17:02 2024 +0100

    Update system.py

commit 94dd842
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Thu Apr 4 01:59:26 2024 +0100

    Update system.py

commit 039e822
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:30:34 2024 +0100

    Update en.json

commit 5d7b123
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:30:32 2024 +0100

    Update en.json

commit 0dcb3fc
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:21:28 2024 +0100

    Update zh.json

commit 6d2fee2
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:21:25 2024 +0100

    Update zh.json

commit 8d643f0
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:21:22 2024 +0100

    Update ru.json

commit 5d7031d
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:21:17 2024 +0100

    Update ru.json

commit 0cf7cf2
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:21:06 2024 +0100

    Update fa.json

commit a427370
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:21:03 2024 +0100

    Update fa.json

commit e7fe60f
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:20:57 2024 +0100

    Update en.json

commit c47d05a
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:20:52 2024 +0100

    Update en.json

commit af17224
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:11:12 2024 +0100

    Update HostsDialog.tsx

commit 76b6bc4
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:02:00 2024 +0100

    Update share.py

commit 9aed1e4
Author: fodhelper <161948085+fodhelper@users.noreply.github.com>
Date:   Wed Apr 3 23:01:16 2024 +0100

    Update system.py
  • Loading branch information
SaintShit committed May 19, 2024
1 parent 50d3d5c commit 9ae4dfa
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 120 deletions.
4 changes: 2 additions & 2 deletions app/dashboard/build/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<meta name="msapplication-TileColor" content="#2b5797" />
<meta name="msapplication-config" content="/favicon/browserconfig.xml" />
<meta name="theme-color" content="#3B81F6" />
<script type="module" crossorigin src="/dashboard/assets/index.2e9c394e.js"></script>
<link rel="modulepreload" crossorigin href="/dashboard/assets/vendor.764109dc.js">
<script type="module" crossorigin src="/dashboard/assets/index.2c05c37d.js"></script>
<link rel="modulepreload" crossorigin href="/dashboard/assets/vendor.8aa8dc93.js">
<link rel="stylesheet" href="/dashboard/assets/index.59de2328.css">
</head>
<body>
Expand Down

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions app/dashboard/build/assets/index.2e9c394e.js

This file was deleted.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/dashboard/build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<meta name="msapplication-TileColor" content="#2b5797" />
<meta name="msapplication-config" content="/favicon/browserconfig.xml" />
<meta name="theme-color" content="#3B81F6" />
<script type="module" crossorigin src="/dashboard/assets/index.2e9c394e.js"></script>
<link rel="modulepreload" crossorigin href="/dashboard/assets/vendor.764109dc.js">
<script type="module" crossorigin src="/dashboard/assets/index.2c05c37d.js"></script>
<link rel="modulepreload" crossorigin href="/dashboard/assets/vendor.8aa8dc93.js">
<link rel="stylesheet" href="/dashboard/assets/index.59de2328.css">
</head>
<body>
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/build/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"hostsDialog.statusText": "User status",
"hostsDialog.proxyProtocol": "Proxy protocol (e.g. VMess)",
"hostsDialog.proxyMethod": "Proxy transport method (e.g. ws)",
"hostsDialog.currentServer": "Current server ip address",
"hostsDialog.currentServer": "IP Address of current server",
"hostsDialog.currentServerv6": "IPv6 of current server",
"hostsDialog.security": "Security Layer",
"hostsDialog.host": "Request Host",
"hostsDialog.port": "Port",
Expand Down
1 change: 1 addition & 0 deletions app/dashboard/build/locales/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"hostsDialog.proxyProtocol": "پروتکل پروکسی (مانند VMess)",
"hostsDialog.proxyMethod": "روش انتقال پروکسی (مانند ws)",
"hostsDialog.currentServer": "IP کنونی سرور",
"hostsDialog.currentServerv6": "IPv6 کنونی سرور",
"hostsDialog.security": "لایه امنیت",
"hostsDialog.host": "هاست درخواست",
"hostsDialog.port": "پورت",
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/build/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"hostsDialog.statusText": "Статус пользователя",
"hostsDialog.proxyProtocol": "Протокол прокси (например, VMess)",
"hostsDialog.proxyMethod": "Метод транспорта прокси (например, ws)",
"hostsDialog.currentServer": "Текущий IP-адрес сервера",
"hostsDialog.currentServer": "IP текущего сервера",
"hostsDialog.currentServerv6": "IPv6 текущего сервера",
"hostsDialog.security": "Security Layer",
"hostsDialog.host": "Host",
"hostsDialog.port": "Port",
Expand Down
1 change: 1 addition & 0 deletions app/dashboard/build/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"hostsDialog.proxyProtocol": "代理协议(例如 VMess)",
"hostsDialog.proxyMethod": "代理传输方法(例如 ws)",
"hostsDialog.currentServer": "当前服务器的 IP 地址",
"hostsDialog.currentServerv6": "当前服务器的 IPv6 地址",
"hostsDialog.security": "安全层",
"hostsDialog.host": "请求主机",
"hostsDialog.port": "端口",
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"hostsDialog.statusText": "User status",
"hostsDialog.proxyProtocol": "Proxy protocol (e.g. VMess)",
"hostsDialog.proxyMethod": "Proxy transport method (e.g. ws)",
"hostsDialog.currentServer": "Current server ip address",
"hostsDialog.currentServer": "IP Address of current server",
"hostsDialog.currentServerv6": "IPv6 of current server",
"hostsDialog.security": "Security Layer",
"hostsDialog.host": "Request Host",
"hostsDialog.port": "Port",
Expand Down
1 change: 1 addition & 0 deletions app/dashboard/public/locales/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"hostsDialog.proxyProtocol": "پروتکل پروکسی (مانند VMess)",
"hostsDialog.proxyMethod": "روش انتقال پروکسی (مانند ws)",
"hostsDialog.currentServer": "IP کنونی سرور",
"hostsDialog.currentServerv6": "IPv6 کنونی سرور",
"hostsDialog.security": "لایه امنیت",
"hostsDialog.host": "هاست درخواست",
"hostsDialog.port": "پورت",
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/public/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"hostsDialog.statusText": "Статус пользователя",
"hostsDialog.proxyProtocol": "Протокол прокси (например, VMess)",
"hostsDialog.proxyMethod": "Метод транспорта прокси (например, ws)",
"hostsDialog.currentServer": "Текущий IP-адрес сервера",
"hostsDialog.currentServer": "IP текущего сервера",
"hostsDialog.currentServerv6": "IPv6 текущего сервера",
"hostsDialog.security": "Security Layer",
"hostsDialog.host": "Host",
"hostsDialog.port": "Port",
Expand Down
1 change: 1 addition & 0 deletions app/dashboard/public/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"hostsDialog.proxyProtocol": "代理协议(例如 VMess)",
"hostsDialog.proxyMethod": "代理传输方法(例如 ws)",
"hostsDialog.currentServer": "当前服务器的 IP 地址",
"hostsDialog.currentServerv6": "当前服务器的 IPv6 地址",
"hostsDialog.security": "安全层",
"hostsDialog.host": "请求主机",
"hostsDialog.port": "端口",
Expand Down
12 changes: 12 additions & 0 deletions app/dashboard/src/components/HostsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ const AccordionInbound: FC<AccordionInboundType> = ({
</Badge>{" "}
{t("hostsDialog.currentServer")}
</Text>
<Text mt={1}>
<Badge>
{"{"}SERVER_IPV6{"}"}
</Badge>{" "}
{t("hostsDialog.currentServerv6")}
</Text>
<Text mt={1}>
<Badge>
{"{"}USERNAME{"}"}
Expand Down Expand Up @@ -372,6 +378,12 @@ const AccordionInbound: FC<AccordionInboundType> = ({
</Badge>{" "}
{t("hostsDialog.currentServer")}
</Text>
<Text mt={1}>
<Badge>
{"{"}SERVER_IPV6{"}"}
</Badge>{" "}
{t("hostsDialog.currentServerv6")}
</Text>
<Text mt={1}>
<Badge>
{"{"}USERNAME{"}"}
Expand Down
17 changes: 12 additions & 5 deletions app/subscription/share.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import base64
import random
import secrets
from datetime import datetime as dt, timedelta
from typing import TYPE_CHECKING, Literal, Union, List
from datetime import datetime as dt
from datetime import timedelta
from typing import TYPE_CHECKING, List, Literal, Union

from jdatetime import date as jd

from app import xray
from app.utils.system import get_public_ip, readable_size
from app.utils.system import get_public_ip, get_public_ipv6, readable_size

from . import *

if TYPE_CHECKING:
from app.models.user import UserResponse

from config import (ACTIVE_STATUS_TEXT, EXPIRED_STATUS_TEXT, LIMITED_STATUS_TEXT, DISABLED_STATUS_TEXT, ONHOLD_STATUS_TEXT)
from config import (ACTIVE_STATUS_TEXT, DISABLED_STATUS_TEXT,
EXPIRED_STATUS_TEXT, LIMITED_STATUS_TEXT,
ONHOLD_STATUS_TEXT)

SERVER_IP = get_public_ip()
SERVER_IPV6 = get_public_ipv6()

STATUS_EMOJIS = {
"active": "✅",
Expand All @@ -33,6 +38,7 @@
"on_hold": ONHOLD_STATUS_TEXT,
}


def get_v2ray_link(remark: str, address: str, inbound: dict, settings: dict):
if inbound["protocol"] == "vmess":
return V2rayShareLink.vmess(
Expand Down Expand Up @@ -269,6 +275,7 @@ def setup_format_variables(extra_data: dict) -> dict:

format_variables = {
"SERVER_IP": SERVER_IP,
"SERVER_IPV6": SERVER_IPV6,
"USERNAME": extra_data.get("username", "{USERNAME}"),
"DATA_USAGE": readable_size(extra_data.get("used_traffic")),
"DATA_LIMIT": data_limit,
Expand Down Expand Up @@ -299,7 +306,7 @@ def process_inbounds_and_tags(
_inbounds.append((protocol, [tag]))
index_dict = {proxy: index for index, proxy in enumerate(xray.config.inbounds_by_tag.keys())}
inbounds = sorted(_inbounds, key=lambda x: index_dict.get(x[1][0], float('inf')))

for protocol, tags in inbounds:
settings = proxies.get(protocol)
if not settings:
Expand Down
46 changes: 37 additions & 9 deletions app/utils/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import psutil
import requests
import ipaddress

from app import scheduler

Expand Down Expand Up @@ -109,26 +110,35 @@ def check_port(port: int) -> bool:

def get_public_ip():
try:
return requests.get('https://api.ipify.org?format=json&ipv=4', timeout=5).json()['ip']
except (requests.exceptions.RequestException,
requests.exceptions.RequestException,
KeyError) as e:
resp = requests.get('http://api4.ipify.org/', timeout=5).text.strip()
if ipaddress.IPv4Address(resp).is_global:
return resp
except:
pass

try:
resp = requests.get('http://ipv4.icanhazip.com/', timeout=5).text.strip()
if ipaddress.IPv4Address(resp).is_global:
return resp
except:
pass

try:
requests.packages.urllib3.util.connection.HAS_IPV6 = False
return requests.get('https://ifconfig.io/ip', timeout=5).text.strip()
except (requests.exceptions.RequestException,
requests.exceptions.RequestException,
KeyError) as e:
resp = requests.get('https://ifconfig.io/ip', timeout=5).text.strip()
if ipaddress.IPv4Address(resp).is_global:
return resp
except requests.exceptions.RequestException:
pass
finally:
requests.packages.urllib3.util.connection.HAS_IPV6 = True

try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect(('8.8.8.8', 80))
return sock.getsockname()[0]
resp = sock.getsockname()[0]
if ipaddress.IPv4Address(resp).is_global:
return resp
except (socket.error, IndexError):
pass
finally:
Expand All @@ -137,6 +147,24 @@ def get_public_ip():
return '127.0.0.1'


def get_public_ipv6():
try:
resp = requests.get('http://api6.ipify.org/', timeout=5).text.strip()
if ipaddress.IPv6Address(resp).is_global:
return '[%s]' % resp
except:
pass

try:
resp = requests.get('http://ipv6.icanhazip.com/', timeout=5).text.strip()
if ipaddress.IPv6Address(resp).is_global:
return '[%s]' % resp
except:
pass

return '[::1]'


def readable_size(size_bytes):
if size_bytes == 0:
return "0 B"
Expand Down

0 comments on commit 9ae4dfa

Please sign in to comment.