aboutsummaryrefslogtreecommitdiff
path: root/info.filter.dpi
blob: e0b7e4767fff5c1dfde92bb58c44d391a093700e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Copyright (c) 2024-2025 Rodrigo Arias Mallo
# SPDX-License-Identifier: GPL-3.0-or-later

IFS= read -d '>' auth # Ignore auth
IFS= read -d '>' cmd

case "$cmd" in
  "<cmd='open_url' url='"*);;
  *) echo $cmd; exit;;
esac

url=${cmd#"<cmd='open_url' url='"}
url=${url%"' '"}

serve_404() {
  printf "<cmd='start_send_page' url='' '>\n"
  printf "Content-type: text/plain\r\n\r\n"
  echo "Not found"
  exit 0
}

serve_manpage() {
  url="$1"
  ref="${url#"info:"}"
  # If page not found, return 404
  #if [ -z "$ref" ]; then
  #  serve_404
  #  exit 0
  #fi
  printf "<cmd='start_send_page' url='' '>\n"
  printf "Content-type: text/html\r\n\r\n"
  perl ~/.dillo/dpi/info/info2html "$ref"
}

case "$url" in
  info:*) serve_manpage "$url";;
  *) serve_404;;
esac