Integração Pangolin Proxy

This commit is contained in:
2025-12-06 21:11:34 -03:00
parent dc7c446254
commit 5291d8ccae
2008 changed files with 1062 additions and 477 deletions

Binary file not shown.

View File

@@ -1,126 +0,0 @@
import os
import time
import json
import hashlib
import requests
import logging
import subprocess
from datetime import datetime
from dotenv import load_dotenv
# Load Env
load_dotenv()
API_URL = os.getenv('API_URL', 'http://localhost:8000/api')
SERIAL_KEY = os.getenv('SERIAL_KEY')
RPZ_FILE = os.getenv('RPZ_FILE', '/etc/unbound/rpz.zone')
UNBOUND_CMD = os.getenv('UNBOUND_CMD', 'unbound-control reload')
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler("agent.log"),
logging.StreamHandler()
]
)
class DNSBlockAgent:
def __init__(self):
self.token = None
self.last_checksum = None
def authenticate(self):
try:
logging.info("Authenticating...")
response = requests.post(f"{API_URL}/auth/login", json={'serial_key': SERIAL_KEY})
response.raise_for_status()
data = response.json()
self.token = data['token']
logging.info("Authenticated successfully.")
except Exception as e:
logging.error(f"Authentication failed: {e}")
self.token = None
def get_domains(self):
if not self.token:
self.authenticate()
if not self.token:
return None
try:
headers = {'Authorization': f'Bearer {self.token}'}
response = requests.get(f"{API_URL}/v1/domains", headers=headers)
if response.status_code == 401:
logging.warning("Token expired, re-authenticating...")
self.authenticate()
if self.token:
headers = {'Authorization': f'Bearer {self.token}'}
response = requests.get(f"{API_URL}/v1/domains", headers=headers)
else:
return None
response.raise_for_status()
return response.json()
except Exception as e:
logging.error(f"Failed to fetch domains: {e}")
return None
def update_rpz(self, domains):
try:
logging.info(f"Updating RPZ file with {len(domains)} domains...")
header = """$TTL 30m
@ IN SOA localhost. root.localhost. (
{} ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ) ; Minimum TTL
NS localhost.
; Blocked Domains
""".format(int(datetime.now().timestamp()))
with open(RPZ_FILE, 'w') as f:
f.write(header)
for domain in domains:
f.write(f"{domain} CNAME .\n")
f.write(f"*.{domain} CNAME .\n")
logging.info("RPZ file updated.")
self.reload_unbound()
except Exception as e:
logging.error(f"Failed to update RPZ: {e}")
def reload_unbound(self):
try:
logging.info("Reloading Unbound...")
subprocess.run(UNBOUND_CMD.split(), check=True)
logging.info("Unbound reloaded.")
except Exception as e:
logging.error(f"Failed to reload Unbound: {e}")
def run(self):
logging.info("Agent started.")
while True:
data = self.get_domains()
if data:
checksum = data.get('checksum')
if checksum != self.last_checksum:
logging.info(f"Checksum changed: {checksum}. Updating...")
self.update_rpz(data.get('domains', []))
self.last_checksum = checksum
else:
logging.info("No changes detected.")
time.sleep(300)
if __name__ == "__main__":
if not SERIAL_KEY:
logging.error("SERIAL_KEY not defined in .env")
exit(1)
agent = DNSBlockAgent()
agent.run()

View File

