summaryrefslogtreecommitdiff
path: root/plugins/server/command.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-09 02:31:33 +0300
committerValery Piashchynski <[email protected]>2021-06-09 02:31:33 +0300
commit6103228ee951c7c8bf5d425471b7c440980c6044 (patch)
tree698c28d3af1814f49958455a6c518ed62032830f /plugins/server/command.go
parent4f3e16892479db4bd8280a46987f3105e46e5c96 (diff)
- Update CI (add new tests)
- Add path scan with regex (find .php/.ph/.sh scripts). When found, try to stat path for potential fix for the [file not exists problem] Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/server/command.go')
-rw-r--r--plugins/server/command.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/plugins/server/command.go b/plugins/server/command.go
new file mode 100644
index 00000000..527cc224
--- /dev/null
+++ b/plugins/server/command.go
@@ -0,0 +1,33 @@
+package server
+
+import (
+ "os"
+ "regexp"
+
+ "github.com/spiral/errors"
+)
+
+// pattern for the path finding
+const pattern string = `^\/*([A-z0-9/.:-]+\.(php|sh|ph))$`
+
+func (server *Plugin) scanCommand(cmd []string) error {
+ const op = errors.Op("server_command_scan")
+ r, err := regexp.Compile(pattern)
+ if err != nil {
+ return err
+ }
+
+ for i := 0; i < len(cmd); i++ {
+ if r.MatchString(cmd[i]) {
+ // try to stat
+ _, err := os.Stat(cmd[i])
+ if err != nil {
+ return errors.E(op, err)
+ }
+
+ // stat successful
+ return nil
+ }
+ }
+ return errors.E(errors.Str("scan failed, possible path not found"), op)
+}