From 501e363746d55b3f70960704836d99661ebb7994 Mon Sep 17 00:00:00 2001 From: Michael 'PoempelFox' Meier Date: Sun, 11 Feb 2018 22:09:33 +0100 Subject: [PATCH 1/7] remove google charts api and replace it with flot pie. Google charts does not permit offline or selfhosted use. If you want to use it, you HAVE to consign your users to googles disgusting everpresent tracking, and that seems a bit of a high price to pay for just displaying a simple pie chart. --- templates/mirrorlist.html | 66 ++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/templates/mirrorlist.html b/templates/mirrorlist.html index e535bc6..b6317b6 100644 --- a/templates/mirrorlist.html +++ b/templates/mirrorlist.html @@ -2,29 +2,51 @@ {{define "headline"}}{{.FileInfo.Path}}{{end}} {{define "head"}} - + + + + + From 705893f9dc15a22a95fab1aac1ed4d11f0d0bcfe Mon Sep 17 00:00:00 2001 From: Michael 'PoempelFox' Meier Date: Thu, 15 Feb 2018 10:14:01 +0100 Subject: [PATCH 2/7] Introduce new setting LocalJSPath that can be used by templates to use local copies of JavaScript files instead of external CDNs that will violate users privacy through tracking. --- README.md | 1 + config/config.go | 2 ++ http/http.go | 1 + mirrors/mirrors.go | 1 + 4 files changed, 5 insertions(+) diff --git a/README.md b/README.md index b77c488..929ff62 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ WeightDistributionRange | Multiplier of the distance to the first mirror to find DisableOnMissingFile | Disable a mirror if an advertised file on rsync/ftp appears to be missing on HTTP MaxLinkHeaders | Amount of backup mirror locations returned in HTTP headers Fallbacks | A list of possible mirrors to use as fallback if a request fails or if the database is unreachable. **These mirrors are not tracked by mirrorbits.** It is assumed they have all the files available in the local repository. +LocalJSPath | A local path or URL containing the JavaScript used by the templates. If this is not set (the default), the JavaScript will just be loaded from the usual CDNs. See also `contrib/FIXME.sh`. ## Running diff --git a/config/config.go b/config/config.go index e407a79..9745641 100644 --- a/config/config.go +++ b/config/config.go @@ -21,6 +21,7 @@ var ( defaultConfig = Configuration{ Repository: "", Templates: "", + LocalJSPath: "", OutputMode: "auto", ListenAddress: ":8080", Gzip: false, @@ -55,6 +56,7 @@ var ( type Configuration struct { Repository string `yaml:"Repository"` Templates string `yaml:"Templates"` + LocalJSPath string `yaml:"LocalJSPath"` OutputMode string `yaml:"OutputMode"` ListenAddress string `yaml:"ListenAddress"` Gzip bool `yaml:"Gzip"` diff --git a/http/http.go b/http/http.go index 5979418..41a412f 100644 --- a/http/http.go +++ b/http/http.go @@ -274,6 +274,7 @@ func (h *HTTP) mirrorHandler(w http.ResponseWriter, r *http.Request, ctx *Contex ClientInfo: clientInfo, IP: remoteIP, Fallback: fallback, + LocalJSPath: GetConfig().LocalJSPath, } var resultRenderer resultsRenderer diff --git a/mirrors/mirrors.go b/mirrors/mirrors.go index ca131db..1b5b233 100644 --- a/mirrors/mirrors.go +++ b/mirrors/mirrors.go @@ -219,6 +219,7 @@ type Results struct { MirrorList Mirrors ExcludedList Mirrors `json:",omitempty"` Fallback bool `json:",omitempty"` + LocalJSPath string } // Redirects is handling the per-mirror authorization of HTTP redirects From 3cc189a162d78d9dd1d60aae6530b93d128317fd Mon Sep 17 00:00:00 2001 From: Michael 'PoempelFox' Meier Date: Fri, 16 Feb 2018 20:21:12 +0100 Subject: [PATCH 3/7] add script for fetching the files to host locally, and support local tiles in mirrorlist.html. --- contrib/localjs/fetchfiles.sh | 81 +++++++++++++++++++++++++++++++++++ templates/mirrorlist.html | 15 +++++-- 2 files changed, 93 insertions(+), 3 deletions(-) create mode 100755 contrib/localjs/fetchfiles.sh diff --git a/contrib/localjs/fetchfiles.sh b/contrib/localjs/fetchfiles.sh new file mode 100755 index 0000000..049a7ec --- /dev/null +++ b/contrib/localjs/fetchfiles.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +# List of scripts to fetch and store locally +whattofetch=( + "https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/excanvas.js" + "https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/excanvas.min.js" + "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" + "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" + "https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.js" + "https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.min.js" + "https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.pie.js" + "https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.pie.min.js" + "https://cdnjs.cloudflare.com/ajax/libs/flot.tooltip/0.9.0/jquery.flot.tooltip.js" + "https://cdnjs.cloudflare.com/ajax/libs/flot.tooltip/0.9.0/jquery.flot.tooltip.min.js" + "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.2/leaflet.css" + "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.2/leaflet.js" + "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.2/images/marker-icon.png" + "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.2/images/marker-shadow.png" + "https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.0.0/MarkerCluster.css" +) + +showhelp() +{ + echo "Syntax: $0 directory" + echo "where directory is the directory in which you want to store the downloaded files." + echo "" +} + +getlocalfilename () +{ + local sfn="$1" + lfn=${sfn#https://cdnjs.cloudflare.com/ajax/libs} +} + +downloadfile () +{ + curl=`which curl` + if [ ${#curl} -gt 4 ] ; then + $curl --output "$2" "$1" + return + fi + wget=`which wget` + if [ ${#wget} -gt 4 ] ; then + $wget --output-document="$2" "$1" + return + fi + echo "Sorry: Neither curl nor wget were found in path." + exit 1 +} + +if [ "$#" -ne 1 ] ; then + showhelp + exit 1 +fi +if [ "$1" == "--help" -o "$1" == "-h" ] ; then + showhelp + exit 0 +fi +localdir="$1" +if [ ! -d "$localdir" ] ; then + echo "Target directory ${localdir} does not exist or is not a directory." + showhelp + exit 1 +fi + +for sf in ${whattofetch[@]}; do + lfn="/void/void/void/void/" + getlocalfilename "$sf" + # lfn is now filled. + tf="${localdir}${lfn}" + if [ -e "$tf" ] ; then + echo "No need to fetch $sf to $tf, it already exists." + else + tdn=`dirname "${tf}"` + if [ ! -e "$tdn" ] ; then + mkdir -p "$tdn" + fi + downloadfile "$sf" "$tf" + fi +done + diff --git a/templates/mirrorlist.html b/templates/mirrorlist.html index b6317b6..45d9a3d 100644 --- a/templates/mirrorlist.html +++ b/templates/mirrorlist.html @@ -2,11 +2,23 @@ {{define "headline"}}{{.FileInfo.Path}}{{end}} {{define "head"}} +{{if not .LocalJSPath}} + + +{{else}} + + + + + + + +{{end}} - - - + +{{end}}