pihole6api 0.1.9__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pihole6api/client.py +16 -1
- pihole6api/conn.py +4 -2
- pihole6api/domain_management.py +15 -0
- {pihole6api-0.1.9.dist-info → pihole6api-0.2.0.dist-info}/METADATA +9 -1
- {pihole6api-0.1.9.dist-info → pihole6api-0.2.0.dist-info}/RECORD +8 -8
- {pihole6api-0.1.9.dist-info → pihole6api-0.2.0.dist-info}/WHEEL +1 -1
- {pihole6api-0.1.9.dist-info → pihole6api-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {pihole6api-0.1.9.dist-info → pihole6api-0.2.0.dist-info}/top_level.txt +0 -0
pihole6api/client.py
CHANGED
@@ -10,6 +10,7 @@ from .config import PiHole6Configuration
|
|
10
10
|
from .network_info import PiHole6NetworkInfo
|
11
11
|
from .actions import PiHole6Actions
|
12
12
|
from .dhcp import PiHole6Dhcp
|
13
|
+
import importlib.metadata
|
13
14
|
|
14
15
|
class PiHole6Client:
|
15
16
|
def __init__(self, base_url, password):
|
@@ -45,4 +46,18 @@ class PiHole6Client:
|
|
45
46
|
|
46
47
|
def close_session(self):
|
47
48
|
"""Close the Pi-hole session by calling the exit method in the connection."""
|
48
|
-
return self.connection.exit()
|
49
|
+
return self.connection.exit()
|
50
|
+
|
51
|
+
def version(self):
|
52
|
+
"""
|
53
|
+
Get the project information from package metadata.
|
54
|
+
|
55
|
+
:return: Dictionary containing version, description, and project URL
|
56
|
+
"""
|
57
|
+
metadata = importlib.metadata.metadata("pihole6api")
|
58
|
+
|
59
|
+
return {
|
60
|
+
"version": metadata["Version"],
|
61
|
+
"description": metadata["Summary"],
|
62
|
+
"project_url": metadata["Project-URL"]
|
63
|
+
}
|
pihole6api/conn.py
CHANGED
@@ -82,18 +82,20 @@ class PiHole6Connection:
|
|
82
82
|
|
83
83
|
if response.status_code == 200:
|
84
84
|
data = response.json()
|
85
|
-
if "session" in data and data["session"]["valid"]:
|
85
|
+
if "session" in data and data["session"]["valid"] and data["session"]["validity"] > 0:
|
86
86
|
self.session_id = data["session"]["sid"]
|
87
87
|
self.csrf_token = data["session"]["csrf"]
|
88
88
|
self.validity = data["session"]["validity"]
|
89
89
|
logger.debug("Authentication successful")
|
90
90
|
return # Successful authentication
|
91
91
|
else:
|
92
|
+
if data.get("session"):
|
93
|
+
logger.error(data["session"].get("message", "API failed without message"))
|
92
94
|
last_exception = Exception("Authentication failed: Invalid session response")
|
93
95
|
else:
|
94
96
|
# Try to extract an error message from the response
|
95
97
|
try:
|
96
|
-
error_msg = response.json().get("
|
98
|
+
error_msg = response.json().get("session", {}).get("message", "Unknown error")
|
97
99
|
except (json.decoder.JSONDecodeError, ValueError):
|
98
100
|
error_msg = f"HTTP {response.status_code}: {response.reason}"
|
99
101
|
last_exception = Exception(f"Authentication failed: {error_msg}")
|
pihole6api/domain_management.py
CHANGED
@@ -85,3 +85,18 @@ class PiHole6DomainManagement:
|
|
85
85
|
:param kind: Kind of domain ("exact" or "regex")
|
86
86
|
"""
|
87
87
|
return self.connection.delete(f"domains/{domain_type}/{kind}/{domain}")
|
88
|
+
|
89
|
+
def get_all_domains(self):
|
90
|
+
"""
|
91
|
+
Get all white and blacklisted domains
|
92
|
+
"""
|
93
|
+
try:
|
94
|
+
# Get whiteliste domains
|
95
|
+
whitelist = self.connection.get("domains/allow/exact")
|
96
|
+
# Get blackliste domains
|
97
|
+
blacklist = self.connection.get("domains/deny/exact")
|
98
|
+
|
99
|
+
return {"whitelist": whitelist, "blacklist": blacklist}
|
100
|
+
except Exception as e:
|
101
|
+
print(f"Error fetching domains: {e}")
|
102
|
+
return None
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pihole6api
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2.0
|
4
4
|
Summary: Python API Client for Pi-hole 6
|
5
5
|
Author-email: Shane Barbetta <shane@barbetta.me>
|
6
6
|
License: MIT
|
@@ -132,6 +132,14 @@ client.actions.restart_dns()
|
|
132
132
|
| `network_info` | View network devices, interfaces, routes |
|
133
133
|
| `actions` | Flush logs, restart services |
|
134
134
|
|
135
|
+
## Contributing
|
136
|
+
|
137
|
+
Please check [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.
|
138
|
+
|
139
|
+
## Changelog
|
140
|
+
|
141
|
+
See [CHANGELOG.md](CHANGELOG.md) for a list of changes.
|
142
|
+
|
135
143
|
## License
|
136
144
|
|
137
145
|
This project is license under the [MIT license](LICENSE).
|
@@ -1,19 +1,19 @@
|
|
1
1
|
pihole6api/__init__.py,sha256=OKDAH2I6UjXcBmcj6rn5aNg5J60GCUBVFJ-_t83GiVQ,898
|
2
2
|
pihole6api/actions.py,sha256=8CBkr8nYfT8yfdCO6F9M9nompaYcFdsaYGiEa1eVDCw,693
|
3
|
-
pihole6api/client.py,sha256=
|
3
|
+
pihole6api/client.py,sha256=8sco9wFCAmF1WTRG72W5Af4fZIoTjvCXXmj-O51MY88,2472
|
4
4
|
pihole6api/client_management.py,sha256=n8Ra_6pRL3Q9jlIK3kIK9bmh74MTfxgYnOHYaUwYGNs,2590
|
5
5
|
pihole6api/config.py,sha256=NdBHOudz147oIs5YVR3U4WLvqk3hU3HlZHnshy1NK4g,4680
|
6
|
-
pihole6api/conn.py,sha256=
|
6
|
+
pihole6api/conn.py,sha256=2JYPgHUmhPSuNdrMaWkEtf2lnqDJ8--g05CYntOBJvQ,9523
|
7
7
|
pihole6api/dhcp.py,sha256=1A3z-3q9x51-6MOC3JMl7yR_5pHmRxZtMWtPqzWxYm0,629
|
8
8
|
pihole6api/dns_control.py,sha256=mxV3AIuGCsx0-1ibpMXor9QUGd_fDFfeaUENPhIK_TY,853
|
9
|
-
pihole6api/domain_management.py,sha256=
|
9
|
+
pihole6api/domain_management.py,sha256=5oJebojAAEEvZtJgxeuK4FazcMxmiB1NpAgStqdUv-E,3988
|
10
10
|
pihole6api/ftl_info.py,sha256=FINHFotI1sQgkL0OPaNqW-rk4h1ua6QHnRh5gFXXRIE,3210
|
11
11
|
pihole6api/group_management.py,sha256=Iip2Na4pUYgC5K9cwOWv_OPD6qdXRzWCmlS-fJlBMjU,2372
|
12
12
|
pihole6api/list_management.py,sha256=CooTeF4EmNPFwnzGoLbHFMhCePJ-ojvRGx7Sxzayy-U,4170
|
13
13
|
pihole6api/metrics.py,sha256=QWqV_7SytMPGEBEZOxsIfxTa6lM9Ksrvlf2BXjDKZmA,7991
|
14
14
|
pihole6api/network_info.py,sha256=E1qQ7DsCb7qplt0oQIyKhUY12ExNF6bv6thm9rbNqwY,1953
|
15
|
-
pihole6api-0.
|
16
|
-
pihole6api-0.
|
17
|
-
pihole6api-0.
|
18
|
-
pihole6api-0.
|
19
|
-
pihole6api-0.
|
15
|
+
pihole6api-0.2.0.dist-info/licenses/LICENSE,sha256=hpO6J6J9O1VZxZeHQTxKMTmuobaHbApiZxp279I4xNU,1062
|
16
|
+
pihole6api-0.2.0.dist-info/METADATA,sha256=oL9701CfySKOOVdWglV7rEmpVBAMMRAr_KSckcTFyGw,3956
|
17
|
+
pihole6api-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
18
|
+
pihole6api-0.2.0.dist-info/top_level.txt,sha256=Qrh46lxEC54rBR8T53em-tuZLWbmi1SDwL1rOhsgrME,11
|
19
|
+
pihole6api-0.2.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|