|
import requests |
|
from bs4 import BeautifulSoup |
|
import json |
|
import re |
|
|
|
BASE_URL = "https://www.dssw.co.uk/reference/authorization-rights/" |
|
|
|
def get_rights_links(): |
|
response = requests.get(BASE_URL) |
|
soup = BeautifulSoup(response.content, 'html.parser') |
|
paths = [a['href'] for a in soup.find_all('a', href=True) if not '/' in a['href'] and not ':' in a['href']] |
|
return paths |
|
|
|
def get_right_details(path): |
|
response = requests.get(BASE_URL + path) |
|
soup = BeautifulSoup(response.content, 'html.parser') |
|
# Extracting the JSON details |
|
bad_json_text = soup.find_all('pre')[0].text |
|
return bad_json_text |
|
|
|
def main(): |
|
rights_paths = get_rights_links() |
|
rights_with_authenticate_user_false = [] |
|
rights_with_allow_root_true = [] |
|
rights_with_session_owner_true = [] |
|
|
|
for path in rights_paths: |
|
details = get_right_details(path) |
|
if "'authenticate-user' : 'false'" in details: |
|
if "'allow-root' : 'true'" in details: |
|
group = "run as root" |
|
elif "'session-owner' : 'true'" in details: |
|
group = "session owner" |
|
else: |
|
group = re.search(r"'group' : '([\w\-]+)',", details, re.MULTILINE).group(1) |
|
rights_with_authenticate_user_false.append(f"{path} ({group})") |
|
|
|
if "'allow-root' : 'true'" in details: |
|
rights_with_allow_root_true.append(path) |
|
if "'session-owner' : 'true'" in details: |
|
rights_with_session_owner_true.append(path) |
|
|
|
print("Rights with 'authenticate-user': 'false':", ", ".join(rights_with_authenticate_user_false)) |
|
print("Rights with 'allow-root': 'true':", ", ".join(rights_with_allow_root_true)) |
|
print("Rights with 'session-owner': 'true':", ", ".join(rights_with_session_owner_true)) |
|
|
|
if __name__ == "__main__": |
|
main() |