diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-04-09 16:15:26 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-04-09 16:15:26 +0200 |
commit | 65cd1f047cca1f06621770d18b2d9bc27e6f999c (patch) | |
tree | 60e4dd8fc70a41697267ea99cf8214506dd62b23 | |
parent | e5689cfdfb619235ac1691e0b0eaccf63ca5ae5a (diff) | |
download | deployment-65cd1f047cca1f06621770d18b2d9bc27e6f999c.tar.gz deployment-65cd1f047cca1f06621770d18b2d9bc27e6f999c.tar.bz2 deployment-65cd1f047cca1f06621770d18b2d9bc27e6f999c.zip |
netzbon letter
-rw-r--r-- | netzbon/.gitignore | 3 | ||||
-rwxr-xr-x | netzbon/generate-letter.sh | 40 | ||||
-rwxr-xr-x | netzbon/render.py | 49 | ||||
-rwxr-xr-x | netzbon/setup-merchants.sh | 39 | ||||
-rw-r--r-- | netzbon/template.tex.j2 | 69 | ||||
-rw-r--r-- | netzbon/test.json | 7 |
6 files changed, 207 insertions, 0 deletions
diff --git a/netzbon/.gitignore b/netzbon/.gitignore new file mode 100644 index 0000000..e2f6acc --- /dev/null +++ b/netzbon/.gitignore @@ -0,0 +1,3 @@ +export/ +tmp/ +result.pdf diff --git a/netzbon/generate-letter.sh b/netzbon/generate-letter.sh new file mode 100755 index 0000000..991a547 --- /dev/null +++ b/netzbon/generate-letter.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# This script is in the public domain. +# +# Call with the JSON file (like test.json) with +# an array of merchants to generate letters for! +# +# You must export +# +# export BASE_URL=https://e.netzbon-basel.ch/ +# +# before running this script! +# + +set -eu +LENGTH=$(jq length < $1) +echo "Generating $LENGTH letters for ${BASE_URL}" +DOMAIN=$( echo "${BASE_URL}" | sed -e "s/https:\/\///" | sed -e "s/\/$//") +mkdir -p export +mkdir -p tmp + +for n in $(seq 1 $LENGTH) +do + echo "Processing merchant $n" + INDEX=$(expr $n - 1 || true) + ID=$(jq -r .[$INDEX].id < $1) + + jq ".[$INDEX]" < $1 | jq '.domain="'"${DOMAIN}"'"' > "tmp/${ID}.json" + cd tmp + ../render.py "${ID}.json" < ../template.tex.j2 > "${ID}.tex" + pdflatex "${ID}.tex" < /dev/null &> /dev/null || true + pdflatex "${ID}.tex" < /dev/null &> /dev/null || true + pdflatex "${ID}.tex" < /dev/null + mv "${ID}.pdf" ../export/ + cd .. + + echo "Done with ${ID}" +done + +pdftk export/*.pdf cat output result.pdf +echo "Combined letters are in 'result.pdf'" diff --git a/netzbon/render.py b/netzbon/render.py new file mode 100755 index 0000000..8bce600 --- /dev/null +++ b/netzbon/render.py @@ -0,0 +1,49 @@ +#!/usr/bin/python3 +# This file is in the public domain. + +"""Expand Jinja2 templates based on JSON input. + +The tool then reads the template from stdin and writes the expanded +output to stdout. + +TODO: proper installation, man page, error handling, --help option. + +@author Christian Grothoff + +""" + +import sys +import json +import jinja2 +from jinja2 import BaseLoader + + +class StdinLoader(BaseLoader): + def __init__ (self): + self.path = '-' + def get_source(self, environment, template): + source = sys.stdin.read() + return source, self.path, lambda: false + + +jsonFile1 = open (sys.argv[1], 'r') +jsonData1 = json.load(jsonFile1) + +jinjaEnv = jinja2.Environment(loader=StdinLoader(), + lstrip_blocks=True, + trim_blocks=True, + undefined=jinja2.StrictUndefined, + autoescape=False) +tmpl = jinjaEnv.get_template('stdin'); + +try: + print(tmpl.render(data = jsonData1)) +except jinja2.TemplateSyntaxError as error: + print("Template syntax error: {error.message} on line {error.lineno}.".format(error=error)) + exit(1) +except jinja2.UndefinedError as error: + print("Template undefined error: {error.message}.".format(error=error)) + exit(1) +except TypeError as error: + print("Template type error: {0}.".format(error.args[0])) + exit(1) diff --git a/netzbon/setup-merchants.sh b/netzbon/setup-merchants.sh new file mode 100755 index 0000000..7fa1d3b --- /dev/null +++ b/netzbon/setup-merchants.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# This script is in the public domain. +# +# You must export +# +# export BASE_URL=e.netzbon-basel.ch +# export MERCHANT_TOKEN=password +# export BANK_TOKEN=password +# +# before running this script! +# +# Call with the JSON file (like test.json) with +# an array of merchants to set up as the first argument! +# +# FIXME: nice error handling is non-existent... +# +set -eu +LENGTH=$(jq length < $1) +echo "Setting up $LENGTH merchants at ${BASE_URL}" + +for n in $(seq 1 $LENGTH) +do + echo "Processing merchant $n" + INDEX=$(expr $n - 1 || true) + NAME=$(jq ".[$INDEX].name" < $1) + ID=$(jq .[$INDEX].id < $1) + PW=$(jq .[$INDEX].pass < $1) + + taler-harness deployment provision-bank-and-merchant \ + "merchant.${BASE_URL}" \ + "bank.${BASE_URL}" \ + "--merchant-management-token=${MERCHANT_TOKEN}" \ + "--bank-admin-token=${BANK_ADMIN_TOKEN}" \ + "--id=${ID}" \ + "--legal-name=${NAME}" \ + "--password=${PW}" + + echo "Done with ${ID}" +done diff --git a/netzbon/template.tex.j2 b/netzbon/template.tex.j2 new file mode 100644 index 0000000..440e95c --- /dev/null +++ b/netzbon/template.tex.j2 @@ -0,0 +1,69 @@ +\documentclass[12pt,a4paper]{letter} +\usepackage[utf8]{inputenc} +\usepackage{ngerman} +\usepackage[nolinks,final,forget]{qrcode} +\date{\today} +% +\selectlanguage{german} + +\signature{Isidor} +\begin{document} +% +\begin{letter}{To \\ {{data.name}}} + +\opening{Dear {{data.name}},} + +We are excited to introduce you to the new digital Netzbon using GNU Taler. +In the enclosed brochure, you will find some introduction on how you can +set up your business to accept e-Netzbon payments. + +This letter provides you with your personalized credentials to access your +e-netzbon bank account and merchant backend. Please keep the password +confidential as otherwise others might gain control over your e-Netzbon! You +are encouraged to set up second-factor authentication (via SMS or E-mail) +before using the system. + +Your initial password is {\bf {{data.pass}}}. + +Using this password and the username {\tt {{data.id}}} you can log into +your e-Netzbon bank account at {\tt https://bank.{{data.domain}}/}. + +Furthermore, we are happy to provided you with a GNU Taler merchant +backend at {\tt https://backend.{{data.domain}}/instances/{{data.id}}/}. +The backend is already configured to use your e-Netzbon bank account +and uses the same password. + +You are encouraged to change the password (separately) in both systems. + +If you want to use a GNU Taler wallet (from {\tt https://wallet.taler.net/}) +you need to add e-Netzbon as a payment service provider before you can use it to +invoice your customers. Scan the following QR code with your Taler wallet to do so: +\begin{center} +\qrcode[hyperlink,level=M,height=3cm]{taler://exchange/exchange.{{data.domain}}/} + +{\tt taler://exchange/exchange.{{data.domain}}/} +\end{center} + +Our welcome package is including five QR code stickers which are pre-configured to +create payments into your e-Netzbon bank account. Your personalized QR code looks +like this: +\begin{center} +\qrcode[hyperlink,level=M,height=3cm]{taler://pay-template/backend.{{data.domain}}/instances/{{data.id}}/default} + +{\tt taler://pay-template/backend.{{data.domain}}/instances/{{data.id}}/default} +\end{center} +You can create additional QR codes or change the settings for this QR code +in the merchant backend. + +Please sign the included terms of service and return them to us. If you want us to +set up a Taler point-of-sale App, please complete the form from the introduction +brochure and return that form to us as well. + +We hope your customers enjoy paying you with e-Netzbon! + + +\closing{Best regards} +\encl{Five QR code stickers, \\ Introduction to GNU Taler for merchants, \\ e-Netzbon Terms of Service (to sign), \\ Return envelope} + +\end{letter} +\end{document} diff --git a/netzbon/test.json b/netzbon/test.json new file mode 100644 index 0000000..9a47fe6 --- /dev/null +++ b/netzbon/test.json @@ -0,0 +1,7 @@ +[ + { + "name": "Test shop", + "id": "test", + "pass": "password" + } +] |