Browse Source

Initial commit

master
root 6 months ago
commit
d5c18cfc3e
  1. 5
      .gitignore
  2. 5
      go.mod
  3. 49
      main.go

5
.gitignore

@ -0,0 +1,5 @@
users/*
root
finger
*.exe
*.sum

5
go.mod

@ -0,0 +1,5 @@
module finger
go 1.16
require github.com/mitchellh/go-finger v0.0.0-20170709001451-be12f0ff8b97 // indirect

49
main.go

@ -0,0 +1,49 @@
package main
import "github.com/mitchellh/go-finger"
import (
"fmt"
"bufio"
"os"
"io/ioutil"
"io"
"context"
)
func main() {
go finger.Serve(finger.HandlerFunc(func(ctx context.Context, w io.Writer, q *finger.Query) {
text := ""
filename := ""
if q.Username == "" {
filename = "root"
} else {
filename = q.Username
}
file, err := os.Open(filename)
if err != nil {
text = "ERR: No such user!"
}
defer func() {
if err = file.Close(); err != nil {
}
}()
if err == nil {
b, err := ioutil.ReadAll(file)
if err != nil {
text = "ERR: No such user!"
} else {
text = "MSG: " + string(b)
}
}
w.Write([]byte(fmt.Sprintln(text)))
}))
fmt.Print("Press 'Enter' to exit...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
}
Loading…
Cancel
Save