mirror of
https://github.com/sstent/containers.git
synced 2025-12-06 08:01:51 +00:00
adding portfwd job
This commit is contained in:
18
.drone/portfwd.yml
Normal file
18
.drone/portfwd.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
clone:
|
||||
git:
|
||||
image: plugins/git
|
||||
when:
|
||||
path: 'portfwd/*'
|
||||
|
||||
pipeline:
|
||||
publish_portfwd:
|
||||
image: plugins/docker
|
||||
repo: registry.service.dc1.consul:5000/portfwd
|
||||
registry: registry.service.dc1.consul:5000
|
||||
insecure: true
|
||||
context: portfwd/
|
||||
dockerfile: portfwd/Dockerfile
|
||||
when:
|
||||
path: 'portfwd/*'
|
||||
...
|
||||
10
portfwd/Dockerfile
Normal file
10
portfwd/Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
FROM alpine:3
|
||||
RUN apk add --no-cache python3 py3-pip
|
||||
|
||||
RUN pip install unificontrol
|
||||
ADD unifi.py ./
|
||||
ENV IP_ADDR=192.168.1.100
|
||||
# EXPOSE 1080
|
||||
|
||||
ENTRYPOINT ["python3","unifi.py"]
|
||||
33
portfwd/unifi.py
Normal file
33
portfwd/unifi.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import ssl
|
||||
import unificontrol
|
||||
from unificontrol.metaprogram import UnifiAPICall, UnifiAPICallNoSite, MetaNameFixer
|
||||
from pprint import pprint
|
||||
import os
|
||||
|
||||
FWD_IP = os.getenv('IP_ADDR')
|
||||
cert = ssl.get_server_certificate(("unifi.service.dc1.consul", 8443))
|
||||
# Store the cert in a safe place
|
||||
...
|
||||
# Fetch the cert from a safe place
|
||||
client = unificontrol.UnifiClient(host="unifi.service.dc1.consul",
|
||||
username="admin", password="tSxLlolgmXq6Zp1HplWK", site="default",
|
||||
cert=cert)
|
||||
|
||||
edit_forward = UnifiAPICall(
|
||||
"update Port forward",
|
||||
"rest/portforward/613a5bb648247c60a5b14ba6",
|
||||
json_args=[
|
||||
('_id', '613a5bb648247c60a5b14ba6'),
|
||||
('enabled', 'true'),
|
||||
('dst_port', '51820'),
|
||||
('fwd', FWD_IP),
|
||||
('fwd_port', '51820'),
|
||||
('name', 'wireguard'),
|
||||
('proto', 'udp'),
|
||||
('site_id', '5c9419f5e718399f4a746e7f'),
|
||||
('src', 'any')],
|
||||
method="PUT",
|
||||
)
|
||||
|
||||
pprint(edit_forward(client))
|
||||
|
||||
Reference in New Issue
Block a user