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 #!/bin/bash
format() {
sed -e 's/^fix:/доза:/' \
-e '/^# ------------------------ >8 ------------------------$/,$d' \
-e '/^#/d'
}
translated="$(curl -s \ translated="$(curl -s \
http://localhost:9000/translate \ http://localhost:9000/translate \
-H 'Content-Type: text/html' \ -H 'Content-Type: text/html' \
--data-binary @- -o- < <(sed 's,^fix:,доза:,' < "$1") | \ --data-binary @- -o- < <(format < "$1") | \
tail -n +2 | \ tail -n +2 | \
perl -pe 's,<SPAN CLASS=UNKNOWN_WORD>(.*?)</SPAN>,\1,g')" 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 # we don't want to flood the upstream from the same IP
mode bypass mode bypass
ttl 30m ttl 30m
timeout {
backend 10m
}
} }
import Caddyfile.yadro proxy:80 import Caddyfile.yadro proxy:80
@ -23,6 +27,12 @@ http://ядро.орг, http://*.ядро.орг {
reverse_proxy { reverse_proxy {
dynamic a puppy 80 dynamic a puppy 80
lb_policy least_conn lb_policy least_conn
transport http {
response_header_timeout 10m
read_timeout 10m
write_timeout 10m
}
} }
cache { cache {
@ -34,7 +44,7 @@ http://ядро.орг, http://*.ядро.орг {
} }
timeout { timeout {
backend 1m backend 10m
} }
} }
} }

View file

@ -75,6 +75,6 @@ handle @surely_static {
redir @known_host https://{kernel}{uri} permanent 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]} reverse_proxy {args[0]}

View file

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

View file

@ -1,10 +1,15 @@
FROM golang:1.23-alpine AS builder FROM golang:1.23-alpine AS builder
WORKDIR /build WORKDIR /build
COPY . . 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 FROM alpine AS runner
WORKDIR /app WORKDIR /app
COPY --from=builder /build/proxy . COPY --from=builder /build/proxy .
EXPOSE 80/tcp EXPOSE 80/tcp
CMD ./proxy CMD ./proxy

View file

@ -68,7 +68,7 @@ func main() {
return original_raw 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) 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`) 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 { response = re.ReplaceAllStringFunc(response, func(original_raw string) string {
kernel := strings.ToLower(string(original_raw)) kernel := strings.ToLower(original_raw)
// Strip `www.` // Strip `www.`
kernel = strings.TrimPrefix(kernel, "www.") kernel = strings.TrimPrefix(kernel, "www.")
@ -104,42 +108,46 @@ func replaceDomains(response []byte) []byte {
return original_raw 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 return response
} }
func translateWithPromtPuppies(response []byte) []byte { func translateWithPromtPuppies(response string) string {
// Don't try to translate empty body (30x, etc) // Don't try to translate empty body (30x, etc)
if len(response) == 0 { if len(response) == 0 {
return response 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") req.Header.Add("Content-Type", "text/html")
resp, err := http.DefaultClient.Do(req) resp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "Error in first", err) fmt.Fprintln(os.Stderr, "Error in while translating", err)
return []byte{0} return ""
} }
response, _ = io.ReadAll(resp.Body) var translated strings.Builder
io.Copy(&translated, resp.Body)
resp.Body.Close() 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 { func modifyResponse(response []byte) []byte {
response = translateWithPromtPuppies(response) s := string(response)
response = replaceDomains(response) s = enfunnify(s)
return response s = translateWithPromtPuppies(s)
s = replaceDomains(s)
return []byte(s)
} }

View file

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