In the latest version of SafeLine (v6.6.0 and above), the Open API now supports API token-based authentication. Although official API documentation is not currently available, you can scrape it yourself if needed.
GitHub:https://github.com/chaitin/SafeLine
Demo:https://demo.waf.chaitin.com:9443/dashboard
First, navigate to System Management in SafeLine and generate an API token.
When making API calls, you need to include the token in the request headers like this:
"X-SLCE-API-TOKEN": "Your API Token from SafeLine"
Below is an example of how to use the SafeLine Open API with an API token to add a new site in Python.
import requests import json # Define the header with your API token header = { "X-SLCE-API-TOKEN": "Your API Token from SafeLine" } # API endpoint to add a site url = 'https://:9443/api/open/site' # Payload containing site details payload = { "ports": ["80"], "server_names": ["*"], "upstreams": ["http://127.0.0.1:9443"], "comment": "", "load_balance": { "balance_type": 1 } } # Convert payload to JSON payload = json.dumps(payload) # Send the POST request response = requests.post(url=url, headers=header, data=payload, verify=False) # Check the response print(response.status_code) print(response.json())
By following these steps, you can securely interact with SafeLine's Open API using token-based authentication, enabling you to automate and manage your web security setup with ease.
以上是Guide to SafeLine Open API: Secure Your Access with API Tokens的详细内容。更多信息请关注PHP中文网其他相关文章!