Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var FileHook = HookComponents{ func(path string, _ tftp.Request) (*HookResult, error) { file, err := os.Open(path) if err != nil { return nil, err } stat, err := file.Stat() if err != nil { return nil, err } return newHookResult(file, nil, int(stat.Size()), nil), nil }, func(s string, _ config.HookExtraArgs) (string, error) { return pathEscape.ReplaceAllLiteralString(s, ""), nil }, }
View Source
var HTTPHook = HookComponents{ func(url string, tftpReq tftp.Request) (*HookResult, error) { client := &http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { if len(via) == 0 { return nil } for key, val := range via[0].Header { if key != "Referer" { req.Header[key] = val } } return nil }, } req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } req.Header.Set("User-Agent", "hooktftp v0.9.1") req.Header.Set("X-Forwarded-For", (*tftpReq.Addr).String()) res, err := client.Do(req) if err != nil { return nil, err } if res.StatusCode != http.StatusOK { res.Body.Close() return nil, fmt.Errorf("Bad response '%v' from %v", res.Status, url) } return newHookResult(res.Body, nil, int(res.ContentLength), nil), nil }, func(s string, extra config.HookExtraArgs) (string, error) { shouldUrlDecode := extra["urldecode"].(bool) if !shouldUrlDecode { return s, nil } unescaped, err := url.PathUnescape(s) if err != nil { return "", err } return unescaped, nil }, }
View Source
var NO_MATCH = regexptransform.NO_MATCH
View Source
var ShellHook = HookComponents{ func(command string, request tftp.Request) (*HookResult, error) { if len(command) == 0 { return nil, errors.New("Empty shell command") } split, err := shlex.Split(command) if err != nil { return nil, err } cmd := exec.Command(split[0], split[1:]...) stdout, err := cmd.StdoutPipe() if err != nil { return nil, err } stderr, err := cmd.StderrPipe() if err != nil { return nil, err } env := os.Environ() env = append(env, fmt.Sprintf("CLIENT_ADDR=%s", (*request.Addr).String())) cmd.Env = env err = cmd.Start() return newHookResult(stdout, stderr, -1, cmd.Wait), err }, func(s string, _ config.HookExtraArgs) (string, error) { return shellEscape.ReplaceAllStringFunc(s, func(s string) string { return "\\" + s }), nil }, }
Functions ¶
This section is empty.
Types ¶
type Hook ¶
type Hook func(path string, request tftp.Request) (*HookResult, error)
func CompileHook ¶
type HookComponents ¶
type HookComponents struct { Execute Hook // contains filtered or unexported fields }
type HookFinalizer ¶
type HookFinalizer func() error
type HookResult ¶
type HookResult struct { Stdout io.ReadCloser Stderr io.ReadCloser Length int Finalize HookFinalizer }
Click to show internal directories.
Click to hide internal directories.