mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
fix locks.
This commit is contained in:
parent
75ad4cefe6
commit
4adf1d7182
@ -22,8 +22,11 @@ type session struct {
|
|||||||
profile types.MemberProfile
|
profile types.MemberProfile
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
|
||||||
lastHostID string
|
lastHostID string
|
||||||
sessions map[string]*oldTypes.Member
|
lockedControls bool
|
||||||
|
lockedLogins bool
|
||||||
|
lockedFileTransfer bool
|
||||||
|
sessions map[string]*oldTypes.Member
|
||||||
|
|
||||||
connClient *websocket.Conn
|
connClient *websocket.Conn
|
||||||
connBackend *websocket.Conn
|
connBackend *websocket.Conn
|
||||||
@ -60,11 +63,15 @@ func (s *session) apiReq(method, path string, request, response any) error {
|
|||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
||||||
body, _ := io.ReadAll(res.Body)
|
body, _ := io.ReadAll(res.Body)
|
||||||
return fmt.Errorf("unexpected status code: %d, body: %s", res.StatusCode, body)
|
return fmt.Errorf("unexpected status code: %d, body: %s", res.StatusCode, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if res.Body == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return json.NewDecoder(res.Body).Decode(response)
|
return json.NewDecoder(res.Body).Decode(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,8 +242,22 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: No WS equivalent, call HTTP API.
|
data := map[string]any{}
|
||||||
return fmt.Errorf("event not implemented: %s", header.Event)
|
|
||||||
|
switch request.Resource {
|
||||||
|
case "login":
|
||||||
|
data["locked_logins"] = true
|
||||||
|
case "control":
|
||||||
|
data["locked_controls"] = true
|
||||||
|
case "file_transfer":
|
||||||
|
data["plugins"] = map[string]any{
|
||||||
|
"filetransfer.enabled": false,
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown resource: %s", request.Resource)
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.apiReq(http.MethodPost, "/api/room/settings", data, nil)
|
||||||
|
|
||||||
case oldEvent.ADMIN_UNLOCK:
|
case oldEvent.ADMIN_UNLOCK:
|
||||||
request := &oldMessage.AdminLock{}
|
request := &oldMessage.AdminLock{}
|
||||||
@ -252,8 +266,22 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: No WS equivalent, call HTTP API.
|
data := map[string]any{}
|
||||||
return fmt.Errorf("event not implemented: %s", header.Event)
|
|
||||||
|
switch request.Resource {
|
||||||
|
case "login":
|
||||||
|
data["locked_logins"] = false
|
||||||
|
case "control":
|
||||||
|
data["locked_controls"] = false
|
||||||
|
case "file_transfer":
|
||||||
|
data["plugins"] = map[string]any{
|
||||||
|
"filetransfer.enabled": true,
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown resource: %s", request.Resource)
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.apiReq(http.MethodPost, "/api/room/settings", data, nil)
|
||||||
|
|
||||||
case oldEvent.ADMIN_CONTROL:
|
case oldEvent.ADMIN_CONTROL:
|
||||||
return s.apiReq(http.MethodPost, "/api/room/control/take", nil, nil)
|
return s.apiReq(http.MethodPost, "/api/room/control/take", nil, nil)
|
||||||
|
@ -196,12 +196,15 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
locks := map[string]string{}
|
locks := map[string]string{}
|
||||||
if request.Settings.LockedLogins {
|
if request.Settings.LockedLogins {
|
||||||
locks["login"] = "" // TODO: We don't know who locked the login.
|
locks["login"] = "" // TODO: We don't know who locked the login.
|
||||||
|
s.lockedLogins = true
|
||||||
}
|
}
|
||||||
if request.Settings.LockedControls {
|
if request.Settings.LockedControls {
|
||||||
locks["control"] = "" // TODO: We don't know who locked the control.
|
locks["control"] = "" // TODO: We don't know who locked the control.
|
||||||
|
s.lockedControls = true
|
||||||
}
|
}
|
||||||
if !filetransferSettings.Enabled {
|
if !filetransferSettings.Enabled {
|
||||||
locks["filetransfer"] = "" // TODO: We don't know who locked the file transfer.
|
locks["file_transfer"] = "" // TODO: We don't know who locked the file transfer.
|
||||||
|
s.lockedFileTransfer = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.SystemInit{
|
return send(&oldMessage.SystemInit{
|
||||||
@ -540,16 +543,90 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
IsActive: request.IsActive,
|
IsActive: request.IsActive,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Admin Events
|
||||||
|
case event.SYSTEM_SETTINGS:
|
||||||
|
request := &message.SystemSettingsUpdate{}
|
||||||
|
err := json.Unmarshal(data.Payload, request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.lockedControls != request.LockedControls {
|
||||||
|
s.lockedControls = request.LockedControls
|
||||||
|
|
||||||
|
if request.LockedControls {
|
||||||
|
err = send(&oldMessage.AdminLock{
|
||||||
|
Event: oldEvent.ADMIN_LOCK,
|
||||||
|
Resource: "control",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
err = send(&oldMessage.AdminLock{
|
||||||
|
Event: oldEvent.ADMIN_UNLOCK,
|
||||||
|
Resource: "control",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.lockedLogins != request.LockedLogins {
|
||||||
|
s.lockedLogins = request.LockedLogins
|
||||||
|
|
||||||
|
if request.LockedLogins {
|
||||||
|
err = send(&oldMessage.AdminLock{
|
||||||
|
Event: oldEvent.ADMIN_LOCK,
|
||||||
|
Resource: "login",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
err = send(&oldMessage.AdminLock{
|
||||||
|
Event: oldEvent.ADMIN_UNLOCK,
|
||||||
|
Resource: "login",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// FileTransfer
|
||||||
|
//
|
||||||
|
|
||||||
|
filetransferSettings := filetransfer.Settings{
|
||||||
|
Enabled: true, // defaults to true
|
||||||
|
}
|
||||||
|
|
||||||
|
err = request.Settings.Plugins.Unmarshal(filetransfer.PluginName, &filetransferSettings)
|
||||||
|
if err != nil && !errors.Is(err, types.ErrPluginSettingsNotFound) {
|
||||||
|
return fmt.Errorf("unable to unmarshal %s plugin settings from global settings: %w", filetransfer.PluginName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.lockedFileTransfer != !filetransferSettings.Enabled {
|
||||||
|
s.lockedFileTransfer = !filetransferSettings.Enabled
|
||||||
|
|
||||||
|
if !filetransferSettings.Enabled {
|
||||||
|
err = send(&oldMessage.AdminLock{
|
||||||
|
Event: oldEvent.ADMIN_LOCK,
|
||||||
|
Resource: "file_transfer",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
err = send(&oldMessage.AdminLock{
|
||||||
|
Event: oldEvent.ADMIN_UNLOCK,
|
||||||
|
Resource: "file_transfer",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Admin Events
|
|
||||||
case:
|
|
||||||
send(&oldMessage.AdminLock{
|
|
||||||
Event: oldEvent.ADMIN_LOCK,
|
|
||||||
})
|
|
||||||
case:
|
|
||||||
send(&oldMessage.AdminLock{
|
|
||||||
Event: oldEvent.ADMIN_UNLOCK,
|
|
||||||
})
|
|
||||||
case:
|
case:
|
||||||
send(&oldMessage.AdminTarget{
|
send(&oldMessage.AdminTarget{
|
||||||
Event: oldEvent.ADMIN_BAN,
|
Event: oldEvent.ADMIN_BAN,
|
||||||
|
Loading…
Reference in New Issue
Block a user