2019-04-07 23:28:01 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-09-09 00:40:06 +00:00
|
|
|
"encoding/json"
|
2019-09-28 20:01:04 +00:00
|
|
|
"fmt"
|
2019-09-25 04:21:59 +00:00
|
|
|
"github.com/gbrlsnchs/jwt/v3"
|
2019-09-28 20:01:04 +00:00
|
|
|
"github.com/google/uuid"
|
2019-04-20 21:57:37 +00:00
|
|
|
"github.com/gorilla/websocket"
|
2019-04-20 06:29:52 +00:00
|
|
|
"github.com/julienschmidt/httprouter"
|
2019-11-17 01:01:38 +00:00
|
|
|
"github.com/pkg/errors"
|
2019-09-09 00:40:06 +00:00
|
|
|
"github.com/pterodactyl/wings/config"
|
2019-04-20 21:57:37 +00:00
|
|
|
"github.com/pterodactyl/wings/server"
|
2019-04-07 23:28:01 +00:00
|
|
|
"go.uber.org/zap"
|
2019-04-20 06:29:52 +00:00
|
|
|
"net/http"
|
2019-04-20 21:57:37 +00:00
|
|
|
"os"
|
2019-04-20 18:59:28 +00:00
|
|
|
"strings"
|
2019-04-21 00:38:12 +00:00
|
|
|
"sync"
|
2019-09-25 04:21:59 +00:00
|
|
|
"time"
|
2019-04-07 23:28:01 +00:00
|
|
|
)
|
|
|
|
|
2019-04-21 19:02:28 +00:00
|
|
|
const (
|
2019-12-22 01:31:21 +00:00
|
|
|
AuthenticationSuccessEvent = "auth success"
|
|
|
|
TokenExpiringEvent = "token expiring"
|
|
|
|
TokenExpiredEvent = "token expired"
|
|
|
|
AuthenticationEvent = "auth"
|
|
|
|
SetStateEvent = "set state"
|
|
|
|
SendServerLogsEvent = "send logs"
|
|
|
|
SendCommandEvent = "send command"
|
|
|
|
ErrorEvent = "daemon error"
|
2019-04-21 19:02:28 +00:00
|
|
|
)
|
|
|
|
|
2019-04-20 06:29:52 +00:00
|
|
|
type WebsocketMessage struct {
|
2019-04-20 18:59:28 +00:00
|
|
|
// The event to perform. Should be one of the following that are supported:
|
2019-04-20 06:29:52 +00:00
|
|
|
//
|
|
|
|
// - status : Returns the server's power state.
|
|
|
|
// - logs : Returns the server log data at the time of the request.
|
|
|
|
// - power : Performs a power action aganist the server based the data.
|
|
|
|
// - command : Performs a command on a server using the data field.
|
2019-04-20 18:59:28 +00:00
|
|
|
Event string `json:"event"`
|
2019-04-07 23:28:01 +00:00
|
|
|
|
2019-04-20 06:29:52 +00:00
|
|
|
// The data to pass along, only used by power/command currently. Other requests
|
2019-04-20 18:59:28 +00:00
|
|
|
// should either omit the field or pass an empty value as it is ignored.
|
|
|
|
Args []string `json:"args,omitempty"`
|
2019-04-20 21:57:37 +00:00
|
|
|
|
2019-09-25 04:21:59 +00:00
|
|
|
// Is set to true when the request is originating from outside of the Daemon,
|
|
|
|
// otherwise set to false for outbound.
|
2019-04-20 21:57:37 +00:00
|
|
|
inbound bool
|
2019-04-20 06:29:52 +00:00
|
|
|
}
|
|
|
|
|
2019-04-21 00:38:12 +00:00
|
|
|
type WebsocketHandler struct {
|
|
|
|
Server *server.Server
|
|
|
|
Mutex sync.Mutex
|
|
|
|
Connection *websocket.Conn
|
2019-09-25 04:21:59 +00:00
|
|
|
JWT *WebsocketTokenPayload
|
2019-04-21 00:38:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 04:21:59 +00:00
|
|
|
type WebsocketTokenPayload struct {
|
|
|
|
jwt.Payload
|
|
|
|
UserID json.Number `json:"user_id"`
|
|
|
|
ServerUUID string `json:"server_uuid"`
|
|
|
|
Permissions []string `json:"permissions"`
|
2019-09-09 00:40:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 04:21:59 +00:00
|
|
|
const (
|
2020-01-18 21:05:44 +00:00
|
|
|
PermissionConnect = "connect"
|
|
|
|
PermissionSendCommand = "send-command"
|
|
|
|
PermissionSendPower = "send-power"
|
|
|
|
PermissionReceiveErrors = "receive-errors"
|
|
|
|
PermissionReceiveInstall = "receive-install"
|
2019-09-25 04:21:59 +00:00
|
|
|
)
|
2019-09-09 00:40:06 +00:00
|
|
|
|
2019-09-25 04:21:59 +00:00
|
|
|
// Checks if the given token payload has a permission string.
|
|
|
|
func (wtp *WebsocketTokenPayload) HasPermission(permission string) bool {
|
|
|
|
for _, k := range wtp.Permissions {
|
|
|
|
if k == permission {
|
|
|
|
return true
|
2019-09-09 00:40:06 +00:00
|
|
|
}
|
2019-09-25 04:21:59 +00:00
|
|
|
}
|
2019-09-09 00:40:06 +00:00
|
|
|
|
2019-09-25 04:21:59 +00:00
|
|
|
return false
|
|
|
|
}
|
2019-09-09 00:40:06 +00:00
|
|
|
|
2019-09-25 04:21:59 +00:00
|
|
|
var alg *jwt.HMACSHA
|
|
|
|
|
|
|
|
// Validates the provided JWT against the known secret for the Daemon and returns the
|
|
|
|
// parsed data.
|
|
|
|
//
|
|
|
|
// This function DOES NOT validate that the token is valid for the connected server, nor
|
|
|
|
// does it ensure that the user providing the token is able to actually do things.
|
|
|
|
func ParseJWT(token []byte) (*WebsocketTokenPayload, error) {
|
|
|
|
var payload WebsocketTokenPayload
|
|
|
|
if alg == nil {
|
|
|
|
alg = jwt.NewHS256([]byte(config.Get().AuthenticationToken))
|
|
|
|
}
|
2019-09-09 00:40:06 +00:00
|
|
|
|
2019-12-28 20:27:21 +00:00
|
|
|
now := time.Now()
|
|
|
|
verifyOptions := jwt.ValidatePayload(
|
|
|
|
&payload.Payload,
|
|
|
|
jwt.ExpirationTimeValidator(now),
|
|
|
|
)
|
|
|
|
|
|
|
|
_, err := jwt.Verify(token, alg, &payload, verifyOptions)
|
2019-09-25 04:21:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-09-09 00:40:06 +00:00
|
|
|
|
2019-09-25 04:21:59 +00:00
|
|
|
if !payload.HasPermission(PermissionConnect) {
|
|
|
|
return nil, errors.New("not authorized to connect to this socket")
|
|
|
|
}
|
|
|
|
|
|
|
|
return &payload, nil
|
|
|
|
}
|
2019-09-09 00:40:06 +00:00
|
|
|
|
2019-09-25 04:21:59 +00:00
|
|
|
// Checks if the JWT is still valid.
|
|
|
|
func (wsh *WebsocketHandler) TokenValid() error {
|
|
|
|
if wsh.JWT == nil {
|
|
|
|
return errors.New("no jwt present")
|
2019-09-09 00:40:06 +00:00
|
|
|
}
|
2019-09-25 04:21:59 +00:00
|
|
|
|
2019-12-28 20:27:21 +00:00
|
|
|
if err := jwt.ExpirationTimeValidator(time.Now())(&wsh.JWT.Payload); err != nil {
|
|
|
|
return err
|
2019-09-25 04:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !wsh.JWT.HasPermission(PermissionConnect) {
|
|
|
|
return errors.New("jwt does not have connect permission")
|
|
|
|
}
|
|
|
|
|
|
|
|
if wsh.Server.Uuid != wsh.JWT.ServerUUID {
|
|
|
|
return errors.New("jwt server uuid mismatch")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2019-09-09 00:40:06 +00:00
|
|
|
}
|
|
|
|
|
2019-04-21 00:38:12 +00:00
|
|
|
// Handle a request for a specific server websocket. This will handle inbound requests as well
|
|
|
|
// as ensure that any console output is also passed down the wire on the socket.
|
2019-04-20 06:29:52 +00:00
|
|
|
func (rt *Router) routeWebsocket(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
c, err := rt.upgrader.Upgrade(w, r, nil)
|
2019-04-07 23:28:01 +00:00
|
|
|
if err != nil {
|
2019-12-22 01:31:21 +00:00
|
|
|
zap.S().Errorw("error upgrading websocket", zap.Error(errors.WithStack(err)))
|
|
|
|
http.Error(w, "failed to upgrade websocket", http.StatusInternalServerError)
|
|
|
|
|
2019-04-20 06:29:52 +00:00
|
|
|
return
|
2019-04-07 23:28:01 +00:00
|
|
|
}
|
2019-09-25 05:05:34 +00:00
|
|
|
|
|
|
|
// Make a ticker and completion channel that is used to continuously poll the
|
|
|
|
// JWT stored in the session to send events to the socket when it is expiring.
|
|
|
|
ticker := time.NewTicker(time.Second * 30)
|
|
|
|
done := make(chan bool)
|
|
|
|
|
|
|
|
// Whenever this function is complete, end the ticker, close out the channel,
|
|
|
|
// and then close the websocket connection.
|
|
|
|
defer func() {
|
|
|
|
ticker.Stop()
|
|
|
|
done <- true
|
|
|
|
c.Close()
|
|
|
|
}()
|
2019-04-20 06:29:52 +00:00
|
|
|
|
2019-12-08 00:43:00 +00:00
|
|
|
s := rt.GetServer(ps.ByName("server"))
|
2019-04-21 00:38:12 +00:00
|
|
|
handler := WebsocketHandler{
|
2019-04-21 19:02:28 +00:00
|
|
|
Server: s,
|
|
|
|
Mutex: sync.Mutex{},
|
2019-04-21 00:38:12 +00:00
|
|
|
Connection: c,
|
2019-12-22 01:31:21 +00:00
|
|
|
JWT: nil,
|
2019-04-21 00:38:12 +00:00
|
|
|
}
|
|
|
|
|
2020-01-18 21:05:44 +00:00
|
|
|
events := []string{
|
|
|
|
server.StatsEvent,
|
|
|
|
server.StatusEvent,
|
|
|
|
server.ConsoleOutputEvent,
|
|
|
|
server.InstallOutputEvent,
|
|
|
|
server.DaemonMessageEvent,
|
2019-04-21 19:02:28 +00:00
|
|
|
}
|
|
|
|
|
2020-01-18 22:04:26 +00:00
|
|
|
eventChannel := make(chan server.Event)
|
2020-01-18 21:05:44 +00:00
|
|
|
for _, event := range events {
|
2020-01-18 22:04:26 +00:00
|
|
|
s.Events().Subscribe(event, eventChannel)
|
2019-09-06 05:08:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-18 21:05:44 +00:00
|
|
|
defer func() {
|
2020-01-18 22:04:26 +00:00
|
|
|
for _, event := range events {
|
|
|
|
s.Events().Unsubscribe(event, eventChannel)
|
|
|
|
}
|
|
|
|
|
|
|
|
close(eventChannel)
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Listen for different events emitted by the server and respond to them appropriately.
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case d := <-eventChannel:
|
|
|
|
handler.SendJson(&WebsocketMessage{
|
|
|
|
Event: d.Topic,
|
|
|
|
Args: []string{d.Data},
|
|
|
|
})
|
|
|
|
}
|
2020-01-18 21:05:44 +00:00
|
|
|
}
|
|
|
|
}()
|
2019-09-06 05:08:10 +00:00
|
|
|
|
2019-09-25 05:05:34 +00:00
|
|
|
// Sit here and check the time to expiration on the JWT every 30 seconds until
|
|
|
|
// the token has expired. If we are within 3 minutes of the token expiring, send
|
|
|
|
// a notice over the socket that it is expiring soon. If it has expired, send that
|
|
|
|
// notice as well.
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
return
|
|
|
|
case <-ticker.C:
|
|
|
|
{
|
|
|
|
if handler.JWT != nil {
|
|
|
|
if handler.JWT.ExpirationTime.Unix()-time.Now().Unix() <= 0 {
|
|
|
|
handler.SendJson(&WebsocketMessage{Event: TokenExpiredEvent})
|
|
|
|
} else if handler.JWT.ExpirationTime.Unix()-time.Now().Unix() <= 180 {
|
|
|
|
handler.SendJson(&WebsocketMessage{Event: TokenExpiringEvent})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2019-04-20 06:29:52 +00:00
|
|
|
for {
|
2019-04-21 00:38:12 +00:00
|
|
|
j := WebsocketMessage{inbound: true}
|
2019-04-07 23:28:01 +00:00
|
|
|
|
2019-09-09 01:03:39 +00:00
|
|
|
_, p, err := c.ReadMessage()
|
|
|
|
if err != nil {
|
2019-09-23 03:47:38 +00:00
|
|
|
if !websocket.IsCloseError(
|
|
|
|
err,
|
|
|
|
websocket.CloseNormalClosure,
|
|
|
|
websocket.CloseGoingAway,
|
|
|
|
websocket.CloseNoStatusReceived,
|
|
|
|
websocket.CloseServiceRestart,
|
|
|
|
websocket.CloseAbnormalClosure,
|
|
|
|
) {
|
2019-04-20 22:45:48 +00:00
|
|
|
zap.S().Errorw("error handling websocket message", zap.Error(err))
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2019-04-20 06:29:52 +00:00
|
|
|
// Discard and JSON parse errors into the void and don't continue processing this
|
|
|
|
// specific socket request. If we did a break here the client would get disconnected
|
|
|
|
// from the socket, which is NOT what we want to do.
|
2019-09-09 01:03:39 +00:00
|
|
|
if err := json.Unmarshal(p, &j); err != nil {
|
2019-04-20 22:45:48 +00:00
|
|
|
continue
|
2019-04-20 06:29:52 +00:00
|
|
|
}
|
2019-04-07 23:28:01 +00:00
|
|
|
|
2019-04-21 00:38:12 +00:00
|
|
|
if err := handler.HandleInbound(j); err != nil {
|
2019-09-28 20:01:04 +00:00
|
|
|
handler.SendErrorJson(err)
|
2019-04-20 06:29:52 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-21 00:38:12 +00:00
|
|
|
}
|
2019-04-20 21:57:37 +00:00
|
|
|
|
2019-04-21 00:38:12 +00:00
|
|
|
// Perform a blocking send operation on the websocket since we want to avoid any
|
|
|
|
// concurrent writes to the connection, which would cause a runtime panic and cause
|
|
|
|
// the program to crash out.
|
2020-01-18 21:05:44 +00:00
|
|
|
func (wsh *WebsocketHandler) SendJson(v *WebsocketMessage) error {
|
2019-12-22 01:31:21 +00:00
|
|
|
// Do not send JSON down the line if the JWT on the connection is not
|
|
|
|
// valid!
|
|
|
|
if err := wsh.TokenValid(); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-18 21:05:44 +00:00
|
|
|
// If we're sending installation output but the user does not have the required
|
|
|
|
// permissions to see the output, don't send it down the line.
|
|
|
|
if v.Event == server.InstallOutputEvent {
|
|
|
|
zap.S().Debugf("%+v", v.Args)
|
|
|
|
if wsh.JWT != nil && !wsh.JWT.HasPermission(PermissionReceiveInstall) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:31:21 +00:00
|
|
|
return wsh.unsafeSendJson(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sends JSON over the websocket connection, ignoring the authentication state of the
|
|
|
|
// socket user. Do not call this directly unless you are positive a response should be
|
|
|
|
// sent back to the client!
|
|
|
|
func (wsh *WebsocketHandler) unsafeSendJson(v interface{}) error {
|
2019-04-21 00:38:12 +00:00
|
|
|
wsh.Mutex.Lock()
|
|
|
|
defer wsh.Mutex.Unlock()
|
|
|
|
|
|
|
|
return wsh.Connection.WriteJSON(v)
|
2019-04-20 06:29:52 +00:00
|
|
|
}
|
2019-04-20 21:57:37 +00:00
|
|
|
|
2019-09-28 20:01:04 +00:00
|
|
|
// Sends an error back to the connected websocket instance by checking the permissions
|
|
|
|
// of the token. If the user has the "receive-errors" grant we will send back the actual
|
|
|
|
// error message, otherwise we just send back a standard error message.
|
|
|
|
func (wsh *WebsocketHandler) SendErrorJson(err error) error {
|
|
|
|
wsh.Mutex.Lock()
|
|
|
|
defer wsh.Mutex.Unlock()
|
|
|
|
|
2019-11-17 00:07:42 +00:00
|
|
|
message := "an unexpected error was encountered while handling this request"
|
2019-11-30 23:19:08 +00:00
|
|
|
if wsh.JWT != nil {
|
|
|
|
if server.IsSuspendedError(err) || wsh.JWT.HasPermission(PermissionReceiveErrors) {
|
|
|
|
message = err.Error()
|
|
|
|
}
|
2019-09-28 20:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m, u := wsh.GetErrorMessage(message)
|
|
|
|
|
|
|
|
wsm := WebsocketMessage{Event: ErrorEvent}
|
|
|
|
wsm.Args = []string{m}
|
|
|
|
|
2019-12-01 00:36:20 +00:00
|
|
|
if !server.IsSuspendedError(err) {
|
|
|
|
zap.S().Errorw(
|
|
|
|
"an error was encountered in the websocket process",
|
|
|
|
zap.String("server", wsh.Server.Uuid),
|
|
|
|
zap.String("error_identifier", u.String()),
|
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
}
|
2019-09-28 20:01:04 +00:00
|
|
|
|
|
|
|
return wsh.Connection.WriteJSON(wsm)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Converts an error message into a more readable representation and returns a UUID
|
|
|
|
// that can be cross-referenced to find the specific error that triggered.
|
|
|
|
func (wsh *WebsocketHandler) GetErrorMessage(msg string) (string, uuid.UUID) {
|
|
|
|
u, _ := uuid.NewRandom()
|
|
|
|
|
|
|
|
m := fmt.Sprintf("Error Event [%s]: %s", u.String(), msg)
|
|
|
|
|
|
|
|
return m, u
|
|
|
|
}
|
|
|
|
|
2019-04-21 00:38:12 +00:00
|
|
|
// Handle the inbound socket request and route it to the proper server action.
|
|
|
|
func (wsh *WebsocketHandler) HandleInbound(m WebsocketMessage) error {
|
|
|
|
if !m.inbound {
|
2019-04-20 21:57:37 +00:00
|
|
|
return errors.New("cannot handle websocket message, not an inbound connection")
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:31:21 +00:00
|
|
|
if m.Event != AuthenticationEvent {
|
|
|
|
if err := wsh.TokenValid(); err != nil {
|
|
|
|
zap.S().Debugw("jwt token is no longer valid", zap.String("message", err.Error()))
|
2019-09-25 04:21:59 +00:00
|
|
|
|
2019-12-22 01:31:21 +00:00
|
|
|
wsh.unsafeSendJson(WebsocketMessage{
|
|
|
|
Event: ErrorEvent,
|
|
|
|
Args: []string{"could not authenticate client: " + err.Error()},
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2019-09-25 04:21:59 +00:00
|
|
|
}
|
|
|
|
|
2019-04-21 00:38:12 +00:00
|
|
|
switch m.Event {
|
2019-09-28 20:01:04 +00:00
|
|
|
case AuthenticationEvent:
|
|
|
|
{
|
|
|
|
token, err := ParseJWT([]byte(strings.Join(m.Args, "")))
|
|
|
|
if err != nil {
|
2019-12-22 01:31:21 +00:00
|
|
|
return err
|
2019-09-28 20:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if token.HasPermission(PermissionConnect) {
|
|
|
|
wsh.JWT = token
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:31:21 +00:00
|
|
|
// On every authentication event, send the current server status back
|
|
|
|
// to the client. :)
|
2020-01-18 22:04:26 +00:00
|
|
|
wsh.Server.Events().Publish(server.StatusEvent, wsh.Server.State)
|
2019-12-22 01:31:21 +00:00
|
|
|
|
|
|
|
wsh.unsafeSendJson(WebsocketMessage{
|
|
|
|
Event: AuthenticationSuccessEvent,
|
|
|
|
Args: []string{},
|
|
|
|
})
|
|
|
|
|
2019-09-28 20:01:04 +00:00
|
|
|
return nil
|
|
|
|
}
|
2019-04-21 19:02:28 +00:00
|
|
|
case SetStateEvent:
|
2019-04-20 21:57:37 +00:00
|
|
|
{
|
2019-09-25 04:21:59 +00:00
|
|
|
if !wsh.JWT.HasPermission(PermissionSendPower) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-04-21 00:38:12 +00:00
|
|
|
switch strings.Join(m.Args, "") {
|
2019-04-20 21:57:37 +00:00
|
|
|
case "start":
|
2019-11-17 00:07:42 +00:00
|
|
|
return wsh.Server.Environment.Start()
|
2019-04-20 21:57:37 +00:00
|
|
|
case "stop":
|
2019-11-17 00:07:42 +00:00
|
|
|
return wsh.Server.Environment.Stop()
|
2019-04-20 21:57:37 +00:00
|
|
|
case "restart":
|
2019-11-17 00:07:42 +00:00
|
|
|
return nil
|
2019-04-21 19:27:53 +00:00
|
|
|
case "kill":
|
2019-11-17 00:07:42 +00:00
|
|
|
return wsh.Server.Environment.Terminate(os.Kill)
|
2019-04-20 21:57:37 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 00:07:42 +00:00
|
|
|
return nil
|
2019-04-20 21:57:37 +00:00
|
|
|
}
|
2019-04-21 19:02:28 +00:00
|
|
|
case SendServerLogsEvent:
|
2019-04-20 21:57:37 +00:00
|
|
|
{
|
2019-09-06 06:05:47 +00:00
|
|
|
if running, _ := wsh.Server.Environment.IsRunning(); !running {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-28 01:03:37 +00:00
|
|
|
logs, err := wsh.Server.Environment.Readlog(1024 * 16)
|
2019-04-20 21:57:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, line := range logs {
|
2019-04-21 00:38:12 +00:00
|
|
|
wsh.SendJson(&WebsocketMessage{
|
2019-05-27 23:58:05 +00:00
|
|
|
Event: server.ConsoleOutputEvent,
|
2019-04-21 00:38:12 +00:00
|
|
|
Args: []string{line},
|
2019-04-20 21:57:37 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2019-04-21 19:02:28 +00:00
|
|
|
case SendCommandEvent:
|
2019-04-20 21:57:37 +00:00
|
|
|
{
|
2019-09-25 04:21:59 +00:00
|
|
|
if !wsh.JWT.HasPermission(PermissionSendCommand) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-09-28 20:01:04 +00:00
|
|
|
if wsh.Server.State == server.ProcessOfflineState {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-04-21 00:38:12 +00:00
|
|
|
return wsh.Server.Environment.SendCommand(strings.Join(m.Args, ""))
|
2019-04-20 21:57:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2019-04-21 00:38:12 +00:00
|
|
|
}
|