-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
43 lines (37 loc) · 1013 Bytes
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"net/http"
"os/exec"
"strings"
)
// To processes the command and executes the appropriate action
func executeCommandHelper(command string, w http.ResponseWriter) {
// handel senKey commands | sendKey>ctrl+c or sendKey>enter
if len(command) > 8 && command[:8] == "sendKey>" {
key := command[8:]
key = strings.ReplaceAll(key, " ", "+")
sendKeyPress(key, w)
return
}
// handel openUrl commands | openUrl>chrome://newtab
if len(command) > 8 && command[:8] == "openUrl>" {
key := command[8:]
execCommand(openBrowser(key), w)
return
}
// handel openUrl commands | openUrl>chrome://newtab
if len(command) > 8 && command[:8] == "mbClick>" {
key := command[8:]
sendMouseClick(key, w)
return
}
// Custom commands
switch command {
case "cmd":
execCommand(exec.Command("cmd", "/C", "start"), w)
case "notepad":
execCommand(exec.Command("C:\\Windows\\system32\\notepad.exe"), w)
default:
http.Error(w, "Unknown command", http.StatusBadRequest)
}
}