|
7 | 7 | "net"
|
8 | 8 | "os"
|
9 | 9 | "os/exec"
|
| 10 | + "regexp" |
10 | 11 | "runtime"
|
11 | 12 | "strconv"
|
12 | 13 | "strings"
|
@@ -47,25 +48,26 @@ func (au authUsers) isAllow(user, pass string) bool {
|
47 | 48 |
|
48 | 49 | // Config - config struct
|
49 | 50 | type Config struct {
|
50 |
| - port int // server port |
51 |
| - cache int // caching command out (in seconds) |
52 |
| - timeout int // timeout for shell command (in seconds) |
53 |
| - host string // server host |
54 |
| - exportVars string // list of environment vars for export to script |
55 |
| - shell string // custom shell |
56 |
| - defaultShell string // shell by default |
57 |
| - defaultShOpt string // shell option for one-liner (-c or /C) |
58 |
| - cert string // SSL certificate |
59 |
| - key string // SSL private key path |
60 |
| - auth authUsers // basic authentication |
61 |
| - exportAllVars bool // export all current environment vars |
62 |
| - setCGI bool // set CGI variables |
63 |
| - setForm bool // parse form from URL |
64 |
| - noIndex bool // don't generate index page |
65 |
| - addExit bool // add /exit command |
66 |
| - oneThread bool // run each shell commands in one thread |
67 |
| - showErrors bool // returns the standard output even if the command exits with a non-zero exit code |
68 |
| - includeStderr bool // also returns output written to stderr (default is stdout only) |
| 51 | + port int // server port |
| 52 | + cache int // caching command out (in seconds) |
| 53 | + timeout int // timeout for shell command (in seconds) |
| 54 | + host string // server host |
| 55 | + exportVars string // list of environment vars for export to script |
| 56 | + shell string // custom shell |
| 57 | + defaultShell string // shell by default |
| 58 | + defaultShOpt string // shell option for one-liner (-c or /C) |
| 59 | + cert string // SSL certificate |
| 60 | + key string // SSL private key path |
| 61 | + auth authUsers // basic authentication |
| 62 | + exportAllVars bool // export all current environment vars |
| 63 | + setCGI bool // set CGI variables |
| 64 | + setForm bool // parse form from URL |
| 65 | + noIndex bool // don't generate index page |
| 66 | + addExit bool // add /exit command |
| 67 | + oneThread bool // run each shell commands in one thread |
| 68 | + showErrors bool // returns the standard output even if the command exits with a non-zero exit code |
| 69 | + includeStderr bool // also returns output written to stderr (default is stdout only) |
| 70 | + formCheckRe *regexp.Regexp // regexp for check form fields |
69 | 71 | }
|
70 | 72 |
|
71 | 73 | // getConfig - parse arguments
|
@@ -105,6 +107,8 @@ func getConfig() (*Config, error) {
|
105 | 107 | flag.Var(&cfg.auth, "basic-auth", "setup HTTP Basic Authentication (\"user_name:password\"), can be used several times")
|
106 | 108 | flag.IntVar(&cfg.timeout, "timeout", 0, "set `timeout` for execute shell command (in seconds)")
|
107 | 109 |
|
| 110 | + formCheck := flag.String("form-check", "", "regexp for check form fields (pass only vars that match the regexp)") |
| 111 | + |
108 | 112 | flag.Usage = func() {
|
109 | 113 | fmt.Printf("usage: %s [options] /path \"shell command\" /path2 \"shell command2\"\n", os.Args[0])
|
110 | 114 | flag.PrintDefaults()
|
@@ -149,6 +153,14 @@ func getConfig() (*Config, error) {
|
149 | 153 | }
|
150 | 154 | }
|
151 | 155 |
|
| 156 | + if formCheck != nil && len(*formCheck) > 0 { |
| 157 | + re, err := regexp.Compile(*formCheck) |
| 158 | + if err != nil { |
| 159 | + return nil, fmt.Errorf("an error has occurred while compiling regexp %s: %s", *formCheck, err) |
| 160 | + } |
| 161 | + cfg.formCheckRe = re |
| 162 | + } |
| 163 | + |
152 | 164 | return &cfg, nil
|
153 | 165 | }
|
154 | 166 |
|
|
0 commit comments