]> git.plutz.net Git - invoices/blob - invoices.cgi
submodule update
[invoices] / invoices.cgi
1 #!/bin/sh
2
3 _EXEC="$(realpath "${0%/*}")"
4 . "$_EXEC/cgilite/cgilite.sh"
5 . "$_EXEC/cgilite/logging.sh"
6 . "$_EXEC/cgilite/storage.sh"
7 . "$_EXEC/cgilite/session.sh"
8
9 yield_page(){
10 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
11 "$_EXEC/cgilite/html-sh.sed" <<EOF
12 [html [head
13   [meta name="viewport" content="width=device-width"]
14   [link rel="stylesheet" type="text/css" href="/invoices.css"]
15   [title Invoices]
16 ] [body class="$1"
17   [div #menu
18     [a "/invoices/" Invoices]
19     [a "/clients/" Clients]
20     [a "/senders/" Senders]
21   ]
22   $(cat)
23 ] ]
24 EOF
25 }
26
27 tid(){
28   # transaction ID to modify a given file
29   local file="$1"
30   { stat -c %F%i%n%N%s%Y "$file" 2>&-
31     printf %s "$SESSION_ID"
32     server_key
33   } | sha256sum | cut -d\  -f1
34 }
35
36 info="$(PATH "${PATH_INFO}")"
37
38 which git && [ ! -d .git ] && {
39   git init
40   mkdir -p clients/ invoices/ senders/
41   printf 'export/
42 serverkey' >.gitignore
43   git add clients/ invoices/ senders/ .gitignore
44   git commit -m 'initialisation of invoice repo'
45 } >&2
46
47 case $info in
48   /invoices.css)
49     . "$_EXEC/cgilite/file.sh"
50     FILE "$_EXEC/invoices.css"
51     ;;
52   /clients)
53     . "$_EXEC/clients.sh"
54     { list_clients
55       printf '[a .new href="/clients/%s" New]' "$(timeid)"
56     } | yield_page clients
57     ;;
58   /clients/*)
59     . "$_EXEC/clients.sh"
60     edit_client "${info#/clients/}" |yield_page client
61     ;;
62   /update_client)
63     . "$_EXEC/clients.sh"
64     update_client
65     ;;
66   /senders)
67     . "$_EXEC/senders.sh"
68     { list_senders
69       printf '[a .new href="/senders/%s" New]' "$(timeid)"
70     } | yield_page senders
71     ;;
72   /senders/*)
73     . "$_EXEC/senders.sh"
74     edit_sender "${info#/senders/}" |yield_page sender
75     ;;
76   /update_sender)
77     . "$_EXEC/senders.sh"
78     update_sender
79     ;;
80   /invoices)
81     . "$_EXEC/invoices.sh"
82     { list_invoices
83       printf '[a .new href="/invoices/%s" New]' "$(timeid)"
84     } | yield_page invoices
85     ;;
86   /invoices/*)
87     . "$_EXEC/invoices.sh"
88     edit_invoice "${info#/invoices/}" |yield_page invoice
89     ;;
90   /update_invoice)
91     . "$_EXEC/invoices.sh"
92     update_invoice
93     ;;
94   /export/*.pdf/*)
95     . "$_EXEC/cgilite/file.sh"
96     file="${info%/*}"
97     FILE "${file#/}" application/pdf
98     ;;
99   *) REDIRECT /invoices
100     ;;
101 esac