1
0
Fork 0
forked from External/ergo
add HTTP auth
add an ipc command to nuke a user
This commit is contained in:
CEF Server 2024-07-29 03:30:44 +00:00
parent 979188cf2a
commit 13e1315ad9
3 changed files with 34 additions and 1 deletions

View file

@ -5,8 +5,11 @@ package irc
import (
"bufio"
"bytes"
"io"
"net/http"
"os/exec"
"strings"
"syscall"
"time"
)
@ -21,7 +24,27 @@ type scriptResponse struct {
err error
}
func RunHttp(command string, args []string, input []byte, timeout time.Duration) (output []byte, err error) {
client := http.Client{
Timeout: timeout,
}
post, err := client.Post(command, "application/json", bytes.NewBuffer(input))
if err != nil {
return nil, err
}
defer post.Body.Close()
output, err = io.ReadAll(post.Body)
if err != nil {
return nil, err
}
return
}
func RunScript(command string, args []string, input []byte, timeout, killTimeout time.Duration) (output []byte, err error) {
if strings.HasPrefix(command, "http") {
return RunHttp(command, args, input, timeout)
}
cmd := exec.Command(command, args...)
stdin, err := cmd.StdinPipe()
if err != nil {