Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict Peer API #536

Open
sohrabp72 opened this issue Nov 29, 2024 · 3 comments
Open

Restrict Peer API #536

sohrabp72 opened this issue Nov 29, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@sohrabp72
Copy link

sohrabp72 commented Nov 29, 2024

based on this link, I tried 2 times to restrict some peers, but it seems the API in the background works as Delete Peer method, it removes peers instead of just restricting them.

Untitled

All these sections' descriptions are the same for deletion.

@sohrabp72 sohrabp72 added the bug Something isn't working label Nov 29, 2024
@donaldzou
Copy link
Owner

Hi! May I see how did you send the request please?

@sohrabp72
Copy link
Author

sohrabp72 commented Nov 29, 2024

Hi! May I see how did you send the request please?

Sure.
here is it:

def restrict(peer_name, uid):
    """
    تابعی برای اعمال محدودیت (restrict) بر روی یک peer.
    """
    # دریافت کلید عمومی (public key) از دیتابیس
    public_key = get_public_key_from_db(peer_name,uid)

    if not public_key:
        print(f"❌ کلید عمومی برای peer {peer_name} پیدا نشد.")
        return

    # ساخت URL برای درخواست restrict به API
    api_url = f"https://webpanel/api/restrictPeers/{configName}"  # آدرس API که restrict را انجام می‌دهد

    # داده‌هایی که باید ارسال شوند
    data = {
        "peers": [public_key]
    }

    try:
        # ارسال درخواست HTTP POST به API برای restrict کردن
        response = requests.post(api_url, headers=HEADERS, json=data)

        # بررسی پاسخ API
        if response.status_code == 200:
            print(f"✅ Restrict اعمال شد برای {peer_name} در UID {uid}")
            print(response.json().get('message'))
        else:
            print(f"❌ خطا در اعمال restrict برای {peer_name}: {response.text}")
    except requests.exceptions.RequestException as e:
        print(f"❌ خطا در ارتباط با API: {e}")

@sohrabp72
Copy link
Author

sohrabp72 commented Nov 29, 2024

I realized something weird, if the Peer I'm going to restrict is in a configuration where its name starts with wg, it will be restricted, if it is in a configuration in which its name starts with numbers like 213512, the peer will be removed, and won't restrict.

Edit: I tested and I can confirm it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants