mirror of
https://github.com/D-Modem/WebOne-go.git
synced 2026-11-28 20:48:05 -08:00
Port WebOne 0.19.0 to Go
A Go translation of WebOne (github.com/atauenis/webone, commit e940b43), the HTTP 1.x proxy that lets old browsers use today's web: config loader with sets of edits and .NET regular expressions, the HTTP/1.0-1.1 server with keep-alive, HTTPS fetching and patching, code pages, the CONNECT proxy (MITM, pass-through, non-HTTP tunnels), the CA and site certificates (MD5/SHA-1 signing included), internal and error pages, Web Archive fallback, converters, web FTP client and online video. WebOne's licence, configuration files and html pages are kept. Go-only options: SslCaDirectory signs with the D-Modem BBS's proxy sub-CA (or its root), SslTrustOwnCA, and DnsServer. README lists the differences: no SSL 2.0/3.0 in Go's TLS, and the upstream bugs fixed on purpose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRRH4kntyPfrY1bFWC3
This commit is contained in:
271 files changed
+11967
-1
No files matched your search
@@ -0,0 +1,144 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/D-Modem/webone-go/internal/rx"
|
||||
)
|
||||
|
||||
// activexCabURL emulates Microsoft's ActiveX codebase search server
|
||||
// (activex.microsoft.com/objects/ocget.dll) from [ActiveXGallery]: the URL
|
||||
// of a component by CLSID or MIME type; "" to ask the real service; "404"
|
||||
// when the installed component is up to date (HttpTransit.GetActiveXCabUrl).
|
||||
func (t *transit) activexCabURL() string {
|
||||
var clsid, version, mime, lang string
|
||||
var hasCLSID, hasVer, hasMime bool
|
||||
if cl := t.req.Header.Get("Content-Length"); cl != "" && cl != "0" {
|
||||
data, _ := io.ReadAll(t.req.Body)
|
||||
t.req.Body = bytes.NewReader(data)
|
||||
body := strings.ToUpper(string(data))
|
||||
if g := rx.FindGroups(`CLSID=\{(.*)\}`, body); g != nil {
|
||||
clsid, hasCLSID = g[1], true
|
||||
}
|
||||
if g := rx.FindGroups(`VERSION=(.*)`, body); g != nil {
|
||||
version, hasVer = g[1], true
|
||||
}
|
||||
if g := rx.FindGroups(`MIMETYPE=(.*)`, body); g != nil {
|
||||
mime, hasMime = g[1], true
|
||||
}
|
||||
} else {
|
||||
q := strings.ToUpper("?" + t.url.RawQuery)
|
||||
if g := rx.FindGroups(`CLSID=%7(.*)%7`, q); g != nil {
|
||||
clsid, hasCLSID = g[1], true
|
||||
}
|
||||
if g := rx.FindGroups(`VERSION=(.*)`, q); g != nil {
|
||||
version, hasVer = g[1], true
|
||||
}
|
||||
if g := rx.FindGroups(`MIMETYPE=(.*)`, q); g != nil {
|
||||
mime, hasMime = g[1], true
|
||||
}
|
||||
}
|
||||
if al := t.req.Header.Get("Accept-Language"); al != "" {
|
||||
if g := rx.FindGroups(`[a-zA-Z]*`, al); g != nil {
|
||||
lang = strings.ToUpper(g[0])
|
||||
}
|
||||
}
|
||||
if !hasCLSID && !hasMime {
|
||||
t.dump("--OCGET Emulation: Request not understood, unknown syntax.--")
|
||||
t.log.Printf("OCGET Emulation: missing search terms.")
|
||||
return ""
|
||||
}
|
||||
if hasVer {
|
||||
version = strings.ReplaceAll(version, ",", ".")
|
||||
}
|
||||
db := t.cfg.ActivexGalleryCLSIDs
|
||||
codebase, found := "", false
|
||||
lookup := func(key string) bool {
|
||||
if _, ok := db[key]; !ok {
|
||||
return false
|
||||
}
|
||||
if hasVer {
|
||||
if reported, ok := parseDotVersion(version); ok {
|
||||
if latest, ok := db[key+",LATEST"]; ok {
|
||||
if lv, ok := parseDotVersion(latest); ok && cmpVersion(reported, lv) >= 0 {
|
||||
return true // up to date
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, ok := db[key+","+lang]; ok {
|
||||
key += "," + lang
|
||||
}
|
||||
codebase, found = db[key], true
|
||||
return false
|
||||
}
|
||||
if hasCLSID && lookup(clsid) {
|
||||
return "404"
|
||||
}
|
||||
if hasMime && lookup(mime) {
|
||||
return "404"
|
||||
}
|
||||
|
||||
report := "something"
|
||||
if hasCLSID {
|
||||
report = clsid
|
||||
}
|
||||
if hasMime {
|
||||
report = mime
|
||||
}
|
||||
if hasVer {
|
||||
report += ";version=" + version
|
||||
}
|
||||
if lang != "" {
|
||||
report += ";language=" + lang
|
||||
}
|
||||
if found {
|
||||
t.dump("--OCGET Emulation: " + report + " is " + codebase + ".--")
|
||||
t.log.Printf("OCGET Emulation: found codebase for %s, return 302.", report)
|
||||
return codebase
|
||||
}
|
||||
t.dump("--OCGET Emulation: using real Microsoft service for " + report + ".--")
|
||||
t.log.Printf("OCGET Emulation: no codebase for %s, use real service.", report)
|
||||
return ""
|
||||
}
|
||||
|
||||
// parseDotVersion parses a .NET Version ("1.2", "1.2.3.4").
|
||||
func parseDotVersion(s string) ([]int, bool) {
|
||||
parts := strings.Split(strings.TrimSpace(s), ".")
|
||||
if len(parts) < 2 || len(parts) > 4 {
|
||||
return nil, false
|
||||
}
|
||||
out := make([]int, len(parts))
|
||||
for i, p := range parts {
|
||||
n, err := strconv.Atoi(p)
|
||||
if err != nil || n < 0 {
|
||||
return nil, false
|
||||
}
|
||||
out[i] = n
|
||||
}
|
||||
return out, true
|
||||
}
|
||||
|
||||
// cmpVersion compares versions as .NET does: a missing part is less than
|
||||
// any number.
|
||||
func cmpVersion(a, b []int) int {
|
||||
for i := 0; i < 4; i++ {
|
||||
x, y := -1, -1
|
||||
if i < len(a) {
|
||||
x = a[i]
|
||||
}
|
||||
if i < len(b) {
|
||||
y = b[i]
|
||||
}
|
||||
if x != y {
|
||||
if x < y {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Reference in new issue
Block a user