signed-commit remote shell (see also https://github.com/dyne/scorsh)
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
737 B
43 lines
737 B
package main
|
|
|
|
import (
|
|
"github.com/fsnotify/fsnotify"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
// parse a request file and return a SCORSHmessage
|
|
func parse_request(fname string) (SCORSHmsg, error) {
|
|
|
|
var ret SCORSHmsg
|
|
_, err := os.Open(fname)
|
|
if err != nil {
|
|
log.Printf("Unable to open file: %s\n", fname)
|
|
return ret, SCORSHErr(SCORSH_ERR_NO_FILE)
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
|
func spooler(watcher *fsnotify.Watcher, worker chan SCORSHmsg) {
|
|
|
|
for {
|
|
select {
|
|
case event := <-watcher.Events:
|
|
if event.Op == fsnotify.Create {
|
|
msg, err := parse_request(event.Name)
|
|
if err != nil {
|
|
log.Printf("Invalid packet received. [%s]\n", err)
|
|
}
|
|
worker <- msg
|
|
}
|
|
case err := <-watcher.Errors:
|
|
log.Println("error:", err)
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|