1
0
Fork 0

хозяйственная работа: некоторый младший щипает здесь и там

This commit is contained in:
Arthur K. 2026-01-27 14:24:29 +03:00
parent 1d4bb2a118
commit 7f7d10aeee
Signed by: wzray
GPG key ID: B97F30FDC4636357
7 changed files with 60 additions and 30 deletions

View file

@ -1,9 +1,15 @@
#!/bin/bash
format() {
sed -e 's/^fix:/доза:/' \
-e '/^# ------------------------ >8 ------------------------$/,$d' \
-e '/^#/d'
}
translated="$(curl -s \
http://localhost:9000/translate \
-H 'Content-Type: text/html' \
--data-binary @- -o- < <(sed 's,^fix:,доза:,' < "$1") | \
--data-binary @- -o- < <(format < "$1") | \
tail -n +2 | \
perl -pe 's,<SPAN CLASS=UNKNOWN_WORD>(.*?)</SPAN>,\1,g')"

View file

@ -14,6 +14,10 @@ http://ядро.орг, http://*.ядро.орг {
# we don't want to flood the upstream from the same IP
mode bypass
ttl 30m
timeout {
backend 10m
}
}
import Caddyfile.yadro proxy:80
@ -23,6 +27,12 @@ http://ядро.орг, http://*.ядро.орг {
reverse_proxy {
dynamic a puppy 80
lb_policy least_conn
transport http {
response_header_timeout 10m
read_timeout 10m
write_timeout 10m
}
}
cache {
@ -34,7 +44,7 @@ http://ядро.орг, http://*.ядро.орг {
}
timeout {
backend 1m
backend 10m
}
}
}

View file

@ -75,6 +75,6 @@ handle @surely_static {
redir @known_host https://{kernel}{uri} permanent
}
# TOOO: cache by path for 30 minutes
# TODO: cache by path for 30 minutes
reverse_proxy {args[0]}

View file

@ -1,7 +1,6 @@
services:
puppies:
networks:
- promty
networks: [promty]
build: puppy
hostname: puppy
volumes:
@ -14,18 +13,20 @@ services:
order: start-first
proxy:
networks:
- promty
networks: [promty]
container_name: proxy
build: proxy
depends_on:
puppies:
condition: service_healthy
caddy:
networks:
- promty
networks: [promty]
container_name: caddy
build: caddy
volumes:
- ./caddy:/etc/caddy
depends_on: [proxy]
ports:
- 80:80
- 9000:9000

View file

@ -1,10 +1,15 @@
FROM golang:1.23-alpine AS builder
WORKDIR /build
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod go build
RUN --mount=type=cache,target=/go/pkg/mod go build;
FROM alpine AS runner
WORKDIR /app
COPY --from=builder /build/proxy .
EXPOSE 80/tcp
CMD ./proxy

View file

@ -68,7 +68,7 @@ func main() {
return original_raw
}
return []byte("http://" + yadro + "/") // TODO: https
return []byte("https://" + yadro + "/")
})))
}
@ -88,11 +88,15 @@ func main() {
http.ListenAndServe("0.0.0.0:80", proxy)
}
func replaceDomains(response []byte) []byte {
func replaceDomains(response string) string {
re := regexp.MustCompile(`(?i)[A-Za-z\-\.]*\.?kernel\.org`)
response = strings.NewReplacer(
"%3F", "?",
"%26", "&",
).Replace(response)
response = re.ReplaceAllFunc(response, func(original_raw []byte) []byte {
kernel := strings.ToLower(string(original_raw))
response = re.ReplaceAllStringFunc(response, func(original_raw string) string {
kernel := strings.ToLower(original_raw)
// Strip `www.`
kernel = strings.TrimPrefix(kernel, "www.")
@ -104,42 +108,46 @@ func replaceDomains(response []byte) []byte {
return original_raw
}
return []byte(yadro)
return yadro
})
response = bytes.ReplaceAll(response, []byte("%3F"), []byte("?"))
response = bytes.ReplaceAll(response, []byte("%26"), []byte("&"))
response = bytes.ReplaceAll(response, []byte("https"), []byte("http")) // TODO: TEMP
return response
}
func translateWithPromtPuppies(response []byte) []byte {
func translateWithPromtPuppies(response string) string {
// Don't try to translate empty body (30x, etc)
if len(response) == 0 {
return response
}
req, _ := http.NewRequest("POST", "http://caddy:9000/translate", bytes.NewReader(response))
req, _ := http.NewRequest("POST", "http://caddy:9000/translate", strings.NewReader(response))
req.Header.Add("Content-Type", "text/html")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Fprintln(os.Stderr, "Error in first", err)
return []byte{0}
fmt.Fprintln(os.Stderr, "Error in while translating", err)
return ""
}
response, _ = io.ReadAll(resp.Body)
var translated strings.Builder
io.Copy(&translated, resp.Body)
resp.Body.Close()
return response
return translated.String()
}
func enfunnify(response string) string {
return strings.NewReplacer(
"tarball", "tar ball",
).Replace(response)
}
func modifyResponse(response []byte) []byte {
response = translateWithPromtPuppies(response)
response = replaceDomains(response)
return response
s := string(response)
s = enfunnify(s)
s = translateWithPromtPuppies(s)
s = replaceDomains(s)
return []byte(s)
}

View file

@ -37,7 +37,7 @@ COPY build/ $WINEPREFIX/drive_c
WORKDIR /app
COPY --from=builder /build/promt-puppy.exe /build/healthcheck .
HEALTHCHECK CMD ./healthcheck;
HEALTHCHECK --start-period=30s --start-interval=1s CMD ./healthcheck;
EXPOSE 80/tcp
VOLUME /cache