@@ -148,13 +148,13 @@
('dis', '/usr/lib/python3.11/dis.py', 'PYMODULE'),
('opcode', '/usr/lib/python3.11/opcode.py', 'PYMODULE'),
('ast', '/usr/lib/python3.11/ast.py', 'PYMODULE'),
('stringprep', '/usr/lib/python3.11/stringprep.py', 'PYMODULE'),
('_py_abc', '/usr/lib/python3.11/_py_abc.py', 'PYMODULE'),
('tracemalloc', '/usr/lib/python3.11/tracemalloc.py', 'PYMODULE'),
('pickle', '/usr/lib/python3.11/pickle.py', 'PYMODULE'),
('pprint', '/usr/lib/python3.11/pprint.py', 'PYMODULE'),
('dataclasses', '/usr/lib/python3.11/dataclasses.py', 'PYMODULE'),
('_compat_pickle', '/usr/lib/python3.11/_compat_pickle.py', 'PYMODULE'),
('_py_abc', '/usr/lib/python3.11/_py_abc.py', 'PYMODULE'),
('stringprep', '/usr/lib/python3.11/stringprep.py', 'PYMODULE'),
('logging.handlers', '/usr/lib/python3.11/logging/handlers.py', 'PYMODULE'),
('http.client', '/usr/lib/python3.11/http/client.py', 'PYMODULE'),
('ssl', '/usr/lib/python3.11/ssl.py', 'PYMODULE'),
@@ -458,8 +458,8 @@
('python3.11/lib-dynload/_json.cpython-311-x86_64-linux-gnu.so',
'/usr/lib/python3.11/lib-dynload/_json.cpython-311-x86_64-linux-gnu.so',
'EXTENSION'),
('libexpat.so.1', '/lib/x86_64-linux-gnu/libexpat.so.1', 'BINARY'),
('libz.so.1', '/lib/x86_64-linux-gnu/libz.so.1', 'BINARY'),
('libexpat.so.1', '/lib/x86_64-linux-gnu/libexpat.so.1', 'BINARY'),
('libcrypto.so.3', '/lib/x86_64-linux-gnu/libcrypto.so.3', 'BINARY'),
('liblzma.so.5', '/lib/x86_64-linux-gnu/liblzma.so.5', 'BINARY'),
('libbz2.so.1.0', '/lib/x86_64-linux-gnu/libbz2.so.1.0', 'BINARY'),
@@ -467,42 +467,25 @@
('libuuid.so.1', '/lib/x86_64-linux-gnu/libuuid.so.1', 'BINARY')],
[],
[],
[('certifi/cacert.pem',
'/home/halbebruno/Projetos/DNSBlock/agent/build_venv/lib/python3.11/site-packages/certifi/cacert.pem',
'DATA'),
('certifi/py.typed',
[('certifi/py.typed',
'/home/halbebruno/Projetos/DNSBlock/agent/build_venv/lib/python3.11/site-packages/certifi/py.typed',
'DATA'),
('certifi/cacert.pem',
'/home/halbebruno/Projetos/DNSBlock/agent/build_venv/lib/python3.11/site-packages/certifi/cacert.pem',
'DATA'),
('base_library.zip',
'/home/halbebruno/Projetos/DNSBlock/agent/build/dnsblock-agent/base_library.zip',
'DATA')],
[('reprlib', '/usr/lib/python3.11/reprlib.py', 'PYMODULE'),
('operator', '/usr/lib/python3.11/operator.py', 'PYMODULE'),
('collections.abc', '/usr/lib/python3.11/collections/abc.py', 'PYMODULE'),
('collections', '/usr/lib/python3.11/collections/__init__.py', 'PYMODULE'),
('linecache', '/usr/lib/python3.11/linecache.py', 'PYMODULE'),
('stat', '/usr/lib/python3.11/stat.py', 'PYMODULE'),
('types', '/usr/lib/python3.11/types.py', 'PYMODULE'),
('warnings', '/usr/lib/python3.11/warnings.py', 'PYMODULE'),
[('sre_compile', '/usr/lib/python3.11/sre_compile.py', 'PYMODULE'),
('traceback', '/usr/lib/python3.11/traceback.py', 'PYMODULE'),
('heapq', '/usr/lib/python3.11/heapq.py', 'PYMODULE'),
('functools', '/usr/lib/python3.11/functools.py', 'PYMODULE'),
('sre_constants', '/usr/lib/python3.11/sre_constants.py', 'PYMODULE'),
('re._parser', '/usr/lib/python3.11/re/_parser.py', 'PYMODULE'),
('re._constants', '/usr/lib/python3.11/re/_constants.py', 'PYMODULE'),
('re._compiler', '/usr/lib/python3.11/re/_compiler.py', 'PYMODULE'),
('re._casefix', '/usr/lib/python3.11/re/_casefix.py', 'PYMODULE'),
('re', '/usr/lib/python3.11/re/__init__.py', 'PYMODULE'),
('sre_parse', '/usr/lib/python3.11/sre_parse.py', 'PYMODULE'),
('abc', '/usr/lib/python3.11/abc.py', 'PYMODULE'),
('ntpath', '/usr/lib/python3.11/ntpath.py', 'PYMODULE'),
('io', '/usr/lib/python3.11/io.py', 'PYMODULE'),
('_collections_abc', '/usr/lib/python3.11/_collections_abc.py', 'PYMODULE'),
('_weakrefset', '/usr/lib/python3.11/_weakrefset.py', 'PYMODULE'),
('enum', '/usr/lib/python3.11/enum.py', 'PYMODULE'),
('keyword', '/usr/lib/python3.11/keyword.py', 'PYMODULE'),
('copyreg', '/usr/lib/python3.11/copyreg.py', 'PYMODULE'),
('stat', '/usr/lib/python3.11/stat.py', 'PYMODULE'),
('sre_parse', '/usr/lib/python3.11/sre_parse.py', 'PYMODULE'),
('weakref', '/usr/lib/python3.11/weakref.py', 'PYMODULE'),
('locale', '/usr/lib/python3.11/locale.py', 'PYMODULE'),
('genericpath', '/usr/lib/python3.11/genericpath.py', 'PYMODULE'),
('linecache', '/usr/lib/python3.11/linecache.py', 'PYMODULE'),
('functools', '/usr/lib/python3.11/functools.py', 'PYMODULE'),
('encodings.zlib_codec',
'/usr/lib/python3.11/encodings/zlib_codec.py',
'PYMODULE'),
@@ -733,9 +716,26 @@
('encodings.ascii', '/usr/lib/python3.11/encodings/ascii.py', 'PYMODULE'),
('encodings.aliases', '/usr/lib/python3.11/encodings/aliases.py', 'PYMODULE'),
('encodings', '/usr/lib/python3.11/encodings/__init__.py', 'PYMODULE'),
('codecs', '/usr/lib/python3.11/codecs.py', 'PYMODULE'),
('abc', '/usr/lib/python3.11/abc.py', 'PYMODULE'),
('locale', '/usr/lib/python3.11/locale.py', 'PYMODULE'),
('ntpath', '/usr/lib/python3.11/ntpath.py', 'PYMODULE'),
('io', '/usr/lib/python3.11/io.py', 'PYMODULE'),
('reprlib', '/usr/lib/python3.11/reprlib.py', 'PYMODULE'),
('heapq', '/usr/lib/python3.11/heapq.py', 'PYMODULE'),
('sre_constants', '/usr/lib/python3.11/sre_constants.py', 'PYMODULE'),
('collections.abc', '/usr/lib/python3.11/collections/abc.py', 'PYMODULE'),
('collections', '/usr/lib/python3.11/collections/__init__.py', 'PYMODULE'),
('posixpath', '/usr/lib/python3.11/posixpath.py', 'PYMODULE'),
('enum', '/usr/lib/python3.11/enum.py', 'PYMODULE'),
('sre_compile', '/usr/lib/python3.11/sre_compile.py', 'PYMODULE'),
('_weakrefset', '/usr/lib/python3.11/_weakrefset.py', 'PYMODULE'),
('_collections_abc', '/usr/lib/python3.11/_collections_abc.py', 'PYMODULE'),
('codecs', '/usr/lib/python3.11/codecs.py', 'PYMODULE'),
('operator', '/usr/lib/python3.11/operator.py', 'PYMODULE'),
('copyreg', '/usr/lib/python3.11/copyreg.py', 'PYMODULE'),
('re._parser', '/usr/lib/python3.11/re/_parser.py', 'PYMODULE'),
('re._constants', '/usr/lib/python3.11/re/_constants.py', 'PYMODULE'),
('re._compiler', '/usr/lib/python3.11/re/_compiler.py', 'PYMODULE'),
('re._casefix', '/usr/lib/python3.11/re/_casefix.py', 'PYMODULE'),
('re', '/usr/lib/python3.11/re/__init__.py', 'PYMODULE'),
('genericpath', '/usr/lib/python3.11/genericpath.py', 'PYMODULE'),
('types', '/usr/lib/python3.11/types.py', 'PYMODULE'),
('warnings', '/usr/lib/python3.11/warnings.py', 'PYMODULE'),
('os', '/usr/lib/python3.11/os.py', 'PYMODULE')])

View File

@@ -102,26 +102,26 @@
('python3.11/lib-dynload/_json.cpython-311-x86_64-linux-gnu.so',
'/usr/lib/python3.11/lib-dynload/_json.cpython-311-x86_64-linux-gnu.so',
'EXTENSION'),
('libexpat.so.1', '/lib/x86_64-linux-gnu/libexpat.so.1', 'BINARY'),
('libz.so.1', '/lib/x86_64-linux-gnu/libz.so.1', 'BINARY'),
('libexpat.so.1', '/lib/x86_64-linux-gnu/libexpat.so.1', 'BINARY'),
('libcrypto.so.3', '/lib/x86_64-linux-gnu/libcrypto.so.3', 'BINARY'),
('liblzma.so.5', '/lib/x86_64-linux-gnu/liblzma.so.5', 'BINARY'),
('libbz2.so.1.0', '/lib/x86_64-linux-gnu/libbz2.so.1.0', 'BINARY'),
('libssl.so.3', '/lib/x86_64-linux-gnu/libssl.so.3', 'BINARY'),
('libuuid.so.1', '/lib/x86_64-linux-gnu/libuuid.so.1', 'BINARY'),
('certifi/cacert.pem',
'/home/halbebruno/Projetos/DNSBlock/agent/build_venv/lib/python3.11/site-packages/certifi/cacert.pem',
'DATA'),
('certifi/py.typed',
'/home/halbebruno/Projetos/DNSBlock/agent/build_venv/lib/python3.11/site-packages/certifi/py.typed',
'DATA'),
('certifi/cacert.pem',
'/home/halbebruno/Projetos/DNSBlock/agent/build_venv/lib/python3.11/site-packages/certifi/cacert.pem',
'DATA'),
('base_library.zip',
'/home/halbebruno/Projetos/DNSBlock/agent/build/dnsblock-agent/base_library.zip',
'DATA')],
[],
False,
False,
1765033492,
1765065952,
[('run',
'/home/halbebruno/Projetos/DNSBlock/agent/build_venv/lib/python3.11/site-packages/PyInstaller/bootloader/Linux-64bit-intel/run',
'EXECUTABLE')],

View File

@@ -97,19 +97,19 @@
('python3.11/lib-dynload/_json.cpython-311-x86_64-linux-gnu.so',
'/usr/lib/python3.11/lib-dynload/_json.cpython-311-x86_64-linux-gnu.so',
'EXTENSION'),
('libexpat.so.1', '/lib/x86_64-linux-gnu/libexpat.so.1', 'BINARY'),
('libz.so.1', '/lib/x86_64-linux-gnu/libz.so.1', 'BINARY'),
('libexpat.so.1', '/lib/x86_64-linux-gnu/libexpat.so.1', 'BINARY'),
('libcrypto.so.3', '/lib/x86_64-linux-gnu/libcrypto.so.3', 'BINARY'),
('liblzma.so.5', '/lib/x86_64-linux-gnu/liblzma.so.5', 'BINARY'),
('libbz2.so.1.0', '/lib/x86_64-linux-gnu/libbz2.so.1.0', 'BINARY'),
('libssl.so.3', '/lib/x86_64-linux-gnu/libssl.so.3', 'BINARY'),
('libuuid.so.1', '/lib/x86_64-linux-gnu/libuuid.so.1', 'BINARY'),
('certifi/cacert.pem',
'/home/halbebruno/Projetos/DNSBlock/agent/build_venv/lib/python3.11/site-packages/certifi/cacert.pem',
'DATA'),
('certifi/py.typed',
'/home/halbebruno/Projetos/DNSBlock/agent/build_venv/lib/python3.11/site-packages/certifi/py.typed',
'DATA'),
('certifi/cacert.pem',
'/home/halbebruno/Projetos/DNSBlock/agent/build_venv/lib/python3.11/site-packages/certifi/cacert.pem',
'DATA'),
('base_library.zip',
'/home/halbebruno/Projetos/DNSBlock/agent/build/dnsblock-agent/base_library.zip',
'DATA')],

