audit dead instances

This commit is contained in:
Arnas Udovic 2025-06-23 12:50:46 +03:00
parent 6e89d579f5
commit 90d319382c
6 changed files with 64 additions and 3 deletions

View file

@ -11,6 +11,7 @@ App can be called directly and do management in console.
- `peertube-instance-index-filter -command index -url https://instances.joinpeertube.org/api/v1/instances/hosts -instance-url https://instances.joinpeertube.org/api/v1/instances` - add url to index of hosts. Later it will be used to collect instances
- `peertube-instance-index-filter -command collect` - collect instances from index of hosts urls
- `peertube-instance-index-filter -command reject -host www.example.com` - reject instance from index to exclude it from global index
- `peertube-instance-index-filter -command audit -filter dead` - go through not rejected instances and check by filters: dead
## Links

31
audit.go Normal file
View file

@ -0,0 +1,31 @@
// peertube-instance-index-filter
// Copyright (C) 2025 Arns Udovič <zordsdavini@arns.lt>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import "net/http"
func doAudit(host string, filter string) bool {
switch filter {
case "dead":
_, err := http.Get("https://" + host)
if err != nil {
return true
}
}
return false
}

View file

@ -1,5 +1,7 @@
FROM golang:1.24
RUN apt-get update && apt-get -y install cron
WORKDIR /usr/src/app
ADD ./peertube-instance-index-filter ./

View file

@ -13,3 +13,9 @@ add-index:
.PHONY: reject
reject:
docker compose -f docker-compose.yaml exec -it peertube-instance-index-filter peertube-instance-index-filter -command reject -host $(host) -reject-reason $(reason)
### audit: Audit hosts. Arguments: filter
.PHONY: audit
audit:
docker compose -f docker-compose.yaml exec -it peertube-instance-index-filter peertube-instance-index-filter -command audit -filter $(filter)

View file

@ -2,14 +2,14 @@ version: "3.9"
services:
peertube-instance-index-filter:
build: ./peertube-instance-index-filter
build: .
volumes:
- ./instances.db:/usr/src/app/instances.db
expose:
- 8081
labels:
- traefik.enable=true
- traefik.http.routers.peertube_instance_index.rule=Host(`index.tv.arns.lt`)
- traefik.http.routers.peertube_instance_index.rule=Host(`index-tv.arns.lt`)
- traefik.http.routers.peertube_instance_index.tls.certresolver=le
- traefik.http.routers.peertube_instance_index.entrypoints=websecure
restart: always

23
main.go
View file

@ -49,12 +49,14 @@ func main() {
var instanceUrl string
var host string
var reason string
var filter string
flag.StringVar(&command, "command", "", "Command to execute: index, reject, collect, serve")
flag.StringVar(&command, "command", "", "Command to execute: index, reject, collect, serve, audit")
flag.StringVar(&url, "url", "", "Url to index hosts")
flag.StringVar(&instanceUrl, "instance-url", "", "Url to fetch instance information")
flag.StringVar(&host, "host", "", "Host to reject")
flag.StringVar(&reason, "reject-reason", "", "Reject reason (optional)")
flag.StringVar(&filter, "filter", "", "filter for audit")
flag.Parse()
fmt.Println(command, host)
@ -66,6 +68,8 @@ func main() {
reject(host, reason)
case "collect":
collect()
case "audit":
audit(filter)
case "serve":
default:
serve()
@ -140,6 +144,23 @@ func collect() {
}
}
func audit(filter string) {
db := connectDB()
defer db.Close()
hosts, err := getHosts(db, 0, 10000, "", "", "url")
if err != nil {
panic(err)
}
for _, url := range hosts {
filtered := doAudit(url, filter)
if filtered {
reject(url, filter)
}
}
}
func serve() {
db := connectDB()
defer db.Close()