mirror of
https://github.com/itdoginfo/allow-domains.git
synced 2025-09-01 10:09:38 +00:00
Added script for srs files
This commit is contained in:
parent
84bb7ec9e7
commit
62ba9150c8
2 changed files with 68 additions and 0 deletions
15
Dockerfile
Normal file
15
Dockerfile
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
FROM ghcr.io/sagernet/sing-box:v1.10.7 AS sing-box
|
||||||
|
|
||||||
|
FROM python:3.10.16-alpine3.21
|
||||||
|
|
||||||
|
COPY --from=sing-box /usr/local/bin/sing-box /bin/sing-box
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY compile-srs.py /app/compile-srs.py
|
||||||
|
|
||||||
|
VOLUME ["/app/Categories", "/app/Services"]
|
||||||
|
|
||||||
|
CMD ["python3", "compile-srs.py"]
|
||||||
|
|
||||||
|
# docker run --rm -v ./Categories:/app/Categories -v ./Services:/app/Services -v ./json:/app/json py-sg:1
|
53
compile-srs.py
Executable file
53
compile-srs.py
Executable file
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/python3.10
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
directories = ['Categories', 'Services']
|
||||||
|
|
||||||
|
output_directory = 'JSON'
|
||||||
|
os.makedirs(output_directory, exist_ok=True)
|
||||||
|
compiled_output_directory = 'SRS'
|
||||||
|
os.makedirs(compiled_output_directory, exist_ok=True)
|
||||||
|
|
||||||
|
for directory in directories:
|
||||||
|
for filename in os.listdir(directory):
|
||||||
|
file_path = os.path.join(directory, filename)
|
||||||
|
|
||||||
|
if os.path.isfile(file_path):
|
||||||
|
domains = []
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
|
for line in file:
|
||||||
|
domain = line.strip()
|
||||||
|
if domain:
|
||||||
|
domains.append(domain)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"version": 2,
|
||||||
|
"rules": [
|
||||||
|
{
|
||||||
|
"domain_suffix": domains
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
output_file_path = os.path.join(output_directory, f"{os.path.splitext(filename)[0]}.json")
|
||||||
|
|
||||||
|
with open(output_file_path, 'w', encoding='utf-8') as output_file:
|
||||||
|
json.dump(data, output_file, indent=4)
|
||||||
|
|
||||||
|
print(f"JSON file generated: {output_file_path}")
|
||||||
|
|
||||||
|
print("\nCompile JSON files to .srs files...")
|
||||||
|
for filename in os.listdir(output_directory):
|
||||||
|
if filename.endswith('.json'):
|
||||||
|
json_file_path = os.path.join(output_directory, filename)
|
||||||
|
srs_file_path = os.path.join(compiled_output_directory, f"{os.path.splitext(filename)[0]}.srs")
|
||||||
|
try:
|
||||||
|
subprocess.run(
|
||||||
|
["sing-box", "rule-set", "compile", json_file_path, "-o", srs_file_path], check=True
|
||||||
|
)
|
||||||
|
print(f"Compiled .srs file: {srs_file_path}")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Compile error {json_file_path}: {e}")
|
Loading…
Add table
Reference in a new issue