# -*- coding: utf-8 -*-
# 6to4 Configuration Script
# Author: github.com/Azumi67
# This is for educational use and my own learning, please provide me with feedback if possible
# This script is designed to simplify the configuration of 6to4 tunnels.
#
# Supported operating systems: Ubuntu 20, Debian 12, Ubuntu 22, Ubuntu 22

import platform
import subprocess
import requests
import tarfile
import sys
import re
import os
import shutil
import time
import colorama
from colorama import Fore, Style
import subprocess
from time import sleep
import readline
import io

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding="utf-8", errors="replace")

if os.geteuid() != 0:
    print("\033[91mThis script must be run as root. Please use sudo -i.\033[0m")
    sys.exit(1)

def display_checkmark(message):
    print("\u2714 " + message)

def logo():
    logo_path = "/etc/logo2.sh"
    try:
        subprocess.run(["bash", "-c", logo_path], check=True)
    except subprocess.CalledProcessError as e:
        return e

    return None
def install_prerequisites():
    print("\033[93mInstalling prerequisites...\033[0m")
    if platform.system() == "Linux":
        loading_bar("\033[93mUpdating\033[0m")
        subprocess.run(['sudo', 'apt', 'update', '-y'], check=True)
        loading_bar("\033[93mInstalling wget, curl, unzip, and tar\033[0m")
        subprocess.run(['sudo', 'apt', 'install', '-y', 'wget', 'curl', 'unzip', 'tar'], check=True)
    elif platform.system() == "Darwin":
        loading_bar("\033[93mInstalling wget, curl, unzip, and gnu-tar\033[0m")
        subprocess.run(['brew', 'install', 'wget', 'curl', 'unzip', 'gnu-tar'], check=True)
    else:
        print("\033[91mWindows is not supported..\033[0m")
        exit(1)

def loading_bar(task):
    print(f"{task}... ", end="", flush=True)
    for _ in range(10):
        time.sleep(0.2) 
        print(".", end="", flush=True)
    display_checkmark("\033[92mdone\033[0m")

def download_binary():
    os_name = platform.system().lower()
    arch = platform.machine()
    url = ""

    if os_name == "linux" and arch == "x86_64":
        url = "https://novin.me/backhaul_linux_amd64.tar.gz"
        file_name = "/tmp/backhaul_linux_amd64.tar.gz"
    elif os_name == "linux" and arch == "aarch64":
        url = "https://novin.me/backhaul_linux_arm64.tar.gz"
        file_name = "/tmp/backhaul_linux_arm64.tar.gz"
    elif os_name == "darwin" and arch == "x86_64":
        url = "https://novin.me/backhaul_darwin_amd64.tar.gz"
        file_name = "/tmp/backhaul_darwin_amd64.tar.gz"
    elif os_name == "darwin" and arch == "arm64":
        url = "https://novin.me/backhaul_darwin_arm64.tar.gz"
        file_name = "/tmp/backhaul_darwin_arm64.tar.gz"
    else:
        print("\033[91mOS or arch Unsupported\033[0m ")
        exit(1)

    print(f"\033[93mDownloading the binary from {url}..\033[0m")
    response = requests.get(url, stream=True)
    response.raise_for_status()
    total_size = int(response.headers.get('content-length', 0))
    downloaded_size = 0
    with open(file_name, 'wb') as file:
        for chunk in response.iter_content(chunk_size=8192):
            file.write(chunk)
            downloaded_size += len(chunk)
            progress = int((downloaded_size / total_size) * 50)
            sys.stdout.write(f"\r[{'#' * progress}{'.' * (50 - progress)}] {downloaded_size / 1024:.2f} KB")
            sys.stdout.flush()
    print("\n\033[92mDownload complete\033[0m")

    target_dir = "/usr/local/bin/backhaul"
    os.makedirs(target_dir, exist_ok=True)

    print("\033[93mExtracting binary..\033[0m")
    if file_name.endswith('.tar.gz'):
        with tarfile.open(file_name, 'r:gz') as tar:
            tar.extractall(path=target_dir)

    print("\033[92mBinary downloaded and extracted\033[0m")

