Compare commits

..

No commits in common. "55dfb5405acbc742839c3f9806a6df2a7b97e034" and "dcb8ad72e3c830a2ec330f1444b693f4ff9f7858" have entirely different histories.

4 changed files with 6 additions and 56 deletions

View File

@ -1,12 +0,0 @@
FROM golang:latest as builder
WORKDIR /build
COPY . .
RUN go get -u
RUN CGO_ENABLED=0 go build -o probehost2
FROM alpine:latest
RUN apk update
RUN apk add mtr
COPY --from=builder /build/probehost2 /
RUN touch /probehost2.log
CMD ["/probehost2"]

View File

@ -1,11 +0,0 @@
version: '2.3'
services:
probehost2:
container_name: probehost2
image: byreqz/probehost2:latest
restart: unless-stopped
ports:
- 1234:8000
volumes:
- ./probehost2.log:/probehost2.log

23
main.go
View File

@ -14,10 +14,10 @@ import (
var logstdout = log.New()
var logfile = log.New()
var logfilepath string
var listenport int
func init() {
var logfilepath string
flag.StringVar(&logfilepath, "logfilepath", "probehost2.log", "sets the output file for the log")
flag.IntVar(&listenport, "port", 8000, "sets the port to listen on")
flag.Parse()
@ -64,6 +64,10 @@ func runner(remoteip string, command string, args... string) string{
return string(cmd)
}
func showhelp(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "placeholder")
}
func validatehosts(hosts []string) []string{
var valid []string
for _, host := range hosts {
@ -106,25 +110,10 @@ func mtr(w http.ResponseWriter, req *http.Request) {
}
}
func traceroute(w http.ResponseWriter, req *http.Request) {
geturl := strings.Split(req.URL.String(), "/")
targets := strings.Split(geturl[2], ",")
hosts := validatehosts(targets)
var res string
for _, host := range hosts {
res = fmt.Sprint(res, runner(req.RemoteAddr, "traceroute", host), "\n")
}
if res == "" {
fmt.Fprintln(w, http.StatusInternalServerError)
} else {
fmt.Fprint(w, strings.TrimSpace(res), "\n")
}
}
func main() {
http.HandleFunc("/ping/", ping)
http.HandleFunc("/mtr/", mtr)
http.HandleFunc("/tracert/", traceroute)
http.HandleFunc("/", showhelp)
logstdout.Info("Serving on :", listenport)
logfile.Info("Serving on :", listenport)
http.ListenAndServe(fmt.Sprint(":", listenport), nil)

View File

@ -1,16 +0,0 @@
# systemd service file for probehost2
[Unit]
Description=probehost2 daemon
Wants=network.target
After=network-online.target
StartLimitBurst=5
StartLimitIntervalSec=20
[Service]
Restart=always
RestartSec=1
ExecStart=/bin/probehost2 --logfilepath "/var/log/probehost2.log" --port 8000
[Install]
WantedBy=multi-user.target