├── requirements.txt ├── README-fa.md ├── README.md └── flow.py /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.28.1 -------------------------------------------------------------------------------- /README-fa.md: -------------------------------------------------------------------------------- 1 | # انتخاب Flow مرزبان 2 | 3 | ## قابلیت ها 4 | - تغییر Flow برای تمامی یوزر ها به صورت همزمان 5 | 6 | # نحوه استفاده 💡 7 | 8 | ابتدا API مرزبان را فعال کنید ، 9 | میتوانید با اضافه کردن DOCS=True اون رو فعال کنید 10 | 11 | قبل از اجرای باید این متغیرها را در فایل تغییر دهید، می توانید این کار را با nano در لینوکس و VSCode در ویندوز انجام دهید. 12 | ```bash 13 | username = 'username' 14 | password = 'password' 15 | DOMAIN = 'domain.com' 16 | PORT = '12345' 17 | ``` 18 | 19 | ## Linux 20 | 21 | ```bash 22 | git clone https://github.com/M03ED/Marzban_Flow_Select 23 | cd Marzban_Flow_Select 24 | wget -qO- https://bootstrap.pypa.io/get-pip.py | python3 - 25 | python3 -m pip install -r requirements.txt 26 | python3 flow.py 27 | ``` 28 | 29 | ## Windows 30 | 1. پروژه رو دانلود و اون رو اکسترکت کنید 31 | 2. حال Python رو نصب کنید ( نسخه 3.10 یا بالاتر ) 32 | 3. یک cmd باز کنید 33 | 4. دستورات زیر رو اجرا کنید 34 | ``` 35 | curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 36 | python get-pip.py 37 | pip install -r requirements.txt 38 | ``` 39 | حالا با این دستور میتونید اسکریپت رو اجرا کنید 40 | ``` 41 | python flow.py 42 | ``` 43 | 44 | # مشارکت 45 | اگر اشکالی می بینید یا ایده ای برای بهتر کردن اسکریپت دارید، می توانید یک Pull Request باز کنید و تغییرات را Commit کنید. 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Marzban_Flow_Select 2 | 3 |

4 | فارسی 5 |

6 | 7 | ## Features 8 | - Change Flow For All Users At Same Time 9 | 10 | # How To Use 💡 11 | 12 | First Enable Api In Your Marzban , 13 | You Can Enable It By Adding DOCS=True To Your env File 14 | 15 | You Need To Change These Variables In File Before You Run It , You Can Do It With nano in Linux And VSCode In Windows 16 | 17 | ```bash 18 | username = 'username' 19 | password = 'password' 20 | DOMAIN = 'domain.com' 21 | PORT = '12345' 22 | ``` 23 | 24 | ## Linux 25 | 26 | ```bash 27 | git clone https://github.com/M03ED/Marzban_Flow_Select 28 | cd Marzban_Flow_Select 29 | wget -qO- https://bootstrap.pypa.io/get-pip.py | python3 - 30 | python3 -m pip install -r requirements.txt 31 | python3 flow.py 32 | ``` 33 | 34 | ## Windows 35 | 1. Download Project And Extract It 36 | 2. Install Python +3.10 37 | 3. Open cmd 38 | 4. Run These Commands 39 | ``` 40 | curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 41 | python get-pip.py 42 | pip install -r requirements.txt 43 | ``` 44 | Now You Can Run Script With This Command 45 | ``` 46 | python flow.py 47 | ``` 48 | 49 | # Contributors 50 | If You See A Bug Or You Have Idea To Make Script Better You Can Make Pull Request And Commit The Changes 51 | -------------------------------------------------------------------------------- /flow.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import logging 3 | 4 | DOMAIN = 'domain.com' # Replace with your actual domain 5 | PORT = 12345 # Replace with the actual port number 6 | username = 'username' # Replace with your actual username 7 | password = 'password' # Replace with your actual password 8 | protocol = 'vless' # Replace with your actual protocol 9 | flow = "xtls-rprx-vision" # Replace with your actual flow 10 | 11 | def get_access_token(username, password): 12 | url = f'https://{DOMAIN}:{PORT}/api/admin/token' 13 | data = { 14 | 'username': username, 15 | 'password': password 16 | } 17 | 18 | try: 19 | response = requests.post(url, data=data) 20 | response.raise_for_status() 21 | access_token = response.json()['access_token'] 22 | return access_token 23 | except requests.exceptions.RequestException as e: 24 | logging.error(f'Error occurred while obtaining access token: {e}') 25 | return None 26 | 27 | def get_users_list(access_token): 28 | url = f'https://{DOMAIN}:{PORT}/api/users' 29 | headers = { 30 | 'accept': 'application/json', 31 | 'Authorization': f'Bearer {access_token}' 32 | } 33 | 34 | try: 35 | response = requests.get(url, headers=headers) 36 | response.raise_for_status() 37 | users_list = response.json() 38 | return users_list 39 | except requests.exceptions.RequestException as e: 40 | logging.error(f'Error occurred while retrieving users list: {e}') 41 | return None 42 | 43 | def flow_select(access_token, username, protocol, flow): 44 | url = f'https://{DOMAIN}:{PORT}/api/user/{username}' 45 | headers = { 46 | 'accept': 'application/json', 47 | 'Authorization': f'Bearer {access_token}', 48 | 'Content-Type': 'application/json' 49 | } 50 | 51 | try: 52 | response = requests.get(url, headers=headers) 53 | response.raise_for_status() 54 | user_details = response.json() 55 | 56 | if user_details['proxies'][protocol]['flow'] != flow: 57 | 58 | user_details['proxies'][protocol]['flow'] = flow 59 | # Modify 'links' and 'subscription_url' 60 | user_details['links'] = [] 61 | user_details['subscription_url'] = "" 62 | if user_details['status'] != "disabled": 63 | user_details['status'] = "active" 64 | 65 | # Create a list of keys to remove 66 | keys_to_remove = [] 67 | for inbound_protocol in user_details.get('inbounds', {}): 68 | if not user_details['inbounds'][inbound_protocol]: 69 | keys_to_remove.append(inbound_protocol) 70 | 71 | # Remove the keys outside of the loop 72 | for key in keys_to_remove: 73 | user_details['inbounds'].pop(key, None) 74 | user_details['proxies'].pop(key, None) 75 | 76 | response = requests.put(url, json=user_details, headers=headers) 77 | response.raise_for_status() 78 | return True 79 | else: 80 | logging.error(f'flow for user {username} already is {flow}') 81 | return False 82 | except requests.exceptions.RequestException as e: 83 | logging.error(f'Error occurred while modifying user: {e}') 84 | return False 85 | 86 | # Configure logging settings 87 | logging.basicConfig(filename='script_log.log', level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s') 88 | 89 | access_token = get_access_token(username, password) 90 | if access_token: 91 | users_list = get_users_list(access_token) 92 | if users_list: 93 | for user in users_list['users']: 94 | # Modify 'flow' for vless proxies 95 | if 'proxies' in user and protocol in user['proxies']: 96 | if flow_select(access_token, user['username'], protocol, flow): 97 | print(f"User {user['username']} flow updated successfully.") 98 | else: 99 | print(f'flow for user {username} already is {flow}') 100 | print("All users modified successfully.") 101 | else: 102 | print("Failed to retrieve the users list.") 103 | else: 104 | print("Failed to obtain the access token.") 105 | --------------------------------------------------------------------------------