├── README.md ├── dep.sh ├── install.sh ├── kol.sh └── run.sh /README.md: -------------------------------------------------------------------------------- 1 | ## اسکریپت مدیریت ورکر کلودفلر با ترموکس 2 | ## Cloudflare worker management script with Termux 3 | --- 4 | 5 | ### برای نصب این ورکر میتونید با استفاده از اسکریپت سلکتور و گزینه ۷ نصب و اجراش کنید ، بعد از نصب اولیه با استفاده از گزینه ۸ میتونید اجراش کنید 6 | #### درتمام مراحل نصب و استفاده فیلترشکن شما باید روشن باشه 7 | --- 8 | #### اسکریپت سلکتور : 9 | 10 | 11 | ``` 12 | bash <(curl -fsSL https://raw.githubusercontent.com/Kolandone/Selector/main/Sel.sh) 13 | ``` 14 | 15 | --- 16 | ## قابلیت ها : 17 | ### ۱ - مشاهده لیست ورکر ها و در صورت نیاز دریافت لینک مشاهده ورکر 18 | ### ۲ - حذف ورکر مورد نظر 19 | ### ۳ - ساخت ورکر با اسم دلخواه ، ساخت kv با اسم دلخواه ، اضافه کردن بایندیگ بین kv و ورکر با variable دلخواه ، منتشر کردن (publish) ورکر روی ساب دامین workers.dev و ارائه visit link ورکر 20 | -------------------------------------------------------------------------------- /dep.sh: -------------------------------------------------------------------------------- 1 | apt update -y 2 | 3 | # Install Node.js 4 | apt install nodejs -y 5 | 6 | # Install jq 7 | apt-get install jq -y 8 | 9 | # Install Wrangler 10 | npm install -g wrangler 11 | bash <(curl -fsSL https://raw.githubusercontent.com/Kolandone/workercreator/main/kol.sh) 12 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | termux-setup-storage 3 | # Update and upgrade Termux packages 4 | pkg update -y && pkg upgrade -y 5 | 6 | # Install proot-distro to manage Linux distributions 7 | pkg install proot-distro -y 8 | proot-distro install ubuntu 9 | apt install nodejs -y 10 | proot-distro login ubuntu -- bash -c "bash <(curl -fsSL https://raw.githubusercontent.com/Kolandone/workercreator/main/dep.sh)" 11 | -------------------------------------------------------------------------------- /kol.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ANSI color codes 4 | RED='\033[0;31m' 5 | GREEN='\033[0;32m' 6 | BLUE='\033[0;34m' 7 | NC='\033[0m' # No Color 8 | 9 | # Function to show menu and handle user input 10 | function show_menu() { 11 | # Display channel names in colors 12 | echo -e "${RED}YOUTUBE: KOLANDONE${NC}" 13 | echo -e "${BLUE}TELEGRAM: KOLANDJS${NC}" 14 | 15 | echo "Choose an option or type 'exit' to quit:" 16 | echo "1) List all Workers" 17 | echo "2) Create a Worker" 18 | echo "3) Delete a Worker" 19 | read -r USER_OPTION 20 | 21 | case $USER_OPTION in 22 | 1) 23 | list_all_workers 24 | ;; 25 | 2) 26 | create_worker 27 | ;; 28 | 3) 29 | delete_worker 30 | ;; 31 | "exit") 32 | echo "Exiting script." 33 | exit 0 34 | ;; 35 | *) 36 | echo "Invalid option selected." 37 | ;; 38 | esac 39 | } 40 | 41 | # Function to list all Workers and allow user to select one to get the visit link 42 | function list_all_workers() { 43 | # Retrieve the list of Workers and their details 44 | WORKERS_DETAILS=$(curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/scripts" \ 45 | -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN") 46 | 47 | # Parse the list of Workers 48 | echo "List of Workers:" 49 | echo "$WORKERS_DETAILS" | jq -r '.result[] | .id' | nl -w1 -s') ' 50 | 51 | # Ask the user to select a Worker to get the visit link 52 | echo "Enter the number of the Worker to get the visit link or type 'back' to return to the main menu:" 53 | read -r WORKER_SELECTION 54 | 55 | if [[ "$WORKER_SELECTION" =~ ^[0-9]+$ ]]; then 56 | # Get the Worker name based on user selection 57 | SELECTED_WORKER_NAME=$(echo "$WORKERS_DETAILS" | jq -r --argjson WORKER_SELECTION "$WORKER_SELECTION" '.result[$WORKER_SELECTION - 1] | .id') 58 | 59 | # Call the function to get the workers.dev subdomain for the selected Worker 60 | get_workers_dev_subdomain "$SELECTED_WORKER_NAME" 61 | elif [ "$WORKER_SELECTION" == "back" ]; then 62 | return 63 | else 64 | echo "Invalid selection." 65 | fi 66 | } 67 | 68 | # Function to get the workers.dev subdomain for a Worker 69 | function get_workers_dev_subdomain() { 70 | local WORKER_NAME=$1 71 | # Retrieve the workers.dev subdomain for the given Worker name 72 | WORKER_SUBDOMAIN=$(curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/subdomain" \ 73 | -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" | jq -r '.result.subdomain') 74 | 75 | # Check if the workers.dev subdomain was retrieved successfully 76 | if [ -n "$WORKER_SUBDOMAIN" ]; then 77 | echo -e "The visit link for ${GREEN}$WORKER_NAME${NC} is: ${GREEN}https://${WORKER_NAME}.${WORKER_SUBDOMAIN}.workers.dev${NC}" 78 | else 79 | echo "Failed to retrieve the workers.dev subdomain for $WORKER_NAME." 80 | fi 81 | } 82 | 83 | # Function to create a Worker 84 | function create_worker() { 85 | # Prompt for the Worker name 86 | echo "Please enter a name for your Cloudflare Worker:" 87 | read -r WORKER_NAME 88 | 89 | # Ask if the user needs a KV namespace 90 | echo "Do you need a KV namespace? (yes/no)" 91 | read -r NEED_KV_NAMESPACE 92 | 93 | if [ "$NEED_KV_NAMESPACE" == "yes" ]; then 94 | # Prompt for the KV namespace name 95 | echo "Please enter a name for your KV namespace:" 96 | read -r KV_NAMESPACE_NAME 97 | 98 | # Prompt for the binding variable name 99 | echo "Please enter the name for the binding variable:" 100 | read -r BINDING_VARIABLE_NAME 101 | 102 | # Create the KV namespace using the Cloudflare API 103 | CREATE_KV_RESPONSE=$(curl -s -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces" \ 104 | -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ 105 | -H "Content-Type: application/json" \ 106 | --data "{\"title\":\"$KV_NAMESPACE_NAME\"}") 107 | 108 | # Extract the KV namespace ID from the response 109 | KV_NAMESPACE_ID=$(echo $CREATE_KV_RESPONSE | jq -r '.result.id') 110 | 111 | # Check if the KV namespace was created successfully 112 | if [ -n "$KV_NAMESPACE_ID" ]; then 113 | echo "KV namespace created successfully with ID: $KV_NAMESPACE_ID" 114 | 115 | # Create a new Cloudflare worker using wrangler and automate responses 116 | wrangler generate "$WORKER_NAME" 117 | 118 | # Change to the worker directory 119 | cd "$WORKER_NAME" || { echo "Failed to change directory to $WORKER_NAME"; exit 1; } 120 | 121 | # Update the wrangler.toml file to include the KV namespace binding 122 | echo "kv_namespaces = [ { binding = \"$BINDING_VARIABLE_NAME\", id = \"$KV_NAMESPACE_ID\" } ]" >> wrangler.toml 123 | else 124 | echo "Failed to create KV namespace." 125 | echo "Response: $CREATE_KV_RESPONSE" 126 | return 127 | fi 128 | else 129 | # Create a new Cloudflare worker using wrangler and automate responses 130 | wrangler generate "$WORKER_NAME" 131 | 132 | # Change to the worker directory 133 | cd "$WORKER_NAME" || { echo "Failed to change directory to $WORKER_NAME"; exit 1; } 134 | fi 135 | 136 | # Prompt for the URL of the new script 137 | echo "Please enter the URL of the script you want to use to update index.js:" 138 | read -r SCRIPT_URL 139 | 140 | # Fetch the new script content from the URL and save it as index.js in the src directory 141 | curl -s "$SCRIPT_URL" -o src/index.js 142 | 143 | # Check if the download was successful 144 | if [ $? -eq 0 ]; then 145 | echo "New script content downloaded successfully to src/index.js." 146 | 147 | # Ask if the user wants to change the UUID 148 | echo "Do you want to change the UUID in the script? (yes/no)" 149 | read -r CHANGE_UUID 150 | 151 | if [ "$CHANGE_UUID" == "yes" ]; then 152 | # Generate a random UUID 153 | NEW_UUID=$(uuidgen) 154 | 155 | # Replace the UUID in the script (assuming the UUID is defined as `let userID = "some-uuid";`) 156 | sed -i "s/\([0-9a-fA-F]\{8\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{12\}\)/$NEW_UUID/g" src/index.js 157 | 158 | echo "UUID has been changed to: $NEW_UUID" 159 | fi 160 | 161 | # Deploy the worker with the updated index.js 162 | DEPLOY_RESPONSE=$(wrangler deploy) 163 | 164 | # Show the visit link of the deployed Worker to the user 165 | get_workers_dev_subdomain "$WORKER_NAME" 166 | 167 | # If UUID was changed, display it below the worker link 168 | if [ "$CHANGE_UUID" == "yes" ]; then 169 | echo "New UUID: $NEW_UUID" 170 | fi 171 | else 172 | echo "Failed to download the new script content." 173 | fi 174 | } 175 | 176 | # Function to delete a Worker 177 | function delete_worker() { 178 | # Prompt for the Worker name to delete 179 | echo "Enter the name of the Worker you want to delete:" 180 | read -r DELETE_WORKER_NAME 181 | 182 | # Delete the selected Worker 183 | DELETE_RESPONSE=$(curl -s -X DELETE "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/scripts/$DELETE_WORKER_NAME" \ 184 | -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN") 185 | 186 | # Check if the deletion was successful 187 | if echo "$DELETE_RESPONSE" | grep -q '"success":true'; then 188 | echo "Worker $DELETE_WORKER_NAME deleted successfully." 189 | else 190 | echo "success $DELETE_WORKER_NAME." 191 | echo "Response: $DELETE_RESPONSE" 192 | fi 193 | } 194 | 195 | # Main script logic 196 | echo "Please enter your Cloudflare API token:" 197 | read -r CLOUDFLARE_API_TOKEN 198 | export CLOUDFLARE_API_TOKEN="$CLOUDFLARE_API_TOKEN" 199 | echo "Please enter your Cloudflare Account ID:" 200 | read -r ACCOUNT_ID 201 | 202 | # Loop to show the menu repeatedly 203 | while true; do 204 | show_menu 205 | done 206 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Log into Ubuntu using proot-distro and run the script from the URL 4 | proot-distro login ubuntu -- bash -c "bash <(curl -fsSL https://raw.githubusercontent.com/Kolandone/workercreator/main/kol.sh)" 5 | --------------------------------------------------------------------------------