def backhaul_menu():
    os.system("clear")
    while True:  
        logo()
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mBackhaul\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[93mChoose what to do:\033[0m")
        print("0  \033[91mStatus\033[0m")
        print("1  \033[93mSingle\033[0m")
        print("2  \033[92mMulti\033[0m")
        print("3  \033[93mEdit Backhaul\033[0m")
        print("4  \033[94mPort Monitoring \033[97m[TCPdump]\033[0m")
        print("5  \033[92mEdit Reset Timer\033[0m")
        print("6  \033[91mUninstall\033[0m")
        print("0. \033[94mExit\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        try:
            choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
            if choice == "0":
                backhaul_status()
            elif choice == "1":
                backhaul_single()
            elif choice == "2":
                backhaul_multi()
            elif choice == "3":
                backhaul_editlocal()
            elif choice == "4":
                backhaul_monitor()
            elif choice == "5":
                edit_backhaul_reset_menu()
            elif choice == "6":
                backhaul_uninstall()
            elif choice == "0.":  
                print("Exiting...")
                break
            else:
                print("Invalid choice.")
            input("Press Enter to continue...")  

        except KeyboardInterrupt:
            display_error("\033[91m\nProgram interrupted. Exiting...\033[0m")
            sys.exit()
def display_error(message):
    print("\u2718 Error: " + message)
    
def backhaul_single():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mTCP\033[0m")
    print("2  \033[92mTCP Mux\033[0m")
    print("3  \033[93mWs\033[0m")
    print("4  \033[92mWss\033[0m")
    print("5  \033[93mWs Mux\033[0m")
    print("6  \033[92mWss Mux\033[0m")
    print("7  \033[93mUDP\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_tcp_single()
            
    elif choice == "2":
        backhaul_tcpmux_single()
            
    elif choice == "3":
        backhaul_ws_single()
            
    elif choice == "4":
        backhaul_wss_single()
            
    elif choice == "5":
        backhaul_wsmux_single()
            
    elif choice == "6":
        backhaul_wssmux_single()

    elif choice == "7":
        backhaul_udp_menu()
            
    elif choice == "0":
        clear()
        backhaul_menu()
        
    else:
        print("Invalid choice.")


def backhaul_udp_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_udpmenu()
            
    elif choice == "2":
        backhaul_kharej_client_udpmenu()
            
    elif choice == "0":
        clear()
        backhaul_single()
            
    else:
        print("Invalid choice.")


def display_checkmark(message):
    print(message)


def backhaul_iran_server_udpmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Port forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service()
    enable_backhaul_reset_server()



def backhaul_kharej_client_udpmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp", 
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
        
    }

    config_path = "/usr/local/bin/backhaul/client.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service()
    enable_backhaul_reset_client()


def backhaul_tcp_single():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmenu()
            
    elif choice == "2":
        backhaul_kharej_client_tcpmenu()
            
    elif choice == "0":
        clear()
        backhaul_single()
            
    else:
        print("Invalid choice.")

def backhaul_tcpmux_single():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmuxmenu()
            
    elif choice == "2":
        backhaul_kharej_client_tcpmuxmenu()
            
    elif choice == "0":
        clear()
        backhaul_single()
            
    else:
        print("Invalid choice.")

def backhaul_ws_single():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmenu()
            
    elif choice == "2":
        backhaul_kharej_client_wsmenu()
            
    elif choice == "0":
        clear()
        backhaul_single()
        
    else:
        print("Invalid choice.")

def backhaul_wsmux_single():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSMux\033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmuxmenu()
            
    elif choice == "2":
        backhaul_kharej_client_wsmuxmenu()
            
    elif choice == "0":
        clear()
        backhaul_single()
            
    else:
        print("Invalid choice.")

def backhaul_wss_single():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmenu()
            
    elif choice == "2":
        backhaul_kharej_client_wssmenu()
            
    elif choice == "0":
        clear()
        backhaul_single()
            
    else:
        print("Invalid choice.")

def backhaul_wssmux_single():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmuxmenu()
            
    elif choice == "2":
        backhaul_kharej_client_wssmuxmenu()
            
    elif choice == "0":
        clear()
        backhaul_single()
            
    else:
        print("Invalid choice.")

def enable_backhaul_reset_server():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_server(interval):
    service_name = "backhaul_reset.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server 
sudo journalctl --vacuum-size=1M --unit=backhaul-server.service
"""

    with open("/etc/backhaul_reset.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def enable_backhaul_reset_client():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client(interval):
    service_name = "backhaul_reset.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client 
sudo journalctl --vacuum-size=1M --unit=backhaul-client.service
"""

    with open("/etc/backhaul_reset.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleserver_service():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server.service")
    os.system("systemctl start backhaul-server.service")
    display_checkmark(f"Service file created at {service_path}")


def create_singleclient_service():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client.service")
    os.system("systemctl restart backhaul-client.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_iran_server_tcpmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Port forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service()
    enable_backhaul_reset_server()
    

def backhaul_kharej_client_tcpmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service()
    enable_backhaul_reset_client()


def backhaul_iran_server_tcpmuxmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Port forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service()
    enable_backhaul_reset_server()

def backhaul_kharej_client_tcpmuxmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service()
    enable_backhaul_reset_client()

def backhaul_iran_server_wsmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Port forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service()
    enable_backhaul_reset_server()

def backhaul_kharej_client_wsmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service()
    enable_backhaul_reset_client()

def self_signedcert(cert_name="server", validity_days=365):
    cert_dir = "/etc/backhaul"
    
    try:
        os.makedirs(cert_dir, exist_ok=True)
    except PermissionError:
        print(f"Permission denied: You need sudo/root permissions to create {cert_dir}")
        return

    try:
        subprocess.run(["openssl", "version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    except subprocess.CalledProcessError:
        print("OpenSSL is not installed. Please install it manually using the following command:")
        print("On Ubuntu/Debian: sudo apt-get install openssl")
        return

    key_file = os.path.join(cert_dir, f"{cert_name}.key")
    subprocess.run([
        "openssl", "genpkey", "-algorithm", "RSA", "-out", key_file, "-pkeyopt", "rsa_keygen_bits:2048"
    ], check=True)

    csr_file = os.path.join(cert_dir, f"{cert_name}.csr")
    csr_subject = (
        "/C=US/ST=California/L=San Francisco/O=Your Company Name/"
        f"CN={cert_name}.com"
    )
    subprocess.run([
        "openssl", "req", "-new", "-key", key_file, "-out", csr_file,
        "-subj", csr_subject
    ], check=True)

    crt_file = os.path.join(cert_dir, f"{cert_name}.crt")
    subprocess.run([
        "openssl", "x509", "-req", "-in", csr_file, "-signkey", key_file, "-out", crt_file, "-days", str(validity_days)
    ], check=True)

    print(f"Certificate generated successfully: {crt_file}")
    print(f"Private Key: {key_file}")
    print(f"Certificate Signing Request: {csr_file}")

def backhaul_iran_server_wssmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Port forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service()
    enable_backhaul_reset_server()

def backhaul_kharej_client_wssmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service()
    enable_backhaul_reset_client()


def backhaul_iran_server_wsmuxmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Port forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service()
    enable_backhaul_reset_server()

def backhaul_kharej_client_wsmuxmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service()
    enable_backhaul_reset_client()

def backhaul_iran_server_wssmuxmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Port forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service()
    enable_backhaul_reset_server()

def backhaul_kharej_client_wssmuxmenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service()
    enable_backhaul_reset_client()

def backhaul_uninstall():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Uninstall Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mSingle\033[0m")
    print("2  \033[92mMulti\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_uninstall_single()
            
    elif choice == "2":
        backhaul_uninstall_multi()
            
    elif choice == "0":
        backhaul_menu()
            
    else:
        print("Invalid choice.")

BACKHAUL_SERVER_SERVICE1 = "backhaul-server1"
BACKHAUL_SERVER_SERVICE2 = "backhaul-server2"
BACKHAUL_SERVER_SERVICE3 = "backhaul-server3"
BACKHAUL_SERVER_SERVICE4 = "backhaul-server4"
BACKHAUL_SERVER_SERVICE5 = "backhaul-server5"
BACKHAUL_SERVER_SERVICE6 = "backhaul-server6"
BACKHAUL_SERVER_SERVICE7 = "backhaul-server7"
BACKHAUL_SERVER_SERVICE8 = "backhaul-server8"
BACKHAUL_SERVER_SERVICE9 = "backhaul-server9"
BACKHAUL_SERVER_SERVICE10 = "backhaul-server10"
BACKHAUL_CLIENT_SERVICE1 = "backhaul-client1"
BACKHAUL_CLIENT_SERVICE2 = "backhaul-client2"
BACKHAUL_CLIENT_SERVICE3 = "backhaul-client3"
BACKHAUL_CLIENT_SERVICE4 = "backhaul-client4"
BACKHAUL_CLIENT_SERVICE5 = "backhaul-client5"
BACKHAUL_CLIENT_SERVICE6 = "backhaul-client6"
BACKHAUL_CLIENT_SERVICE7 = "backhaul-client7"
BACKHAUL_CLIENT_SERVICE8 = "backhaul-client8"
BACKHAUL_CLIENT_SERVICE9 = "backhaul-client9"
BACKHAUL_CLIENT_SERVICE10 = "backhaul-client10"
SERVER_TOML1 = "/usr/local/bin/backhaul/server1.toml"
SERVER_TOML2 = "/usr/local/bin/backhaul/server2.toml"
SERVER_TOML3 = "/usr/local/bin/backhaul/server3.toml"
SERVER_TOML4 = "/usr/local/bin/backhaul/server4.toml"
SERVER_TOML5 = "/usr/local/bin/backhaul/server5.toml"
SERVER_TOML6 = "/usr/local/bin/backhaul/server6.toml"
SERVER_TOML7 = "/usr/local/bin/backhaul/server7.toml"
SERVER_TOML8 = "/usr/local/bin/backhaul/server8.toml"
SERVER_TOML9 = "/usr/local/bin/backhaul/server9.toml"
SERVER_TOML10 = "/usr/local/bin/backhaul/server10.toml"
CLIENT_TOML1 = "/usr/local/bin/backhaul/client1.toml"
CLIENT_TOML2 = "/usr/local/bin/backhaul/client2.toml"
CLIENT_TOML3 = "/usr/local/bin/backhaul/client3.toml"
CLIENT_TOML4 = "/usr/local/bin/backhaul/client4.toml"
CLIENT_TOML5 = "/usr/local/bin/backhaul/client5.toml"
CLIENT_TOML6 = "/usr/local/bin/backhaul/client6.toml"
CLIENT_TOML7 = "/usr/local/bin/backhaul/client7.toml"
CLIENT_TOML8 = "/usr/local/bin/backhaul/client8.toml"
CLIENT_TOML9 = "/usr/local/bin/backhaul/client9.toml"
CLIENT_TOML10 = "/usr/local/bin/backhaul/client10.toml"
BACKHAUL_RESET_SCRIPT1 = "/etc/backhaul_reset1.sh"
BACKHAUL_RESET_SCRIPT2 = "/etc/backhaul_reset2.sh"
BACKHAUL_RESET_SCRIPT3 = "/etc/backhaul_reset3.sh"
BACKHAUL_RESET_SCRIPT4 = "/etc/backhaul_reset4.sh"
BACKHAUL_RESET_SCRIPT5 = "/etc/backhaul_reset5.sh"
BACKHAUL_RESET_SCRIPT6 = "/etc/backhaul_reset6.sh"
BACKHAUL_RESET_SCRIPT7 = "/etc/backhaul_reset7.sh"
BACKHAUL_RESET_SCRIPT8 = "/etc/backhaul_reset8.sh"
BACKHAUL_RESET_SCRIPT9 = "/etc/backhaul_reset9.sh"
BACKHAUL_RESET_SCRIPT10 = "/etc/backhaul_reset10.sh"
BACKHAUL_SERVER_JSON1 = "/etc/backhaul_server1.json"
BACKHAUL_SERVER_JSON2 = "/etc/backhaul_server2.json"
BACKHAUL_SERVER_JSON3 = "/etc/backhaul_server3.json"
BACKHAUL_SERVER_JSON4 = "/etc/backhaul_server4.json"
BACKHAUL_SERVER_JSON5 = "/etc/backhaul_server5.json"
BACKHAUL_SERVER_JSON6 = "/etc/backhaul_server6.json"
BACKHAUL_SERVER_JSON7 = "/etc/backhaul_server7.json"
BACKHAUL_SERVER_JSON8 = "/etc/backhaul_server8.json"
BACKHAUL_SERVER_JSON9 = "/etc/backhaul_server9.json"
BACKHAUL_SERVER_JSON10 = "/etc/backhaul_server10.json"
BACKHAUL_CLIENT_JSON1 = "/etc/backhaul_client1.json"
BACKHAUL_CLIENT_JSON2 = "/etc/backhaul_client2.json"
BACKHAUL_CLIENT_JSON3 = "/etc/backhaul_client3.json"
BACKHAUL_CLIENT_JSON4 = "/etc/backhaul_client4.json"
BACKHAUL_CLIENT_JSON5 = "/etc/backhaul_client5.json"
BACKHAUL_CLIENT_JSON6 = "/etc/backhaul_client6.json"
BACKHAUL_CLIENT_JSON7 = "/etc/backhaul_client7.json"
BACKHAUL_CLIENT_JSON8 = "/etc/backhaul_client8.json"
BACKHAUL_CLIENT_JSON9 = "/etc/backhaul_client9.json"
BACKHAUL_CLIENT_JSON10 = "/etc/backhaul_client10.json"
BACKHAUL_DIR = "/etc/blackhaul"
BACKHAUL_INSTALL_DIR = "/usr/local/bin/backhaul"

def backhaul_uninstall_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Uninstall Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93m[1]IRAN [10]Kharej\033[0m")
    print("2  \033[92m[10]IRAN [1]Kharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_uninstall_multi2()
            
    elif choice == "2":
        backhaul_uninstall_multi3()
            
    elif choice == "0":
        backhaul_uninstall()
            
    else:
        print("Invalid choice.")

def backhaul_uninstall_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Uninstall Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server Configs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_uninstall_multi_iran()
            
    elif choice == "2":
        backhaul_uninstall_multi_kharej()
            
    elif choice == "0":
        backhaul_uninstall_multi()
            
    else:
        print("Invalid choice.")

def backhaul_uninstall_multi3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Uninstall Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers\033[0m")
    print("2  \033[92mKharej Client Configs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_uninstall_multi_iran2()
            
    elif choice == "2":
        backhaul_uninstall_multi_kharej2()
            
    elif choice == "0":
        backhaul_uninstall_multi()
            
    else:
        print("Invalid choice.")

def backhaul_uninstall_multi_iran():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Uninstall \033[97mIRAN\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Config [1]\033[0m")
    print("2  \033[93mIRAN Config [2]\033[0m")
    print("3  \033[92mIRAN Config [3]\033[0m")
    print("4  \033[93mIRAN Config [4]\033[0m")
    print("5  \033[93mIRAN Config [5]\033[0m")
    print("6  \033[92mIRAN Config [6]\033[0m")
    print("7  \033[93mIRAN Config [7]\033[0m")
    print("8  \033[93mIRAN Config [8]\033[0m")
    print("9  \033[92mIRAN Config [9]\033[0m")
    print("10  \033[93mIRAN Config [10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11  \033[97mAll of them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_uninstall_multi_iran1()
            
    elif choice == "2":
        backhaul_uninstall_multi_iran2()
            
    elif choice == "3":
        backhaul_uninstall_multi_iran3()
            
    elif choice == "4":
        backhaul_uninstall_multi_iran4()
            
    elif choice == "5":
        backhaul_uninstall_multi_iran5()
            
    elif choice == "6":
        backhaul_uninstall_multi_iran6()
            
    elif choice == "7":
        backhaul_uninstall_multi_iran7()
            
    elif choice == "8":
        backhaul_uninstall_multi_iran8()
            
    elif choice == "9":
        backhaul_uninstall_multi_iran9()
            
    elif choice == "10":
        backhaul_uninstall_multi_iran10()
            
    elif choice == "11":
        backhaul_uninstall_multiple_iran()
            
    elif choice == "0":
        backhaul_uninstall_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_uninstall_multi_kharej():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Uninstall \033[97mKharej \033[93mMenu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej Client [1]\033[0m")
    print("2  \033[93mKharej Client [2]\033[0m")
    print("3  \033[92mKharej Client [3]\033[0m")
    print("4  \033[93mKharej Client [4]\033[0m")
    print("5  \033[93mKharej Client [5]\033[0m")
    print("6  \033[92mKharej Client [6]\033[0m")
    print("7  \033[93mKharej Client [7]\033[0m")
    print("8  \033[93mKharej Client [8]\033[0m")
    print("9  \033[92mKharej Client [9]\033[0m")
    print("10  \033[93mKharej Client [10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11  \033[97mAll of them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_uninstall_multi_kharej1()
            
    elif choice == "2":
        backhaul_uninstall_multi_kharej2()
            
    elif choice == "3":
        backhaul_uninstall_multi_kharej3()
            
    elif choice == "4":
        backhaul_uninstall_multi_kharej4()
            
    elif choice == "5":
        backhaul_uninstall_multi_kharej5()
            
    elif choice == "6":
        backhaul_uninstall_multi_kharej6()
            
    elif choice == "7":
        backhaul_uninstall_multi_kharej7()
            
    elif choice == "8":
        backhaul_uninstall_multi_kharej8()
            
    elif choice == "9":
        backhaul_uninstall_multi_kharej9()
            
    elif choice == "10":
        backhaul_uninstall_multi_kharej10()
            
    elif choice == "11":
        backhaul_uninstall_multiple_kharej()
            
    elif choice == "0":
        backhaul_uninstall_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_uninstall_multi_iran2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Uninstall \033[97mIRAN\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server [1]\033[0m")
    print("2  \033[93mIRAN Server [2]\033[0m")
    print("3  \033[92mIRAN Server [3]\033[0m")
    print("4  \033[93mIRAN Server [4]\033[0m")
    print("5  \033[93mIRAN Server [5]\033[0m")
    print("6  \033[92mIRAN Server [6]\033[0m")
    print("7  \033[93mIRAN Server [7]\033[0m")
    print("8  \033[93mIRAN Server [8]\033[0m")
    print("9  \033[92mIRAN Server [9]\033[0m")
    print("10  \033[93mIRAN Server [10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11  \033[97mAll of them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_uninstall_multi_iran1()
            
    elif choice == "2":
        backhaul_uninstall_multi_iran2()
            
    elif choice == "3":
        backhaul_uninstall_multi_iran3()
            
    elif choice == "4":
        backhaul_uninstall_multi_iran4()
            
    elif choice == "5":
        backhaul_uninstall_multi_iran5()
            
    elif choice == "6":
        backhaul_uninstall_multi_iran6()
            
    elif choice == "7":
        backhaul_uninstall_multi_iran7()
            
    elif choice == "8":
        backhaul_uninstall_multi_iran8()
            
    elif choice == "9":
        backhaul_uninstall_multi_iran9()
            
    elif choice == "10":
        backhaul_uninstall_multi_iran10()
            
    elif choice == "11":
        backhaul_uninstall_multiple_iran()
            
    elif choice == "0":
        backhaul_uninstall_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_uninstall_multi_kharej2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Uninstall \033[97mKharej \033[93mMenu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej Config [1]\033[0m")
    print("2  \033[93mKharej Config [2]\033[0m")
    print("3  \033[92mKharej Config [3]\033[0m")
    print("4  \033[93mKharej Config [4]\033[0m")
    print("5  \033[93mKharej Config [5]\033[0m")
    print("6  \033[92mKharej Config [6]\033[0m")
    print("7  \033[93mKharej Config [7]\033[0m")
    print("8  \033[93mKharej Config [8]\033[0m")
    print("9  \033[92mKharej Config [9]\033[0m")
    print("10  \033[93mKharej Config [10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11  \033[97mAll of them\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_uninstall_multi_kharej1()
            
    elif choice == "2":
        backhaul_uninstall_multi_kharej2()
            
    elif choice == "3":
        backhaul_uninstall_multi_kharej3()
            
    elif choice == "4":
        backhaul_uninstall_multi_kharej4()
            
    elif choice == "5":
        backhaul_uninstall_multi_kharej5()
            
    elif choice == "6":
        backhaul_uninstall_multi_kharej6()
            
    elif choice == "7":
        backhaul_uninstall_multi_kharej7()
            
    elif choice == "8":
        backhaul_uninstall_multi_kharej8()
            
    elif choice == "9":
        backhaul_uninstall_multi_kharej9()
            
    elif choice == "10":
        backhaul_uninstall_multi_kharej10()
            
    elif choice == "11":
        backhaul_uninstall_multiple_kharej()
            
    elif choice == "0":
        backhaul_uninstall_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_uninstall_multi_iran1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran [1]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE1)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_SERVER_JSON1, "file")
    delete_dir(SERVER_TOML1, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT1, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

def backhaul_uninstall_multi_iran2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran [2]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE2)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_SERVER_JSON2, "file")
    delete_dir(SERVER_TOML2, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT2, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

def backhaul_uninstall_multi_iran3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran [3]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE3)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_SERVER_JSON3, "file")
    delete_dir(SERVER_TOML3, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT3, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

def backhaul_uninstall_multi_iran4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran [4]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE4)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_SERVER_JSON4, "file")
    delete_dir(SERVER_TOML4, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT4, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

def backhaul_uninstall_multi_iran5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran [5]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE5)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_SERVER_JSON5, "file")
    delete_dir(SERVER_TOML5, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT5, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

def backhaul_uninstall_multi_iran6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran [6]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE6)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_SERVER_JSON6, "file")
    delete_dir(SERVER_TOML6, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT6, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

def backhaul_uninstall_multi_iran7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran [7]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE7)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_SERVER_JSON7, "file")
    delete_dir(SERVER_TOML7, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT7, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

def backhaul_uninstall_multi_iran8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran [8]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE8)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_SERVER_JSON8, "file")
    delete_dir(SERVER_TOML8, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT8, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

def backhaul_uninstall_multi_iran9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran [9]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE9)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_SERVER_JSON9, "file")
    delete_dir(SERVER_TOML9, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT9, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

def backhaul_uninstall_multi_iran10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran [10]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE10)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_SERVER_JSON10, "file")
    delete_dir(SERVER_TOML10, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT10, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

BACKHAUL_SERVER_SERVICE_B = "backhaul-server{}"
BACKHAUL_CLIENT_SERVICE_B = "backhaul-client{}"
SERVER_TOML_B = "/usr/local/bin/backhaul/server{}.toml"
CLIENT_TOML_B = "/usr/local/bin/backhaul/client{}.toml"
BACKHAUL_JSON_B = "/etc/backhaul_server{}.json"
BACKHAUL_JSON_BB = "/etc/backhaul_client{}.json"
BACKHAUL_RESET_SCRIPT_B = "/etc/backhaul_reset{}.sh"
BACKHAUL_DAEMON_SCRIPT_B = "/usr/local/bin/backhaul_daemon{}.sh"
SYSTEMD_SERVICE_B = "/etc/systemd/system/backhaul-server{}.service"
CLIENT_SYSTEMD_SERVICE_B = "/etc/systemd/system/backhaul-client{}.service"
BACKHAUL_INSTALL_DIR = "/usr/local/bin/backhaul"


def delete_related_files(index, service_type):
    if service_type == "server":
        delete_dir(SYSTEMD_SERVICE_B.format(index), "file")
        delete_dir(SERVER_TOML_B.format(index), "file")
        delete_dir(BACKHAUL_JSON_B.format(index), "file")
        delete_dir(BACKHAUL_RESET_SCRIPT_B.format(index), "file")
        delete_dir(BACKHAUL_DAEMON_SCRIPT_B.format(index), "file")
    elif service_type == "client":
        delete_dir(CLIENT_SYSTEMD_SERVICE_B.format(index), "file")
        delete_dir(CLIENT_TOML_B.format(index), "file")
        delete_dir(BACKHAUL_JSON_BB.format(index), "file")
        delete_dir(BACKHAUL_RESET_SCRIPT_B.format(index), "file")
        delete_dir(BACKHAUL_DAEMON_SCRIPT_B.format(index), "file")

def backhaul_uninstall_multiple_iran():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Multiple Iran Servers\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')

    for i in range(1, 11):
        print(f"\033[93mUninstalling Iran Server {i}...\033[0m")
        uninstall_service(BACKHAUL_SERVER_SERVICE_B.format(i))
        delete_related_files(i, "server")
    
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of all Iran Servers complete.\033[0m")

def backhaul_uninstall_multiple_kharej():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Multiple Kharej Clients\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')

    for i in range(1, 11):
        print(f"\033[93mUninstalling Kharej Client {i}...\033[0m")
        uninstall_service(BACKHAUL_CLIENT_SERVICE_B.format(i))
        delete_related_files(i, "client")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Kharej Client uninstallation")
    display_checkmark("\n\033[92mUninstallation of all Kharej Clients complete.\033[0m")


def backhaul_uninstall_multi_kharej1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej [1]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej ...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE1)
    display_notification("\033[93mRemoving configuration files for Kharej ...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_CLIENT_JSON1, "file")
    delete_dir(CLIENT_TOML1, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT1, "file")
    rmv_backhauldirectory()
    reloaddaemon()

    loadbar("Finishing Kharej uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej complete.\033[0m")

def backhaul_uninstall_multi_kharej2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej [2]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE2)
    display_notification("\033[93mRemoving configuration files for Kharej...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_CLIENT_JSON2, "file")
    delete_dir(CLIENT_TOML2, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT2, "file")
    rmv_backhauldirectory()
    reloaddaemon()

    loadbar("Finishing Kharej uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej complete.\033[0m")

def backhaul_uninstall_multi_kharej3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej [3]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE3)
    display_notification("\033[93mRemoving configuration files for Kharej...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_CLIENT_JSON3, "file")
    delete_dir(CLIENT_TOML3, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT3, "file")
    rmv_backhauldirectory()
    reloaddaemon()

    loadbar("Finishing Kharej uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej complete.\033[0m")

def backhaul_uninstall_multi_kharej4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej [4]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE4)
    display_notification("\033[93mRemoving configuration files for Kharej...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_CLIENT_JSON4, "file")
    delete_dir(CLIENT_TOML4, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT4, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Kharej uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej complete.\033[0m")

def backhaul_uninstall_multi_kharej5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej [5]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE5)
    display_notification("\033[93mRemoving configuration files for Kharej...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_CLIENT_JSON5, "file")
    delete_dir(CLIENT_TOML5, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT5, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Kharej uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej complete.\033[0m")

def backhaul_uninstall_multi_kharej6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej [6]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE6)
    display_notification("\033[93mRemoving configuration files for Kharej...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_CLIENT_JSON6, "file")
    delete_dir(CLIENT_TOML6, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT6, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Kharej uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej complete.\033[0m")

def backhaul_uninstall_multi_kharej7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej [7]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE7)
    display_notification("\033[93mRemoving configuration files for Kharej...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_CLIENT_JSON7, "file")
    delete_dir(CLIENT_TOML7, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT7, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Kharej uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej complete.\033[0m")

def backhaul_uninstall_multi_kharej8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej [8]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE8)
    display_notification("\033[93mRemoving configuration files for Kharej...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_CLIENT_JSON8, "file")
    delete_dir(CLIENT_TOML8, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT8, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Kharej uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej complete.\033[0m")

def backhaul_uninstall_multi_kharej9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej [9]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE9)
    display_notification("\033[93mRemoving configuration files for Kharej...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_CLIENT_JSON9, "file")
    delete_dir(CLIENT_TOML9, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT9, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Kharej uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej complete.\033[0m")

def backhaul_uninstall_multi_kharej10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej [10]\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE10)
    display_notification("\033[93mRemoving configuration files for Kharej...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_CLIENT_JSON10, "file")
    delete_dir(CLIENT_TOML10, "file")
    delete_dir(BACKHAUL_RESET_SCRIPT10, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Kharej uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej complete.\033[0m")

def backhaul_uninstall_single():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Uninstall Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_uninstall_single_iran()
            
    elif choice == "2":
        backhaul_uninstall_single_kharej()
            
    elif choice == "0":
        backhaul_uninstall()
            
    else:
        print("Invalid choice.")

BACKHAUL_SERVER_SERVICE = "backhaul-server"
BACKHAUL_CLIENT_SERVICE = "backhaul-client"
SERVER_TOML = "/usr/local/bin/backhaul/server.toml"
CLIENT_TOML = "/usr/local/bin/backhaul/client.toml"
BACKHAUL_JSON = "/etc/backhaul.json"
BACKHAUL_DIR = "/etc/blackhaul"
BACKHAUL_INSTALL_DIR = "/usr/local/bin/backhaul"

def backhaul_uninstall_single_iran():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Iran Server\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Iran Server...\033[0m")
    uninstall_service(BACKHAUL_SERVER_SERVICE)
    display_notification("\033[93mRemoving configuration files for Iran Server...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_JSON, "file")
    delete_dir(SERVER_TOML, "file")
    rmv_backhauldirectory()
    reloaddaemon()
    loadbar("Finishing Iran Server uninstallation")
    display_checkmark("\n\033[92mUninstallation of Iran Server complete.\033[0m")

def display_notification(message):
    print("\u2728 " + message)

def backhaul_uninstall_single_kharej():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mUninstalling Kharej Client\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93mUninstalling Kharej Client...\033[0m")
    uninstall_service(BACKHAUL_CLIENT_SERVICE)
    display_notification("\033[93mRemoving configuration files for Kharej Client...\033[0m")
    delete_dir(BACKHAUL_DIR, "directory")
    delete_dir(BACKHAUL_JSON, "file")
    delete_dir(CLIENT_TOML, "file")
    rmv_backhauldirectory()
    reloaddaemon()

    loadbar("Finishing Kharej Client uninstallation")
    display_checkmark("\n\033[92mUninstallation of Kharej Client complete.\033[0m")

def uninstall_service(service_name):
    subprocess.run(["systemctl", "stop", service_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    subprocess.run(["systemctl", "disable", service_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    service_file = f"/etc/systemd/system/{service_name}.service"
    if os.path.exists(service_file):
        os.remove(service_file)

def delete_dir(path, type_of_path):
    if os.path.exists(path):
        try:
            if type_of_path == "directory":
                shutil.rmtree(path)  
            elif type_of_path == "file":
                os.remove(path) 
        except OSError as e:
            print(f"\033[91mError: {e}\033[0m")

def rmv_backhauldirectory():
    print("\033[93mWould you like to delete the \033[92mBackhaul project\033[93m directory? (\033[92myes\033[93m/\033[91mno\033[93m) :\033[0m ", end="")
    choice = input().strip().lower()
    if choice in ["yes", "y"]:
        delete_dir(BACKHAUL_INSTALL_DIR, "directory")

def reloaddaemon():
    print("\n\033[93mReloading systemd daemon...\033[0m")
    subprocess.run(["systemctl", "daemon-reload"])

def loadbar(action, length=20):
    print(f"\n\033[93m{action}...\033[0m", end="")
    for i in range(length):
        time.sleep(0.1)  
        print("\033[92m█\033[0m", end="", flush=True)
    print()  

def backhaul_editlocal():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mSingle\033[0m")
    print("2  \033[92mMulti\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_edit_single()
            
    elif choice == "2":
        backhaul_edit_multi()
            
    elif choice == "0":
        backhaul_menu()
            
    else:
        print("Invalid choice.")

def backhaul_edit_single():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Single\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mEdit TCP\033[0m")
    print("2  \033[92mEdit TCPMux\033[0m")
    print("3  \033[93mEdit WS\033[0m")
    print("4  \033[92mEdit WSMux\033[0m")
    print("5  \033[93mEdit WSs\033[0m")
    print("6  \033[92mEdit WSsMux\033[0m")
    print("7  \033[93mEdit UDP\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_edit_tcpsingle()
            
    elif choice == "2":
        backhaul_edit_tcpmuxsingle()
            
    elif choice == "3":
        backhaul_edit_wssingle()
            
    elif choice == "4":
        backhaul_edit_wsmuxsingle()
            
    elif choice == "5":
        backhaul_edit_wsssingle()
            
    elif choice == "6":
        backhaul_edit_wssmuxsingle()

    elif choice == "7":
        backhaul_edit_udpsingle()
            
    elif choice == "0":
        clear()
        backhaul_editlocal()
            
    else:
        print("Invalid choice.")

def backhaul_edit_udpsingle():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Single UDP\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server()
        configws_single_server_menu(lines)
            
    elif choice == "2":
        lines = read_config_client()
        configws_single_client_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_single()
            
    else:
        print("Invalid choice.")

def backhaul_edit_tcpsingle():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Single TCP\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server()
        configws_single_server_menu(lines)
            
    elif choice == "2":
        lines = read_config_client()
        configws_single_client_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_single()
            
    else:
        print("Invalid choice.")

def backhaul_edit_tcpmuxsingle():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Single TCPMux\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server()
        configwssmux_single_server_menu(lines)
            
    elif choice == "2":
        lines = read_config_client()
        configwssmux_single_client_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_single()
            
    else:
        print("Invalid choice.")

            
def backhaul_edit_wssingle():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Single WS\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server()
        configws_single_server_menu(lines)
            
    elif choice == "2":
        lines = read_config_client()
        configws_single_client_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_single()
            
    else:
        print("Invalid choice.")

def backhaul_edit_wsmuxsingle():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Single WSMux\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server()
        configwssmux_single_server_menu(lines)
        
    elif choice == "2":
        lines = read_config_client()
        configwssmux_single_client_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_single()
            
    else:
        print("Invalid choice.")

def backhaul_edit_wsssingle():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Single WSs\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server()
        configwss_single_server_menu(lines)
            
    elif choice == "2":
        lines = read_config_client()
        configwss_single_client_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_single()
            
    else:
        print("Invalid choice.")

def backhaul_edit_wssmuxsingle():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Single WSsMux\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server()
        configwssmux_single_server_menu(lines)
            
    elif choice == "2":
        lines = read_config_client()
        configwssmux_single_client_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_single()
            
    else:
        print("Invalid choice.")
CONFIG_SERVER = "/usr/local/bin/backhaul/server.toml"
SERVICE_SERVER = "backhaul-server"
CONFIG_CLIENT = "/usr/local/bin/backhaul/client.toml"
SERVICE_CLIENT = "backhaul-client"

def edit_value(lines, key, new_value):
    for i, line in enumerate(lines):
        if line.startswith(key):
            lines[i] = f'{key} = "{new_value}"\n'
    return lines

def read_config_server():
    with open(CONFIG_SERVER, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server(lines):
    with open(CONFIG_SERVER, 'w') as file:
        file.writelines(lines)

def restart_service_server():
    os.system(f"systemctl restart {SERVICE_SERVER}")

def display_server(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def bind_addr(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def toggle_falsetrue(lines, key):
    for i, line in enumerate(lines):
        if line.startswith(key):
            current_value = line.split("=")[-1].strip().lower()
            if current_value == "true":
                lines[i] = f'{key} = false\n'
            else:
                lines[i] = f'{key} = true\n'
    return lines

def edit_numeric(lines, key, new_value):
    for i, line in enumerate(lines):
        if line.startswith(key):
            lines[i] = f'{key} = {new_value}\n'
    return lines


def edit_ports(lines):
    ports_section = False
    ports_index_start = -1
    ports_index_end = -1
    ports = []

    for i, line in enumerate(lines):
        if line.startswith("ports = ["):
            ports_section = True
            ports_index_start = i
        if ports_section and line.strip() == "]":
            ports_index_end = i
            break

    if ports_index_start != -1 and ports_index_end != -1:
        ports = lines[ports_index_start + 1:ports_index_end]

    print("\033[93m───────────────────────────────────────\033[0m")
    print("\033[92mCurrent Ports Configuration:\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    for i, port in enumerate(ports):
        print(f"{i + 1}) {port.strip()}")

    choice = input("\n\033[93mEnter the \033[92mnumber \033[93mto edit \033[97mor 'add' \033[92m to add a new port\033[97m:\033[0m ").strip().lower()

    if choice == 'add':
        add_choice = input("\033[93m (1)\033[92m regular port \033[93m (2)\033[94m port range? \033[0m").strip()

        if add_choice == '1':
            print("\033[93m╭───────────────────────────────────────╮\033[0m")
            print("1) \033[93mlocal_port=remote_port \033[97m(example: 4000=5000)")
            print("2) \033[93mlocal_ip:local_port=remote_port \033[97m(example: 127.0.0.2:443=5201)")
            print("3) \033[93mlocal_port=remote_ip:remote_port \033[97m(example: 443=1.1.1.1:5201)")
            print("4) \033[93mlocal_ip:local_port=remote_ip:remote_port \033[97m(example: 127.0.0.2:443=1.1.1.1:5201)")
            print("\033[93m╰───────────────────────────────────────╯\033[0m")

            regular_format_choice = input("Enter choice: \033[0m").strip()

            if regular_format_choice == '1':
                local_port = input("\033[93mEnter local port: \033[0m").strip()
                remote_port = input("\033[93mEnter remote port: \033[0m").strip()
                new_port = f'{local_port}={remote_port}'
            elif regular_format_choice == '2':
                local_ip = input("\033[93mEnter local IP: \033[0m").strip()
                local_port = input("\033[93mEnter local port: \033[0m").strip()
                remote_port = input("\033[93mEnter remote port: \033[0m").strip()
                new_port = f'{local_ip}:{local_port}={remote_port}'
            elif regular_format_choice == '3':
                local_port = input("\033[93mEnter local port: \033[0m").strip()
                remote_ip = input("\033[93mEnter remote IP: \033[0m").strip()
                remote_port = input("\033[93mEnter remote port: \033[0m").strip()
                new_port = f'{local_port}={remote_ip}:{remote_port}'
            elif regular_format_choice == '4':
                local_ip = input("\033[93mEnter local IP: \033[0m").strip()
                local_port = input("\033[93mEnter local port: \033[0m").strip()
                remote_ip = input("\033[93mEnter remote IP: \033[0m").strip()
                remote_port = input("\033[93mEnter remote port: \033[0m").strip()
                new_port = f'{local_ip}:{local_port}={remote_ip}:{remote_port}'
            else:
                print("\033[91mInvalid choice!\033[0m")
                return lines

        elif add_choice == '2':
            print("\033[93m╭───────────────────────────────────────╮\033[0m")
            print("1)\033[93m port-range \033[97m(example: 443-600)")
            print("2)\033[93m port-range:remote-port \033[97m(example: 443-600:5201)")
            print("3)\033[93m port-range=remote_ip:remote-port \033[97m(example: 443-600=1.1.1.1:5201)")
            print("\033[93m╰───────────────────────────────────────╯\033[0m")
            
            range_format_choice = input("Enter choice: \033[0m").strip()

            if range_format_choice == '1':
                port_range = input("\033[93mEnter \033[92mport range \033[93m(e.g., 500-600): \033[0m").strip()
                new_port = f'{port_range}'
            elif range_format_choice == '2':
                port_range = input("\033[93mEnter \033[92mport range \033[93m(e.g., 500-600): \033[0m").strip()
                forward_port = input("\033[93mEnter \033[92mremote port\033[93m: \033[0m").strip()
                new_port = f'{port_range}:{forward_port}'
            elif range_format_choice == '3':
                port_range = input("\033[93mEnter \033[92mport range\033[93m (e.g., 500-600): \033[0m").strip()
                remote_ip = input("\033[93mEnter \033[92mremote IP: \033[0m").strip()
                forward_port = input("\033[93mEnter \033[92mremote port: \033[0m").strip()
                new_port = f'{port_range}={remote_ip}:{forward_port}'
            else:
                print("\033[91mInvalid choice!\033[0m")
                return lines

        else:
            print("\033[91mWrong choice, choose 1 or 2.\033[0m")
            return lines

        ports.append(f'    "{new_port}",\n')

    else:
        index = int(choice) - 1
        current_port = ports[index].strip()

        if '-' in current_port or ':' in current_port:
            new_port = input(f"\033[93mEdit port range \033[96m{current_port}\033[97m (press Enter to keep unchanged)\033[93m: \033[0m")
        else:
            new_port = input(f"\033[93mEdit regular port \033[96m{current_port}\033[97m (press Enter to keep unchanged)\033[93m: \033[0m")

        if new_port:
            ports[index] = f'    "{new_port}",\n'

    lines = lines[:ports_index_start + 1] + ports + lines[ports_index_end:]

    return lines



def true_value(lines, key):
    for line in lines:
        if line.startswith(key):
            return line.split("=")[-1].strip().replace('"', '')
    return None

def toggle_option(lines, key):
    current_val = true_value(lines, key)
    print("\033[93m───────────────────────────────────────\033[0m")
    print(f"\033[93mCurrent \033[92m{key}\033[93m:\033[97m {current_val}\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose a new value:\033[0m")
    print("1)\033[92m true\033[0m")
    print("2)\033[91m false\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("Enter your choice: ").strip()
    
    if choice == "1":
        new_value = "true"
    elif choice == "2":
        new_value = "false"
    else:
        print("\033[91mWrong choice!\033[0m")
        return lines
    
    for i, line in enumerate(lines):
        if line.startswith(key):
            lines[i] = f'{key} = {new_value}\n'
            break
    
    return lines


def read_config_client():
    with open(CONFIG_CLIENT, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client(lines):
    with open(CONFIG_CLIENT, 'w') as file:
        file.writelines(lines)

def restart_service_client():
    os.system(f"systemctl restart {SERVICE_CLIENT}")

def display_client(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")


def remote_addr(lines):
    for i, line in enumerate(lines):
        if line.startswith("remote_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')

            match = re.match(r'^\[?(.*?)\]?:([0-9]+)$', current_value)
            if not match:
                raise ValueError("Invalid remote_addr format")

            ip, current_port = match.groups()

            new_ip = input(f"\033[93mEnter new Iran Server IP \033[97m(current: {ip})\033[93m: \033[0m").strip() or ip
            new_port = input(f"\033[93mEnter new Iran Server port \033[97m(current: {current_port})\033[93m: \033[0m").strip() or current_port

            if ":" in new_ip and not new_ip.startswith("["):
                new_ip = f"[{new_ip}]"
            elif "." in new_ip and new_ip.startswith("["):
                new_ip = new_ip.strip("[]") 

            lines[i] = f'remote_addr = "{new_ip}:{new_port}"\n'
            break
    return lines


def configwss_single_server_menu(lines):
    while True:
        display_server(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port\033[0m (bind_addr) [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server(lines)
            restart_service_server()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
        elif choice == "10":
            backhaul_edit_single()
        else:
            print("\n\033[91mWrong choice, try again.")

def configwss_single_client_menu(lines):
    while True:
        display_client(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client(lines)
            restart_service_client()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_single()
        else:
            print("\n\033[91mWrong choice, try again.")


def configws_single_server_menu(lines):
    while True:
        display_server(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port\033[0m (bind_addr) [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server(lines)
            restart_service_server()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_single()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_single_client_menu(lines):
    while True:
        display_client(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client(lines)
            restart_service_client()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_single()
        else:
            print("\n\033[91mWrong choice, try again.")


def configwssmux_single_server_menu(lines):
    while True:
        display_server(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port\033[0m (bind_addr) [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server(lines)
            restart_service_server()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_single()
        else:
            print("\n\033[91mWrong choice, try again.")

def configwssmux_single_client_menu(lines):
    while True:
        display_client(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client(lines)
            restart_service_client()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_single()
        else:
            print("\n\033[91mWrong choice, try again.")

def current_value(lines, key):
    for line in lines:
        if line.startswith(key):
            return line.split("=")[-1].strip().replace('"', '')
    return None


SERVER_CONFIG = "/usr/local/bin/backhaul/server.toml"
CLIENT_CONFIG = "/usr/local/bin/backhaul/client.toml"
SERVER_SERVICE = "backhaul-server"
CLIENT_SERVICE = "backhaul-client"

def backhaul_status():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Status Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mSingle\033[0m")
    print("2  \033[92mMulti\033[0m")
    print("0. \033[94mback to the main script\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_single_status()
            
    elif choice == "2":
        backhaul_multi_status()
            
    elif choice == "0":
        clear()
        backhaul_menu()
            
    else:
        print("Invalid choice.")

def backhaul_single_status():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mBackhaul Status Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mYou are viewing the status of your Backhaul services:\033[0m")

    if os.path.exists(SERVER_CONFIG):
        print("\n\033[92mServer:\033[0m")
        service_status(SERVER_SERVICE)
        transport_server = transport_method(SERVER_CONFIG)
        print(f" \033[93mTunnel Method:\033[97m {transport_server} \033[0m")
        service_logs(SERVER_SERVICE)

    if os.path.exists(CLIENT_CONFIG):
        print("\n\033[92mClient:\033[0m")
        service_status(CLIENT_SERVICE)
        transport_client = transport_method(CLIENT_CONFIG)
        print(f" \033[93mTunnel Method:\033[97m {transport_client} \033[0m")
        service_logs(CLIENT_SERVICE)
    
    print("\n0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice: \033[0m")
    if choice == "0":
        backhaul_status()
    else:
        print("\n\033[91mInvalid choice, please try again.\033[0m")

SERVER_CONFIG_MULTI = "/usr/local/bin/backhaul/server{}.toml"
CLIENT_CONFIG_MULTI = "/usr/local/bin/backhaul/client{}.toml"
SERVER_SERVICE_MULTI = "backhaul-server{}"
CLIENT_SERVICE_MULTI = "backhaul-client{}"

def analyze_ports(directory_path, multi=False):
    ports = set()
    file_names = [f"server{i}.toml" for i in range(1, 11)] if multi else ["server.toml"]
    for file_name in file_names:
        file_path = os.path.join(directory_path, file_name)
        if os.path.exists(file_path):
            with open(file_path, 'r') as file:
                in_ports_section = False
                for line in file:
                    line = line.strip()
                    if line.startswith("ports"):
                        in_ports_section = True
                        continue
                    if in_ports_section and (line == "]" or not line):
                        in_ports_section = False
                        continue
                    if in_ports_section:
                        line = line.strip(', "')
                        if '=' in line:
                            src, dest = line.split('=')
                            ports.add(int(src))
                            ports.add(int(dest))
                        elif '-' in line:
                            start, end = map(int, line.split('-'))
                            ports.update(range(start, end + 1))
                        else:
                            ports.add(int(line))
    return sorted(ports)

def calculate_port(ports, interval=10):
    usage_data = {port: 0 for port in ports}
    port_filters = ' or '.join([f'port {port}' for port in ports])
    tcpdump_cmd = f"tcpdump -i any -n -q -tttt {port_filters}"
    process = subprocess.Popen(tcpdump_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
    start_time = time.time()
    try:
        while time.time() - start_time < interval:
            line = process.stdout.readline()
            if not line:
                break
            match = re.search(r'(\d+) bytes', line)
            if match:
                packet_size = int(match.group(1))
                for port in ports:
                    if f' {port} ' in line:
                        usage_data[port] += packet_size
                        break
    finally:
        process.terminate()
    for port in usage_data:
        usage_data[port] = round(usage_data[port] / (1024 ** 3), 4)
    return usage_data

def backhaul_singleport():
    directory_path = "/usr/local/bin/backhaul"
    ports = analyze_ports(directory_path, multi=False)
    usage = calculate_port(ports)
    print(f"\033[93mSingle Port Usage \033[92m(in GB)\033[93m:\033[97m{usage}\033[0m")
    input("Press Enter to return to the previous menu..")
    backhaul_monitor()

def backhaul_multiport():
    directory_path = "/usr/local/bin/backhaul"
    ports = analyze_ports(directory_path, multi=True)
    usage = calculate_port(ports)
    print(f"\033[93mMulti Port Usage\033[92m (in GB)\033[93m:\033[97m {usage}\033[0m")
    input("Press Enter to return to the previous menu..")
    backhaul_monitor()

def backhaul_monitor():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Port Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mSingle\033[0m")
    print("2  \033[92mMulti\033[0m")
    print("0. \033[94mback to the main script\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    
    if choice == "1":
        backhaul_singleport()
    elif choice == "2":
        backhaul_multiport()
    elif choice == "0":
        os.system("clear")
        backhaul_menu()  
    else:
        print("Wrong choice")
        time.sleep(1)
        backhaul_monitor()

def backhaul_multi_status():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Status Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93m[1]IRAN [10]Kharej\033[0m")
    print("2  \033[92m[10]IRAN [1]Kharej\033[0m")
    print("0. \033[94mback to the main script\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_multi_status2()
            
    elif choice == "2":
        backhaul_multi_status3()
            
    elif choice == "0":
        clear()
        backhaul_menu()
            
    else:
        print("Invalid choice.")

def backhaul_multi_status2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mBackhaul Status Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mYou are viewing the status of your Backhaul services:\033[0m")

    for i in range(1, 11):
        server_service_name = SERVER_SERVICE_MULTI.format(i)
        server_config_file = SERVER_CONFIG_MULTI.format(i)
        
        if os.path.exists(server_config_file):
            print(f"\n\033[92mServer\033[97m Config {i}:\033[0m")
            service_status(server_service_name)
            transport_server = transport_method(server_config_file)
            print(f" \033[93mTunnel Method:\033[97m {transport_server} \033[0m")
            service_logs(server_service_name)

    for i in range(1, 11):
        client_service_name = CLIENT_SERVICE_MULTI.format(i)
        client_config_file = CLIENT_CONFIG_MULTI.format(i)

        if os.path.exists(client_config_file):
            print(f"\n\033[92mClient {i}:\033[0m")
            service_status(client_service_name)
            transport_client = transport_method(client_config_file)
            print(f" \033[93mTunnel Method:\033[97m {transport_client} \033[0m")
            service_logs(client_service_name)

    print("\n0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice: \033[0m")
    if choice == "0":
        backhaul_multi_status()
    else:
        print("\n\033[91mInvalid choice, please try again.\033[0m")

def backhaul_multi_status3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mBackhaul Status Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mYou are viewing the status of your Backhaul services:\033[0m")

    for i in range(1, 11):
        server_service_name = SERVER_SERVICE_MULTI.format(i)
        server_config_file = SERVER_CONFIG_MULTI.format(i)
        
        if os.path.exists(server_config_file):
            print(f"\n\033[92mServer {i}:\033[0m")
            service_status(server_service_name)
            transport_server = transport_method(server_config_file)
            print(f" \033[93mTunnel Method:\033[97m {transport_server} \033[0m")
            service_logs(server_service_name)

    for i in range(1, 11):
        client_service_name = CLIENT_SERVICE_MULTI.format(i)
        client_config_file = CLIENT_CONFIG_MULTI.format(i)

        if os.path.exists(client_config_file):
            print(f"\n\033[92mClient\033[97m Config {i}:\033[0m")
            service_status(client_service_name)
            transport_client = transport_method(client_config_file)
            print(f" \033[93mTunnel Method:\033[97m {transport_client} \033[0m")
            service_logs(client_service_name)

    print("\n0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice: \033[0m")
    if choice == "0":
        backhaul_multi_status()
    else:
        print("\n\033[91mInvalid choice, please try again.\033[0m")

def service_status(service_name):
    output = subprocess.run(
        ["systemctl", "is-active", service_name], capture_output=True, text=True
    )
    status = output.stdout.strip()

    if status == "active":
        print(f" \033[93mStatus:\033[92m Online\033[0m | \033[93mService Name:\033[97m {service_name}\033[0m")
    else:
        print(f" \033[93mStatus:\033[91m Offline\033[0m | \033[93mService Name:\033[97m {service_name}\033[0m")

def transport_method(config_file):
    try:
        with open(config_file, "r") as file:
            for line in file:
                line = line.strip()

                if line.startswith("transport"):
                    transport = line.split("=")[-1].strip().replace('"', '')
                    return transport

    except FileNotFoundError:
        return "\033[91mFile not found\033[0m"
    
    return "\033[91mUnknown transport\033[0m"



def service_logs(service_name):
    print("\033[93mService Logs:\033[0m")
    output = subprocess.run(
        ["journalctl", "-u", service_name, "--no-pager", "-n", "5"],
        capture_output=True, text=True
    )
    logs = output.stdout.strip()
    if logs:
        print(f"\033[97m{logs}\033[0m")
    else:
        print("\033[91mNo entries\033[0m")

def backhaul_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93m[1] IRAN [10]Kharej\033[0m")
    print("2  \033[92m[10]IRAN [1] Kharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_multi2()
            
    elif choice == "2":
        backhaul_multi3()
            
    elif choice == "0":
        clear()
        backhaul_menu()
            
    else:
        print("Invalid choice.")

def backhaul_multi3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mTCP\033[0m")
    print("2  \033[92mTCP Mux\033[0m")
    print("3  \033[93mWs\033[0m")
    print("4  \033[92mWss\033[0m")
    print("5  \033[93mWs Mux\033[0m")
    print("6  \033[92mWss Mux\033[0m")
    print("7  \033[93mUDP\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_tcp_multi2()
            
    elif choice == "2":
        backhaul_tcpmux_multi2()
            
    elif choice == "3":
        backhaul_ws_multi2()
            
    elif choice == "4":
        backhaul_wss_multi2()
            
    elif choice == "5":
        backhaul_wsmux_multi2()
            
    elif choice == "6":
        backhaul_wssmux_multi2()

    elif choice == "7":
        backhaul_udp_multi2()
            
    elif choice == "0":
        clear()
        backhaul_multi()
            
    else:
        print("Invalid choice.")

def backhaul_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mTCP\033[0m")
    print("2  \033[92mTCP Mux\033[0m")
    print("3  \033[93mWs\033[0m")
    print("4  \033[92mWss\033[0m")
    print("5  \033[93mWs Mux\033[0m")
    print("6  \033[92mWss Mux\033[0m")
    print("7  \033[93mUDP\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_tcp_multi()
            
    elif choice == "2":
        backhaul_tcpmux_multi()
            
    elif choice == "3":
        backhaul_ws_multi()
            
    elif choice == "4":
        backhaul_wss_multi()
            
    elif choice == "5":
        backhaul_wsmux_multi()
            
    elif choice == "6":
        backhaul_wssmux_multi()

    elif choice == "7":
        backhaul_udp_multi()
            
    elif choice == "0":
        clear()
        backhaul_multi()
            
    else:
        print("Invalid choice.")

def backhaul_udp_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[93m multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server Configs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_udp_multimenu()
            
    elif choice == "2":
        backhaul_kharej_client_udp_multimenu()
            
    elif choice == "0":
        clear()
        backhaul_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_udp_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[93m multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers\033[0m")
    print("2  \033[92mKharej Client Configs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_udp_multimenu2()
            
    elif choice == "2":
        backhaul_kharej_client_udp_multimenu2()
            
    elif choice == "0":
        clear()
        backhaul_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_udp_multimenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[96m IRAN Server\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_udpmenu_multic1()
            
    elif choice == "2":
        backhaul_iran_server_udpmenu_multic2()
            
    elif choice == "3":
        backhaul_iran_server_udpmenu_multic3()
            
    elif choice == "4":
        backhaul_iran_server_udpmenu_multic4()
            
    elif choice == "5":
        backhaul_iran_server_udpmenu_multic5()
            
    elif choice == "6":
        backhaul_iran_server_udpmenu_multic6()
            
    elif choice == "7":
        backhaul_iran_server_udpmenu_multic7()
            
    elif choice == "8":
        backhaul_iran_server_udpmenu_multic8()
            
    elif choice == "9":
        backhaul_iran_server_udpmenu_multic9()
            
    elif choice == "10":
        backhaul_iran_server_udpmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_udp_multi()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_udp_multimenu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[96m Kharej Clients\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_kharej1_client_udpmenu_multi()
            
    elif choice == "2":
        backhaul_kharej2_client_udpmenu_multi()
            
    elif choice == "3":
        backhaul_kharej3_client_udpmenu_multi()
            
    elif choice == "4":
        backhaul_kharej4_client_udpmenu_multi()
            
    elif choice == "5":
        backhaul_kharej5_client_udpmenu_multi()
            
    elif choice == "6":
        backhaul_kharej6_client_udpmenu_multi()
            
    elif choice == "7":
        backhaul_kharej7_client_udpmenu_multi()
            
    elif choice == "8":
        backhaul_kharej8_client_udpmenu_multi()
            
    elif choice == "9":
        backhaul_kharej9_client_udpmenu_multi()
            
    elif choice == "10":
        backhaul_kharej10_client_udpmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_udp_multi()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_udp_multimenu2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[96m IRAN Server\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_iran_server_udpmenu_multic1()
            
    elif choice == "2":
        backhaul2_iran_server_udpmenu_multic2()
            
    elif choice == "3":
        backhaul2_iran_server_udpmenu_multic3()
            
    elif choice == "4":
        backhaul2_iran_server_udpmenu_multic4()
            
    elif choice == "5":
        backhaul2_iran_server_udpmenu_multic5()
            
    elif choice == "6":
        backhaul2_iran_server_udpmenu_multic6()
            
    elif choice == "7":
        backhaul2_iran_server_udpmenu_multic7()
            
    elif choice == "8":
        backhaul2_iran_server_udpmenu_multic8()
            
    elif choice == "9":
        backhaul2_iran_server_udpmenu_multic9()
            
    elif choice == "10":
        backhaul2_iran_server_udpmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_udp_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_udp_multimenu2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[96m Kharej Client\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_kharej1_client_udpmenu_multi()
            
    elif choice == "2":
        backhaul2_kharej2_client_udpmenu_multi()
            
    elif choice == "3":
        backhaul2_kharej3_client_udpmenu_multi()
            
    elif choice == "4":
        backhaul2_kharej4_client_udpmenu_multi()
            
    elif choice == "5":
        backhaul2_kharej5_client_udpmenu_multi()
            
    elif choice == "6":
        backhaul2_kharej6_client_udpmenu_multi()
            
    elif choice == "7":
        backhaul2_kharej7_client_udpmenu_multi()
            
    elif choice == "8":
        backhaul2_kharej8_client_udpmenu_multi()
            
    elif choice == "9":
        backhaul2_kharej9_client_udpmenu_multi()
            
    elif choice == "10":
        backhaul2_kharej10_client_udpmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_udp_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_udpmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [1] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }
    
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

#2

def backhaul_iran_server_udpmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [2] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

#3

def backhaul_iran_server_udpmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [3] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

#4

def backhaul_iran_server_udpmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [4] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

#5

def backhaul_iran_server_udpmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [5] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

#6

def backhaul_iran_server_udpmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [6] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

#7

def backhaul_iran_server_udpmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [7] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

#8

def backhaul_iran_server_udpmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [8] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

#9

def backhaul_iran_server_udpmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [9] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

#10

def backhaul_iran_server_udpmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [10] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

def backhaul_kharej1_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

#2

def backhaul_kharej2_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

#3

def backhaul_kharej3_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

#4

def backhaul_kharej4_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

#5
def backhaul_kharej5_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

#6

def backhaul_kharej6_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

#7

def backhaul_kharej7_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

#8
def backhaul_kharej8_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

#9
def backhaul_kharej9_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

#10
def backhaul_kharej10_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()
def backhaul2_iran_server_udpmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [1] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }
    
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

# 2

def backhaul2_iran_server_udpmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [2] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

# 3

def backhaul2_iran_server_udpmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [3] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

# 4

def backhaul2_iran_server_udpmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [4] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

# 5

def backhaul2_iran_server_udpmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [5] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

# 6

def backhaul2_iran_server_udpmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [6] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

# 7

def backhaul2_iran_server_udpmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [7] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

# 8

def backhaul2_iran_server_udpmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [8] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

# 9

def backhaul2_iran_server_udpmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [9] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

# 10

def backhaul2_iran_server_udpmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [10] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

def backhaul2_kharej1_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [1] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

# 2

def backhaul2_kharej2_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [2] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

# 3

def backhaul2_kharej3_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [3] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

# 4

def backhaul2_kharej4_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [4] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

# 5
def backhaul2_kharej5_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [5] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

# 6

def backhaul2_kharej6_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [6] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

# 7

def backhaul2_kharej7_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [7] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

# 8
def backhaul2_kharej8_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [8] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

# 9
def backhaul2_kharej9_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [9] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

# 10
def backhaul2_kharej10_client_udpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [10] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "udp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

def backhaul_tcp_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmenu_multi()
            
    elif choice == "2":
        backhaul_kharej_client_tcpmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_tcp_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers\033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmenu_multi2()
            
    elif choice == "2":
        backhaul_kharej_client_tcpmenu_multi2()
            
    elif choice == "0":
        clear()
        backhaul_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[96m IRAN Server\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmenu_multic1()
            
    elif choice == "2":
        backhaul_iran_server_tcpmenu_multic2()
            
    elif choice == "3":
        backhaul_iran_server_tcpmenu_multic3()
            
    elif choice == "4":
        backhaul_iran_server_tcpmenu_multic4()
            
    elif choice == "5":
        backhaul_iran_server_tcpmenu_multic5()
            
    elif choice == "6":
        backhaul_iran_server_tcpmenu_multic6()
            
    elif choice == "7":
        backhaul_iran_server_tcpmenu_multic7()
            
    elif choice == "8":
        backhaul_iran_server_tcpmenu_multic8()
            
    elif choice == "9":
        backhaul_iran_server_tcpmenu_multic9()
            
    elif choice == "10":
        backhaul_iran_server_tcpmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_tcp_multi()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[96m Kharej Clients\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_kharej1_client_tcpmenu_multi()
            
    elif choice == "2":
        backhaul_kharej2_client_tcpmenu_multi()
            
    elif choice == "3":
        backhaul_kharej3_client_tcpmenu_multi()
            
    elif choice == "4":
        backhaul_kharej4_client_tcpmenu_multi()
            
    elif choice == "5":
        backhaul_kharej5_client_tcpmenu_multi()
            
    elif choice == "6":
        backhaul_kharej6_client_tcpmenu_multi()
            
    elif choice == "7":
        backhaul_kharej7_client_tcpmenu_multi()
            
    elif choice == "8":
        backhaul_kharej8_client_tcpmenu_multi()
            
    elif choice == "9":
        backhaul_kharej9_client_tcpmenu_multi()
            
    elif choice == "10":
        backhaul_kharej10_client_tcpmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_tcp_multi()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_tcpmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[96m IRAN Servers\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_iran_server_tcpmenu_multic1()
            
    elif choice == "2":
        backhaul2_iran_server_tcpmenu_multic2()
            
    elif choice == "3":
        backhaul2_iran_server_tcpmenu_multic3()
            
    elif choice == "4":
        backhaul2_iran_server_tcpmenu_multic4()
            
    elif choice == "5":
        backhaul2_iran_server_tcpmenu_multic5()
            
    elif choice == "6":
        backhaul2_iran_server_tcpmenu_multic6()
            
    elif choice == "7":
        backhaul2_iran_server_tcpmenu_multic7()
            
    elif choice == "8":
        backhaul2_iran_server_tcpmenu_multic8()
            
    elif choice == "9":
        backhaul2_iran_server_tcpmenu_multic9()
            
    elif choice == "10":
        backhaul2_iran_server_tcpmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_tcp_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_tcpmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[96m Kharej Client\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_kharej1_client_tcpmenu_multi()
            
    elif choice == "2":
        backhaul2_kharej2_client_tcpmenu_multi()
            
    elif choice == "3":
        backhaul2_kharej3_client_tcpmenu_multi()
            
    elif choice == "4":
        backhaul2_kharej4_client_tcpmenu_multi()
            
    elif choice == "5":
        backhaul2_kharej5_client_tcpmenu_multi()
            
    elif choice == "6":
        backhaul2_kharej6_client_tcpmenu_multi()
            
    elif choice == "7":
        backhaul2_kharej7_client_tcpmenu_multi()
            
    elif choice == "8":
        backhaul2_kharej8_client_tcpmenu_multi()
            
    elif choice == "9":
        backhaul2_kharej9_client_tcpmenu_multi()
            
    elif choice == "10":
        backhaul2_kharej10_client_tcpmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_tcp_multi2()
            
    else:
        print("Invalid choice.")

def create_singleserver_service1():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server1.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server1.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server1.service")
    os.system("systemctl start backhaul-server1.service")
    display_checkmark(f"Service file created at {service_path}")

def enable_backhaul_reset_server1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server1(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_server1(interval):
    service_name = "backhaul_reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon1.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon1.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon1.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server1 
sudo journalctl --vacuum-size=1M --unit=backhaul-server1.service
"""

    with open("/etc/backhaul_reset1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def backhaul_iran_server_tcpmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [1] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

#2
def enable_backhaul_reset_server2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server2(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_server2(interval):
    service_name = "backhaul_reset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset2.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon2.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon2.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon2.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server2 
sudo journalctl --vacuum-size=1M --unit=backhaul-server2.service
"""

    with open("/etc/backhaul_reset2.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset2.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleserver_service2():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server2.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server2.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server2.service")
    os.system("systemctl start backhaul-server2.service")
    display_checkmark(f"Service file created at {service_path}")

def backhaul_iran_server_tcpmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [2] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

#3

def enable_backhaul_reset_server3():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server3(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")

def reset_backhaul_server3(interval):
    service_name = "backhaul_reset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset3.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon3.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon3.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon3.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server3 
sudo journalctl --vacuum-size=1M --unit=backhaul-server3.service
"""

    with open("/etc/backhaul_reset3.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset3.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])


def create_singleserver_service3():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server3.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server3.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server3.service")
    os.system("systemctl start backhaul-server3.service")
    display_checkmark(f"Service file created at {service_path}")

def backhaul_iran_server_tcpmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [3] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

#4
def enable_backhaul_reset_server4():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server4(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")

def reset_backhaul_server4(interval):
    service_name = "backhaul_reset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset4.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon4.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon4.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon4.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server4 
sudo journalctl --vacuum-size=1M --unit=backhaul-server4.service
"""

    with open("/etc/backhaul_reset4.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset4.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleserver_service4():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server4.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server4.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server4.service")
    os.system("systemctl start backhaul-server4.service")
    display_checkmark(f"Service file created at {service_path}")

def backhaul_iran_server_tcpmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [4] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

#5
def enable_backhaul_reset_server5():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server5(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")

def reset_backhaul_server5(interval):
    service_name = "backhaul_reset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset5.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon5.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon5.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon5.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server5 
sudo journalctl --vacuum-size=1M --unit=backhaul-server5.service
"""

    with open("/etc/backhaul_reset5.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset5.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleserver_service5():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server5.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server5.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server5.service")
    os.system("systemctl start backhaul-server5.service")
    display_checkmark(f"Service file created at {service_path}")

def backhaul_iran_server_tcpmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [5] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

#6
def enable_backhaul_reset_server6():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server6(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")

def reset_backhaul_server6(interval):
    service_name = "backhaul_reset6.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset6.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon6.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon6.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon6.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server6 
sudo journalctl --vacuum-size=1M --unit=backhaul-server6.service
"""

    with open("/etc/backhaul_reset6.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset6.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleserver_service6():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server6.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server6.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server6.service")
    os.system("systemctl start backhaul-server6.service")
    display_checkmark(f"Service file created at {service_path}")

def backhaul_iran_server_tcpmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [6] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

#7
def enable_backhaul_reset_server7():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server7(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")

def reset_backhaul_server7(interval):
    service_name = "backhaul_reset7.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset7.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon7.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon7.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon7.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server7
sudo journalctl --vacuum-size=1M --unit=backhaul-server7.service
"""

    with open("/etc/backhaul_reset7.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset7.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleserver_service7():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server7.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server7.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server7.service")
    os.system("systemctl start backhaul-server7.service")
    display_checkmark(f"Service file created at {service_path}")

def backhaul_iran_server_tcpmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [7] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

#8
def enable_backhaul_reset_server8():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server8(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")

def reset_backhaul_server8(interval):
    service_name = "backhaul_reset8.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset8.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon8.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon8.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon8.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server8
sudo journalctl --vacuum-size=1M --unit=backhaul-server8.service
"""

    with open("/etc/backhaul_reset8.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset8.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleserver_service8():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server8.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server8.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server8.service")
    os.system("systemctl start backhaul-server8.service")
    display_checkmark(f"Service file created at {service_path}")

def backhaul_iran_server_tcpmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [8] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

#9
def enable_backhaul_reset_server9():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server9(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")

def reset_backhaul_server9(interval):
    service_name = "backhaul_reset9.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset9.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon9.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon9.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon9.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server9
sudo journalctl --vacuum-size=1M --unit=backhaul-server9.service
"""

    with open("/etc/backhaul_reset9.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset9.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleserver_service9():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server9.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server9.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server9.service")
    os.system("systemctl start backhaul-server9.service")
    display_checkmark(f"Service file created at {service_path}")

def backhaul_iran_server_tcpmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [9] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

#10
def enable_backhaul_reset_server10():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server10(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")

def reset_backhaul_server10(interval):
    service_name = "backhaul_reset10.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset10.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon10.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon10.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon10.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-server10
sudo journalctl --vacuum-size=1M --unit=backhaul-server10.service
"""

    with open("/etc/backhaul_reset10.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset10.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleserver_service10():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/server10.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-server10.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-server10.service")
    os.system("systemctl start backhaul-server10.service")
    display_checkmark(f"Service file created at {service_path}")

def backhaul_iran_server_tcpmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [10] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#client tcp
def enable_backhaul_reset_client1():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client1(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client1(interval):
    service_name = "backhaul_reset1.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset1.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon1.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon1.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon1.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client1 
sudo journalctl --vacuum-size=1M --unit=backhaul-client1.service
"""

    with open("/etc/backhaul_reset1.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset1.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleclient_service1():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client1.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client1.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client1.service")
    os.system("systemctl restart backhaul-client1.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_kharej1_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

#2
def enable_backhaul_reset_client2():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client2(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client2(interval):
    service_name = "backhaul_reset2.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset2.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon2.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon2.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon2.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client2 
sudo journalctl --vacuum-size=1M --unit=backhaul-client2.service
"""

    with open("/etc/backhaul_reset2.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset2.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleclient_service2():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client2.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client2.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client2.service")
    os.system("systemctl restart backhaul-client2.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_kharej2_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

#3
def enable_backhaul_reset_client3():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client3(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client3(interval):
    service_name = "backhaul_reset3.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset3.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon3.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon3.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon3.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client3 
sudo journalctl --vacuum-size=1M --unit=backhaul-client3.service
"""

    with open("/etc/backhaul_reset3.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset3.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleclient_service3():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client3.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client3.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client3.service")
    os.system("systemctl restart backhaul-client3.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_kharej3_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

#4
def enable_backhaul_reset_client4():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client4(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client4(interval):
    service_name = "backhaul_reset4.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset4.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon4.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon4.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon4.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client4 
sudo journalctl --vacuum-size=1M --unit=backhaul-client4.service
"""

    with open("/etc/backhaul_reset4.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset4.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleclient_service4():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client4.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client4.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client4.service")
    os.system("systemctl restart backhaul-client4.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_kharej4_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

#5
def enable_backhaul_reset_client5():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client5(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client5(interval):
    service_name = "backhaul_reset5.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset5.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon5.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon5.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon5.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client5 
sudo journalctl --vacuum-size=1M --unit=backhaul-client5.service
"""

    with open("/etc/backhaul_reset5.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset5.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleclient_service5():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client5.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client5.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client5.service")
    os.system("systemctl restart backhaul-client5.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_kharej5_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

#6
def enable_backhaul_reset_client6():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client6(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client6(interval):
    service_name = "backhaul_reset6.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset6.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon6.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon6.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon6.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client6 
sudo journalctl --vacuum-size=1M --unit=backhaul-client6.service
"""

    with open("/etc/backhaul_reset6.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset6.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleclient_service6():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client6.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client6.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client6.service")
    os.system("systemctl restart backhaul-client6.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_kharej6_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

#7
def enable_backhaul_reset_client7():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client7(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client7(interval):
    service_name = "backhaul_reset7.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset7.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon7.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon7.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon7.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client7 
sudo journalctl --vacuum-size=1M --unit=backhaul-client7.service
"""

    with open("/etc/backhaul_reset7.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset7.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleclient_service7():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client7.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client7.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client7.service")
    os.system("systemctl restart backhaul-client7.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_kharej7_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

#8
def enable_backhaul_reset_client8():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client8(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client8(interval):
    service_name = "backhaul_reset8.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset8.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon8.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon8.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon8.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client8 
sudo journalctl --vacuum-size=1M --unit=backhaul-client8.service
"""

    with open("/etc/backhaul_reset8.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset8.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleclient_service8():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client8.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client8.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client8.service")
    os.system("systemctl restart backhaul-client8.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_kharej8_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

#9
def enable_backhaul_reset_client9():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client9(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client9(interval):
    service_name = "backhaul_reset9.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset9.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon9.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon9.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon9.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client9 
sudo journalctl --vacuum-size=1M --unit=backhaul-client9.service
"""

    with open("/etc/backhaul_reset9.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset9.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleclient_service9():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client9.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client9.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client9.service")
    os.system("systemctl restart backhaul-client9.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_kharej9_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

#10
def enable_backhaul_reset_client10():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to enable/edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client10(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def reset_backhaul_client10(interval):
    service_name = "backhaul_reset10.service"

    daemon_script_content = f"""#!/bin/bash
INTERVAL={interval}

while true; do
    /bin/bash /etc/backhaul_reset10.sh
    sleep $INTERVAL
done
"""

    with open("/usr/local/bin/backhaul_daemon10.sh", "w") as daemon_script_file:
        daemon_script_file.write(daemon_script_content)

    subprocess.run(["chmod", "+x", "/usr/local/bin/backhaul_daemon10.sh"])

    service_content = f"""[Unit]
Description=Custom Daemon

[Service]
ExecStart=/usr/local/bin/backhaul_daemon10.sh
Restart=always

[Install]
WantedBy=multi-user.target
"""

    with open(f"/etc/systemd/system/{service_name}", "w") as service_file:
        service_file.write(service_content)

    ipsec_reset_script_content = """#!/bin/bash
systemctl daemon-reload 
systemctl restart backhaul-client10 
sudo journalctl --vacuum-size=1M --unit=backhaul-client10.service
"""

    with open("/etc/backhaul_reset10.sh", "w") as script_file:
        script_file.write(ipsec_reset_script_content)

    subprocess.run(["chmod", "+x", "/etc/backhaul_reset10.sh"])
    subprocess.run(["systemctl", "daemon-reload"])
    subprocess.run(["systemctl", "enable", service_name])
    subprocess.run(["systemctl", "restart", service_name])

def create_singleclient_service10():
    service_content = """
[Unit]
Description=Backhaul Reverse Tunnel Client Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/backhaul/backhaul -c /usr/local/bin/backhaul/client10.toml
Restart=always
RestartSec=3
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
"""
    service_path = "/etc/systemd/system/backhaul-client10.service"
    with open(service_path, 'w') as service_file:
        service_file.write(service_content)
    
    os.system("systemctl daemon-reload")
    os.system("systemctl enable backhaul-client10.service")
    os.system("systemctl restart backhaul-client10.service")
    display_checkmark(f"Client service file created at {service_path}")

def backhaul_kharej10_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

def backhaul2_iran_server_tcpmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [1] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

# 2

def backhaul2_iran_server_tcpmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [2] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

# 3

def backhaul2_iran_server_tcpmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [3] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

# 4
def backhaul2_iran_server_tcpmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [4] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

# 5

def backhaul2_iran_server_tcpmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [5] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

# 6
def backhaul2_iran_server_tcpmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [6] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

# 7
def backhaul2_iran_server_tcpmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [7] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

# 8
def backhaul2_iran_server_tcpmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [8] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

# 9
def backhaul2_iran_server_tcpmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [9] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

# 10
def backhaul2_iran_server_tcpmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [10] \033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_config10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#client tcp

def backhaul2_kharej1_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [1]\033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

# 2

def backhaul2_kharej2_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [2] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

# 3
def backhaul2_kharej3_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [3] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

# 4

def backhaul2_kharej4_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [4] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

# 5
def backhaul2_kharej5_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [5] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

# 6
def backhaul2_kharej6_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97mServer [6] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

# 7

def backhaul2_kharej7_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [7] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

# 8
def backhaul2_kharej8_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [8] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

# 9
def backhaul2_kharej9_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

# 10
def backhaul2_kharej10_client_tcpmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [10] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcp",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

#tcpmux
def backhaul_tcpmux_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmuxmenu_multi()
            
    elif choice == "2":
        backhaul_kharej_client_tcpmuxmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_tcpmux_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers\033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmuxmenu_multi2()
            
    elif choice == "2":
        backhaul_kharej_client_tcpmuxmenu_multi2()
            
    elif choice == "0":
        clear()
        backhaul_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[96m IRAN Server\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmuxmenu_multic1()
            
    elif choice == "2":
        backhaul_iran_server_tcpmuxmenu_multic2()
            
    elif choice == "3":
        backhaul_iran_server_tcpmuxmenu_multic3()
            
    elif choice == "4":
        backhaul_iran_server_tcpmuxmenu_multic4()
            
    elif choice == "5":
        backhaul_iran_server_tcpmuxmenu_multic5()
            
    elif choice == "6":
        backhaul_iran_server_tcpmuxmenu_multic6()
            
    elif choice == "7":
        backhaul_iran_server_tcpmuxmenu_multic7()
            
    elif choice == "8":
        backhaul_iran_server_tcpmuxmenu_multic8()
            
    elif choice == "9":
        backhaul_iran_server_tcpmuxmenu_multic9()
            
    elif choice == "10":
        backhaul_iran_server_tcpmuxmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_tcpmux_multi()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[96m Kharej Clients\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_kharej1_client_tcpmuxmenu_multi()
            
    elif choice == "2":
        backhaul_kharej2_client_tcpmuxmenu_multi()
            
    elif choice == "3":
        backhaul_kharej3_client_tcpmuxmenu_multi()
            
    elif choice == "4":
        backhaul_kharej4_client_tcpmuxmenu_multi()
            
    elif choice == "5":
        backhaul_kharej5_client_tcpmuxmenu_multi()
            
    elif choice == "6":
        backhaul_kharej6_client_tcpmuxmenu_multi()
            
    elif choice == "7":
        backhaul_kharej7_client_tcpmuxmenu_multi()
            
    elif choice == "8":
        backhaul_kharej8_client_tcpmuxmenu_multi()
            
    elif choice == "9":
        backhaul_kharej9_client_tcpmuxmenu_multi()
            
    elif choice == "10":
        backhaul_kharej10_client_tcpmuxmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_tcpmux_multi()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_tcpmuxmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[96m IRAN Servers\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_iran_server_tcpmuxmenu_multic1()
            
    elif choice == "2":
        backhaul2_iran_server_tcpmuxmenu_multic2()
            
    elif choice == "3":
        backhaul2_iran_server_tcpmuxmenu_multic3()
            
    elif choice == "4":
        backhaul2_iran_server_tcpmuxmenu_multic4()
            
    elif choice == "5":
        backhaul2_iran_server_tcpmuxmenu_multic5()
            
    elif choice == "6":
        backhaul2_iran_server_tcpmuxmenu_multic6()
            
    elif choice == "7":
        backhaul2_iran_server_tcpmuxmenu_multic7()
            
    elif choice == "8":
        backhaul2_iran_server_tcpmuxmenu_multic8()
            
    elif choice == "9":
        backhaul2_iran_server_tcpmuxmenu_multic9()
            
    elif choice == "10":
        backhaul2_iran_server_tcpmuxmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_tcpmux_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_tcpmuxmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[96m Kharej Client Configs\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfigs [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfigs [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfigs [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfigs [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfigs [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfigs [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfigs [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfigs [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfigs [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfigs [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")

    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_kharej1_client_tcpmuxmenu_multi()
            
    elif choice == "2":
        backhaul2_kharej2_client_tcpmuxmenu_multi()
            
    elif choice == "3":
        backhaul2_kharej3_client_tcpmuxmenu_multi()
            
    elif choice == "4":
        backhaul2_kharej4_client_tcpmuxmenu_multi()
            
    elif choice == "5":
        backhaul2_kharej5_client_tcpmuxmenu_multi()
            
    elif choice == "6":
        backhaul2_kharej6_client_tcpmuxmenu_multi()
            
    elif choice == "7":
        backhaul2_kharej7_client_tcpmuxmenu_multi()
            
    elif choice == "8":
        backhaul2_kharej8_client_tcpmuxmenu_multi()
            
    elif choice == "9":
        backhaul2_kharej9_client_tcpmuxmenu_multi()
            
    elif choice == "10":
        backhaul2_kharej10_client_tcpmuxmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_tcpmux_multi2()
            
    else:
        print("Invalid choice.")

#1     
def backhaul_iran_server_tcpmuxmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [1] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Config [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Config [1]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

#2
def backhaul_iran_server_tcpmuxmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [2] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Config [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Config [2]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

#3
def backhaul_iran_server_tcpmuxmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [3] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Config [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Config [3]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

#4
def backhaul_iran_server_tcpmuxmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [4] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Config [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Config [4]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

#5
def backhaul_iran_server_tcpmuxmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [5] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Config [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Config [5]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

#6
def backhaul_iran_server_tcpmuxmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [6] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Config [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Config [6]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

#7
def backhaul_iran_server_tcpmuxmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [7] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Config [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Config [7]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

#8
def backhaul_iran_server_tcpmuxmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [8] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Config [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Config [8]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

#9
def backhaul_iran_server_tcpmuxmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [9] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Config [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Config [9]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

#10
def backhaul_iran_server_tcpmuxmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [10] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Config [10]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Config [10]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#client tcpmux
def backhaul_kharej1_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

#2
def backhaul_kharej2_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

#3
def backhaul_kharej3_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

#4
def backhaul_kharej4_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

#5
def backhaul_kharej5_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

#6
def backhaul_kharej6_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

#7
def backhaul_kharej7_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

#8
def backhaul_kharej8_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

#9
def backhaul_kharej9_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

#10
def backhaul_kharej10_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

def backhaul2_iran_server_tcpmuxmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [1] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Server [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Server [1]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

# 2
def backhaul2_iran_server_tcpmuxmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [2] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Server [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Server [2]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

# 3
def backhaul2_iran_server_tcpmuxmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [3] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Server [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Server [3]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

# 4
def backhaul2_iran_server_tcpmuxmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [4] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Server [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Server [4]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

# 5
def backhaul2_iran_server_tcpmuxmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [5] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Server [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Server [5]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

# 6
def backhaul2_iran_server_tcpmuxmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [6] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Server [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Server [6]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

# 7
def backhaul2_iran_server_tcpmuxmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [7] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Server [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Server [7]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

# 8
def backhaul2_iran_server_tcpmuxmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [8] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Server [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Server [8]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

# 9
def backhaul2_iran_server_tcpmuxmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [9] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Server [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Server [9]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

# 10
def backhaul2_iran_server_tcpmuxmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [10] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port\033[97m Server [10]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken Server [10]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#client tcpmux
def backhaul2_kharej1_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [1] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

# 2
def backhaul2_kharej2_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [2] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

# 3
def backhaul2_kharej3_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [3] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

# 4
def backhaul2_kharej4_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [4] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

# 5
def backhaul2_kharej5_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [5] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

# 6
def backhaul2_kharej6_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [6] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

# 7
def backhaul2_kharej7_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [7] Config \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [7] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

# 8
def backhaul2_kharej8_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [8] Config \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [8] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

# 9
def backhaul2_kharej9_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [9] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

# 10
def backhaul2_kharej10_client_tcpmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [9] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "tcpmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

#ws Server
def backhaul_ws_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmenu_multi()
            
    elif choice == "2":
        backhaul_kharej_client_wsmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_ws_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers\033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmenu_multi2()
            
    elif choice == "2":
        backhaul_kharej_client_wsmenu_multi2()
            
    elif choice == "0":
        clear()
        backhaul_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[96m IRAN Server\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmenu_multic1()
            
    elif choice == "2":
        backhaul_iran_server_wsmenu_multic2()
            
    elif choice == "3":
        backhaul_iran_server_wsmenu_multic3()
            
    elif choice == "4":
        backhaul_iran_server_wsmenu_multic4()
            
    elif choice == "5":
        backhaul_iran_server_wsmenu_multic5()
            
    elif choice == "6":
        backhaul_iran_server_wsmenu_multic6()
            
    elif choice == "7":
        backhaul_iran_server_wsmenu_multic7()
            
    elif choice == "8":
        backhaul_iran_server_wsmenu_multic8()
            
    elif choice == "9":
        backhaul_iran_server_wsmenu_multic9()
            
    elif choice == "10":
        backhaul_iran_server_wsmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_ws_multi()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[96m Kharej Clients\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_kharej1_client_wsmenu_multi()
            
    elif choice == "2":
        backhaul_kharej2_client_wsmenu_multi()
            
    elif choice == "3":
        backhaul_kharej3_client_wsmenu_multi()
            
    elif choice == "4":
        backhaul_kharej4_client_wsmenu_multi()
            
    elif choice == "5":
        backhaul_kharej5_client_wsmenu_multi()
            
    elif choice == "6":
        backhaul_kharej6_client_wsmenu_multi()
            
    elif choice == "7":
        backhaul_kharej7_client_wsmenu_multi()
            
    elif choice == "8":
        backhaul_kharej8_client_wsmenu_multi()
            
    elif choice == "9":
        backhaul_kharej9_client_wsmenu_multi()
            
    elif choice == "10":
        backhaul_kharej10_client_wsmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_ws_multi()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wsmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[96m IRAN Servers\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_iran_server_wsmenu_multic1()
            
    elif choice == "2":
        backhaul2_iran_server_wsmenu_multic2()
            
    elif choice == "3":
        backhaul2_iran_server_wsmenu_multic3()
            
    elif choice == "4":
        backhaul2_iran_server_wsmenu_multic4()
            
    elif choice == "5":
        backhaul2_iran_server_wsmenu_multic5()
            
    elif choice == "6":
        backhaul2_iran_server_wsmenu_multic6()
            
    elif choice == "7":
        backhaul2_iran_server_wsmenu_multic7()
            
    elif choice == "8":
        backhaul2_iran_server_wsmenu_multic8()
            
    elif choice == "9":
        backhaul2_iran_server_wsmenu_multic9()
            
    elif choice == "10":
        backhaul2_iran_server_wsmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_ws_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wsmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[96m Kharej Client\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_kharej1_client_wsmenu_multi()
            
    elif choice == "2":
        backhaul2_kharej2_client_wsmenu_multi()
            
    elif choice == "3":
        backhaul2_kharej3_client_wsmenu_multi()
            
    elif choice == "4":
        backhaul2_kharej4_client_wsmenu_multi()
            
    elif choice == "5":
        backhaul2_kharej5_client_wsmenu_multi()
            
    elif choice == "6":
        backhaul2_kharej6_client_wsmenu_multi()
            
    elif choice == "7":
        backhaul2_kharej7_client_wsmenu_multi()
            
    elif choice == "8":
        backhaul2_kharej8_client_wsmenu_multi()
            
    elif choice == "9":
        backhaul2_kharej9_client_wsmenu_multi()
            
    elif choice == "10":
        backhaul2_kharej10_client_wsmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_ws_multi2()
            
    else:
        print("Invalid choice.")

#ws servers
def backhaul_iran_server_wsmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [1] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

#2
def backhaul_iran_server_wsmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [2] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

#3
def backhaul_iran_server_wsmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [3] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

#4
def backhaul_iran_server_wsmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [4] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

#5
def backhaul_iran_server_wsmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [5] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

#6
def backhaul_iran_server_wsmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [6] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

#7
def backhaul_iran_server_wsmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [7] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

#8
def backhaul_iran_server_wsmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [8] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

#9
def backhaul_iran_server_wsmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [9] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

#10
def backhaul_iran_server_wsmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Config [10] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#ws Clients
def backhaul_kharej1_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

#2
def backhaul_kharej2_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

#3
def backhaul_kharej3_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

#4
def backhaul_kharej4_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()
#5
def backhaul_kharej5_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

#6
def backhaul_kharej6_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

#7
def backhaul_kharej7_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

#8
def backhaul_kharej8_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

#9
def backhaul_kharej9_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

#10
def backhaul_kharej10_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

def backhaul2_iran_server_wsmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [1] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

# 2
def backhaul2_iran_server_wsmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [2] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

# 3
def backhaul2_iran_server_wsmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [3] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

# 4
def backhaul2_iran_server_wsmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [4] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

# 5
def backhaul2_iran_server_wsmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [5] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

# 6
def backhaul2_iran_server_wsmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [6] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

# 7
def backhaul2_iran_server_wsmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [7] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

# 8
def backhaul2_iran_server_wsmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [8] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

# 9
def backhaul2_iran_server_wsmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [9] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

# 10
def backhaul2_iran_server_wsmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN Server [10] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#ws Clients
def backhaul2_kharej1_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [1] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

# 2
def backhaul2_kharej2_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [2] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

# 3
def backhaul2_kharej3_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [3] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

# 4
def backhaul2_kharej4_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [4] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()
# 5
def backhaul2_kharej5_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [5] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

# 6
def backhaul2_kharej6_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [6] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

# 7
def backhaul2_kharej7_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [7] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

# 8
def backhaul2_kharej8_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [8] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

# 9
def backhaul2_kharej9_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [9] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

# 10
def backhaul2_kharej10_client_wsmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [10] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "ws",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

#ws mux 
def backhaul_wsmux_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSMux\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmuxmenu_multi()
            
    elif choice == "2":
        backhaul_kharej_client_wsmuxmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_wsmux_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSMux\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers\033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmuxmenu_multi2()
            
    elif choice == "2":
        backhaul_kharej_client_wsmuxmenu_multi2()
            
    elif choice == "0":
        clear()
        backhaul_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSMux\033[96m IRAN Server\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmuxmenu_multic1()
            
    elif choice == "2":
        backhaul_iran_server_wsmuxmenu_multic2()
            
    elif choice == "3":
        backhaul_iran_server_wsmuxmenu_multic3()
            
    elif choice == "4":
        backhaul_iran_server_wsmuxmenu_multic4()
            
    elif choice == "5":
        backhaul_iran_server_wsmuxmenu_multic5()
            
    elif choice == "6":
        backhaul_iran_server_wsmuxmenu_multic6()
            
    elif choice == "7":
        backhaul_iran_server_wsmuxmenu_multic7()
            
    elif choice == "8":
        backhaul_iran_server_wsmuxmenu_multic8()
            
    elif choice == "9":
        backhaul_iran_server_wsmuxmenu_multic9()
            
    elif choice == "10":
        backhaul_iran_server_wsmuxmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_wsmux_multi()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSMux\033[96m Kharej Clients\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_kharej1_client_wsmuxmenu_multi()
            
    elif choice == "2":
        backhaul_kharej2_client_wsmuxmenu_multi()
            
    elif choice == "3":
        backhaul_kharej3_client_wsmuxmenu_multi()
            
    elif choice == "4":
        backhaul_kharej4_client_wsmuxmenu_multi()
            
    elif choice == "5":
        backhaul_kharej5_client_wsmuxmenu_multi()
            
    elif choice == "6":
        backhaul_kharej6_client_wsmuxmenu_multi()
            
    elif choice == "7":
        backhaul_kharej7_client_wsmuxmenu_multi()
            
    elif choice == "8":
        backhaul_kharej8_client_wsmuxmenu_multi()
            
    elif choice == "9":
        backhaul_kharej9_client_wsmuxmenu_multi()
            
    elif choice == "10":
        backhaul_kharej10_client_wsmuxmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_wsmux_multi()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wsmuxmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSMux\033[96m IRAN Servers\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_iran_server_wsmuxmenu_multic1()
            
    elif choice == "2":
        backhaul2_iran_server_wsmuxmenu_multic2()
            
    elif choice == "3":
        backhaul2_iran_server_wsmuxmenu_multic3()
            
    elif choice == "4":
        backhaul2_iran_server_wsmuxmenu_multic4()
            
    elif choice == "5":
        backhaul2_iran_server_wsmuxmenu_multic5()
            
    elif choice == "6":
        backhaul2_iran_server_wsmuxmenu_multic6()
            
    elif choice == "7":
        backhaul2_iran_server_wsmuxmenu_multic7()
            
    elif choice == "8":
        backhaul2_iran_server_wsmuxmenu_multic8()
            
    elif choice == "9":
        backhaul2_iran_server_wsmuxmenu_multic9()
            
    elif choice == "10":
        backhaul2_iran_server_wsmuxmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_wsmux_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wsmuxmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSMux\033[96m Kharej Client\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_kharej1_client_wsmuxmenu_multi()
            
    elif choice == "2":
        backhaul2_kharej2_client_wsmuxmenu_multi()
            
    elif choice == "3":
        backhaul2_kharej3_client_wsmuxmenu_multi()
            
    elif choice == "4":
        backhaul2_kharej4_client_wsmuxmenu_multi()
            
    elif choice == "5":
        backhaul2_kharej5_client_wsmuxmenu_multi()
            
    elif choice == "6":
        backhaul2_kharej6_client_wsmuxmenu_multi()
            
    elif choice == "7":
        backhaul2_kharej7_client_wsmuxmenu_multi()
            
    elif choice == "8":
        backhaul2_kharej8_client_wsmuxmenu_multi()
            
    elif choice == "9":
        backhaul2_kharej9_client_wsmuxmenu_multi()
            
    elif choice == "10":
        backhaul2_kharej10_client_wsmuxmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_wsmux_multi2()
            
    else:
        print("Invalid choice.")

#wsmux servers
def backhaul_iran_server_wsmuxmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [1] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

#2
def backhaul_iran_server_wsmuxmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [2] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

#3
def backhaul_iran_server_wsmuxmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [3] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

#4
def backhaul_iran_server_wsmuxmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [4] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

#5
def backhaul_iran_server_wsmuxmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [5] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

#6
def backhaul_iran_server_wsmuxmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [6] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

#7
def backhaul_iran_server_wsmuxmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [7] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

#8
def backhaul_iran_server_wsmuxmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [8] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

#9
def backhaul_iran_server_wsmuxmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [9] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

#10
def backhaul_iran_server_wsmuxmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [10] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#clients wsmux
def backhaul_kharej1_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

#2
def backhaul_kharej2_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

#3
def backhaul_kharej3_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

#4
def backhaul_kharej4_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

#5
def backhaul_kharej5_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

#6
def backhaul_kharej6_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

#7
def backhaul_kharej7_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

#8
def backhaul_kharej8_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

#9
def backhaul_kharej9_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

#10
def backhaul_kharej10_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

def backhaul2_iran_server_wsmuxmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [1] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

# 2
def backhaul2_iran_server_wsmuxmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [2] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

# 3
def backhaul2_iran_server_wsmuxmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [3] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

# 4
def backhaul2_iran_server_wsmuxmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [4] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

# 5
def backhaul2_iran_server_wsmuxmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [5] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

# 6
def backhaul2_iran_server_wsmuxmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [6] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

# 7
def backhaul2_iran_server_wsmuxmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [7] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

# 8
def backhaul2_iran_server_wsmuxmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [8] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

# 9
def backhaul2_iran_server_wsmuxmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [9] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

# 10
def backhaul2_iran_server_wsmuxmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [10] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#clients wsmux
def backhaul2_kharej1_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [1] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

# 2
def backhaul2_kharej2_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [2] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

# 3
def backhaul2_kharej3_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [3] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

# 4
def backhaul2_kharej4_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [4] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

# 5
def backhaul2_kharej5_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [5] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

# 6
def backhaul2_kharej6_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [6] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

# 7
def backhaul2_kharej7_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [7] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

# 8
def backhaul2_kharej8_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [8] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

# 9
def backhaul2_kharej9_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [9] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

# 10
def backhaul2_kharej10_client_wsmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [10] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wsmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

#wss
def backhaul_wss_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmenu_multi()
            
    elif choice == "2":
        backhaul_kharej_client_wssmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_wss_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers\033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmenu_multi2()
            
    elif choice == "2":
        backhaul_kharej_client_wssmenu_multi2()
            
    elif choice == "0":
        clear()
        backhaul_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[96m IRAN Server\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmenu_multic1()
            
    elif choice == "2":
        backhaul_iran_server_wssmenu_multic2()
            
    elif choice == "3":
        backhaul_iran_server_wssmenu_multic3()
            
    elif choice == "4":
        backhaul_iran_server_wssmenu_multic4()
            
    elif choice == "5":
        backhaul_iran_server_wssmenu_multic5()
            
    elif choice == "6":
        backhaul_iran_server_wssmenu_multic6()
            
    elif choice == "7":
        backhaul_iran_server_wssmenu_multic7()
            
    elif choice == "8":
        backhaul_iran_server_wssmenu_multic8()
            
    elif choice == "9":
        backhaul_iran_server_wssmenu_multic9()
            
    elif choice == "10":
        backhaul_iran_server_wssmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_wss_multi()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[96m Kharej Clients\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_kharej1_client_wssmenu_multi()
            
    elif choice == "2":
        backhaul_kharej2_client_wssmenu_multi()
            
    elif choice == "3":
        backhaul_kharej3_client_wssmenu_multi()
            
    elif choice == "4":
        backhaul_kharej4_client_wssmenu_multi()
            
    elif choice == "5":
        backhaul_kharej5_client_wssmenu_multi()
            
    elif choice == "6":
        backhaul_kharej6_client_wssmenu_multi()
            
    elif choice == "7":
        backhaul_kharej7_client_wssmenu_multi()
            
    elif choice == "8":
        backhaul_kharej8_client_wssmenu_multi()
            
    elif choice == "9":
        backhaul_kharej9_client_wssmenu_multi()
            
    elif choice == "10":
        backhaul_kharej10_client_wssmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_wss_multi()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wssmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[96m IRAN Servers\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_iran_server_wssmenu_multic1()
            
    elif choice == "2":
        backhaul2_iran_server_wssmenu_multic2()
            
    elif choice == "3":
        backhaul2_iran_server_wssmenu_multic3()
            
    elif choice == "4":
        backhaul2_iran_server_wssmenu_multic4()
            
    elif choice == "5":
        backhaul2_iran_server_wssmenu_multic5()
            
    elif choice == "6":
        backhaul2_iran_server_wssmenu_multic6()
            
    elif choice == "7":
        backhaul2_iran_server_wssmenu_multic7()
            
    elif choice == "8":
        backhaul2_iran_server_wssmenu_multic8()
            
    elif choice == "9":
        backhaul2_iran_server_wssmenu_multic9()
            
    elif choice == "10":
        backhaul2_iran_server_wssmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_wss_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wssmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[96m Kharej Client\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_kharej1_client_wssmenu_multi()
            
    elif choice == "2":
        backhaul2_kharej2_client_wssmenu_multi()
            
    elif choice == "3":
        backhaul2_kharej3_client_wssmenu_multi()
            
    elif choice == "4":
        backhaul2_kharej4_client_wssmenu_multi()
            
    elif choice == "5":
        backhaul2_kharej5_client_wssmenu_multi()
            
    elif choice == "6":
        backhaul2_kharej6_client_wssmenu_multi()
            
    elif choice == "7":
        backhaul2_kharej7_client_wssmenu_multi()
            
    elif choice == "8":
        backhaul2_kharej8_client_wssmenu_multi()
            
    elif choice == "9":
        backhaul2_kharej9_client_wssmenu_multi()
            
    elif choice == "10":
        backhaul2_kharej10_client_wssmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_wss_multi2()
            
    else:
        print("Invalid choice.")

# wss servers

def backhaul_iran_server_wssmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [1] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

#2
def backhaul_iran_server_wssmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [2] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

#3
def backhaul_iran_server_wssmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [3] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

#4
def backhaul_iran_server_wssmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [4] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

#5
def backhaul_iran_server_wssmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [5] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

#6
def backhaul_iran_server_wssmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [6] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

#7
def backhaul_iran_server_wssmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [7] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

#8
def backhaul_iran_server_wssmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [8] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

#9
def backhaul_iran_server_wssmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [9] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

#10
def backhaul_iran_server_wssmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [10] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#clients
def backhaul_kharej1_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

#2
def backhaul_kharej2_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

#3
def backhaul_kharej3_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

#4
def backhaul_kharej4_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

#5
def backhaul_kharej5_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

#6
def backhaul_kharej6_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

#7
def backhaul_kharej7_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

#8
def backhaul_kharej8_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

#9
def backhaul_kharej9_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

#10
def backhaul_kharej10_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

def backhaul2_iran_server_wssmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [1] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

# 2
def backhaul2_iran_server_wssmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [2] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

# 3
def backhaul2_iran_server_wssmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [3] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

# 4
def backhaul2_iran_server_wssmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [4] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

# 5
def backhaul2_iran_server_wssmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [5] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

# 6
def backhaul2_iran_server_wssmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [6] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

# 7
def backhaul2_iran_server_wssmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [7] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

# 8
def backhaul2_iran_server_wssmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [8] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

# 9
def backhaul2_iran_server_wssmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [9] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

# 10
def backhaul2_iran_server_wssmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [10] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#clients
def backhaul2_kharej1_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [1] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

# 2
def backhaul2_kharej2_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [2] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

# 3
def backhaul2_kharej3_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [3] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

# 4
def backhaul2_kharej4_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [4] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

# 5
def backhaul2_kharej5_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [5] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

# 6
def backhaul2_kharej6_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [6] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

# 7
def backhaul2_kharej7_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [7] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

# 8
def backhaul2_kharej8_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [8] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

# 9
def backhaul2_kharej9_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [9] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

# 10
def backhaul2_kharej10_client_wssmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [10] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wss",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

#wssmux
def backhaul_wssmux_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmuxmenu_multi()
            
    elif choice == "2":
        backhaul_kharej_client_wssmuxmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_wssmux_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers\033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmuxmenu_multi2()
            
    elif choice == "2":
        backhaul_kharej_client_wssmuxmenu_multi2()
            
    elif choice == "0":
        clear()
        backhaul_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[96m IRAN Server\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmuxmenu_multic1()
            
    elif choice == "2":
        backhaul_iran_server_wssmuxmenu_multic2()
            
    elif choice == "3":
        backhaul_iran_server_wssmuxmenu_multic3()
            
    elif choice == "4":
        backhaul_iran_server_wssmuxmenu_multic4()
            
    elif choice == "5":
        backhaul_iran_server_wssmuxmenu_multic5()
            
    elif choice == "6":
        backhaul_iran_server_wssmuxmenu_multic6()
            
    elif choice == "7":
        backhaul_iran_server_wssmuxmenu_multic7()
            
    elif choice == "8":
        backhaul_iran_server_wssmuxmenu_multic8()
            
    elif choice == "9":
        backhaul_iran_server_wssmuxmenu_multic9()
            
    elif choice == "10":
        backhaul_iran_server_wssmuxmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_wssmux_multi()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[96m Kharej Clients\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_kharej1_client_wssmuxmenu_multi()
            
    elif choice == "2":
        backhaul_kharej2_client_wssmuxmenu_multi()
            
    elif choice == "3":
        backhaul_kharej3_client_wssmuxmenu_multi()
            
    elif choice == "4":
        backhaul_kharej4_client_wssmuxmenu_multi()
            
    elif choice == "5":
        backhaul_kharej5_client_wssmuxmenu_multi()
            
    elif choice == "6":
        backhaul_kharej6_client_wssmuxmenu_multi()
            
    elif choice == "7":
        backhaul_kharej7_client_wssmuxmenu_multi()
            
    elif choice == "8":
        backhaul_kharej8_client_wssmuxmenu_multi()
            
    elif choice == "9":
        backhaul_kharej9_client_wssmuxmenu_multi()
            
    elif choice == "10":
        backhaul_kharej10_client_wssmuxmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_wssmux_multi()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wssmuxmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[96m IRAN Servers\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_iran_server_wssmuxmenu_multic1()
            
    elif choice == "2":
        backhaul2_iran_server_wssmuxmenu_multic2()
            
    elif choice == "3":
        backhaul2_iran_server_wssmuxmenu_multic3()
            
    elif choice == "4":
        backhaul2_iran_server_wssmuxmenu_multic4()
            
    elif choice == "5":
        backhaul2_iran_server_wssmuxmenu_multic5()
            
    elif choice == "6":
        backhaul2_iran_server_wssmuxmenu_multic6()
            
    elif choice == "7":
        backhaul2_iran_server_wssmuxmenu_multic7()
            
    elif choice == "8":
        backhaul2_iran_server_wssmuxmenu_multic8()
            
    elif choice == "9":
        backhaul2_iran_server_wssmuxmenu_multic9()
            
    elif choice == "10":
        backhaul2_iran_server_wssmuxmenu_multic10()
            
    elif choice == "0":
        clear()
        backhaul_wssmux_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wssmuxmenu_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[96m Kharej Client\033[93m Multi Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul2_kharej1_client_wssmuxmenu_multi()
            
    elif choice == "2":
        backhaul2_kharej2_client_wssmuxmenu_multi()
            
    elif choice == "3":
        backhaul2_kharej3_client_wssmuxmenu_multi()
            
    elif choice == "4":
        backhaul2_kharej4_client_wssmuxmenu_multi()
            
    elif choice == "5":
        backhaul2_kharej5_client_wssmuxmenu_multi()
            
    elif choice == "6":
        backhaul2_kharej6_client_wssmuxmenu_multi()
            
    elif choice == "7":
        backhaul2_kharej7_client_wssmuxmenu_multi()
            
    elif choice == "8":
        backhaul2_kharej8_client_wssmuxmenu_multi()
            
    elif choice == "9":
        backhaul2_kharej9_client_wssmuxmenu_multi()
            
    elif choice == "10":
        backhaul2_kharej10_client_wssmuxmenu_multi()
            
    elif choice == "0":
        clear()
        backhaul_wssmux_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wssmuxmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [1] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

#2
def backhaul_iran_server_wssmuxmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [2] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

#3
def backhaul_iran_server_wssmuxmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [3] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

#4
def backhaul_iran_server_wssmuxmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [4] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

#5
def backhaul_iran_server_wssmuxmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [5] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

#6
def backhaul_iran_server_wssmuxmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [6] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

#7
def backhaul_iran_server_wssmuxmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [7] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

#8
def backhaul_iran_server_wssmuxmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [8] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

#9
def backhaul_iran_server_wssmuxmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [9] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

#10
def backhaul_iran_server_wssmuxmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mConfig [10] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Config 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mConfig [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#clients
def backhaul_kharej1_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

#2
def backhaul_kharej2_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

#3
def backhaul_kharej3_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

#4
def backhaul_kharej4_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

#5
def backhaul_kharej5_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

#6
def backhaul_kharej6_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

#7
def backhaul_kharej7_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

#8
def backhaul_kharej8_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

#9
def backhaul_kharej9_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

#10

def backhaul_kharej10_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mConfig [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mConfig [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

def backhaul2_iran_server_wssmuxmenu_multic1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [1] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server1.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[93m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 1]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [1]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service1()
    enable_backhaul_reset_server1()

# 2
def backhaul2_iran_server_wssmuxmenu_multic2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [2] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server2.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 2]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [2]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service2()
    enable_backhaul_reset_server2()

# 3
def backhaul2_iran_server_wssmuxmenu_multic3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [3] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server3.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 3]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [3]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service3()
    enable_backhaul_reset_server3()

# 4
def backhaul2_iran_server_wssmuxmenu_multic4():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [4] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server4.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 4]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [4]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service4()
    enable_backhaul_reset_server4()

# 5
def backhaul2_iran_server_wssmuxmenu_multic5():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [5] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server5.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 5]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [5]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service5()
    enable_backhaul_reset_server5()

# 6
def backhaul2_iran_server_wssmuxmenu_multic6():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [6] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server6.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 6]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [6]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service6()
    enable_backhaul_reset_server6()

# 7
def backhaul2_iran_server_wssmuxmenu_multic7():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [7] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server7.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 7]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [7]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service7()
    enable_backhaul_reset_server7()

# 8
def backhaul2_iran_server_wssmuxmenu_multic8():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [8] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server8.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 8]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [8]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service8()
    enable_backhaul_reset_server8()

# 9
def backhaul2_iran_server_wssmuxmenu_multic9():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [9] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server9.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 9]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [9]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service9()
    enable_backhaul_reset_server9()

# 10
def backhaul2_iran_server_wssmuxmenu_multic10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mIRAN \033[97mServer [10] \033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")
    
    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()
    cert_directory="/etc/backhaul"
    if os.path.exists(cert_directory):
        print(f"\033[93mSelf cert exists, skipping\033[0m")
    else:
        self_signedcert()
    print("\033[93m───────────────────────────────────────\033[0m")
    port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m: \033[0m").strip()
    if port.isdigit():
        bind_addr = f"0.0.0.0:{port}"
    else:
        bind_addr = "0.0.0.0:8443"

    sniffer_enabled = input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y"
    sniffer_log = "/etc/backhaul_server10.json" if sniffer_enabled else ""

    config = {
        "bind_addr": bind_addr,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "channel_size": int(input("\033[93mEnter the\033[92m channel size \033[97m(default 2048)\033[93m: \033[0m") or 2048),
        "heartbeat": int(input("\033[93mEnter the \033[92mheartbeat interval\033[97m (default 40)\033[93m: \033[0m") or 40),
        "mux_con": int(input("\033[93mEnter the \033[92mmux concurrency \033[97m(default 8)\033[93m: \033[0m") or 8),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "tls_cert" : "/etc/backhaul/server.crt",
        "tls_key" : "/etc/backhaul/server.key",
        "sniffer": sniffer_enabled,
        "sniffer_log": sniffer_log,
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("Enter web port: ") or "0"),
        "log_level": "info",
    }

    print("\033[93mChoose \033[92mForward Type:\033[0m")
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
    print("1)\033[92m Regular Port Forward\033[0m")
    print("2)\033[92m Port Range Forward\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    
    forward_type = int(input("Choose a forward type (1-2): "))

    ports = []
    if forward_type == 1:
        print("\033[92m ^ ^\033[0m")
        print("\033[92m(\033[91mO,O\033[92m)\033[0m")
        print("\033[92m(   ) \033[92mPort Forward\033[93m Menu\033[0m")
        print('\033[92m "-"\033[93m══════════════════════════════════════════════\033[0m')
        print("\033[93mChoose \033[92mForward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m TCP forward\033[0m")
        print("2)\033[93m Forward from \033[97mspecific \033[96mlocal IP\033[0m")
        print("3)\033[93m Forward to a \033[97mspecific \033[96mremote IP\033[0m")
        print("4)\033[93m Forward from \033[97mspecific \033[92mlocal IP \033[93mto a \033[96mremote IP\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")
        
        choice = int(input("Choose an option (1-4): "))

        count = int(input("\033[93mHow \033[92mmany ports \033[93mdo you want to forward \033[97m[Server 10]:\033[93m? \033[0m"))
        for i in range(1, count + 1):
            if choice == 1:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m: \033[0m")
                ports.append(f"{local_port}={remote_port}")
            elif choice == 2:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP\033[96m {i}\033[93m:  \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_port}")
            elif choice == 3:
                local_port = input(f"\033[93mEnter \033[92mlocal port\033[96m {i}\033[93m:  \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP\033[96m {i}\033[93m:  \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port\033[96m {i}\033[93m:  \033[0m")
                ports.append(f"{local_port}={remote_ip}:{remote_port}")
            elif choice == 4:
                local_ip = input(f"\033[93mEnter \033[92mlocal IP \033[96m{i}\033[93m: \033[0m")
                local_port = input(f"\033[93mEnter \033[92mlocal port \033[96m{i}\033[93m: \033[0m")
                remote_ip = input(f"\033[93mEnter \033[92mremote IP \033[96m{i}\033[93m: \033[0m")
                remote_port = input(f"\033[93mEnter \033[92mremote port \033[96m{i}\033[93m: \033[0m")
                ports.append(f"{local_ip}:{local_port}={remote_ip}:{remote_port}")

    elif forward_type == 2:
        print("\033[93m───────────────────────────────────────\033[0m")
        print("\033[93mChoose \033[92mPort Range Forward option:\033[0m")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("\033[97mThis is \033[92mServer [10]\033[97m:\033[0m")
        print("1)\033[92m Listen on all ports in the range\033[0m")
        print("2)\033[93m Forward traffic to a specific port\033[0m")
        print("3)\033[94m Forward traffic to a specific IP and port\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        range_choice = int(input("Choose an option (1-3): "))
        port_range = input("\033[93mEnter \033[92mport range \033[97m(e.g: 100-900)\033[93m: \033[0m")
        
        if range_choice == 1:
            ports.append(f"{port_range}")
        elif range_choice == 2:
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}:{forward_port}")
        elif range_choice == 3:
            forward_ip = input(f"\033[93mEnter \033[92mRemote IP\033[93m: \033[0m")
            forward_port = input(f"\033[93mEnter \033[92mRemote port\033[93m: \033[0m")
            ports.append(f"{port_range}={forward_ip}:{forward_port}")

    config["ports"] = ports

    config_path = "/usr/local/bin/backhaul/server10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[server]\n")
        for key, value in config.items():
            if key == "ports":
                config_file.write("ports = [\n")
                for port in value:
                    config_file.write(f'    "{port}",\n')
                config_file.write("]\n")
            else:
                if isinstance(value, bool):
                    config_file.write(f'{key} = {"true" if value else "false"}\n')
                elif isinstance(value, int):
                    config_file.write(f'{key} = {value}\n')
                else:
                    config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mConfig file created at {config_path}\033[0m")
    create_singleserver_service10()
    enable_backhaul_reset_server10()

#clients
def backhaul2_kharej1_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [1] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [1] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [1]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [1]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client1.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client1.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service1()
    enable_backhaul_reset_client1()

# 2
def backhaul2_kharej2_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [2] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [2] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [2]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [2]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client2.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client2.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service2()
    enable_backhaul_reset_client2()

# 3
def backhaul2_kharej3_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [3] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [3] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [3]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [3]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client3.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client3.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service3()
    enable_backhaul_reset_client3()

# 4
def backhaul2_kharej4_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [4] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [4] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [4]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [4]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client4.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client4.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service4()
    enable_backhaul_reset_client4()

# 5
def backhaul2_kharej5_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [5] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [5] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [5]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [5]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client5.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client5.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service5()
    enable_backhaul_reset_client5()

# 6
def backhaul2_kharej6_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [6] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [6] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [6]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [6]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client6.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client6.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service6()
    enable_backhaul_reset_client6()

# 7
def backhaul2_kharej7_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [7] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [7] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [7]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [7]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client7.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client7.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service7()
    enable_backhaul_reset_client7()

# 8
def backhaul2_kharej8_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [8] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [8] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [8]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [8]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client8.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client8.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service8()
    enable_backhaul_reset_client8()

# 9
def backhaul2_kharej9_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [9] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [9] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [9]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [9]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client9.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client9.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service9()
    enable_backhaul_reset_client9()

# 10

def backhaul2_kharej10_client_wssmuxmenu_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul \033[92mKharej Client Config [10] \033[93mSingle Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m───────────────────────────────────────\033[0m")

    backhaul_directory = "/usr/local/bin/backhaul"
    if os.path.exists(backhaul_directory):
        print(f"\033[93mbackhaul exists, skipping\033[0m")
    else:
        install_prerequisites()
        download_binary()

    print("\033[93m───────────────────────────────────────\033[0m")

    remote_addr = input("\033[93mEnter\033[92m IRAN \033[96mServer [10] \033[97m(IPv4/IPv6)\033[93m: \033[0m").strip()
    if ":" in remote_addr:  
        remote_addr = f"[{remote_addr}]"
    tunnel_port = input("\033[93mEnter \033[92mTunnel Port \033[97mServer [10]\033[93m : \033[0m").strip()
    remote_addr_with_port = f"{remote_addr}:{tunnel_port}"
    aggressive_pool = input("\033[93mEnable \033[92maggressive pool (\033[92mtrue\033[93m/\033[91mfalse\033[93m)? [default: false] \033[0m").strip().lower() == "true"


    config = {
        "remote_addr": remote_addr_with_port,
        "transport": "wssmux",
        "token": input("\033[93mEnter the \033[92mtoken \033[97mServer [10]\033[93m: \033[0m").strip(),
        "connection_pool": int(input("\033[93mEnter the \033[92mconnection pool\033[97m (default 8)\033[93m: \033[0m") or 8),
        "aggressive_pool": aggressive_pool,
        "keepalive_period": int(input("\033[93mEnter the \033[92mkeepalive period\033[97m (default 75)\033[93m: \033[0m") or 75),
        "dial_timeout": int(input("\033[93mEnter the \033[92mdial timeout\033[97m (default 10)\033[93m: \033[0m") or 10),
        "nodelay": input("\033[93mEnable nodelay (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "retry_interval": int(input("\033[93mEnter the \033[92mretry interval\033[97m (default 3)\033[93m: \033[0m") or 3),
        "mux_version": int(input("\033[93mEnter the \033[92mmux version \033[97m(1 or 2, default 1)\033[93m: \033[0m") or 1),
        "mux_framesize": int(input("\033[93mEnter the \033[92mmux frame size\033[97m (default 32768)\033[93m: \033[0m") or 32768),
        "mux_recievebuffer": int(input("\033[93mEnter the \033[92mmux receive buffer size\033[97m (default 4194304)\033[93m: \033[0m") or 4194304),
        "mux_streambuffer": int(input("\033[93mEnter the \033[92mmux stream buffer size \033[97m(default 65536)\033[93m: \033[0m") or 65536),
        "sniffer": input("\033[93mEnable sniffer (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y",
        "sniffer_log": "/etc/backhaul_client10.json",
        "web_port": int(input("\033[93mEnable \033[92mweb interface\033[93m (\033[92my\033[93m/\033[91mn\033[93m)? \033[0m").strip().lower() == "y" and input("\033[93mEnter interface port:\033[0m ")),
        "log_level": "info",
    }

    config_path = "/usr/local/bin/backhaul/client10.toml"
    with open(config_path, 'w') as config_file:
        config_file.write("[client]\n")
        for key, value in config.items():
            if isinstance(value, bool):
                config_file.write(f'{key} = {"true" if value else "false"}\n')
            elif isinstance(value, int):
                config_file.write(f'{key} = {value}\n')
            else:
                config_file.write(f'{key} = "{value}"\n')

    display_checkmark(f"\033[92mClient config file created at {config_path}\033[0m")
    create_singleclient_service10()
    enable_backhaul_reset_client10()

def backhaul_edit_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Multi\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93m[1]IRAN [10]Kharej\033[0m")
    print("2  \033[92m[10]IRAN [1]Kharej\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_edit_multi2()
            
    elif choice == "2":
        backhaul_edit_multi3()
            
    elif choice == "0":
        clear()
        backhaul_editlocal()
            
    else:
        print("Invalid choice.")

def backhaul_edit_multi2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Multi\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mEdit TCP\033[0m")
    print("2  \033[92mEdit TCPMux\033[0m")
    print("3  \033[93mEdit WS\033[0m")
    print("4  \033[92mEdit WSMux\033[0m")
    print("5  \033[93mEdit WSs\033[0m")
    print("6  \033[92mEdit WSsMux\033[0m")
    print("7  \033[93mEdit UDP\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_edit_tcpmulti()
            
    elif choice == "2":
        backhaul_edit_tcpmuxmulti()
            
    elif choice == "3":
        backhaul_edit_wsmulti()
            
    elif choice == "4":
        backhaul_edit_wsmuxmulti()
            
    elif choice == "5":
        backhaul_edit_wssmulti()
            
    elif choice == "6":
        backhaul_edit_wssmuxmulti()
    
    elif choice == "7":
        backhaul_edit_udpmulti()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi()
            
    else:
        print("Invalid choice.")

def backhaul_edit_multi3():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul Multi\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mEdit TCP\033[0m")
    print("2  \033[92mEdit TCPMux\033[0m")
    print("3  \033[93mEdit WS\033[0m")
    print("4  \033[92mEdit WSMux\033[0m")
    print("5  \033[93mEdit WSs\033[0m")
    print("6  \033[92mEdit WSsMux\033[0m")
    print("7  \033[93mEdit UDP\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_edit_tcpmulti2()
            
    elif choice == "2":
        backhaul_edit_tcpmuxmulti2()
            
    elif choice == "3":
        backhaul_edit_wsmulti2()
            
    elif choice == "4":
        backhaul_edit_wsmuxmulti2()
            
    elif choice == "5":
        backhaul_edit_wssmulti2()
            
    elif choice == "6":
        backhaul_edit_wssmuxmulti2()
    
    elif choice == "7":
        backhaul_edit_udpmulti2()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi()
            
    else:
        print("Invalid choice.")

def backhaul_edit_udpmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_udpmenu_editmulti()
            
    elif choice == "2":
        backhaul_kharej_client_udpmenu_editmulti()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_edit_udpmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers \033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_udpmenu_editmulti2()
            
    elif choice == "2":
        backhaul_kharej_client_udpmenu_editmulti2()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_udpmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[96m IRAN Server\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configws_multi_server1_menu(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configws_multi_server2_menu(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configws_multi_server3_menu(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configws_multi_server4_menu(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configws_multi_server5_menu(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configws_multi_server6_menu(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configws_multi_server7_menu(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configws_multi_server8_menu(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configws_multi_server9_menu(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configws_multi_server10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmulti()
            
    else:
        print("Invalid choice.")
#inja
def backhaul_kharej_client_udpmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[96m Kharej Clients\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configws_multi_client1_menu(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configws_multi_client2_menu(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configws_multi_client3_menu(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configws_multi_client4_menu(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configws_multi_client5_menu(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configws_multi_client6_menu(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configws_multi_client7_menu(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configws_multi_client8_menu(lines)
            
    elif choice == "9":
        lines = read_config_client9()
        configws_multi_client9_menu(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configws_multi_client10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmulti()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_udpmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[96m IRAN Servers\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configws_multi_server1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configws_multi_server2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configws_multi_server3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configws_multi_server4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configws_multi_server5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configws_multi_server6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configws_multi_server7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configws_multi_server8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configws_multi_server9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configws_multi_server10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmulti2()
            
    else:
        print("Invalid choice.")
#inja
def backhaul_kharej_client_udpmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m UDP\033[96m Kharej Client Configs\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configws_multi_client1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configws_multi_client2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configws_multi_client3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configws_multi_client4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configws_multi_client5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configws_multi_client6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configws_multi_client7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configws_multi_client8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_client9()
        configws_multi_client9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configws_multi_client10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmulti2()
            
    else:
        print("Invalid choice.")

def backhaul_edit_tcpmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmenu_editmulti()
            
    elif choice == "2":
        backhaul_kharej_client_tcpmenu_editmulti()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_edit_tcpmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers \033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmenu_editmulti2()
            
    elif choice == "2":
        backhaul_kharej_client_tcpmenu_editmulti2()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_tcpmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[96m IRAN Server\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configws_multi_server1_menu(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configws_multi_server2_menu(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configws_multi_server3_menu(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configws_multi_server4_menu(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configws_multi_server5_menu(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configws_multi_server6_menu(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configws_multi_server7_menu(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configws_multi_server8_menu(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configws_multi_server9_menu(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configws_multi_server10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmulti()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_tcpmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[96m Kharej Clients\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configws_multi_client1_menu(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configws_multi_client2_menu(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configws_multi_client3_menu(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configws_multi_client4_menu(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configws_multi_client5_menu(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configws_multi_client6_menu(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configws_multi_client7_menu(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configws_multi_client8_menu(lines)
            
    elif choice == "9":
        lines = read_config_client9()
        configws_multi_client9_menu(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configws_multi_client10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmulti()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_tcpmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[96m IRAN Servers\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configws_multi_server1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configws_multi_server2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configws_multi_server3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configws_multi_server4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configws_multi_server5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configws_multi_server6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configws_multi_server7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configws_multi_server8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configws_multi_server9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configws_multi_server10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmulti2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_tcpmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCP\033[96m Kharej Client Configs\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configws_multi_client1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configws_multi_client2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configws_multi_client3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configws_multi_client4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configws_multi_client5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configws_multi_client6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configws_multi_client7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configws_multi_client8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_client9()
        configws_multi_client9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configws_multi_client10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmulti2()
            
    else:
        print("Invalid choice.")

CONFIG_SERVER1 = "/usr/local/bin/backhaul/server1.toml"
SERVICE_SERVER1 = "backhaul-server1"
CONFIG_SERVER2 = "/usr/local/bin/backhaul/server2.toml"
SERVICE_SERVER2 = "backhaul-server2"
CONFIG_SERVER3 = "/usr/local/bin/backhaul/server3.toml"
SERVICE_SERVER3 = "backhaul-server3"
CONFIG_SERVER4 = "/usr/local/bin/backhaul/server4.toml"
SERVICE_SERVER4 = "backhaul-server4"
CONFIG_SERVER5 = "/usr/local/bin/backhaul/server5.toml"
SERVICE_SERVER5 = "backhaul-server5"
CONFIG_SERVER6 = "/usr/local/bin/backhaul/server6.toml"
SERVICE_SERVER6 = "backhaul-server6"
CONFIG_SERVER7 = "/usr/local/bin/backhaul/server7.toml"
SERVICE_SERVER7 = "backhaul-server7"
CONFIG_SERVER8 = "/usr/local/bin/backhaul/server8.toml"
SERVICE_SERVER8 = "backhaul-server8"
CONFIG_SERVER9 = "/usr/local/bin/backhaul/server9.toml"
SERVICE_SERVER9 = "backhaul-server9"
CONFIG_SERVER10 = "/usr/local/bin/backhaul/server10.toml"
SERVICE_SERVER10 = "backhaul-server10"
CONFIG_CLIENT1 = "/usr/local/bin/backhaul/client1.toml"
SERVICE_CLIENT1 = "backhaul-client1"
CONFIG_CLIENT2 = "/usr/local/bin/backhaul/client2.toml"
SERVICE_CLIENT2 = "backhaul-client2"
CONFIG_CLIENT3 = "/usr/local/bin/backhaul/client3.toml"
SERVICE_CLIENT3 = "backhaul-client3"
CONFIG_CLIENT4 = "/usr/local/bin/backhaul/client4.toml"
SERVICE_CLIENT4 = "backhaul-client4"
CONFIG_CLIENT5 = "/usr/local/bin/backhaul/client5.toml"
SERVICE_CLIENT5 = "backhaul-client5"
CONFIG_CLIENT6 = "/usr/local/bin/backhaul/client6.toml"
SERVICE_CLIENT6 = "backhaul-client6"
CONFIG_CLIENT7 = "/usr/local/bin/backhaul/client7.toml"
SERVICE_CLIENT7 = "backhaul-client7"
CONFIG_CLIENT8 = "/usr/local/bin/backhaul/client8.toml"
SERVICE_CLIENT8 = "backhaul-client8"
CONFIG_CLIENT9 = "/usr/local/bin/backhaul/client9.toml"
SERVICE_CLIENT9 = "backhaul-client9"
CONFIG_CLIENT10 = "/usr/local/bin/backhaul/client10.toml"
SERVICE_CLIENT10 = "backhaul-client10"

def read_config_server1():
    with open(CONFIG_SERVER1, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server1(lines):
    with open(CONFIG_SERVER1, 'w') as file:
        file.writelines(lines)

def restart_service_server1():
    os.system(f"systemctl restart {SERVICE_SERVER1}")

def read_config_server2():
    with open(CONFIG_SERVER2, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server2(lines):
    with open(CONFIG_SERVER2, 'w') as file:
        file.writelines(lines)

def restart_service_server2():
    os.system(f"systemctl restart {SERVICE_SERVER2}")

def read_config_server3():
    with open(CONFIG_SERVER3, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server3(lines):
    with open(CONFIG_SERVER3, 'w') as file:
        file.writelines(lines)

def restart_service_server3():
    os.system(f"systemctl restart {SERVICE_SERVER3}")

def read_config_server4():
    with open(CONFIG_SERVER4, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server4(lines):
    with open(CONFIG_SERVER4, 'w') as file:
        file.writelines(lines)

def restart_service_server4():
    os.system(f"systemctl restart {SERVICE_SERVER4}")

def read_config_server5():
    with open(CONFIG_SERVER5, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server5(lines):
    with open(CONFIG_SERVER5, 'w') as file:
        file.writelines(lines)

def restart_service_server5():
    os.system(f"systemctl restart {SERVICE_SERVER5}")

def read_config_server6():
    with open(CONFIG_SERVER6, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server6(lines):
    with open(CONFIG_SERVER6, 'w') as file:
        file.writelines(lines)

def restart_service_server6():
    os.system(f"systemctl restart {SERVICE_SERVER6}")

def read_config_server7():
    with open(CONFIG_SERVER7, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server7(lines):
    with open(CONFIG_SERVER7, 'w') as file:
        file.writelines(lines)

def restart_service_server7():
    os.system(f"systemctl restart {SERVICE_SERVER7}")

def read_config_server8():
    with open(CONFIG_SERVER8, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server8(lines):
    with open(CONFIG_SERVER8, 'w') as file:
        file.writelines(lines)

def restart_service_server8():
    os.system(f"systemctl restart {SERVICE_SERVER8}")

def read_config_server9():
    with open(CONFIG_SERVER9, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server9(lines):
    with open(CONFIG_SERVER9, 'w') as file:
        file.writelines(lines)

def restart_service_server9():
    os.system(f"systemctl restart {SERVICE_SERVER9}")

def read_config_server10():
    with open(CONFIG_SERVER10, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_server10(lines):
    with open(CONFIG_SERVER10, 'w') as file:
        file.writelines(lines)

def restart_service_server10():
    os.system(f"systemctl restart {SERVICE_SERVER10}")

def read_config_client1():
    with open(CONFIG_CLIENT1, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client1(lines):
    with open(CONFIG_CLIENT1, 'w') as file:
        file.writelines(lines)

def restart_service_client1():
    os.system(f"systemctl restart {SERVICE_CLIENT1}")

def read_config_client2():
    with open(CONFIG_CLIENT2, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client2(lines):
    with open(CONFIG_CLIENT2, 'w') as file:
        file.writelines(lines)

def restart_service_client2():
    os.system(f"systemctl restart {SERVICE_CLIENT2}")

def read_config_client3():
    with open(CONFIG_CLIENT3, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client3(lines):
    with open(CONFIG_CLIENT3, 'w') as file:
        file.writelines(lines)

def restart_service_client3():
    os.system(f"systemctl restart {SERVICE_CLIENT3}")

def read_config_client4():
    with open(CONFIG_CLIENT4, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client4(lines):
    with open(CONFIG_CLIENT4, 'w') as file:
        file.writelines(lines)

def restart_service_client4():
    os.system(f"systemctl restart {SERVICE_CLIENT4}")

def read_config_client5():
    with open(CONFIG_CLIENT5, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client5(lines):
    with open(CONFIG_CLIENT5, 'w') as file:
        file.writelines(lines)

def restart_service_client5():
    os.system(f"systemctl restart {SERVICE_CLIENT5}")

def read_config_client6():
    with open(CONFIG_CLIENT6, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client6(lines):
    with open(CONFIG_CLIENT6, 'w') as file:
        file.writelines(lines)

def restart_service_client6():
    os.system(f"systemctl restart {SERVICE_CLIENT6}")

def read_config_client7():
    with open(CONFIG_CLIENT7, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client7(lines):
    with open(CONFIG_CLIENT7, 'w') as file:
        file.writelines(lines)

def restart_service_client7():
    os.system(f"systemctl restart {SERVICE_CLIENT7}")

def read_config_client8():
    with open(CONFIG_CLIENT8, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client8(lines):
    with open(CONFIG_CLIENT8, 'w') as file:
        file.writelines(lines)

def restart_service_client8():
    os.system(f"systemctl restart {SERVICE_CLIENT8}")

def read_config_client9():
    with open(CONFIG_CLIENT9, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client9(lines):
    with open(CONFIG_CLIENT9, 'w') as file:
        file.writelines(lines)

def restart_service_client9():
    os.system(f"systemctl restart {SERVICE_CLIENT9}")

def read_config_client10():
    with open(CONFIG_CLIENT10, 'r') as file:
        lines = file.readlines()
    return lines

def write_config_client10(lines):
    with open(CONFIG_CLIENT10, 'w') as file:
        file.writelines(lines)

def restart_service_client10():
    os.system(f"systemctl restart {SERVICE_CLIENT10}")

def bind_addr_server1(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mConfig [1] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind_addr_server2(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mConfig [2] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind_addr_server3(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mConfig [3] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind_addr_server4(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mConfig [4] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind_addr_server5(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mConfig [5] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind_addr_server6(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mConfig [6] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind_addr_server7(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mConfig [7] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind_addr_server8(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mConfig [8] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind_addr_server9(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mConfig [9] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind_addr_server10(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mConfig [10] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind2_addr_server1(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mServer [1] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind2_addr_server2(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mServer [2] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind2_addr_server3(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mServer [3] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind2_addr_server4(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mServer [4] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind2_addr_server5(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mServer [5] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind2_addr_server6(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mServer [6] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind2_addr_server7(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mServer [7] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind2_addr_server8(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mServer [8] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind2_addr_server9(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mServer [9] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def bind2_addr_server10(lines):
    for i, line in enumerate(lines):
        if line.startswith("bind_addr"):
            current_value = line.split("=")[-1].strip().replace('"', '')
            ip, current_port = current_value.split(":")
            
            new_port = input(f"\033[93mEnter \033[92mnew \033[96mTunnel port \033[97mServer [10] \033[97m(current: {current_port})\033[93m: \033[0m").strip()
            if new_port:
                lines[i] = f'bind_addr = "{ip}:{new_port}"\n'
            break
    return lines

def display_server1(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Config [1] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_server2(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Config [2] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_server3(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Config [3] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_server4(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Config [4] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_server5(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Config [5] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_server6(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Config [6] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_server7(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Config [7] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_server8(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Config [8] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_server9(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Config [9] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_server10(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer Config [10] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_server1(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer [1] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_server2(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer [2] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_server3(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer [3] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_server4(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer [4] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_server5(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer [5] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_server6(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer [6] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_server7(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer [7] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_server8(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer [8] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_server9(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer [9] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_server10(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mServer [10] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Server] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def restart_service_server1():
    os.system(f"systemctl restart {SERVICE_SERVER1}")

def restart_service_server2():
    os.system(f"systemctl restart {SERVICE_SERVER2}")

def restart_service_server3():
    os.system(f"systemctl restart {SERVICE_SERVER3}")

def restart_service_server4():
    os.system(f"systemctl restart {SERVICE_SERVER4}")

def restart_service_server5():
    os.system(f"systemctl restart {SERVICE_SERVER5}")

def restart_service_server6():
    os.system(f"systemctl restart {SERVICE_SERVER6}")

def restart_service_server7():
    os.system(f"systemctl restart {SERVICE_SERVER7}")

def restart_service_server8():
    os.system(f"systemctl restart {SERVICE_SERVER8}")

def restart_service_server9():
    os.system(f"systemctl restart {SERVICE_SERVER9}")

def restart_service_server10():
    os.system(f"systemctl restart {SERVICE_SERVER10}")

def restart_service_client1():
    os.system(f"systemctl restart {SERVICE_CLIENT1}")

def restart_service_client2():
    os.system(f"systemctl restart {SERVICE_CLIENT2}")

def restart_service_client3():
    os.system(f"systemctl restart {SERVICE_CLIENT3}")

def restart_service_client4():
    os.system(f"systemctl restart {SERVICE_CLIENT4}")

def restart_service_client5():
    os.system(f"systemctl restart {SERVICE_CLIENT5}")

def restart_service_client6():
    os.system(f"systemctl restart {SERVICE_CLIENT6}")

def restart_service_client7():
    os.system(f"systemctl restart {SERVICE_CLIENT7}")

def restart_service_client8():
    os.system(f"systemctl restart {SERVICE_CLIENT8}")

def restart_service_client9():
    os.system(f"systemctl restart {SERVICE_CLIENT9}")

def restart_service_client10():
    os.system(f"systemctl restart {SERVICE_CLIENT10}")

def display_client1(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient [1] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_client2(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient [2] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_client3(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient [3] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_client4(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient [4] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_client5(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient [5] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_client6(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient [6] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_client7(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient [7] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_client8(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient [8] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_client9(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient [9] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display_client10(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mClient [10] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_client1(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfig [1] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_client2(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfig [2] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_client3(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfig [3] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_client4(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfig [4] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_client5(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfig [5] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_client6(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfig [6] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_client7(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfig [7] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_client8(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfig [8] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_client9(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfig [9] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def display2_client10(lines):
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[93mConfig [10] Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════\033[0m')
    print("\033[93m╭──────────────────\033[92m[Client] Configuration\033[93m─────────────────────╮\033[0m")
    for line in lines:
        print(line.strip())
    print("\033[93m╰─────────────────────────────────────────────────────────────╯\033[0m")

def configws_multi_server1_menu2(lines):
    while True:
        display2_server1(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [1]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server1(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server1(lines)
            restart_service_server1()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server2_menu2(lines):
    while True:
        display2_server2(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [2]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server2(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server2(lines)
            restart_service_server2()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server3_menu2(lines):
    while True:
        display2_server3(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [3]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server3(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server3(lines)
            restart_service_server3()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server4_menu2(lines):
    while True:
        display2_server4(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [4]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server4(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server4(lines)
            restart_service_server4()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server5_menu2(lines):
    while True:
        display2_server5(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [5]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server5(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server5(lines)
            restart_service_server5()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server6_menu2(lines):
    while True:
        display2_server6(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [6]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server6(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server6(lines)
            restart_service_server6()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server7_menu2(lines):
    while True:
        display2_server7(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [7]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server7(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server7(lines)
            restart_service_server7()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server8_menu2(lines):
    while True:
        display2_server8(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [8]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server8(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server8(lines)
            restart_service_server8()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server9_menu2(lines):
    while True:
        display2_server9(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [9]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server9(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server9(lines)
            restart_service_server9()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server10_menu2(lines):
    while True:
        display2_server10(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [10]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server10(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server10(lines)
            restart_service_server10()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#client
def configws_multi_client1_menu2(lines):
    while True:
        display2_client1(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client1(lines)
            restart_service_client1()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_client2_menu2(lines):
    while True:
        display2_client2(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client2(lines)
            restart_service_client2()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#3
def configws_multi_client3_menu2(lines):
    while True:
        display2_client3(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client3(lines)
            restart_service_client3()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#4
def configws_multi_client4_menu2(lines):
    while True:
        display2_client4(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client4(lines)
            restart_service_client4()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#5
def configws_multi_client5_menu2(lines):
    while True:
        display2_client5(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client5(lines)
            restart_service_client5()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#6
def configws_multi_client6_menu2(lines):
    while True:
        display2_client6(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client6(lines)
            restart_service_client6()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#7
def configws_multi_client7_menu2(lines):
    while True:
        display2_client7(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client7(lines)
            restart_service_client7()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#8
def configws_multi_client8_menu2(lines):
    while True:
        display2_client8(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client8(lines)
            restart_service_client8()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#9
def configws_multi_client9_menu2(lines):
    while True:
        display2_client9(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client9(lines)
            restart_service_client9()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#10
def configws_multi_client10_menu2(lines):
    while True:
        display2_client10(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client10(lines)
            restart_service_client10()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server1_menu(lines):
    while True:
        display_server1(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [1]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server1(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server1(lines)
            restart_service_server1()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server2_menu(lines):
    while True:
        display_server2(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [2]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server2(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server2(lines)
            restart_service_server2()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server3_menu(lines):
    while True:
        display_server3(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [3]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server3(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server3(lines)
            restart_service_server3()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server4_menu(lines):
    while True:
        display_server4(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [4]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server4(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server4(lines)
            restart_service_server4()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server5_menu(lines):
    while True:
        display_server5(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [5]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server5(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server5(lines)
            restart_service_server5()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server6_menu(lines):
    while True:
        display_server6(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [6]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server6(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server6(lines)
            restart_service_server6()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server7_menu(lines):
    while True:
        display_server7(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [7]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server7(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server7(lines)
            restart_service_server7()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server8_menu(lines):
    while True:
        display_server8(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [8]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server8(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server8(lines)
            restart_service_server8()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server9_menu(lines):
    while True:
        display_server9(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [9]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server9(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server9(lines)
            restart_service_server9()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_server10_menu(lines):
    while True:
        display_server10(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [10]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server10(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server10(lines)
            restart_service_server10()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#client
def configws_multi_client1_menu(lines):
    while True:
        display_client1(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client1(lines)
            restart_service_client1()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configws_multi_client2_menu(lines):
    while True:
        display_client2(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client2(lines)
            restart_service_client2()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#3
def configws_multi_client3_menu(lines):
    while True:
        display_client3(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client3(lines)
            restart_service_client3()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#4
def configws_multi_client4_menu(lines):
    while True:
        display_client4(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client4(lines)
            restart_service_client4()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#5
def configws_multi_client5_menu(lines):
    while True:
        display_client5(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client5(lines)
            restart_service_client5()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#6
def configws_multi_client6_menu(lines):
    while True:
        display_client6(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client6(lines)
            restart_service_client6()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#7
def configws_multi_client7_menu(lines):
    while True:
        display_client7(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client7(lines)
            restart_service_client7()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#8
def configws_multi_client8_menu(lines):
    while True:
        display_client8(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client8(lines)
            restart_service_client8()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#9
def configws_multi_client9_menu(lines):
    while True:
        display_client9(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client9(lines)
            restart_service_client9()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#10
def configws_multi_client10_menu(lines):
    while True:
        display_client10(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client10(lines)
            restart_service_client10()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def backhaul_edit_wsmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmenu_editmulti()
            
    elif choice == "2":
        backhaul_kharej_client_wsmenu_editmulti()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_edit_wsmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers \033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmenu_editmulti2()
            
    elif choice == "2":
        backhaul_kharej_client_wsmenu_editmulti2()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi3()
            
    else:
        print("Invalid choice.") 

def backhaul_iran_server_wsmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[96m IRAN Server\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configws_multi_server1_menu(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configws_multi_server2_menu(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configws_multi_server3_menu(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configws_multi_server4_menu(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configws_multi_server5_menu(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configws_multi_server6_menu(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configws_multi_server7_menu(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configws_multi_server8_menu(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configws_multi_server9_menu(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configws_multi_server10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wsmulti()
        
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wsmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[96m Kharej Clients\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configws_multi_client1_menu(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configws_multi_client2_menu(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configws_multi_client3_menu(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configws_multi_client4_menu(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configws_multi_client5_menu(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configws_multi_client6_menu(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configws_multi_client7_menu(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configws_multi_client8_menu(lines)
            
    elif choice == "9":
        lines = read_config_client9()
        configws_multi_client9_menu(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configws_multi_client10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wsmulti()
            
    else:
        print("Invalid choice.")


def backhaul_iran_server_wsmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[96m IRAN Servers\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServers [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServers [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServers [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServers [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServers [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServers [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServers [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServers [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServers [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServers [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configws_multi_server1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configws_multi_server2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configws_multi_server3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configws_multi_server4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configws_multi_server5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configws_multi_server6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configws_multi_server7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configws_multi_server8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configws_multi_server9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configws_multi_server10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wsmulti2()
        
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wsmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WS\033[96m Kharej Client Configs\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configws_multi_client1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configws_multi_client2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configws_multi_client3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configws_multi_client4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configws_multi_client5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configws_multi_client6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configws_multi_client7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configws_multi_client8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_client9()
        configws_multi_client9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configws_multi_client10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wsmulti2()
            
    else:
        print("Invalid choice.")


def backhaul_edit_tcpmuxmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmuxmenu_editmulti()
            
    elif choice == "2":
        backhaul_kharej_client_tcpmuxmenu_editmulti()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_edit_tcpmuxmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers \033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_tcpmuxmenu_editmulti2()
            
    elif choice == "2":
        backhaul_kharej_client_tcpmuxmenu_editmulti2()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_tcpmuxmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[96m IRAN Server\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configwsmux_multi_server1_menu(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configwsmux_multi_server2_menu(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configwsmux_multi_server3_menu(lines)
        
    elif choice == "4":
        lines = read_config_server4()
        configwsmux_multi_server4_menu(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configwsmux_multi_server5_menu(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configwsmux_multi_server6_menu(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configwsmux_multi_server7_menu(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configwsmux_multi_server8_menu(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configwsmux_multi_server9_menu(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configwsmux_multi_server10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmuxmulti()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_tcpmuxmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[96m Kharej Clients\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configwsmux_multi_client1_menu(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configwsmux_multi_client2_menu(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configwsmux_multi_client3_menu(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configwsmux_multi_client4_menu(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configwsmux_multi_client5_menu(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configwsmux_multi_client6_menu(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configwsmux_multi_client7_menu(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configwsmux_multi_client8_menu(lines)
        
    elif choice == "9":
        lines = read_config_client9()
        configwsmux_multi_client9_menu(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configwsmux_multi_client10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmuxmulti()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_tcpmuxmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[96m IRAN Servers\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configwsmux_multi_server1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configwsmux_multi_server2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configwsmux_multi_server3_menu2(lines)
        
    elif choice == "4":
        lines = read_config_server4()
        configwsmux_multi_server4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configwsmux_multi_server5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configwsmux_multi_server6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configwsmux_multi_server7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configwsmux_multi_server8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configwsmux_multi_server9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configwsmux_multi_server10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmuxmulti2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_tcpmuxmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m TCPMux\033[96m Kharej Client Configs\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfigt [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configwsmux_multi_client1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configwsmux_multi_client2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configwsmux_multi_client3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configwsmux_multi_client4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configwsmux_multi_client5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configwsmux_multi_client6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configwsmux_multi_client7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configwsmux_multi_client8_menu2(lines)
        
    elif choice == "9":
        lines = read_config_client9()
        configwsmux_multi_client9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configwsmux_multi_client10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_tcpmuxmulti2()
            
    else:
        print("Invalid choice.")

def configwsmux_multi_server1_menu(lines):
    while True:
        display_server1(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [1]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server1(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server1(lines)
            restart_service_server1()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#2
def configwsmux_multi_server2_menu(lines):
    while True:
        display_server2(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [2]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server2(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server2(lines)
            restart_service_server2()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#3
def configwsmux_multi_server3_menu(lines):
    while True:
        display_server3(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [3]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server3(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server3(lines)
            restart_service_server3()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configwsmux_multi_server4_menu(lines):
    while True:
        display_server4(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [4]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server4(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server4(lines)
            restart_service_server4()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#5
def configwsmux_multi_server5_menu(lines):
    while True:
        display_server5(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [5]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server5(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server5(lines)
            restart_service_server5()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")
#6
def configwsmux_multi_server6_menu(lines):
    while True:
        display_server6(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [6]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server6(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server6(lines)
            restart_service_server6()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#7
def configwsmux_multi_server7_menu(lines):
    while True:
        display_server7(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [7]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server7(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server7(lines)
            restart_service_server7()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")
#8
def configwsmux_multi_server8_menu(lines):
    while True:
        display_server8(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [8]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server8(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server8(lines)
            restart_service_server8()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#9
def configwsmux_multi_server9_menu(lines):
    while True:
        display_server9(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [9]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server9(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server9(lines)
            restart_service_server9()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#10
def configwsmux_multi_server10_menu(lines):
    while True:
        display_server10(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [10]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server10(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server10(lines)
            restart_service_server10()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configwsmux_multi_client1_menu(lines):
    while True:
        display_client1(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client1(lines)
            restart_service_client1()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#2
def configwsmux_multi_client2_menu(lines):
    while True:
        display_client2(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client2(lines)
            restart_service_client2()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#3
def configwsmux_multi_client3_menu(lines):
    while True:
        display_client3(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client3(lines)
            restart_service_client3()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#4
def configwsmux_multi_client4_menu(lines):
    while True:
        display_client4(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client4(lines)
            restart_service_client4()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#5
def configwsmux_multi_client5_menu(lines):
    while True:
        display_client5(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client5(lines)
            restart_service_client5()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#6
def configwsmux_multi_client6_menu(lines):
    while True:
        display_client6(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client6(lines)
            restart_service_client6()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configwsmux_multi_client7_menu(lines):
    while True:
        display_client7(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client7(lines)
            restart_service_client7()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")
#8
def configwsmux_multi_client8_menu(lines):
    while True:
        display_client8(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client8(lines)
            restart_service_client8()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")
#9
def configwsmux_multi_client9_menu(lines):
    while True:
        display_client9(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client9(lines)
            restart_service_client9()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#10
def configwsmux_multi_client10_menu(lines):
    while True:
        display_client10(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client10(lines)
            restart_service_client10()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configwsmux_multi_server1_menu2(lines):
    while True:
        display2_server1(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [1]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server1(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server1(lines)
            restart_service_server1()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#2
def configwsmux_multi_server2_menu2(lines):
    while True:
        display2_server2(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [2]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server2(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server2(lines)
            restart_service_server2()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#3
def configwsmux_multi_server3_menu2(lines):
    while True:
        display2_server3(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [3]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server3(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server3(lines)
            restart_service_server3()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configwsmux_multi_server4_menu2(lines):
    while True:
        display2_server4(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [4]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server4(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server4(lines)
            restart_service_server4()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#5
def configwsmux_multi_server5_menu2(lines):
    while True:
        display2_server5(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [5]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server5(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server5(lines)
            restart_service_server5()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")
#6
def configwsmux_multi_server6_menu2(lines):
    while True:
        display2_server6(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [6]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server6(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server6(lines)
            restart_service_server6()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#7
def configwsmux_multi_server7_menu2(lines):
    while True:
        display2_server7(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [7]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server7(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server7(lines)
            restart_service_server7()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")
#8
def configwsmux_multi_server8_menu2(lines):
    while True:
        display2_server8(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [8]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server8(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server8(lines)
            restart_service_server8()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#9
def configwsmux_multi_server9_menu2(lines):
    while True:
        display2_server9(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [9]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server9(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server9(lines)
            restart_service_server9()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#10
def configwsmux_multi_server10_menu2(lines):
    while True:
        display2_server10(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")
        current_mux_con = current_value(lines, "mux_con")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [10]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mToggle \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mToggle \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print(f"9. \033[93mModify \033[92mmux_con\033[96m [Current: {current_mux_con}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"13. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("14. \033[92mSave and Restart\033[0m")
        print("15. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server10(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_con \033[93m (current: {current_mux_con}): \033[0m")
            lines = edit_numeric(lines, "mux_con", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "11":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "13":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "14":
            write_config_server10(lines)
            restart_service_server10()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configwsmux_multi_client1_menu2(lines):
    while True:
        display2_client1(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client1(lines)
            restart_service_client1()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#2
def configwsmux_multi_client2_menu2(lines):
    while True:
        display2_client2(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client2(lines)
            restart_service_client2()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#3
def configwsmux_multi_client3_menu2(lines):
    while True:
        display2_client3(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client3(lines)
            restart_service_client3()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#4
def configwsmux_multi_client4_menu2(lines):
    while True:
        display2_client4(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client4(lines)
            restart_service_client4()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#5
def configwsmux_multi_client5_menu2(lines):
    while True:
        display2_client5(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client5(lines)
            restart_service_client5()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#6
def configwsmux_multi_client6_menu2(lines):
    while True:
        display2_client6(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client6(lines)
            restart_service_client6()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def configwsmux_multi_client7_menu2(lines):
    while True:
        display2_client7(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client7(lines)
            restart_service_client7()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")
#8
def configwsmux_multi_client8_menu2(lines):
    while True:
        display2_client8(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client8(lines)
            restart_service_client8()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")
#9
def configwsmux_multi_client9_menu2(lines):
    while True:
        display2_client9(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client9(lines)
            restart_service_client9()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#10
def configwsmux_multi_client10_menu2(lines):
    while True:
        display2_client10(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_mux_version = current_value(lines, "mux_version")
        current_mux_framesize = current_value(lines, "mux_framesize")
        current_mux_recievebuffer = current_value(lines, "mux_recievebuffer")
        current_mux_streambuffer = current_value(lines, "mux_streambuffer")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print(f"9. \033[93mModify \033[92mmux_version\033[96m [Current: {current_mux_version}]\033[0m")
        print(f"10. \033[93mModify \033[92mmux_framesize\033[96m [Current: {current_mux_framesize}]\033[0m")
        print(f"11. \033[93mModify \033[92mmux_recievebuffer\033[96m [Current: {current_mux_recievebuffer}]\033[0m")
        print(f"12. \033[93mModify \033[92mmux_streambuffer\033[96m [Current: {current_mux_streambuffer}]\033[0m")
        print("13. \033[92mSave and Restart\033[0m")
        print("14. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            new_value = input(f"\033[93mEnter \033[92mnew mux_version \033[93m (current: {current_mux_version}): \033[0m")
            lines = edit_numeric(lines, "mux_version", new_value)
        elif choice == "10":
            new_value = input(f"\033[93mEnter \033[92mnew mux_framesize \033[93m (current: {current_mux_framesize}): \033[0m")
            lines = edit_numeric(lines, "mux_framesize", new_value)
        elif choice == "11`":
            new_value = input(f"\033[93mEnter \033[92mnew mux_recievebuffer \033[93m (current: {current_mux_recievebuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_recievebuffer", new_value)
        elif choice == "12":
            new_value = input(f"\033[93mEnter \033[92mnew mux_streambuffer \033[93m (current: {current_mux_streambuffer}): \033[0m")
            lines = edit_numeric(lines, "mux_streambuffer", new_value)
        elif choice == "13":
            write_config_client10(lines)
            restart_service_client10()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "15":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")
            
# ws mux
def backhaul_edit_wsmuxmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WsMux\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmuxmenu_editmulti()
            
    elif choice == "2":
        backhaul_kharej_client_wsmuxmenu_editmulti()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_edit_wsmuxmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WsMux\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers\033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wsmuxmenu_editmulti2()
            
    elif choice == "2":
        backhaul_kharej_client_wsmuxmenu_editmulti2()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wsmuxmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WsMux\033[96m IRAN Server\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configwsmux_multi_server1_menu(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configwsmux_multi_server2_menu(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configwsmux_multi_server3_menu(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configwsmux_multi_server4_menu(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configwsmux_multi_server5_menu(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configwsmux_multi_server6_menu(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configwsmux_multi_server7_menu(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configwsmux_multi_server8_menu(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configwsmux_multi_server9_menu(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configwsmux_multi_server10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wsmuxmulti()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wsmuxmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WsMux\033[96m Kharej Clients\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configwsmux_multi_client1_menu(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configwsmux_multi_client2_menu(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configwsmux_multi_client3_menu(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configwsmux_multi_client4_menu(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configwsmux_multi_client5_menu(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configwsmux_multi_client6_menu(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configwsmux_multi_client7_menu(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configwsmux_multi_client8_menu(lines)
            
    elif choice == "9":
        lines = read_config_client9()
        configwsmux_multi_client9_menu(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configwsmux_multi_client10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wsmuxmulti()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wsmuxmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WsMux\033[96m IRAN Servers\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configwsmux_multi_server1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configwsmux_multi_server2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configwsmux_multi_server3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configwsmux_multi_server4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configwsmux_multi_server5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configwsmux_multi_server6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configwsmux_multi_server7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configwsmux_multi_server8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configwsmux_multi_server9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configwsmux_multi_server10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wsmuxmulti2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wsmuxmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WsMux\033[96m Kharej Client Configs\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configwsmux_multi_client1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configwsmux_multi_client2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configwsmux_multi_client3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configwsmux_multi_client4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configwsmux_multi_client5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configwsmux_multi_client6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configwsmux_multi_client7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configwsmux_multi_client8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_client9()
        configwsmux_multi_client9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configwsmux_multi_client10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wsmuxmulti2()
            
    else:
        print("Invalid choice.")

#wss mux
def backhaul_edit_wssmuxmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmuxmenu_editmulti()
            
    elif choice == "2":
        backhaul_kharej_client_wssmuxmenu_editmulti()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_edit_wssmuxmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers \033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmuxmenu_editmulti2()
            
    elif choice == "2":
        backhaul_kharej_client_wssmuxmenu_editmulti2()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wssmuxmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[96m IRAN Server\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configwsmux_multi_server1_menu(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configwsmux_multi_server2_menu(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configwsmux_multi_server3_menu(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configwsmux_multi_server4_menu(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configwsmux_multi_server5_menu(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configwsmux_multi_server6_menu(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configwsmux_multi_server7_menu(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configwsmux_multi_server8_menu(lines)
        
    elif choice == "9":
        lines = read_config_server9()
        configwsmux_multi_server9_menu(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configwsmux_multi_server10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wssmuxmulti()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wssmuxmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[96m Kharej Clients\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configwsmux_multi_client1_menu(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configwsmux_multi_client2_menu(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configwsmux_multi_client3_menu(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configwsmux_multi_client4_menu(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configwsmux_multi_client5_menu(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configwsmux_multi_client6_menu(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configwsmux_multi_client7_menu(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configwsmux_multi_client8_menu(lines)
        
    elif choice == "9":
        lines = read_config_client9()
        configwsmux_multi_client9_menu(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configwsmux_multi_client10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wssmuxmulti()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wssmuxmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[96m IRAN Servers\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configwsmux_multi_server1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configwsmux_multi_server2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configwsmux_multi_server3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configwsmux_multi_server4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configwsmux_multi_server5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configwsmux_multi_server6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_server7()
        configwsmux_multi_server7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configwsmux_multi_server8_menu2(lines)
        
    elif choice == "9":
        lines = read_config_server9()
        configwsmux_multi_server9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configwsmux_multi_server10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wssmuxmulti2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wssmuxmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSsMux\033[96m Kharej Client Configs\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configwsmux_multi_client1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configwsmux_multi_client2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configwsmux_multi_client3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configwsmux_multi_client4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configwsmux_multi_client5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configwsmux_multi_client6_menu2(lines)
            
    elif choice == "7":
        lines = read_config_client7()
        configwsmux_multi_client7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configwsmux_multi_client8_menu2(lines)
        
    elif choice == "9":
        lines = read_config_client9()
        configwsmux_multi_client9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configwsmux_multi_client10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wssmuxmulti2()
            
    else:
        print("Invalid choice.")

def backhaul_edit_wssmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server \033[97mConfigs\033[0m")
    print("2  \033[92mKharej Clients\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmenu_editmulti()
            
    elif choice == "2":
        backhaul_kharej_client_wssmenu_editmulti()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi2()
            
    else:
        print("Invalid choice.")

def backhaul_edit_wssmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Servers \033[0m")
    print("2  \033[92mKharej Client \033[97mConfigs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        backhaul_iran_server_wssmenu_editmulti2()
            
    elif choice == "2":
        backhaul_kharej_client_wssmenu_editmulti2()
            
    elif choice == "0":
        clear()
        backhaul_edit_multi3()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wssmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[96m IRAN Server\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mConfig [1]\033[0m")
    print("2  \033[93mIRAN \033[97mConfig [2]\033[0m")
    print("3  \033[92mIRAN \033[97mConfig [3]\033[0m")
    print("4  \033[93mIRAN \033[97mConfig [4]\033[0m")
    print("5  \033[93mIRAN \033[97mConfig [5]\033[0m")
    print("6  \033[92mIRAN \033[97mConfig [6]\033[0m")
    print("7  \033[93mIRAN \033[97mConfig [7]\033[0m")
    print("8  \033[93mIRAN \033[97mConfig [8]\033[0m")
    print("9  \033[92mIRAN \033[97mConfig [9]\033[0m")
    print("10 \033[93mIRAN \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configwss_multi_server1_menu(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configwss_multi_server2_menu(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configwss_multi_server3_menu(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configwss_multi_server4_menu(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configwss_multi_server5_menu(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configwss_multi_server6_menu(lines)
        
    elif choice == "7":
        lines = read_config_server7()
        configwss_multi_server7_menu(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configwss_multi_server8_menu(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configwss_multi_server9_menu(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configwss_multi_server10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wssmulti()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wssmenu_editmulti():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[96m Kharej Clients\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mClient [1]\033[0m")
    print("2  \033[93mKharej \033[97mClient [2]\033[0m")
    print("3  \033[92mKharej \033[97mClient [3]\033[0m")
    print("4  \033[93mKharej \033[97mClient [4]\033[0m")
    print("5  \033[93mKharej \033[97mClient [5]\033[0m")
    print("6  \033[92mKharej \033[97mClient [6]\033[0m")
    print("7  \033[93mKharej \033[97mClient [7]\033[0m")
    print("8  \033[93mKharej \033[97mClient [8]\033[0m")
    print("9  \033[92mKharej \033[97mClient [9]\033[0m")
    print("10 \033[93mKharej \033[97mClient [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configwss_multi_client1_menu(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configwss_multi_client2_menu(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configwss_multi_client3_menu(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configwss_multi_client4_menu(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configwss_multi_client5_menu(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configwss_multi_client6_menu(lines)
        
    elif choice == "7":
        lines = read_config_client7()
        configwss_multi_client7_menu(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configwss_multi_client8_menu(lines)
            
    elif choice == "9":
        lines = read_config_client9()
        configwss_multi_client9_menu(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configwss_multi_client10_menu(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wssmulti()
            
    else:
        print("Invalid choice.")

def backhaul_iran_server_wssmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[96m IRAN Servers\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN \033[97mServer [1]\033[0m")
    print("2  \033[93mIRAN \033[97mServer [2]\033[0m")
    print("3  \033[92mIRAN \033[97mServer [3]\033[0m")
    print("4  \033[93mIRAN \033[97mServer [4]\033[0m")
    print("5  \033[93mIRAN \033[97mServer [5]\033[0m")
    print("6  \033[92mIRAN \033[97mServer [6]\033[0m")
    print("7  \033[93mIRAN \033[97mServer [7]\033[0m")
    print("8  \033[93mIRAN \033[97mServer [8]\033[0m")
    print("9  \033[92mIRAN \033[97mServer [9]\033[0m")
    print("10 \033[93mIRAN \033[97mServer [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_server1()
        configwss_multi_server1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_server2()
        configwss_multi_server2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_server3()
        configwss_multi_server3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_server4()
        configwss_multi_server4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_server5()
        configwss_multi_server5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_server6()
        configwss_multi_server6_menu2(lines)
        
    elif choice == "7":
        lines = read_config_server7()
        configwss_multi_server7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_server8()
        configwss_multi_server8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_server9()
        configwss_multi_server9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_server10()
        configwss_multi_server10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wssmulti2()
            
    else:
        print("Invalid choice.")

def backhaul_kharej_client_wssmenu_editmulti2():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m WSs\033[96m Kharej Client Configs\033[93m Edit Menu\033[0m")
    print('\033[92m "-"\033[93m════════════════════════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej \033[97mConfig [1]\033[0m")
    print("2  \033[93mKharej \033[97mConfig [2]\033[0m")
    print("3  \033[92mKharej \033[97mConfig [3]\033[0m")
    print("4  \033[93mKharej \033[97mConfig [4]\033[0m")
    print("5  \033[93mKharej \033[97mConfig [5]\033[0m")
    print("6  \033[92mKharej \033[97mConfig [6]\033[0m")
    print("7  \033[93mKharej \033[97mConfig [7]\033[0m")
    print("8  \033[93mKharej \033[97mConfig [8]\033[0m")
    print("9  \033[92mKharej \033[97mConfig [9]\033[0m")
    print("10 \033[93mKharej \033[97mConfig [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        lines = read_config_client1()
        configwss_multi_client1_menu2(lines)
            
    elif choice == "2":
        lines = read_config_client2()
        configwss_multi_client2_menu2(lines)
            
    elif choice == "3":
        lines = read_config_client3()
        configwss_multi_client3_menu2(lines)
            
    elif choice == "4":
        lines = read_config_client4()
        configwss_multi_client4_menu2(lines)
            
    elif choice == "5":
        lines = read_config_client5()
        configwss_multi_client5_menu2(lines)
            
    elif choice == "6":
        lines = read_config_client6()
        configwss_multi_client6_menu2(lines)
        
    elif choice == "7":
        lines = read_config_client7()
        configwss_multi_client7_menu2(lines)
            
    elif choice == "8":
        lines = read_config_client8()
        configwss_multi_client8_menu2(lines)
            
    elif choice == "9":
        lines = read_config_client9()
        configwss_multi_client9_menu2(lines)
            
    elif choice == "10":
        lines = read_config_client10()
        configwss_multi_client10_menu2(lines)
            
    elif choice == "0":
        clear()
        backhaul_edit_wssmulti2()
            
    else:
        print("Invalid choice.")

#wss servers
def configwss_multi_server1_menu(lines):
    while True:
        display_server1(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [1]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server1(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server1(lines)
            restart_service_server1()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#2
def configwss_multi_server2_menu(lines):
    while True:
        display_server2(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [2]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server2(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server2(lines)
            restart_service_server2()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#3
def configwss_multi_server3_menu(lines):
    while True:
        display_server3(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [3]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server3(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server3(lines)
            restart_service_server3()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#4
def configwss_multi_server4_menu(lines):
    while True:
        display_server4(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [4]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server4(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server4(lines)
            restart_service_server4()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#5
def configwss_multi_server5_menu(lines):
    while True:
        display_server5(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [5]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server5(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server5(lines)
            restart_service_server5()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#6
def configwss_multi_server6_menu(lines):
    while True:
        display_server6(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [6]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server6(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server6(lines)
            restart_service_server6()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#7
def configwss_multi_server7_menu(lines):
    while True:
        display_server7(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [7]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server7(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server7(lines)
            restart_service_server7()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#8
def configwss_multi_server8_menu(lines):
    while True:
        display_server8(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [8]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server8(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server8(lines)
            restart_service_server8()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#9
def configwss_multi_server9_menu(lines):
    while True:
        display_server9(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [9]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server9(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server9(lines)
            restart_service_server9()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#10
def configwss_multi_server10_menu(lines):
    while True:
        display_server10(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mConfig [10]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind_addr_server10(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server10(lines)
            restart_service_server10()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#clients
def configwss_multi_client1_menu(lines):
    while True:
        display_client1(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client1(lines)
            restart_service_client1()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#2
def configwss_multi_client2_menu(lines):
    while True:
        display_client2(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client2(lines)
            restart_service_client2()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#3
def configwss_multi_client3_menu(lines):
    while True:
        display_client3(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client3(lines)
            restart_service_client3()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#4
def configwss_multi_client4_menu(lines):
    while True:
        display_client4(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client4(lines)
            restart_service_client4()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#5
def configwss_multi_client5_menu(lines):
    while True:
        display_client5(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client5(lines)
            restart_service_client5()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#6
def configwss_multi_client6_menu(lines):
    while True:
        display_client6(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client6(lines)
            restart_service_client6()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#7
def configwss_multi_client7_menu(lines):
    while True:
        display_client7(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client7(lines)
            restart_service_client7()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#8
def configwss_multi_client8_menu(lines):
    while True:
        display_client8(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client8(lines)
            restart_service_client8()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

#9
def configwss_multi_client9_menu(lines):
    while True:
        display_client9(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client9(lines)
            restart_service_client9()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def clear():
    os.system("clear")

#10
def configwss_multi_client10_menu(lines):
    while True:
        display_client10(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mConfig [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mConfig [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client10(lines)
            restart_service_client10()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi2()
        else:
            print("\n\033[91mWrong choice, try again.")

def configwss_multi_server1_menu2(lines):
    while True:
        display2_server1(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [1]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server1(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server1(lines)
            restart_service_server1()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#2
def configwss_multi_server2_menu2(lines):
    while True:
        display2_server2(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [2]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server2(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server2(lines)
            restart_service_server2()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi()
        else:
            print("\n\033[91mWrong choice, try again.")

#3
def configwss_multi_server3_menu2(lines):
    while True:
        display2_server3(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [3]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server3(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server3(lines)
            restart_service_server3()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#4
def configwss_multi_server4_menu2(lines):
    while True:
        display2_server4(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [4]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server4(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server4(lines)
            restart_service_server4()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#5
def configwss_multi_server5_menu2(lines):
    while True:
        display2_server5(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [5]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server5(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server5(lines)
            restart_service_server5()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#6
def configwss_multi_server6_menu2(lines):
    while True:
        display2_server6(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [6]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server6(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server6(lines)
            restart_service_server6()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#7
def configwss_multi_server7_menu2(lines):
    while True:
        display2_server7(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [7]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server7(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server7(lines)
            restart_service_server7()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#8
def configwss_multi_server8_menu2(lines):
    while True:
        display2_server8(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [8]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server8(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server8(lines)
            restart_service_server8()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#9
def configwss_multi_server9_menu2(lines):
    while True:
        display2_server9(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [9]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server9(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server9(lines)
            restart_service_server9()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#10
def configwss_multi_server10_menu2(lines):
    while True:
        display2_server10(lines)
        current_bind_addr = current_value(lines, "bind_addr")
        current_token = current_value(lines, "token")
        current_channel_size = current_value(lines, "channel_size")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_heartbeat = current_value(lines, "heartbeat")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mTunnel port \033[97mServer [10]\033[96m [Current: {current_bind_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mchannel_size\033[96m [Current: {current_channel_size}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mheartbeat\033[96m [Current: {current_heartbeat}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print("8. \033[93mEdit/Add \033[92mports\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = bind2_addr_server10(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew channel_size \033[93m (current: {current_channel_size}): \033[0m")
            lines = edit_numeric(lines, "channel_size", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew heartbeat interval \033[93m (current: {current_heartbeat}): \033[0m")
            lines = edit_numeric(lines, "heartbeat", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            lines = edit_ports(lines)
        elif choice == "9":
            write_config_server10(lines)
            restart_service_server10()
            display_checkmark("\n\033[92mConfiguration saved and service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#clients
def configwss_multi_client1_menu2(lines):
    while True:
        display2_client1(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [1]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [1]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client1(lines)
            restart_service_client1()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#2
def configwss_multi_client2_menu2(lines):
    while True:
        display2_client2(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [2]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [2]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client2(lines)
            restart_service_client2()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#3
def configwss_multi_client3_menu2(lines):
    while True:
        display2_client3(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [3]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [3]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client3(lines)
            restart_service_client3()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#4
def configwss_multi_client4_menu2(lines):
    while True:
        display2_client4(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [4]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [4]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client4(lines)
            restart_service_client4()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#5
def configwss_multi_client5_menu2(lines):
    while True:
        display2_client5(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [5]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [5]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client5(lines)
            restart_service_client5()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#6
def configwss_multi_client6_menu2(lines):
    while True:
        display2_client6(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [6]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [6]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client6(lines)
            restart_service_client6()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#7
def configwss_multi_client7_menu2(lines):
    while True:
        display2_client7(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [7]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [7]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client7(lines)
            restart_service_client7()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#8
def configwss_multi_client8_menu2(lines):
    while True:
        display2_client8(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [8]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [8]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client8(lines)
            restart_service_client8()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

#9
def configwss_multi_client9_menu2(lines):
    while True:
        display2_client9(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [9]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [9]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client9(lines)
            restart_service_client9()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")

def clear():
    os.system("clear")

#10
def configwss_multi_client10_menu2(lines):
    while True:
        display2_client10(lines)
        current_remote_addr = current_value(lines, "remote_addr")
        current_token = current_value(lines, "token")
        current_connection_pool = current_value(lines, "connection_pool")
        current_keepalive_period = current_value(lines, "keepalive_period")
        current_dial_timeout = current_value(lines, "dial_timeout")
        current_retry_interval = current_value(lines, "retry_interval")

        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print(f"1. \033[93mModify \033[92mIran Server IP\033[0m and \033[92mport\033[96m [Current: {current_remote_addr}]\033[0m")
        print(f"2. \033[93mModify \033[92mtoken \033[97mServer [10]\033[96m [Current: {current_token}]\033[0m")
        print(f"3. \033[93mModify \033[92mconnection_pool\033[96m [Current: {current_connection_pool}]\033[0m")
        print(f"4. \033[93mModify \033[92mkeepalive_period\033[96m [Current: {current_keepalive_period}]\033[0m")
        print(f"5. \033[93mModify \033[92mdial_timeout\033[96m [Current: {current_dial_timeout}]\033[0m")
        print(f"6. \033[93mModify \033[92mnodelay\033[96m [Current: {current_value(lines, 'nodelay')}]\033[0m")
        print(f"7. \033[93mModify \033[92msniffer\033[96m [Current: {current_value(lines, 'sniffer')}]\033[0m")
        print(f"8. \033[93mModify \033[92mretry_interval\033[96m [Current: {current_retry_interval}]\033[0m")
        print("9. \033[92mSave and Restart\033[0m")
        print("10. \033[94mBack to the edit menu\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        choice = input("\nEnter your choice: ").strip()

        if choice == "1":
            lines = remote_addr(lines)
        elif choice == "2":
            new_value = input(f"\033[93mEnter \033[92mnew token \033[97mServer [10]\033[93m (current: {current_token}): \033[0m")
            lines = edit_value(lines, "token", new_value)
        elif choice == "3":
            new_value = input(f"\033[93mEnter \033[92mnew connection_pool \033[93m (current: {current_connection_pool}): \033[0m")
            lines = edit_numeric(lines, "connection_pool", new_value)
        elif choice == "4":
            new_value = input(f"\033[93mEnter \033[92mnew keepalive_period \033[93m (current: {current_keepalive_period}): \033[0m")
            lines = edit_numeric(lines, "keepalive_period", new_value)
        elif choice == "5":
            new_value = input(f"\033[93mEnter \033[92mnew dial_timeout \033[93m (current: {current_dial_timeout}): \033[0m")
            lines = edit_numeric(lines, "dial_timeout", new_value)
        elif choice == "6":
            lines = toggle_option(lines, "nodelay")
        elif choice == "7":
            lines = toggle_option(lines, "sniffer")
        elif choice == "8":
            new_value = input(f"\033[93mEnter \033[92mnew retry_interval \033[93m (current: {current_retry_interval}): \033[0m")
            lines = edit_numeric(lines, "retry_interval", new_value)
        elif choice == "9":
            write_config_client10(lines)
            restart_service_client10()
            display_checkmark("\n\033[92mConfiguration saved and client service restarted\033[0m")
            
        elif choice == "10":
            backhaul_edit_multi3()
        else:
            print("\n\033[91mWrong choice, try again.")


def edit_backhaul_reset_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m Reset Time\033[93m Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mSingle\033[0m")
    print("2  \033[92mMulti\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        edit_backhaul_reset_single()
    elif choice == "2":
        edit_backhaul_reset_multi()
    elif choice == "0":
        backhaul_menu()
    else:
        print("\033[91mInvalid choice, please try again.\033[0m")

def edit_backhaul_reset_single():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m Reset Time\033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server\033[0m")
    print("2  \033[92mKharej Client\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        edit_backhaul_reset_server()
    elif choice == "2":
        edit_backhaul_reset_client()
    elif choice == "3":
        edit_backhaul_reset_menu()
    else:
        print("\033[91mInvalid choice, please try again.\033[0m")

def edit_backhaul_reset_server():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_server(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")


def edit_backhaul_reset_client():
    print("\033[93m───────────────────────────────────────\033[0m")
    display_notification("\033[93mQuestion time !\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    enable_reset = input(
        "\033[93mDo you want to edit \033[96mBackhaul \033[92mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m"
    ).lower()
    if enable_reset in ["yes", "y"]:
        print("\033[93m╭───────────────────────────────────────╮\033[0m")
        print("1. \033[92mHour\033[0m")
        print("2. \033[93mMinute\033[0m")
        print("\033[93m╰───────────────────────────────────────╯\033[0m")

        time_unit_choice = input("\033[93mEnter your choice :\033[0m ").strip()
        if time_unit_choice == "1":
            time_unit = "hour"
        elif time_unit_choice == "2":
            time_unit = "minute"
        else:
            print("\033[91mWrong choice\033[0m")
            return

        time_value = input(
            "\033[93mEnter the \033[92mdesired input\033[93m:\033[0m "
        ).strip()
        interval_seconds = (
            int(time_value) * 3600 if time_unit == "hour" else int(time_value) * 60
        )
        reset_backhaul_client(interval_seconds)
        print("\033[93m────────────────────────────────────────\033[0m")



def edit_backhaul_reset_multi():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m Reset Time\033[93m Single Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN[1]  Kharej [10]\033[0m")
    print("2  \033[92mIRAN[10] Kharej [1]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")

    if choice == "1":
        edit_backhaul_reset_iranserver1()
    elif choice == "2":
        edit_backhaul_reset_iranserver10()
    elif choice == "3":
        edit_backhaul_reset_menu()
    else:
        print("\033[91mInvalid choice, please try again.\033[0m")

def edit_backhaul_reset_iranserver1():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m Reset Time\033[93m multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej Client [1]\033[0m")
    print("2  \033[93mKharej Client [2]\033[0m")
    print("3  \033[93mKharej Client [3]\033[0m")
    print("4  \033[92mKharej Client [4]\033[0m")
    print("5  \033[93mKharej Client [5]\033[0m")
    print("6  \033[93mKharej Client [6]\033[0m")
    print("7  \033[93mKharej Client [7]\033[0m")
    print("8  \033[92mKharej Client [8]\033[0m")
    print("9  \033[93mKharej Client [9]\033[0m")
    print("10 \033[93mKharej Client [10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11  \033[97mIRAN Configs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        enable_backhaul_reset_client1()
    elif choice == "2":
        enable_backhaul_reset_client2()
    elif choice == "3":
        enable_backhaul_reset_client3()
    elif choice == "4":
        enable_backhaul_reset_client4()
    elif choice == "5":
        enable_backhaul_reset_client5()
    elif choice == "6":
        enable_backhaul_reset_client6()
    elif choice == "7":
        enable_backhaul_reset_client7()
    elif choice == "8":
        enable_backhaul_reset_client8()
    elif choice == "9":
        enable_backhaul_reset_client9()
    elif choice == "10":
        enable_backhaul_reset_client10()
    elif choice == "11":
        enable_backhaul_reset_iranserver_menu()
    elif choice == "0":
        edit_backhaul_reset_multi()
    else:
        print("\033[91mInvalid choice, please try again.\033[0m")

def enable_backhaul_reset_iranserver_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m Reset Time\033[93m multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Config [1]\033[0m")
    print("2  \033[93mIRAN Config [2]\033[0m")
    print("3  \033[93mIRAN Config [3]\033[0m")
    print("4  \033[92mIRAN Config [4]\033[0m")
    print("5  \033[93mIRAN Config [5]\033[0m")
    print("6  \033[93mIRAN Config [6]\033[0m")
    print("7  \033[93mIRAN Config [7]\033[0m")
    print("8  \033[92mIRAN Config [8]\033[0m")
    print("9  \033[93mIRAN Config [9]\033[0m")
    print("10 \033[93mIRAN Config [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        enable_backhaul_reset_server1()
    elif choice == "2":
        enable_backhaul_reset_server2()
    elif choice == "3":
        enable_backhaul_reset_server3()
    elif choice == "4":
        enable_backhaul_reset_server4()
    elif choice == "5":
        enable_backhaul_reset_server5()
    elif choice == "6":
        enable_backhaul_reset_server6()
    elif choice == "7":
        enable_backhaul_reset_server7()
    elif choice == "8":
        enable_backhaul_reset_server8()
    elif choice == "9":
        enable_backhaul_reset_server9()
    elif choice == "10":
        enable_backhaul_reset_server10()
    elif choice == "0":
        edit_backhaul_reset_iranserver1()
    else:
        print("\033[91mInvalid choice, please try again.\033[0m")

def edit_backhaul_reset_iranserver10():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m Reset Time\033[93m multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mIRAN Server [1]\033[0m")
    print("2  \033[93mIRAN Server [2]\033[0m")
    print("3  \033[93mIRAN Server [3]\033[0m")
    print("4  \033[92mIRAN Server [4]\033[0m")
    print("5  \033[93mIRAN Server [5]\033[0m")
    print("6  \033[93mIRAN Server [6]\033[0m")
    print("7  \033[93mIRAN Server [7]\033[0m")
    print("8  \033[92mIRAN Server [8]\033[0m")
    print("9  \033[93mIRAN Server [9]\033[0m")
    print("10 \033[93mIRAN Server [10]\033[0m")
    print("\033[93m───────────────────────────────────────\033[0m")
    print("11  \033[97mKharej Configs\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        enable_backhaul_reset_server1()
    elif choice == "2":
        enable_backhaul_reset_server2()
    elif choice == "3":
        enable_backhaul_reset_server3()
    elif choice == "4":
        enable_backhaul_reset_server4()
    elif choice == "5":
        enable_backhaul_reset_server5()
    elif choice == "6":
        enable_backhaul_reset_server6()
    elif choice == "7":
        enable_backhaul_reset_server7()
    elif choice == "8":
        enable_backhaul_reset_server8()
    elif choice == "9":
        enable_backhaul_reset_server9()
    elif choice == "10":
        enable_backhaul_reset_server10()
    elif choice == "11":
        enable_backhaul_reset_kharejclients_menu()
    elif choice == "0":
        edit_backhaul_reset_multi()
    else:
        print("\033[91mInvalid choice, please try again.\033[0m")

def enable_backhaul_reset_kharejclients_menu():
    os.system("clear")
    print("\033[92m ^ ^\033[0m")
    print("\033[92m(\033[91mO,O\033[92m)\033[0m")
    print("\033[92m(   ) \033[92mBackhaul\033[96m Reset Time\033[93m multi Menu\033[0m")
    print('\033[92m "-"\033[93m══════════════════════════════════\033[0m')
    print("\033[93m╭───────────────────────────────────────╮\033[0m")
    print("\033[93mChoose what to do:\033[0m")
    print("1  \033[93mKharej Config [1]\033[0m")
    print("2  \033[93mKharej Config [2]\033[0m")
    print("3  \033[93mKharej Config [3]\033[0m")
    print("4  \033[92mKharej Config [4]\033[0m")
    print("5  \033[93mKharej Config [5]\033[0m")
    print("6  \033[93mKharej Config [6]\033[0m")
    print("7  \033[93mKharej Config [7]\033[0m")
    print("8  \033[92mKharej Config [8]\033[0m")
    print("9  \033[93mKharej Config [9]\033[0m")
    print("10 \033[93mKharej Config [10]\033[0m")
    print("0. \033[94mback to the previous menu\033[0m")
    print("\033[93m╰───────────────────────────────────────╯\033[0m")
    choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
    if choice == "1":
        enable_backhaul_reset_client1()
    elif choice == "2":
        enable_backhaul_reset_client2()
    elif choice == "3":
        enable_backhaul_reset_client3()
    elif choice == "4":
        enable_backhaul_reset_client4()
    elif choice == "5":
        enable_backhaul_reset_client5()
    elif choice == "6":
        enable_backhaul_reset_client6()
    elif choice == "7":
        enable_backhaul_reset_client7()
    elif choice == "8":
        enable_backhaul_reset_client8()
    elif choice == "9":
        enable_backhaul_reset_client9()
    elif choice == "10":
        enable_backhaul_reset_client10()
    elif choice == "0":
        edit_backhaul_reset_iranserver10()
    else:
        print("\033[91mInvalid choice, please try again.\033[0m")


backhaul_menu()
