import os import json import time import websockets import asyncio import requests import logging from pathlib import Path import pyfiglet from colorama import Fore, Style, init from requests.auth import HTTPProxyAuth # Initialize colorama init() # Simple color function with ANSI escape codes for underline color = { "reset": Style.RESET_ALL, "bright": Style.BRIGHT, "dim": Style.DIM, "underscore": '\033[4m', # ANSI escape code for underline "blink": '\033[5m', "reverse": '\033[7m', "hidden": '\033[8m', "fg": { "black": Fore.BLACK, "red": Fore.RED, "green": Fore.GREEN, "yellow": Fore.YELLOW, "blue": Fore.BLUE, "magenta": Fore.MAGENTA, "cyan": Fore.CYAN, "white": Fore.WHITE, } } # Import the database module (placeholder) # from database import database, update_database, init_database def format_metrics(data): credits_earned = data['creditsEarned'] total_uptime = data['totalUptime'] network_performance = data['networkPerformance'] days = total_uptime // 86400 hours = (total_uptime % 86400) // 3600 minutes = (total_uptime % 3600) // 60 uptime_string = f"{days}d {hours}h {minutes}m" if days > 0 else f"{hours}h {minutes}m" network_percentile_formatted = f"{network_performance * 100:.0f}%" return f"Credits Earned: {credits_earned} | Provider Uptime: {uptime_string} | Network Percentile: {network_percentile_formatted}" async def main(): # Clear the console os.system('clear') # Use pyfiglet to generate the ASCII art ascii_art = pyfiglet.figlet_format('Oasis Terminal', font='standard') print(f"{color['fg']['blue']}{color['bright']}{ascii_art}{color['reset']}") print(f"{color['fg']['green']}{color['bright']}📡 Monitoring Oasis.ai{color['reset']}") print(f"{color['fg']['cyan']}👨‍💻 Created by: @dwtexe{color['reset']}") print(f"{color['fg']['magenta']}🔍 Starting Oasis Terminal script...{color['reset']}\n") # Initialize the database (placeholder) # init_database() print(f"{color['fg']['yellow']}Database initialized.{color['reset']}") # Read proxies from a text file with open('proxies.txt', 'r') as f: proxies = [line.strip() for line in f if line.strip()] # Create WebSocket connections using the proxies for proxy in proxies: await connect_websocket(proxy) async def connect_websocket(proxy): print(f"{color['fg']['cyan']}Attempting to connect websocket using proxy {proxy}...{color['reset']}") # Placeholder for database token check database_token = 'YOUR_TOKEN' # Replace with actual token retrieval if database_token: async with websockets.connect(f"wss://api.oasis.ai/websocket?token={database_token}", extra_headers={"Proxy-Authorization": f"Basic {proxy}"}) as websocket: print(f"{color['fg']['green']}{color['bright']}WebSocket connection established using proxy {proxy}.{color['reset']}") # Placeholder for database update # update_database({"stats": {"status": "active"}}) await start_heartbeat_interval(websocket) await start_settings_interval(websocket) async for message in websocket: await handle_message(websocket, message) else: print(f"{color['fg']['red']}{color['bright']}No token available. Cannot connect to WebSocket.{color['reset']}") async def handle_message(websocket, message): message = json.loads(message) print(f"{color['fg']['blue']}{color['bright']}Received WebSocket message:{color['reset']} {color['fg']['yellow']}==>{color['reset']} {color['fg']['green']}Type: {message['type']}{color['reset']}") if message['type'] == 'serverMetrics': formatted_metrics = format_metrics(message['data']) print(f"{color['fg']['cyan']}{formatted_metrics}{color['reset']}") print(f"{color['fg']['magenta']}Updating database with server metrics...{color['reset']}") # Placeholder for database update # update_database({"stats": {**message['data']}}) else: print(f"{color['fg']['green']}Data: {json.dumps(message['data'], indent=2)}{color['reset']}") print(f"{color['fg']['cyan']}{'─' * 70}{color['reset']}") async def send_message(websocket, message): if websocket.closed: print(f"{color['fg']['red']}Cannot send message. WebSocket is not open.{color['reset']}") # Placeholder for database update # update_database({"stats": {"status": "offline"}}) return try: print(f"{color['fg']['blue']}Sending message of type: {message['type']}{color['reset']}") await websocket.send(json.dumps(message)) except Exception as e: logging.error(f"{color['fg']['red']}{color['bright']}Error sending message:{color['reset']} {e}") async def start_heartbeat_interval(websocket): print(f"{color['fg']['yellow']}Starting heartbeat interval...{color['reset']}") while True: await asyncio.sleep(60) print(f"{color['fg']['cyan']}Sending heartbeat...{color['reset']}") # Placeholder for database status database_status = 'active' # Replace with actual status retrieval await send_message(websocket, { "type": "heartbeat", "data": {"status": database_status}, }) await send_settings_data(websocket) async def start_settings_interval(websocket): print(f"{color['fg']['yellow']}Starting settings interval...{color['reset']}") print(f"{color['fg']['cyan']}{'─' * 70}{color['reset']}") while True: await asyncio.sleep(120) await send_settings_data(websocket) async def send_settings_data(websocket): # Placeholder function to send settings data pass if __name__ == "__main__": asyncio.run(main())