Skip to content

Commit

Permalink
disable SSL verification
Browse files Browse the repository at this point in the history
  • Loading branch information
houshmand-2005 committed May 29, 2024
1 parent ff7563d commit f6e5f01
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion telegram_bot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def get_token(panel_data: PanelType) -> PanelType | ValueError:
for scheme in ["https", "http"]:
url = f"{scheme}://{panel_data.panel_domain}/api/admin/token"
try:
async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(verify=False) as client:
response = await client.post(url, data=payload, timeout=5)
response.raise_for_status()
json_obj = response.json()
Expand Down
15 changes: 12 additions & 3 deletions utils/get_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import asyncio
import ssl
import sys
from asyncio import Task
from ssl import SSLError
Expand All @@ -24,7 +25,11 @@

TASKS = []
INTERVAL = "0.7"

task_node_mapping = {}
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE


async def get_panel_logs(panel_data: PanelType) -> None:
Expand All @@ -46,7 +51,8 @@ async def get_panel_logs(panel_data: PanelType) -> None:
try:
async with websockets.client.connect(
f"{scheme}://{panel_data.panel_domain}/api/core"
+ f"/logs?interval={INTERVAL}&token={token}"
+ f"/logs?interval={INTERVAL}&token={token}",
ssl=ssl_context if scheme == "wss" else None,
) as ws:
log_message = "Establishing connection for the main panel"
await send_logs(log_message)
Expand Down Expand Up @@ -82,11 +88,14 @@ async def get_nodes_logs(panel_data: PanelType, node: NodeType) -> None:
if isinstance(get_panel_token, ValueError):
raise get_panel_token
token = get_panel_token.panel_token
for scheme in ["ws", "wss"]:
for scheme in ["wss", "ws"]:
while True:
try:
url = f"{scheme}://{panel_data.panel_domain}/api/node/{node.node_id}/logs?interval={INTERVAL}&token={token}" # pylint: disable=line-too-long
async with websockets.client.connect(url) as ws:
async with websockets.client.connect(
url,
ssl=ssl_context if scheme == "wss" else None,
) as ws:
log_message = (
"Establishing connection for"
+ f" node number {node.node_id} name: {node.node_name}"
Expand Down
12 changes: 6 additions & 6 deletions utils/panel_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def get_token(panel_data: PanelType) -> PanelType | ValueError:
for scheme in ["https", "http"]:
url = f"{scheme}://{panel_data.panel_domain}/api/admin/token"
try:
async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(verify=False) as client:
response = await client.post(url, data=payload, timeout=5)
response.raise_for_status()
json_obj = response.json()
Expand Down Expand Up @@ -91,7 +91,7 @@ async def all_user(panel_data: PanelType) -> list[UserType] | ValueError:
for scheme in ["https", "http"]:
url = f"{scheme}://{panel_data.panel_domain}/api/users"
try:
async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(url, headers=headers, timeout=10)
response.raise_for_status()
user_inform = response.json()
Expand Down Expand Up @@ -147,7 +147,7 @@ async def enable_all_user(panel_data: PanelType) -> None | ValueError:
url = f"{scheme}://{panel_data.panel_domain}/api/user/{username.name}"
status = {"status": "active"}
try:
async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(verify=False) as client:
response = await client.put(url, json=status, headers=headers)
response.raise_for_status()
message = f"Enabled user: {username.name}"
Expand Down Expand Up @@ -198,7 +198,7 @@ async def enable_selected_users(
url = f"{scheme}://{panel_data.panel_domain}/api/user/{username}"
status = {"status": "active"}
try:
async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(verify=False) as client:
response = await client.put(url, json=status, headers=headers)
response.raise_for_status()
message = f"Enabled user: {username}"
Expand Down Expand Up @@ -247,7 +247,7 @@ async def disable_user(panel_data: PanelType, username: UserType) -> None | Valu
for scheme in ["https", "http"]:
url = f"{scheme}://{panel_data.panel_domain}/api/user/{username.name}"
try:
async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(verify=False) as client:
response = await client.put(url, json=status, headers=headers)
response.raise_for_status()
message = f"Disabled user: {username.name}"
Expand Down Expand Up @@ -303,7 +303,7 @@ async def get_nodes(panel_data: PanelType) -> list[NodeType] | ValueError:
for scheme in ["https", "http"]:
url = f"{scheme}://{panel_data.panel_domain}/api/nodes"
try:
async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(url, headers=headers, timeout=10)
response.raise_for_status()
user_inform = response.json()
Expand Down
2 changes: 1 addition & 1 deletion utils/parse_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def check_ip(ip_address: str) -> None | str:
if "ipapi.co" in endpoint:
url += "/country"
try:
async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(verify=False) as client:
resp = await client.get(url, timeout=2)
info = resp.json()
country = info.get(key) if key else resp.text
Expand Down

0 comments on commit f6e5f01

Please sign in to comment.