| 43 | } |
| 44 | |
| 45 | func (this *ScriptAction) runAction(action string, listType IPListType, item *pb.IPItem) error { |
| 46 | // TODO 智能支持 .sh 脚本文件 |
| 47 | var cmd = executils.NewTimeoutCmd(30*time.Second, this.config.Path) |
| 48 | cmd.WithEnv([]string{ |
| 49 | "ACTION=" + action, |
| 50 | "TYPE=" + item.Type, |
| 51 | "IP_FROM=" + item.IpFrom, |
| 52 | "IP_TO=" + item.IpTo, |
| 53 | "EXPIRED_AT=" + fmt.Sprintf("%d", item.ExpiredAt), |
| 54 | "LIST_TYPE=" + listType, |
| 55 | }) |
| 56 | if len(this.config.Cwd) > 0 { |
| 57 | cmd.WithDir(this.config.Cwd) |
| 58 | } else { |
| 59 | cmd.WithDir(filepath.Dir(this.config.Path)) |
| 60 | } |
| 61 | cmd.WithStderr() |
| 62 | err := cmd.Run() |
| 63 | if err != nil { |
| 64 | return fmt.Errorf("%w, output: %s", err, cmd.Stderr()) |
| 65 | } |
| 66 | return nil |
| 67 | } |