From 5e6d09a1cc75b4d3a9031fba689d0b019c92fa1d Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Wed, 30 Jun 2021 13:25:19 +0100 Subject: [PATCH] Add notification to antenna --- Makefile | 9 ++++++++- tools/gemcall | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 tools/gemcall diff --git a/Makefile b/Makefile index bed7805..93aed63 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ DESTDIR=~/public_gemini .PHONY: all -all: pull build +all: pull build deploy notify-antenna .PHONY: pull pull: @@ -15,5 +15,12 @@ clean: .PHONY: build build: ${HOME}/bin/kiln build + +.PHONY: deploy +deploy: mkdir -p $(DESTDIR)/ cp -R public/* $(DESTDIR)/ + +.PHONY: notify-antenna +notify-antenna: + tools/gemcall -u gemini://warmedal.se/~antenna/submit?dimension.sh/~nikdoof/logs/atom.xml \ No newline at end of file diff --git a/tools/gemcall b/tools/gemcall new file mode 100755 index 0000000..378a892 --- /dev/null +++ b/tools/gemcall @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import socket +import urllib.parse as up +import ssl +import sys +import getopt + + +def printhelp(): + print('gemcall -u [-c -k ]') + + +up.uses_relative.append("gemini") +up.uses_netloc.append("gemini") + +url = '' +clientcert = '' +clientkey = '' + +try: + opts, args = getopt.getopt(sys.argv[1:], "hu:c:k:", ["help", "url=", "clientcert=", "clientkey="]) +except getopt.GetoptError: + printhelp() + sys.exit(2) + +for opt, arg in opts: + if opt in ("-h", "--help"): + printhelp() + sys.exit() + elif opt in ("-c", "--clientcert"): + clientcert = arg + elif opt in ("-k", "--clientkey"): + clientkey = arg + elif opt in ("-u", "--url"): + url = arg + +parsed = up.urlparse(url).encode("idna") + +context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) +context.minimum_version = ssl.TLSVersion.TLSv1_2 +context.check_hostname = False +context.verify_mode = ssl.CERT_NONE +if (clientcert and clientkey): + context.load_cert_chain(clientcert, clientkey) + +sock = socket.create_connection((parsed.hostname, parsed.port or 1965)) +ssock = context.wrap_socket(sock, server_hostname=parsed.hostname) +ssock.sendall((up.urlunparse(parsed).decode("UTF-8")+"\r\n").encode("ascii")) +print(ssock.makefile(mode="rb").read().decode('UTF-8'))