View File

@@ -19,8 +19,8 @@ missing module named _frozen_importlib_external - imported by importlib._bootstr
excluded module named _frozen_importlib - imported by importlib (optional), importlib.abc (optional)
missing module named winreg - imported by importlib._bootstrap_external (conditional), platform (delayed, optional), mimetypes (optional), urllib.request (delayed, conditional, optional), requests.utils (delayed, conditional, optional)
missing module named nt - imported by os (delayed, conditional, optional), ntpath (optional), shutil (conditional), importlib._bootstrap_external (conditional)
missing module named org - imported by pickle (optional)
missing module named _winapi - imported by encodings (delayed, conditional, optional), ntpath (optional), subprocess (conditional), mimetypes (optional)
missing module named org - imported by pickle (optional)
missing module named _scproxy - imported by urllib.request (conditional)
missing module named msvcrt - imported by subprocess (optional), getpass (optional)
missing module named win32evtlog - imported by logging.handlers (delayed, optional)
@@ -28,8 +28,8 @@ missing module named win32evtlogutil - imported by logging.handlers (delayed, op
missing module named simplejson - imported by requests.compat (conditional, optional)
missing module named dummy_threading - imported by requests.cookies (optional)
missing module named typing_extensions - imported by urllib3.util.retry (conditional), urllib3._collections (conditional), urllib3.util.ssltransport (conditional), urllib3.connectionpool (conditional), urllib3.poolmanager (conditional), urllib3.contrib.emscripten.fetch (conditional), charset_normalizer.legacy (conditional)
missing module named zstandard - imported by urllib3.util.request (optional), urllib3.response (optional)
missing module named compression - imported by urllib3.util.request (optional), urllib3.response (optional)
missing module named backports - imported by urllib3.util.request (conditional, optional), urllib3.response (conditional, optional)
missing module named compression - imported by urllib3.util.request (conditional, optional), urllib3.response (conditional, optional)
missing module named 'h2.events' - imported by urllib3.http2.connection (top-level)
missing module named 'h2.connection' - imported by urllib3.http2.connection (top-level)
missing module named h2 - imported by urllib3.http2.connection (top-level)

View File

@@ -1288,6 +1288,18 @@ imported by:
</div>
<div class="node">
<a name="backports"></a>
<a target="code" href="" type="text/plain"><tt>backports</tt></a>
<span class="moduletype">MissingModule</span> <div class="import">
imported by:
<a href="#urllib3.response">urllib3.response</a>
&#8226; <a href="#urllib3.util.request">urllib3.util.request</a>
</div>
</div>
<div class="node">
<a name="base64"></a>
<a target="code" href="/usr/lib/python3.11/base64.py" type="text/plain"><tt>base64</tt></a>
@@ -7467,7 +7479,6 @@ imported by:
&#8226; <a href="#urllib.request">urllib.request</a>
&#8226; <a href="#urllib3.connection">urllib3.connection</a>
&#8226; <a href="#urllib3.http2.connection">urllib3.http2.connection</a>
&#8226; <a href="#urllib3.response">urllib3.response</a>
&#8226; <a href="#urllib3.util.retry">urllib3.util.retry</a>
&#8226; <a href="#urllib3.util.ssl_match_hostname">urllib3.util.ssl_match_hostname</a>
&#8226; <a href="#urllib3.util.url">urllib3.util.url</a>
@@ -8582,6 +8593,7 @@ imported by:
&#8226; <a href="#urllib3.connection">urllib3.connection</a>
&#8226; <a href="#urllib3.connectionpool">urllib3.connectionpool</a>
&#8226; <a href="#urllib3.response">urllib3.response</a>
&#8226; <a href="#urllib3.util.request">urllib3.util.request</a>
&#8226; <a href="#urllib3.util.ssl_">urllib3.util.ssl_</a>
&#8226; <a href="#uuid">uuid</a>
&#8226; <a href="#warnings">warnings</a>
@@ -9814,6 +9826,7 @@ imported by:
<span class="moduletype">SourceModule</span> <div class="import">
imports:
<a href="#__future__">__future__</a>
&#8226; <a href="#backports">backports</a>
&#8226; <a href="#brotli">brotli</a>
&#8226; <a href="#brotlicffi">brotlicffi</a>
&#8226; <a href="#collections">collections</a>
@@ -9823,7 +9836,6 @@ imports:
&#8226; <a href="#io">io</a>
&#8226; <a href="#json">json</a>
&#8226; <a href="#logging">logging</a>
&#8226; <a href="#re">re</a>
&#8226; <a href="#socket">socket</a>
&#8226; <a href="#sys">sys</a>
&#8226; <a href="#typing">typing</a>
@@ -9838,7 +9850,6 @@ imports:
&#8226; <a href="#urllib3.util.retry">urllib3.util.retry</a>
&#8226; <a href="#warnings">warnings</a>
&#8226; <a href="#zlib">zlib</a>
&#8226; <a href="#zstandard">zstandard</a>
</div>
<div class="import">
@@ -9956,17 +9967,18 @@ imported by:
<span class="moduletype">SourceModule</span> <div class="import">
imports:
<a href="#__future__">__future__</a>
&#8226; <a href="#backports">backports</a>
&#8226; <a href="#base64">base64</a>
&#8226; <a href="#brotli">brotli</a>
&#8226; <a href="#brotlicffi">brotlicffi</a>
&#8226; <a href="#compression">compression</a>
&#8226; <a href="#enum">enum</a>
&#8226; <a href="#io">io</a>
&#8226; <a href="#sys">sys</a>
&#8226; <a href="#typing">typing</a>
&#8226; <a href="#urllib3.exceptions">urllib3.exceptions</a>
&#8226; <a href="#urllib3.util">urllib3.util</a>
&#8226; <a href="#urllib3.util.util">urllib3.util.util</a>
&#8226; <a href="#zstandard">zstandard</a>
</div>
<div class="import">
@@ -10453,18 +10465,6 @@ imported by:
</div>
</div>
<div class="node">
<a name="zstandard"></a>
<a target="code" href="" type="text/plain"><tt>zstandard</tt></a>
<span class="moduletype">MissingModule</span> <div class="import">
imported by:
<a href="#urllib3.response">urllib3.response</a>
&#8226; <a href="#urllib3.util.request">urllib3.util.request</a>
</div>
</div>
</body>

Some files were not shown because too many files have changed in this diff Show More