Created
April 20, 2025 10:57
-
-
Save Nusab19/cbc861cc66b707e54c1e5dfb2441d795 to your computer and use it in GitHub Desktop.
Code to disable access policy in cloudflare pages
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
#!/usr/bin/env python3 | |
import requests | |
import sys | |
# Configure these variables with your actual Cloudflare account details | |
ACCOUNT_ID = "your_account_id_here" # eg. "6a2784243169ac723308b65ae743e5ca" | |
API_TOKEN = "your_api_token_here" # eg. "a-FJVHPa04_9TS0L5RjYIcTgtLfc8NwP9PNqyd6m" | |
def main(): | |
# Check if credentials are set | |
if ACCOUNT_ID == "your_account_id_here" or API_TOKEN == "your_api_token_here": | |
print("ERROR: Please update the ACCOUNT_ID and API_TOKEN variables with your actual credentials.") | |
sys.exit(1) | |
# Common headers for all requests | |
headers = { | |
"Authorization": f"Bearer {API_TOKEN}", | |
"Content-Type": "application/json" | |
} | |
# Get all access apps | |
print(f"Fetching Access apps for account: {ACCOUNT_ID}...") | |
url = f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/access/apps" | |
try: | |
response = requests.get(url, headers=headers) | |
response.raise_for_status() | |
data = response.json() | |
if not data["success"]: | |
print(f"ERROR: API request failed with errors: {data['errors']}") | |
sys.exit(1) | |
apps = data["result"] | |
print(f"Found {len(apps)} Access app(s).") | |
# Delete each app | |
for app in apps: | |
app_uid = app["uid"] | |
app_name = app["name"] | |
print(f"Deleting Access app: {app_name} (UID: {app_uid})...") | |
delete_url = f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/access/apps/{app_uid}" | |
delete_response = requests.delete(delete_url, headers=headers) | |
delete_data = delete_response.json() | |
if delete_data["success"]: | |
print(f"✓ Successfully deleted '{app_name}'") | |
else: | |
print(f"✗ Failed to delete '{app_name}': {delete_data['errors']}") | |
print("\nDeletion process complete.") | |
except requests.exceptions.RequestException as e: | |
print(f"ERROR: Request failed: {e}") | |
sys.exit(1) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment