mirror of
https://github.com/byReqz/probehost2.git
synced 2024-11-22 06:41:15 +00:00
Compare commits
5 Commits
dcb8ad72e3
...
55dfb5405a
Author | SHA1 | Date | |
---|---|---|---|
|
55dfb5405a | ||
|
0c4db69e08 | ||
|
a62d199c8b | ||
|
fed9b40c86 | ||
|
0eb1a032dc |
12
docker/Dockerfile
Normal file
12
docker/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
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"]
|
11
docker/docker-compose.yml
Normal file
11
docker/docker-compose.yml
Normal file
@ -0,0 +1,11 @@
|
||||
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
23
main.go
@ -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,10 +64,6 @@ 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 {
|
||||
@ -110,10 +106,25 @@ 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("/", showhelp)
|
||||
http.HandleFunc("/tracert/", traceroute)
|
||||
logstdout.Info("Serving on :", listenport)
|
||||
logfile.Info("Serving on :", listenport)
|
||||
http.ListenAndServe(fmt.Sprint(":", listenport), nil)
|
||||
|
16
systemd/probehost2.service
Normal file
16
systemd/probehost2.service
Normal file
@ -0,0 +1,16 @@
|
||||
# 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
|
Loading…
Reference in New Issue
Block a user