git ssb

0+

cel / dillo-history



Commit 8905bee234248703ba30c218618022d453d48dee

Implement offline browsing "last" mode

cel committed on 12/17/2019, 4:20:57 AM
Parent: db27d78788c79045c2250b824da6224adf277b6b

Files changed

Makefilechanged
README.mdchanged
history.filter.dpichanged
MakefileView
@@ -10,8 +10,11 @@
1010 cp /etc/dillo/dpidrc $@
1111
1212 install-proto: $(DPIDRC)
1313 echo 'proto.history=$(NAME)/$(BIN)' >> $<
14 + echo 'proto.last=$(NAME)/$(BIN)' >> $<
15 + echo 'proto.last-http=$(NAME)/$(BIN)' >> $<
16 + echo 'proto.last-https=$(NAME)/$(BIN)' >> $<
1417
1518 install: $(BIN) install-proto
1619 mkdir -p $(DPI_DIR)/$(NAME)
1720 cp -f $(BIN) $(DPI_DIR)/$(NAME)
README.mdView
@@ -9,8 +9,10 @@
99 The history file is `~/.dillo/history.txt` and its format is TSV. Each entry contains a timestamp, SHA256 content hash, and URL.
1010
1111 The plugin serves requests of the form `history:[<limit>][/<pattern>]` where `<limit>` is the number of entries to show (default is 35) and `<pattern>` is a regex to grep for the history files (for URL, hash, and/or timestamp) (default is to show all entries).
1212
13 +The plugin also serves request of the form `last:<url>`, or `last-<url>` for schemas `http` and `https`. These are served with the contents of the last blob recorded for the given URL (with the "last:" or "last-" prefix removed). This is effectively an offline browsing mode. Relative URLs work when using the "last-" prefix but not with the "last:" prefix.
14 +
1315 ## Screenshot
1416
1517 ![dillo-history-screenshot.png](&REcIx+kvUF2vQt0PDyb49f2q4qDEZ08b07hlskwScMI=.sha256 "Screenshot showing dillo-history")
1618
@@ -24,11 +26,7 @@
2426
2527 Install the plugin with `make install && dpidc stop`.
2628 Install the patch by downloading Dillo's source code, applying the patch and compiling dillo.
2729
28-## Future work
29-
30-Make a HTTP proxy or patch for dillo to allow for navigating the web in an offine mode, by serving requests with the last known content for their URL from the history file. Similarly, make a time travel mode where it would use only history entries before a certain date. It could allow for navigating between different versions of the same URL that were recorded at different times.
31-
3230 ## License
3331
3432 MIT
history.filter.dpiView
@@ -7,18 +7,21 @@
77 esac
88 url=${cmd#"<cmd='open_url' url='"}
99 url=${url%"' '"}
1010
11 +dillo_dir=${0%/*/*/*}
12 +history_file=$dillo_dir/history.txt
13 +
1114 serve_404() {
12- printf "<cmd='start_send_page' url='' '>\n"
15 + printf "<cmd='start_send_page' url='' '>"
1316 printf "Content-type: text/plain\r\n\r\n"
1417 echo Not found
1518 }
1619
1720 serve_history() {
1821 limit=${1:-35}
1922 grep=$2
20- printf "<cmd='start_send_page' url='' '>\n"
23 + printf "<cmd='start_send_page' url='' '>"
2124 printf "Content-type: text/html\r\n\r\n"
2225 cat <<-EOF
2326 <!doctype html>
2427 <html>
@@ -28,10 +31,8 @@
2831 </head>
2932 <body>
3033 EOF
3134 exec 2>&1
32- dillo_dir=${0%/*/*/*}
33- history_file=$dillo_dir/history.txt
3435 if [ -n "$grep" ]; then grep "$grep"; else cat
3536 fi < "$history_file" | tail -n $limit | tac | awk '
3637 {
3738 timestamp = $1 " " $2
@@ -46,9 +47,35 @@
4647 </html>
4748 EOF
4849 }
4950
51 +serve_last() {
52 + url=$1
53 + blob=$(tac "$history_file" | awk -v url="$url" '$5 == url {print $4; exit}')
54 + if [ -z "$blob" ]
55 + then
56 + printf "<cmd='send_status_message' msg='Not found' '>"
57 + printf "<cmd='start_send_page' url='' '>"
58 + printf "\r\n\r\n"
59 + printf "Not found"
60 + return
61 + fi
62 + if ! file="$(ssb-blob-path "$blob")"
63 + then
64 + printf "<cmd='send_status_message' msg='Unable to get blob id' '>"
65 + printf "<cmd='start_send_page' url='' '>"
66 + printf "\r\n\r\n"
67 + printf "Unable to get blob id"
68 + return
69 + fi
70 + printf "<cmd='start_send_page' url='' '>"
71 + printf "\r\n\r\n"
72 + cat "$file"
73 +}
74 +
5075 case "$url" in
5176 history:*/*) a="${url#history:}"; serve_history "${a%/*}" "${a#*/}";;
5277 history:*) serve_history "${url#history:}";;
78 + last:*) serve_last "${url#last:}";;
79 + last-*) serve_last "${url#last-}";;
5380 *) serve_404;;
5481 esac

Built with git-ssb-web