Compare commits

..

4 Commits

Author SHA1 Message Date
Guillaume BOURGEOIS 26cd02d77a feat(panos): new PAN-OS / Panorama firewall-containment integration
PAN-OS XML API, 10 commands: register/unregister IP tag (Dynamic Address
Group fast-block, no commit), address create/delete, custom URL category
create/edit, EDL list/refresh, commit. API-key auth, targets a vsys, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 23:13:35 +02:00
Guillaume BOURGEOIS 53034f35da feat(zscaler): new Zscaler Internet Access containment integration
ZIA REST API, 12 commands: URL/IP block-list add/remove, block-list and
allow-list read, allow-list add, category URL add, Sandbox report, activate
changes. Session-based obfuscated-API-key auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 23:13:34 +02:00
Guillaume BOURGEOIS fb82de7f93 feat(cisco-umbrella-enforcement): new Cisco Umbrella Enforcement integration
Umbrella Enforcement API, 4 commands: add domain (DNS-layer block),
list enforced domains, delete domain. Customer-key auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 23:13:24 +02:00
Guillaume BOURGEOIS 8ee19ffe85 feat(fortigate): new FortiGate network-containment integration
FortiOS REST API v2, 11 commands: ban/unban/list banned IPs (quarantine),
firewall address object create/delete/list, address-group update/list,
firewall policy and service listing. Bearer-token auth, multi-VDOM, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 23:13:24 +02:00
41 changed files with 3715 additions and 0 deletions
@@ -0,0 +1,62 @@
id: cisco_umbrella_enforcement
name: Cisco Umbrella Enforcement
version: 1.0.0
description: "Cisco Umbrella Enforcement API — DNS-layer containment: push malicious domains to the enforcement block list, list enforced domains, and remove them. Customer-key authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: add domain event (block), list domains, delete domain."
category: network
# Per-instance configuration. The customer key is appended as the 'customerKey'
# query parameter on every request.
config_schema:
properties:
api_url:
type: string
description: "Enforcement API base URL"
default: "https://s-platform.api.opendns.com"
api_key:
type: string
description: "Umbrella Enforcement customer key"
x-soar-sensitive: true
required:
- api_key
commands:
- id: add_domain
name: umbrella-add-domain
description: "Submit a security event that adds a domain to the Umbrella enforcement block list."
inputs_schema:
properties:
domain: { type: string, description: "Domain to block (e.g. malicious.example.com)" }
url: { type: string, description: "Destination URL (defaults to http://<domain>/)" }
device_id: { type: string, description: "Reporting device id (defaults to a fixed Riposte device id)" }
device_version: { type: string, description: "Reporting device version (default 1.0)" }
provider_name: { type: string, description: "Provider name (default 'Riposte SOAR')" }
required: [domain]
outputs_schema: { properties: {} }
- id: list_domains
name: umbrella-list-domains
description: "List the domains currently in the enforcement block list."
risk: read
inputs_schema:
properties:
page: { type: number, description: "Page number (default 1)" }
limit: { type: number, description: "Domains per page (default 200)" }
required: []
outputs_schema: { properties: {} }
- id: delete_domain
name: umbrella-delete-domain
description: "Remove a domain from the enforcement block list by its numeric id."
inputs_schema:
properties:
domain_id: { type: string, description: "Numeric id of the domain to remove (from umbrella-list-domains)" }
required: [domain_id]
outputs_schema: { properties: {} }
- id: test_connection
name: umbrella-test-connection
description: "Verify connectivity and the customer key (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,69 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
import datetime
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return (str(cfg.get("api_url") or "https://s-platform.api.opendns.com")).rstrip("/")
def request(method, path, cfg, body=None, params=None):
p = {"customerKey": str(cfg.get("api_key", ""))}
if params:
p.update(params)
url = _base(cfg) + path + "?" + urllib.parse.urlencode(p)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
domain = str(inputs.get("domain") or "").strip()
if not domain:
raise Exception("domain is required")
url = str(inputs.get("url") or ("http://" + domain + "/"))
device_id = str(inputs.get("device_id") or "ba6a59f4-e692-4724-ba36-c28132c761de")
device_version = str(inputs.get("device_version") or "1.0")
provider_name = str(inputs.get("provider_name") or "Riposte SOAR")
ts = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.0Z")
body = {
"alertTime": ts,
"deviceId": device_id,
"deviceVersion": device_version,
"dstDomain": domain,
"dstUrl": url,
"eventTime": ts,
"protocolVersion": "1.0a",
"providerName": provider_name,
}
return request("POST", "/1.0/events", cfg, body=body)
_run(main)
@@ -0,0 +1,53 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return (str(cfg.get("api_url") or "https://s-platform.api.opendns.com")).rstrip("/")
def request(method, path, cfg, body=None, params=None):
p = {"customerKey": str(cfg.get("api_key", ""))}
if params:
p.update(params)
url = _base(cfg) + path + "?" + urllib.parse.urlencode(p)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
domain_id = str(inputs.get("domain_id") or "").strip()
if not domain_id:
raise Exception("domain_id is required")
result = request("DELETE", "/1.0/domains/" + urllib.parse.quote(str(domain_id), safe=""), cfg)
if not result:
return {"ok": True, "deleted": domain_id}
return result
_run(main)
@@ -0,0 +1,59 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return (str(cfg.get("api_url") or "https://s-platform.api.opendns.com")).rstrip("/")
def request(method, path, cfg, body=None, params=None):
p = {"customerKey": str(cfg.get("api_key", ""))}
if params:
p.update(params)
url = _base(cfg) + path + "?" + urllib.parse.urlencode(p)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
page_raw = inputs.get("page")
limit_raw = inputs.get("limit")
try:
page = int(page_raw) if page_raw not in (None, "") else 1
except (TypeError, ValueError):
page = 1
try:
limit = int(limit_raw) if limit_raw not in (None, "") else 200
except (TypeError, ValueError):
limit = 200
return request("GET", "/1.0/domains", cfg, params={"page": page, "limit": limit})
_run(main)
@@ -0,0 +1,47 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return (str(cfg.get("api_url") or "https://s-platform.api.opendns.com")).rstrip("/")
def request(method, path, cfg, body=None, params=None):
p = {"customerKey": str(cfg.get("api_key", ""))}
if params:
p.update(params)
url = _base(cfg) + path + "?" + urllib.parse.urlencode(p)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
request("GET", "/1.0/domains", cfg, params={"page": 1, "limit": 1})
return {"ok": True}
_run(main)
+137
View File
@@ -0,0 +1,137 @@
id: fortigate
name: FortiGate
version: 1.0.0
description: "Fortinet FortiGate (FortiOS REST API v2) — network containment: ban/unban IP addresses (quarantine), manage firewall address objects and address groups, and read firewall policies and services. API-token authentication; stdlib-only, no extra Python dependencies. Supports multi-VDOM."
changelog: "1.0.0 — Initial release: ban/unban/list banned IPs, address object create/delete/list, address-group update/list, firewall policy and service listing."
category: network
# Per-instance configuration. The API token is sent as 'Authorization: Bearer <token>'.
# vdom is an optional default applied to every request (overridable per command).
config_schema:
properties:
server:
type: string
description: "FortiGate URL (e.g. https://192.168.0.1)"
api_key:
type: string
description: "FortiOS REST API token"
x-soar-sensitive: true
vdom:
type: string
description: "Default VDOM (leave empty for the management VDOM)"
insecure:
type: boolean
description: "Trust any TLS certificate (not secure)"
default: false
required:
- server
- api_key
commands:
- id: ban_ip
name: fortigate-ban-ip
description: "Quarantine one or more source IP addresses (adds them to the FortiGate banned-IP list)."
inputs_schema:
properties:
ip_addresses: { type: string, description: "Comma-separated IPv4/IPv6 addresses to ban" }
expiry_seconds: { type: number, description: "Ban duration in seconds (0 or empty = indefinite)" }
vdom: { type: string, description: "VDOM override" }
required: [ip_addresses]
outputs_schema: { properties: {} }
- id: unban_ip
name: fortigate-unban-ip
description: "Remove one or more IP addresses from the FortiGate banned-IP list."
inputs_schema:
properties:
ip_addresses: { type: string, description: "Comma-separated addresses to unban (empty = clear all)" }
vdom: { type: string, description: "VDOM override" }
required: []
outputs_schema: { properties: {} }
- id: list_banned_ips
name: fortigate-list-banned-ips
description: "List the currently banned (quarantined) IP addresses."
risk: read
inputs_schema:
properties:
vdom: { type: string, description: "VDOM override" }
required: []
outputs_schema: { properties: {} }
- id: create_address
name: fortigate-create-firewall-address
description: "Create a firewall address object (subnet type)."
inputs_schema:
properties:
name: { type: string, description: "Address object name" }
subnet: { type: string, description: "Subnet as 'IP netmask' or CIDR (e.g. '10.0.0.5 255.255.255.255' or '10.0.0.5/32')" }
comment: { type: string, description: "Optional comment" }
vdom: { type: string, description: "VDOM override" }
required: [name, subnet]
outputs_schema: { properties: {} }
- id: delete_address
name: fortigate-delete-firewall-address
description: "Delete a firewall address object by name."
inputs_schema:
properties:
name: { type: string, description: "Address object name" }
vdom: { type: string, description: "VDOM override" }
required: [name]
outputs_schema: { properties: {} }
- id: list_addresses
name: fortigate-list-firewall-addresses
description: "List firewall address objects (optionally a single one by name)."
risk: read
inputs_schema:
properties:
name: { type: string, description: "Optional address object name to fetch a single entry" }
vdom: { type: string, description: "VDOM override" }
required: []
outputs_schema: { properties: {} }
- id: update_address_group
name: fortigate-update-firewall-address-group
description: "Replace the members of a firewall address group (e.g. a blocked-hosts group referenced by a deny policy)."
inputs_schema:
properties:
name: { type: string, description: "Address group name" }
members: { type: string, description: "Comma-separated address object names that become the group's members" }
vdom: { type: string, description: "VDOM override" }
required: [name, members]
outputs_schema: { properties: {} }
- id: list_address_groups
name: fortigate-list-firewall-address-groups
description: "List firewall address groups (optionally a single one by name)."
risk: read
inputs_schema:
properties:
name: { type: string, description: "Optional address group name to fetch a single entry" }
vdom: { type: string, description: "VDOM override" }
required: []
outputs_schema: { properties: {} }
- id: list_policies
name: fortigate-list-firewall-policies
description: "List IPv4 firewall policies (optionally a single one by policy id)."
risk: read
inputs_schema:
properties:
policy_id: { type: string, description: "Optional policy id to fetch a single entry" }
vdom: { type: string, description: "VDOM override" }
required: []
outputs_schema: { properties: {} }
- id: list_services
name: fortigate-list-firewall-services
description: "List custom firewall services (optionally a single one by name)."
risk: read
inputs_schema:
properties:
name: { type: string, description: "Optional service name to fetch a single entry" }
vdom: { type: string, description: "VDOM override" }
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: fortigate-test-connection
description: "Verify connectivity and the API token (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
+74
View File
@@ -0,0 +1,74 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
raw_ips = inputs.get("ip_addresses")
if not raw_ips or not str(raw_ips).strip():
raise Exception("ip_addresses is required")
ip_list = [ip.strip() for ip in str(raw_ips).split(",") if ip.strip()]
if not ip_list:
raise Exception("ip_addresses is required")
expiry_raw = inputs.get("expiry_seconds")
if expiry_raw is None or str(expiry_raw).strip() == "":
expiry = 0
else:
expiry = int(expiry_raw)
body = {"ip_addresses": ip_list, "expiry": expiry}
return request("POST", "/monitor/user/banned/add_users", cfg, inputs, body=body)
_run(main)
@@ -0,0 +1,72 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = inputs.get("name")
if not name or not str(name).strip():
raise Exception("name is required")
subnet = inputs.get("subnet")
if not subnet or not str(subnet).strip():
raise Exception("subnet is required")
body = {"name": name, "type": "ipmask", "subnet": subnet}
comment = inputs.get("comment")
if comment and str(comment).strip():
body["comment"] = comment
return request("POST", "/cmdb/firewall/address", cfg, inputs, body=body)
_run(main)
@@ -0,0 +1,65 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = inputs.get("name")
if not name or not str(name).strip():
raise Exception("name is required")
path = "/cmdb/firewall/address/" + urllib.parse.quote(str(name), safe="")
return request("DELETE", path, cfg, inputs)
_run(main)
@@ -0,0 +1,64 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = inputs.get("name")
if name and str(name).strip():
path = "/cmdb/firewall/addrgrp/" + urllib.parse.quote(str(name), safe="")
return request("GET", path, cfg, inputs)
return request("GET", "/cmdb/firewall/addrgrp", cfg, inputs)
_run(main)
@@ -0,0 +1,64 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = inputs.get("name")
if name and str(name).strip():
path = "/cmdb/firewall/address/" + urllib.parse.quote(str(name), safe="")
return request("GET", path, cfg, inputs)
return request("GET", "/cmdb/firewall/address", cfg, inputs)
_run(main)
@@ -0,0 +1,60 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
return request("GET", "/monitor/user/banned", cfg, inputs)
_run(main)
@@ -0,0 +1,64 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
policy_id = inputs.get("policy_id")
if policy_id is not None and str(policy_id).strip():
path = "/cmdb/firewall/policy/" + urllib.parse.quote(str(policy_id), safe="")
return request("GET", path, cfg, inputs)
return request("GET", "/cmdb/firewall/policy", cfg, inputs)
_run(main)
@@ -0,0 +1,64 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = inputs.get("name")
if name and str(name).strip():
path = "/cmdb/firewall/service/custom/" + urllib.parse.quote(str(name), safe="")
return request("GET", path, cfg, inputs)
return request("GET", "/cmdb/firewall/service/custom", cfg, inputs)
_run(main)
@@ -0,0 +1,61 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
request("GET", "/monitor/system/status", cfg, inputs)
return {"ok": True}
_run(main)
@@ -0,0 +1,65 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
raw_ips = inputs.get("ip_addresses")
ip_list = [ip.strip() for ip in str(raw_ips).split(",") if ip.strip()] if raw_ips else []
if ip_list:
return request("POST", "/monitor/user/banned/clear_users", cfg, inputs, body={"ip_addresses": ip_list})
return request("POST", "/monitor/user/banned/clear_all", cfg, inputs, body={})
_run(main)
@@ -0,0 +1,72 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx():
cfg = _cfg()
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, inputs, body=None, extra_params=None):
base = str(cfg.get("server", "")).rstrip("/") + "/api/v2"
url = base + path
params = {}
vdom = (inputs.get("vdom") if inputs else None) or cfg.get("vdom")
if vdom:
params["vdom"] = vdom
if extra_params:
params.update(extra_params)
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60, context=_ctx()) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
print(json.dumps(fn(cfg, inputs)))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = inputs.get("name")
if not name or not str(name).strip():
raise Exception("name is required")
raw_members = inputs.get("members")
if not raw_members or not str(raw_members).strip():
raise Exception("members is required")
members_list = [m.strip() for m in str(raw_members).split(",") if m.strip()]
if not members_list:
raise Exception("members is required")
body = {"member": [{"name": m} for m in members_list]}
path = "/cmdb/firewall/addrgrp/" + urllib.parse.quote(str(name), safe="")
return request("PUT", path, cfg, inputs, body=body)
_run(main)
+125
View File
@@ -0,0 +1,125 @@
id: panos
name: PAN-OS / Panorama
version: 1.0.0
description: "Palo Alto Networks PAN-OS / Panorama (XML API) — firewall containment: register/unregister IP tags for Dynamic Address Groups (fast block, no commit), create/delete address objects, create/edit custom URL categories, list and refresh External Dynamic Lists, and commit. API-key authentication; stdlib-only, no extra Python dependencies. Targets a firewall vsys."
changelog: "1.0.0 — Initial release: register/unregister IP tag, address create/delete, custom URL category create/edit, EDL list/refresh, commit."
category: network
# Per-instance configuration. The API key is sent as the 'key' query parameter.
# vsys is the firewall virtual system (default vsys1).
config_schema:
properties:
server:
type: string
description: "PAN-OS / Panorama URL (e.g. https://192.168.0.1)"
api_key:
type: string
description: "PAN-OS API key"
x-soar-sensitive: true
port:
type: number
description: "HTTPS port (default 443)"
default: 443
vsys:
type: string
description: "Virtual system (default vsys1)"
default: "vsys1"
insecure:
type: boolean
description: "Trust any TLS certificate (not secure)"
default: false
required:
- server
- api_key
commands:
- id: register_ip_tag
name: panos-register-ip-tag
description: "Register (tag) an IP address so a Dynamic Address Group matching the tag blocks it immediately — no commit required."
inputs_schema:
properties:
ip: { type: string, description: "IP address to tag" }
tags: { type: string, description: "Comma-separated tags to attach" }
timeout: { type: number, description: "Tag timeout in seconds (0 or empty = no timeout)" }
required: [ip, tags]
outputs_schema: { properties: {} }
- id: unregister_ip_tag
name: panos-unregister-ip-tag
description: "Remove tags from an IP address (releases it from tag-based Dynamic Address Groups)."
inputs_schema:
properties:
ip: { type: string, description: "IP address to untag" }
tags: { type: string, description: "Comma-separated tags to remove" }
required: [ip, tags]
outputs_schema: { properties: {} }
- id: create_address
name: panos-create-address
description: "Create an address object (ip-netmask, ip-range, or fqdn)."
inputs_schema:
properties:
name: { type: string, description: "Address object name" }
value: { type: string, description: "Address value (e.g. 10.0.0.5/32, 10.0.0.1-10.0.0.9, or bad.example.com)" }
type: { type: string, description: "Address type: ip-netmask (default), ip-range, or fqdn" }
description: { type: string, description: "Optional description" }
required: [name, value]
outputs_schema: { properties: {} }
- id: delete_address
name: panos-delete-address
description: "Delete an address object by name."
inputs_schema:
properties:
name: { type: string, description: "Address object name" }
required: [name]
outputs_schema: { properties: {} }
- id: create_custom_url_category
name: panos-create-custom-url-category
description: "Create a custom URL category populated with the given URLs (used by a URL-filtering deny rule)."
inputs_schema:
properties:
name: { type: string, description: "Custom URL category name" }
urls: { type: string, description: "Comma-separated URLs/domains to include" }
description: { type: string, description: "Optional description" }
required: [name, urls]
outputs_schema: { properties: {} }
- id: edit_custom_url_category
name: panos-edit-custom-url-category
description: "Replace the URL list of an existing custom URL category."
inputs_schema:
properties:
name: { type: string, description: "Custom URL category name" }
urls: { type: string, description: "Comma-separated URLs/domains that become the category's full list" }
required: [name, urls]
outputs_schema: { properties: {} }
- id: list_edl
name: panos-list-edl
description: "List External Dynamic Lists configured on the device."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
- id: refresh_edl
name: panos-refresh-edl
description: "Force an immediate refresh of an External Dynamic List."
inputs_schema:
properties:
name: { type: string, description: "External Dynamic List name" }
required: [name]
outputs_schema: { properties: {} }
- id: commit
name: panos-commit
description: "Commit the candidate configuration."
inputs_schema:
properties:
description: { type: string, description: "Optional commit description" }
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: panos-test-connection
description: "Verify connectivity and the API key (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
+100
View File
@@ -0,0 +1,100 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
import xml.etree.ElementTree as ET
from xml.sax.saxutils import escape
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
server = str(cfg.get("server", "")).rstrip("/")
port = cfg.get("port") or 443
return server + ":" + str(port) + "/api/"
def _vsys(cfg):
return cfg.get("vsys") or "vsys1"
def _xpath_addr_prefix(cfg):
return ("/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='"
+ _vsys(cfg) + "']")
def api(cfg, params):
p = dict(params)
p["key"] = str(cfg.get("api_key", ""))
url = _base(cfg) + "?" + urllib.parse.urlencode(p)
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=90, context=_ctx(cfg)) as r:
raw = r.read()
text = raw.decode("utf-8", "replace")
try:
root = ET.fromstring(raw)
except Exception:
raise Exception("Invalid XML response: " + text[:500])
if root.attrib.get("status") != "success":
raise Exception("PAN-OS error: " + text[:800])
return root, text
def _to_dict(elem):
# Shallow XML→dict for returning results
d = dict(elem.attrib)
children = list(elem)
if not children:
if elem.text and elem.text.strip():
d["_text"] = elem.text.strip()
return d
for c in children:
cd = _to_dict(c)
if c.tag in d:
if not isinstance(d[c.tag], list):
d[c.tag] = [d[c.tag]]
d[c.tag].append(cd)
else:
d[c.tag] = cd
return d
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
description = str(inputs.get("description") or "").strip()
cmd = "<commit>"
if description:
cmd += "<description>" + escape(description) + "</description>"
cmd += "</commit>"
root, text = api(cfg, {"type": "commit", "cmd": cmd})
job = root.findtext(".//job")
return {"ok": True, "job": job}
_run(main)
@@ -0,0 +1,111 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
import xml.etree.ElementTree as ET
from xml.sax.saxutils import escape
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
server = str(cfg.get("server", "")).rstrip("/")
port = cfg.get("port") or 443
return server + ":" + str(port) + "/api/"
def _vsys(cfg):
return cfg.get("vsys") or "vsys1"
def _xpath_addr_prefix(cfg):
return ("/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='"
+ _vsys(cfg) + "']")
def api(cfg, params):
p = dict(params)
p["key"] = str(cfg.get("api_key", ""))
url = _base(cfg) + "?" + urllib.parse.urlencode(p)
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=90, context=_ctx(cfg)) as r:
raw = r.read()
text = raw.decode("utf-8", "replace")
try:
root = ET.fromstring(raw)
except Exception:
raise Exception("Invalid XML response: " + text[:500])
if root.attrib.get("status") != "success":
raise Exception("PAN-OS error: " + text[:800])
return root, text
def _to_dict(elem):
# Shallow XML→dict for returning results
d = dict(elem.attrib)
children = list(elem)
if not children:
if elem.text and elem.text.strip():
d["_text"] = elem.text.strip()
return d
for c in children:
cd = _to_dict(c)
if c.tag in d:
if not isinstance(d[c.tag], list):
d[c.tag] = [d[c.tag]]
d[c.tag].append(cd)
else:
d[c.tag] = cd
return d
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = str(inputs.get("name") or "").strip()
if not name:
raise Exception("name is required")
value = str(inputs.get("value") or "").strip()
if not value:
raise Exception("value is required")
addr_type = str(inputs.get("type") or "ip-netmask").strip() or "ip-netmask"
if addr_type not in ("ip-netmask", "ip-range", "fqdn"):
raise Exception("type must be one of ip-netmask, ip-range, fqdn")
description = str(inputs.get("description") or "").strip()
element = "<" + addr_type + ">" + escape(value) + "</" + addr_type + ">"
if description:
element += "<description>" + escape(description) + "</description>"
xpath = _xpath_addr_prefix(cfg) + "/address/entry[@name='" + name + "']"
api(cfg, {"type": "config", "action": "set", "xpath": xpath, "element": element})
return {"ok": True, "name": name}
_run(main)
@@ -0,0 +1,110 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
import xml.etree.ElementTree as ET
from xml.sax.saxutils import escape
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
server = str(cfg.get("server", "")).rstrip("/")
port = cfg.get("port") or 443
return server + ":" + str(port) + "/api/"
def _vsys(cfg):
return cfg.get("vsys") or "vsys1"
def _xpath_addr_prefix(cfg):
return ("/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='"
+ _vsys(cfg) + "']")
def api(cfg, params):
p = dict(params)
p["key"] = str(cfg.get("api_key", ""))
url = _base(cfg) + "?" + urllib.parse.urlencode(p)
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=90, context=_ctx(cfg)) as r:
raw = r.read()
text = raw.decode("utf-8", "replace")
try:
root = ET.fromstring(raw)
except Exception:
raise Exception("Invalid XML response: " + text[:500])
if root.attrib.get("status") != "success":
raise Exception("PAN-OS error: " + text[:800])
return root, text
def _to_dict(elem):
# Shallow XML→dict for returning results
d = dict(elem.attrib)
children = list(elem)
if not children:
if elem.text and elem.text.strip():
d["_text"] = elem.text.strip()
return d
for c in children:
cd = _to_dict(c)
if c.tag in d:
if not isinstance(d[c.tag], list):
d[c.tag] = [d[c.tag]]
d[c.tag].append(cd)
else:
d[c.tag] = cd
return d
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = str(inputs.get("name") or "").strip()
if not name:
raise Exception("name is required")
urls = [s.strip() for s in str(inputs.get("urls") or "").split(",") if s.strip()]
if not urls:
raise Exception("urls is required")
description = str(inputs.get("description") or "").strip()
members = "".join("<member>" + escape(u) + "</member>" for u in urls)
element = "<list>" + members + "</list><type>URL List</type>"
if description:
element += "<description>" + escape(description) + "</description>"
xpath = (
_xpath_addr_prefix(cfg) + "/profiles/custom-url-category/entry[@name='" + name + "']"
)
api(cfg, {"type": "config", "action": "set", "xpath": xpath, "element": element})
return {"ok": True, "name": name}
_run(main)
@@ -0,0 +1,96 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
import xml.etree.ElementTree as ET
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
server = str(cfg.get("server", "")).rstrip("/")
port = cfg.get("port") or 443
return server + ":" + str(port) + "/api/"
def _vsys(cfg):
return cfg.get("vsys") or "vsys1"
def _xpath_addr_prefix(cfg):
return ("/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='"
+ _vsys(cfg) + "']")
def api(cfg, params):
p = dict(params)
p["key"] = str(cfg.get("api_key", ""))
url = _base(cfg) + "?" + urllib.parse.urlencode(p)
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=90, context=_ctx(cfg)) as r:
raw = r.read()
text = raw.decode("utf-8", "replace")
try:
root = ET.fromstring(raw)
except Exception:
raise Exception("Invalid XML response: " + text[:500])
if root.attrib.get("status") != "success":
raise Exception("PAN-OS error: " + text[:800])
return root, text
def _to_dict(elem):
# Shallow XML→dict for returning results
d = dict(elem.attrib)
children = list(elem)
if not children:
if elem.text and elem.text.strip():
d["_text"] = elem.text.strip()
return d
for c in children:
cd = _to_dict(c)
if c.tag in d:
if not isinstance(d[c.tag], list):
d[c.tag] = [d[c.tag]]
d[c.tag].append(cd)
else:
d[c.tag] = cd
return d
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = str(inputs.get("name") or "").strip()
if not name:
raise Exception("name is required")
xpath = _xpath_addr_prefix(cfg) + "/address/entry[@name='" + name + "']"
api(cfg, {"type": "config", "action": "delete", "xpath": xpath})
return {"ok": True, "name": name}
_run(main)
@@ -0,0 +1,107 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
import xml.etree.ElementTree as ET
from xml.sax.saxutils import escape
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
server = str(cfg.get("server", "")).rstrip("/")
port = cfg.get("port") or 443
return server + ":" + str(port) + "/api/"
def _vsys(cfg):
return cfg.get("vsys") or "vsys1"
def _xpath_addr_prefix(cfg):
return ("/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='"
+ _vsys(cfg) + "']")
def api(cfg, params):
p = dict(params)
p["key"] = str(cfg.get("api_key", ""))
url = _base(cfg) + "?" + urllib.parse.urlencode(p)
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=90, context=_ctx(cfg)) as r:
raw = r.read()
text = raw.decode("utf-8", "replace")
try:
root = ET.fromstring(raw)
except Exception:
raise Exception("Invalid XML response: " + text[:500])
if root.attrib.get("status") != "success":
raise Exception("PAN-OS error: " + text[:800])
return root, text
def _to_dict(elem):
# Shallow XML→dict for returning results
d = dict(elem.attrib)
children = list(elem)
if not children:
if elem.text and elem.text.strip():
d["_text"] = elem.text.strip()
return d
for c in children:
cd = _to_dict(c)
if c.tag in d:
if not isinstance(d[c.tag], list):
d[c.tag] = [d[c.tag]]
d[c.tag].append(cd)
else:
d[c.tag] = cd
return d
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = str(inputs.get("name") or "").strip()
if not name:
raise Exception("name is required")
urls = [s.strip() for s in str(inputs.get("urls") or "").split(",") if s.strip()]
if not urls:
raise Exception("urls is required")
members = "".join("<member>" + escape(u) + "</member>" for u in urls)
element = "<list>" + members + "</list>"
xpath = (
_xpath_addr_prefix(cfg)
+ "/profiles/custom-url-category/entry[@name='" + name + "']/list"
)
api(cfg, {"type": "config", "action": "edit", "xpath": xpath, "element": element})
return {"ok": True, "name": name}
_run(main)
+96
View File
@@ -0,0 +1,96 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
import xml.etree.ElementTree as ET
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
server = str(cfg.get("server", "")).rstrip("/")
port = cfg.get("port") or 443
return server + ":" + str(port) + "/api/"
def _vsys(cfg):
return cfg.get("vsys") or "vsys1"
def _xpath_addr_prefix(cfg):
return ("/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='"
+ _vsys(cfg) + "']")
def api(cfg, params):
p = dict(params)
p["key"] = str(cfg.get("api_key", ""))
url = _base(cfg) + "?" + urllib.parse.urlencode(p)
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=90, context=_ctx(cfg)) as r:
raw = r.read()
text = raw.decode("utf-8", "replace")
try:
root = ET.fromstring(raw)
except Exception:
raise Exception("Invalid XML response: " + text[:500])
if root.attrib.get("status") != "success":
raise Exception("PAN-OS error: " + text[:800])
return root, text
def _to_dict(elem):
# Shallow XML→dict for returning results
d = dict(elem.attrib)
children = list(elem)
if not children:
if elem.text and elem.text.strip():
d["_text"] = elem.text.strip()
return d
for c in children:
cd = _to_dict(c)
if c.tag in d:
if not isinstance(d[c.tag], list):
d[c.tag] = [d[c.tag]]
d[c.tag].append(cd)
else:
d[c.tag] = cd
return d
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
xpath = _xpath_addr_prefix(cfg) + "/external-list"
root, text = api(cfg, {"type": "config", "action": "get", "xpath": xpath})
result_elem = root.find("result")
if result_elem is None:
return {"result": {}}
return {"result": _to_dict(result_elem)}
_run(main)
+101
View File
@@ -0,0 +1,101 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
import xml.etree.ElementTree as ET
from xml.sax.saxutils import escape
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
server = str(cfg.get("server", "")).rstrip("/")
port = cfg.get("port") or 443
return server + ":" + str(port) + "/api/"
def _vsys(cfg):
return cfg.get("vsys") or "vsys1"
def _xpath_addr_prefix(cfg):
return ("/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='"
+ _vsys(cfg) + "']")
def api(cfg, params):
p = dict(params)
p["key"] = str(cfg.get("api_key", ""))
url = _base(cfg) + "?" + urllib.parse.urlencode(p)
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=90, context=_ctx(cfg)) as r:
raw = r.read()
text = raw.decode("utf-8", "replace")
try:
root = ET.fromstring(raw)
except Exception:
raise Exception("Invalid XML response: " + text[:500])
if root.attrib.get("status") != "success":
raise Exception("PAN-OS error: " + text[:800])
return root, text
def _to_dict(elem):
# Shallow XML→dict for returning results
d = dict(elem.attrib)
children = list(elem)
if not children:
if elem.text and elem.text.strip():
d["_text"] = elem.text.strip()
return d
for c in children:
cd = _to_dict(c)
if c.tag in d:
if not isinstance(d[c.tag], list):
d[c.tag] = [d[c.tag]]
d[c.tag].append(cd)
else:
d[c.tag] = cd
return d
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
name = str(inputs.get("name") or "").strip()
if not name:
raise Exception("name is required")
cmd = (
"<request><system><external-list><refresh><name>"
+ escape(name)
+ "</name></refresh></external-list></system></request>"
)
api(cfg, {"type": "op", "cmd": cmd})
return {"ok": True, "name": name}
_run(main)
@@ -0,0 +1,119 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
import xml.etree.ElementTree as ET
from xml.sax.saxutils import escape, quoteattr
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
server = str(cfg.get("server", "")).rstrip("/")
port = cfg.get("port") or 443
return server + ":" + str(port) + "/api/"
def _vsys(cfg):
return cfg.get("vsys") or "vsys1"
def _xpath_addr_prefix(cfg):
return ("/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='"
+ _vsys(cfg) + "']")
def api(cfg, params):
p = dict(params)
p["key"] = str(cfg.get("api_key", ""))
url = _base(cfg) + "?" + urllib.parse.urlencode(p)
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=90, context=_ctx(cfg)) as r:
raw = r.read()
text = raw.decode("utf-8", "replace")
try:
root = ET.fromstring(raw)
except Exception:
raise Exception("Invalid XML response: " + text[:500])
if root.attrib.get("status") != "success":
raise Exception("PAN-OS error: " + text[:800])
return root, text
def _to_dict(elem):
# Shallow XML→dict for returning results
d = dict(elem.attrib)
children = list(elem)
if not children:
if elem.text and elem.text.strip():
d["_text"] = elem.text.strip()
return d
for c in children:
cd = _to_dict(c)
if c.tag in d:
if not isinstance(d[c.tag], list):
d[c.tag] = [d[c.tag]]
d[c.tag].append(cd)
else:
d[c.tag] = cd
return d
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
ip = str(inputs.get("ip") or "").strip()
if not ip:
raise Exception("ip is required")
tags = [s.strip() for s in str(inputs.get("tags") or "").split(",") if s.strip()]
if not tags:
raise Exception("tags is required")
timeout_attr = ""
timeout = inputs.get("timeout")
if timeout not in (None, ""):
try:
t = int(timeout)
except (TypeError, ValueError):
t = 0
if t > 0:
timeout_attr = ' timeout="' + str(t) + '"'
members = "".join(
"<member" + timeout_attr + ">" + escape(tag) + "</member>" for tag in tags
)
uid_xml = (
"<uid-message><version>1.0</version><type>update</type><payload><register>"
"<entry ip=" + quoteattr(ip) + ' persistent="1"><tag>' + members + "</tag>"
"</entry></register></payload></uid-message>"
)
api(cfg, {"type": "user-id", "vsys": _vsys(cfg), "cmd": uid_xml})
return {"ok": True, "ip": ip, "tags": tags}
_run(main)
@@ -0,0 +1,92 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
import xml.etree.ElementTree as ET
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
server = str(cfg.get("server", "")).rstrip("/")
port = cfg.get("port") or 443
return server + ":" + str(port) + "/api/"
def _vsys(cfg):
return cfg.get("vsys") or "vsys1"
def _xpath_addr_prefix(cfg):
return ("/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='"
+ _vsys(cfg) + "']")
def api(cfg, params):
p = dict(params)
p["key"] = str(cfg.get("api_key", ""))
url = _base(cfg) + "?" + urllib.parse.urlencode(p)
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=90, context=_ctx(cfg)) as r:
raw = r.read()
text = raw.decode("utf-8", "replace")
try:
root = ET.fromstring(raw)
except Exception:
raise Exception("Invalid XML response: " + text[:500])
if root.attrib.get("status") != "success":
raise Exception("PAN-OS error: " + text[:800])
return root, text
def _to_dict(elem):
# Shallow XML→dict for returning results
d = dict(elem.attrib)
children = list(elem)
if not children:
if elem.text and elem.text.strip():
d["_text"] = elem.text.strip()
return d
for c in children:
cd = _to_dict(c)
if c.tag in d:
if not isinstance(d[c.tag], list):
d[c.tag] = [d[c.tag]]
d[c.tag].append(cd)
else:
d[c.tag] = cd
return d
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
cmd = "<show><system><info></info></system></show>"
api(cfg, {"type": "op", "cmd": cmd})
return {"ok": True}
_run(main)
@@ -0,0 +1,107 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error, ssl
import xml.etree.ElementTree as ET
from xml.sax.saxutils import escape, quoteattr
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _base(cfg):
server = str(cfg.get("server", "")).rstrip("/")
port = cfg.get("port") or 443
return server + ":" + str(port) + "/api/"
def _vsys(cfg):
return cfg.get("vsys") or "vsys1"
def _xpath_addr_prefix(cfg):
return ("/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='"
+ _vsys(cfg) + "']")
def api(cfg, params):
p = dict(params)
p["key"] = str(cfg.get("api_key", ""))
url = _base(cfg) + "?" + urllib.parse.urlencode(p)
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=90, context=_ctx(cfg)) as r:
raw = r.read()
text = raw.decode("utf-8", "replace")
try:
root = ET.fromstring(raw)
except Exception:
raise Exception("Invalid XML response: " + text[:500])
if root.attrib.get("status") != "success":
raise Exception("PAN-OS error: " + text[:800])
return root, text
def _to_dict(elem):
# Shallow XML→dict for returning results
d = dict(elem.attrib)
children = list(elem)
if not children:
if elem.text and elem.text.strip():
d["_text"] = elem.text.strip()
return d
for c in children:
cd = _to_dict(c)
if c.tag in d:
if not isinstance(d[c.tag], list):
d[c.tag] = [d[c.tag]]
d[c.tag].append(cd)
else:
d[c.tag] = cd
return d
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
ip = str(inputs.get("ip") or "").strip()
if not ip:
raise Exception("ip is required")
tags = [s.strip() for s in str(inputs.get("tags") or "").split(",") if s.strip()]
if not tags:
raise Exception("tags is required")
members = "".join("<member>" + escape(tag) + "</member>" for tag in tags)
uid_xml = (
"<uid-message><version>1.0</version><type>update</type><payload><unregister>"
"<entry ip=" + quoteattr(ip) + "><tag>" + members + "</tag>"
"</entry></unregister></payload></uid-message>"
)
api(cfg, {"type": "user-id", "vsys": _vsys(cfg), "cmd": uid_xml})
return {"ok": True, "ip": ip, "tags": tags}
_run(main)
+137
View File
@@ -0,0 +1,137 @@
id: zscaler
name: Zscaler Internet Access
version: 1.0.0
description: "Zscaler Internet Access (ZIA REST API) — web-layer containment: block/unblock URLs and IPs (advanced block list), manage the allow list, add URLs to custom categories, read Sandbox reports, and activate configuration changes. Session-based API-key authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: URL/IP block list add/remove, block-list and allow-list read, allow-list add, category URL add, Sandbox report, activate changes."
category: network
# Per-instance configuration. Authentication is session-based: each command logs
# in with the obfuscated API key + username/password, then reuses the session
# cookie for the request.
config_schema:
properties:
cloud:
type: string
description: "Zscaler cloud base URL (e.g. https://zsapi.zscalertwo.net)"
username:
type: string
description: "ZIA admin username"
password:
type: string
description: "ZIA admin password"
x-soar-sensitive: true
api_key:
type: string
description: "ZIA API key"
x-soar-sensitive: true
insecure:
type: boolean
description: "Trust any TLS certificate (not secure)"
default: false
required:
- cloud
- username
- password
- api_key
commands:
- id: blacklist_url
name: zscaler-blacklist-url
description: "Add one or more URLs to the advanced block list."
inputs_schema:
properties:
urls: { type: string, description: "Comma-separated URLs to block" }
required: [urls]
outputs_schema: { properties: {} }
- id: undo_blacklist_url
name: zscaler-undo-blacklist-url
description: "Remove one or more URLs from the advanced block list."
inputs_schema:
properties:
urls: { type: string, description: "Comma-separated URLs to remove" }
required: [urls]
outputs_schema: { properties: {} }
- id: blacklist_ip
name: zscaler-blacklist-ip
description: "Add one or more IP addresses to the advanced block list."
inputs_schema:
properties:
ips: { type: string, description: "Comma-separated IP addresses to block" }
required: [ips]
outputs_schema: { properties: {} }
- id: undo_blacklist_ip
name: zscaler-undo-blacklist-ip
description: "Remove one or more IP addresses from the advanced block list."
inputs_schema:
properties:
ips: { type: string, description: "Comma-separated IP addresses to remove" }
required: [ips]
outputs_schema: { properties: {} }
- id: get_blacklist
name: zscaler-get-blacklist
description: "Get the current advanced block list (URLs and IPs)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
- id: whitelist_url
name: zscaler-whitelist-url
description: "Add one or more URLs to the allow list."
inputs_schema:
properties:
urls: { type: string, description: "Comma-separated URLs to allow" }
required: [urls]
outputs_schema: { properties: {} }
- id: get_whitelist
name: zscaler-get-whitelist
description: "Get the current allow list."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
- id: category_add_url
name: zscaler-category-add-url
description: "Add one or more URLs to a custom URL category."
inputs_schema:
properties:
category_id: { type: string, description: "URL category id (from zscaler-get-categories)" }
urls: { type: string, description: "Comma-separated URLs to add to the category" }
required: [category_id, urls]
outputs_schema: { properties: {} }
- id: get_categories
name: zscaler-get-categories
description: "List URL categories (id and name)."
risk: read
inputs_schema:
properties:
custom_only: { type: boolean, description: "Return only custom categories (default false)" }
required: []
outputs_schema: { properties: {} }
- id: sandbox_report
name: zscaler-sandbox-report
description: "Get the Zscaler Sandbox report for a file by MD5 hash."
risk: read
inputs_schema:
properties:
md5: { type: string, description: "MD5 hash of the file" }
details: { type: string, description: "Report detail level: 'full' or 'summary' (default full)" }
required: [md5]
outputs_schema: { properties: {} }
- id: activate_changes
name: zscaler-activate-changes
description: "Activate pending configuration changes in the Zscaler session."
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: zscaler-test-connection
description: "Verify connectivity and credentials by opening a session (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,99 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
result = client.call("POST", "/status/activate")
if not result:
return {"ok": True}
return result
_run(main)
@@ -0,0 +1,111 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
raw_ips = inputs.get("ips")
if not raw_ips:
raise Exception("ips is required")
ips = [s.strip() for s in str(raw_ips).split(",") if s.strip()]
if not ips:
raise Exception("ips is required")
result = client.call(
"POST",
"/security/advanced/blacklistUrls",
params={"action": "ADD_TO_LIST"},
body={"blacklistUrls": ips},
)
if not result:
return {"ok": True, "added": ips}
return result
_run(main)
@@ -0,0 +1,111 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
raw_urls = inputs.get("urls")
if not raw_urls:
raise Exception("urls is required")
urls = [s.strip() for s in str(raw_urls).split(",") if s.strip()]
if not urls:
raise Exception("urls is required")
result = client.call(
"POST",
"/security/advanced/blacklistUrls",
params={"action": "ADD_TO_LIST"},
body={"blacklistUrls": urls},
)
if not result:
return {"ok": True, "added": urls}
return result
_run(main)
@@ -0,0 +1,115 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
category_id = inputs.get("category_id")
if not category_id:
raise Exception("category_id is required")
raw_urls = inputs.get("urls")
if not raw_urls:
raise Exception("urls is required")
urls = [s.strip() for s in str(raw_urls).split(",") if s.strip()]
if not urls:
raise Exception("urls is required")
path = "/urlCategories/" + urllib.parse.quote(str(category_id), safe="")
result = client.call(
"PUT",
path,
params={"action": "ADD_TO_LIST"},
body={"configuredUrls": urls},
)
if not result:
return {"ok": True}
return result
_run(main)
@@ -0,0 +1,96 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
return client.call("GET", "/security/advanced")
_run(main)
@@ -0,0 +1,100 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
custom_only = inputs.get("custom_only", False)
params = None
if str(custom_only).strip().lower() in ("1", "true", "yes"):
params = {"customOnly": "true"}
return client.call("GET", "/urlCategories", params=params)
_run(main)
@@ -0,0 +1,96 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
return client.call("GET", "/security")
_run(main)
@@ -0,0 +1,102 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
md5 = inputs.get("md5")
if not md5:
raise Exception("md5 is required")
details = inputs.get("details") or "full"
path = "/sandbox/report/" + urllib.parse.quote(str(md5), safe="")
return client.call("GET", path, params={"details": details})
_run(main)
@@ -0,0 +1,97 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
client.call("GET", "/status")
return {"ok": True}
_run(main)
@@ -0,0 +1,111 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
raw_ips = inputs.get("ips")
if not raw_ips:
raise Exception("ips is required")
ips = [s.strip() for s in str(raw_ips).split(",") if s.strip()]
if not ips:
raise Exception("ips is required")
result = client.call(
"POST",
"/security/advanced/blacklistUrls",
params={"action": "REMOVE_FROM_LIST"},
body={"blacklistUrls": ips},
)
if not result:
return {"ok": True, "removed": ips}
return result
_run(main)
@@ -0,0 +1,111 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
raw_urls = inputs.get("urls")
if not raw_urls:
raise Exception("urls is required")
urls = [s.strip() for s in str(raw_urls).split(",") if s.strip()]
if not urls:
raise Exception("urls is required")
result = client.call(
"POST",
"/security/advanced/blacklistUrls",
params={"action": "REMOVE_FROM_LIST"},
body={"blacklistUrls": urls},
)
if not result:
return {"ok": True, "removed": urls}
return result
_run(main)
@@ -0,0 +1,113 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error, http.cookiejar, ssl
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def obfuscate_api_key(api_key):
now = str(int(time.time() * 1000))
n = now[-6:]
r = str(int(n) >> 1).zfill(6)
key = ""
for i in range(len(n)):
key += api_key[int(n[i])]
for j in range(len(r)):
key += api_key[int(r[j]) + 2]
return now, key
class Client:
def __init__(self, cfg):
self.cfg = cfg
self.base = str(cfg.get("cloud", "")).rstrip("/") + "/api/v1"
self.ctx = _ctx(cfg)
self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()),
urllib.request.HTTPSHandler(context=self.ctx) if self.ctx else urllib.request.HTTPSHandler(),
)
def call(self, method, path, body=None, params=None):
url = self.base + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with self.opener.open(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def login(self):
ts, obf = obfuscate_api_key(str(self.cfg.get("api_key", "")))
body = {
"apiKey": obf,
"username": self.cfg.get("username", ""),
"password": self.cfg.get("password", ""),
"timestamp": ts,
}
return self.call("POST", "/authenticatedSession", body=body)
def logout(self):
try:
self.call("DELETE", "/authenticatedSession")
except Exception:
pass
def _run(fn):
try:
cfg = _cfg()
inputs = _inputs()
client = Client(cfg)
client.login()
try:
result = fn(client, inputs)
finally:
client.logout()
print(json.dumps(result))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(client, inputs):
raw_urls = inputs.get("urls")
if not raw_urls:
raise Exception("urls is required")
new_urls = [s.strip() for s in str(raw_urls).split(",") if s.strip()]
if not new_urls:
raise Exception("urls is required")
sec = client.call("GET", "/security")
if not isinstance(sec, dict):
sec = {}
existing = sec.get("whitelistUrls") or []
merged = existing + [u for u in new_urls if u not in existing]
sec["whitelistUrls"] = merged
result = client.call("PUT", "/security", body=sec)
if not result:
return {"ok": True, "whitelistUrls": merged}
return result
_run(main)