mirror of
https://tildegit.org/solderpunk/molly-brown.git
synced 2025-04-13 09:29:46 +00:00
Allow redirects to other hosts. Closes #26.
This commit is contained in:
parent
e42c366565
commit
16ed9e5cff
2 changed files with 27 additions and 2 deletions
21
config.go
21
config.go
|
@ -5,6 +5,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
|
@ -93,6 +94,18 @@ func getConfig(filename string) (Config, error) {
|
|||
}
|
||||
config.CGIPaths = cgiPaths
|
||||
|
||||
// Validate redirects
|
||||
for _, value := range config.TempRedirects {
|
||||
if strings.Contains(value, "://") && !strings.HasPrefix(value, "gemini://") {
|
||||
return config, errors.New("Invalid cross-protocol redirect to " + value)
|
||||
}
|
||||
}
|
||||
for _, value := range config.PermRedirects {
|
||||
if strings.Contains(value, "://") && !strings.HasPrefix(value, "gemini://") {
|
||||
return config, errors.New("Ignoring cross-protocol redirect to " + value)
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
|
@ -164,9 +177,17 @@ func parseMollyFiles(path string, config *Config, errorLog *log.Logger) {
|
|||
config.DirectoryReverse = mollyFile.DirectoryReverse
|
||||
config.DirectoryTitles = mollyFile.DirectoryTitles
|
||||
for key, value := range mollyFile.TempRedirects {
|
||||
if strings.Contains(value, "://") && !strings.HasPrefix(value, "gemini://") {
|
||||
errorLog.Println("Ignoring cross-protocol redirect to " + value + " in .molly file " + mollyPath)
|
||||
continue
|
||||
}
|
||||
config.TempRedirects[key] = value
|
||||
}
|
||||
for key, value := range mollyFile.PermRedirects {
|
||||
if strings.Contains(value, "://") && !strings.HasPrefix(value, "gemini://") {
|
||||
errorLog.Println("Ignoring cross-protocol redirect to " + value + " in .molly file " + mollyPath)
|
||||
continue
|
||||
}
|
||||
config.PermRedirects[key] = value
|
||||
}
|
||||
for key, value := range mollyFile.MimeOverrides {
|
||||
|
|
|
@ -193,8 +193,12 @@ func handleRedirectsInner(URL *url.URL, redirects map[string]string, status int,
|
|||
continue
|
||||
}
|
||||
if compiled.MatchString(URL.Path) {
|
||||
URL.Path = compiled.ReplaceAllString(URL.Path, dst)
|
||||
conn.Write([]byte(strStatus + " " + URL.String() + "\r\n"))
|
||||
new_target := compiled.ReplaceAllString(URL.Path, dst)
|
||||
if !strings.HasPrefix(new_target, "gemini://") {
|
||||
URL.Path = new_target
|
||||
new_target = URL.String()
|
||||
}
|
||||
conn.Write([]byte(strStatus + " " + new_target + "\r\n"))
|
||||
log.Status = status
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue