mirror of
https://github.com/m1k1o/neko.git
synced 2025-05-24 14:37:05 +02:00
http endpoints for transferring files
This commit is contained in:
parent
fa45619dbb
commit
1505abb703
4 changed files with 147 additions and 0 deletions
|
@ -3,6 +3,7 @@ package websocket
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
@ -33,6 +34,14 @@ func New(sessions types.SessionManager, desktop types.DesktopManager, capture ty
|
|||
logger.Info().Msgf("control locked on behalf of control protection")
|
||||
}
|
||||
|
||||
if conf.FileTransferPath[len(conf.FileTransferPath)-1] != '/' {
|
||||
conf.FileTransferPath += "/"
|
||||
}
|
||||
err := os.Mkdir(conf.FileTransferPath, 0755)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
logger.Panic().Err(err).Msg("unable to create file transfer directory")
|
||||
}
|
||||
|
||||
// apply default locks
|
||||
for _, lock := range conf.Locks {
|
||||
state.Lock(lock, "") // empty session ID
|
||||
|
@ -314,6 +323,22 @@ func (ws *WebSocketHandler) IsAdmin(password string) (bool, error) {
|
|||
return false, fmt.Errorf("invalid password")
|
||||
}
|
||||
|
||||
func (ws *WebSocketHandler) CanTransferFiles(password string) (bool, error) {
|
||||
if !ws.conf.FileTransfer {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if !ws.conf.UnprivFileTransfer {
|
||||
return ws.IsAdmin(password)
|
||||
}
|
||||
|
||||
return password == ws.conf.Password, nil
|
||||
}
|
||||
|
||||
func (ws *WebSocketHandler) MakeFilePath(filename string) string {
|
||||
return fmt.Sprintf("%s%s", ws.conf.FileTransferPath, filename)
|
||||
}
|
||||
|
||||
func (ws *WebSocketHandler) authenticate(r *http.Request) (bool, error) {
|
||||
passwords, ok := r.URL.Query()["password"]
|
||||
if !ok || len(passwords[0]) < 1 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue