Files: db27d78788c79045c2250b824da6224adf277b6b / history.filter.dpi
1119 bytesRaw
1 | #!/bin/bash |
2 | read -d '>' auth |
3 | read -d '>' cmd |
4 | case "$cmd" in |
5 | "<cmd='open_url' url='"*);; |
6 | *) echo $cmd; exit;; |
7 | esac |
8 | url=${cmd#"<cmd='open_url' url='"} |
9 | url=${url%"' '"} |
10 | |
11 | serve_404() { |
12 | printf "<cmd='start_send_page' url='' '>\n" |
13 | printf "Content-type: text/plain\r\n\r\n" |
14 | echo Not found |
15 | } |
16 | |
17 | serve_history() { |
18 | limit=${1:-35} |
19 | grep=$2 |
20 | printf "<cmd='start_send_page' url='' '>\n" |
21 | printf "Content-type: text/html\r\n\r\n" |
22 | cat <<-EOF |
23 | <!doctype html> |
24 | <html> |
25 | <head> |
26 | <meta charset=utf-8> |
27 | <title>History</title> |
28 | </head> |
29 | <body> |
30 | EOF |
31 | exec 2>&1 |
32 | dillo_dir=${0%/*/*/*} |
33 | history_file=$dillo_dir/history.txt |
34 | if [ -n "$grep" ]; then grep "$grep"; else cat |
35 | fi < "$history_file" | tail -n $limit | tac | awk ' |
36 | { |
37 | timestamp = $1 " " $2 |
38 | if ($3 != "+0000") { |
39 | timestamp = timestamp " " $3 |
40 | } |
41 | printf "<div>%s <a href=\"ssb:%s\"> <code>%s</code></a> <a href=\"%s\">%s</a></div>\n", |
42 | timestamp, $4, $4, $5, $5 |
43 | }' |
44 | cat <<-EOF |
45 | </body> |
46 | </html> |
47 | EOF |
48 | } |
49 | |
50 | case "$url" in |
51 | history:*/*) a="${url#history:}"; serve_history "${a%/*}" "${a#*/}";; |
52 | history:*) serve_history "${url#history:}";; |
53 | *) serve_404;; |
54 | esac |
55 |
Built with git-ssb-web